Bug 255626 - net/samba413: Orphaned files in STAGEDIR
Summary: net/samba413: Orphaned files in STAGEDIR
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: Timur I. Bakeyev
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-05-05 18:09 UTC by Mark Felder
Modified: 2023-10-02 02:42 UTC (History)
5 users (show)

See Also:
bugzilla: maintainer-feedback? (timur)


Attachments
remove empty files (512 bytes, patch)
2021-05-05 18:10 UTC, Mark Felder
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Felder freebsd_committer freebsd_triage 2021-05-05 18:09:33 UTC
===> Checking for items in STAGEDIR missing from pkg-plist
Error: Orphaned: bin/ecp.QnDgKzC3
Error: Orphaned: bin/ecp.RwhbsIDr
Error: Orphaned: bin/ecp.zkCfXZGw
Error: Orphaned: sbin/ecp.13yuHIqY
Error: Orphaned: sbin/ecp.Q31ZkEo6
Error: Orphaned: sbin/ecp.RQ651qO3
Error: Orphaned: sbin/ecp.iRqOwgUD
Error: Orphaned: sbin/ecp.uuZYIUTL
Error: Orphaned: sbin/ecp.xsOn7p5F


I've looked everywhere trying to figure out how these empty files are being created, but coming up empty handed. Very very strange.
Comment 1 Mark Felder freebsd_committer freebsd_triage 2021-05-05 18:10:10 UTC
Created attachment 224699 [details]
remove empty files
Comment 2 Timur I. Bakeyev freebsd_committer freebsd_triage 2021-05-05 22:38:38 UTC
Thanks, Mark, your fix, seems, pretty trivial to apply :)

I was trying to translate to `make` this shell construction:

```
find /usr/local/bin /usr/local/sbin /usr/local/libexec -type f -print0 | \
        ${XARGS} -0 -I % -S 1024 -n 1 ${SH} -c "case \"\`${FILE} --brief --mime-type '%'\`\" in 'application/'*) ${ECHO_CMD} '%' && ${STRIP_CMD} '%';; esac" STRIP
```

But got lost in additional escapes...

As Dmitry pointed me privately before all the problem exposes itself in FreeBSD 13 environment due clash of two issues:

1. `strip` creates temporary file before it actually starts the processing of the file and, in case it is not strippable(shell script, for example) just leave this temporary file around, without proper cleanup.

2. Before 13 it used to create that temporary file in /tmp, which was excluded from poudriere monitoring, but now the file is created in the same directory where original file is, hence leaving those orphaned temporary files around.


I guess it's worth a separate PR against the bin*, really.
Comment 3 Michael Osipov 2023-09-06 14:38:11 UTC
Here is the problem:

osipovmi@deblndw011x:/var/tmp/freebsd-src (stable/13 =)
$ git diff origin/stable/12..HEAD -- ./contrib/elftoolchain/elfcopy/main.c

commit 96e101bec9808987537af6e529a3ef4f1da9cb83
Author: Chris Rees <crees@FreeBSD.org>
Date:   2021-02-15 12:37:06 +0100

    elftoolchain: stop leaving tempfiles on error

    Temporary files were not cleaned up, resulting in $TMPDIR or even
    the current directory becoming littered with ecp.* files.

    This happened with error and even sometimes on success!

    Approved by:            dim
    MFC after:              4 weeks
    Accepted upstream:      https://sourceforge.net/p/elftoolchain/code/3918/
    Differential Revision:  https://reviews.freebsd.org/D28651

    (cherry picked from commit 5ac70383c8b32eeec80426e837960977971c7c2b)

has neven been cherry-picked from stable/13 to stable/12, thus https://reviews.freebsd.org/D28651 does not perform any cleanup.

Though the cherry-pick produces a conflict, it can be easily resolved:
osipovmi@deblndw011x:/var/tmp/freebsd-src (stable/12 *+=|CHERRY-PICKING)
$ git diff
diff --cc contrib/elftoolchain/elfcopy/main.c
index 995f031dfa69,964d3358de60..000000000000
--- a/contrib/elftoolchain/elfcopy/main.c
+++ b/contrib/elftoolchain/elfcopy/main.c
@@@ -702,8 -737,7 +737,12 @@@ create_file(struct elfcopy *ecp, const
     }

     if ((ecp->ein = elf_begin(ifd, ELF_C_READ, NULL)) == NULL) {
++<<<<<<< HEAD
 +       if (fstat(ifd, &sb) == 0 && sb.st_size == 0)
 +           errx(EXIT_FAILURE, "file format not recognized");
++=======
+        cleanup_tempfile(tempfile);
++>>>>>>> 96e101bec980 (elftoolchain: stop leaving tempfiles on error)
         errx(EXIT_FAILURE, "elf_begin() failed: %s",
             elf_errmsg(-1));
     }
Comment 4 Dimitry Andric freebsd_committer freebsd_triage 2023-09-06 15:04:33 UTC
(In reply to Michael Osipov from comment #3)
https://cgit.freebsd.org/src/commit/?id=a42a905c2afc90012996a4f361d0360056db11b7
Comment 5 Michael Osipov 2023-09-06 15:06:44 UTC
(In reply to Dimitry Andric from comment #4)

Magic, thank you. I will retest!
Comment 6 Michael Osipov 2023-09-06 17:49:40 UTC
Works on 12-STABLE!
Comment 7 Joseph Mingrone freebsd_committer freebsd_triage 2023-10-01 16:45:13 UTC
The attached patch doesn't fix the plist errors on 12.4 because it's trying to remove the temp files before they are created.

Here is a workaround for the plist errors. https://reviews.freebsd.org/D42030
Comment 8 commit-hook freebsd_committer freebsd_triage 2023-10-01 19:53:36 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=93a83389164030ca740440499ac8486d7fb78261

commit 93a83389164030ca740440499ac8486d7fb78261
Author:     Joseph Mingrone <jrm@FreeBSD.org>
AuthorDate: 2023-10-01 16:16:22 +0000
Commit:     Joseph Mingrone <jrm@FreeBSD.org>
CommitDate: 2023-10-01 19:46:38 +0000

    net/samba413: Work around 12.4 bug with orphaned temp files

    Because src commit 96e101bec9 never made it into 12.4, temporary files
    are littering the staging directory and causing plist errors.  Since
    12.4 will be EOL soon, just work around the issue.

    PR:             255626
    Approved by:    portmgr (rene)
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D42030

 net/samba413/Makefile | 3 +++
 1 file changed, 3 insertions(+)
Comment 9 Joseph Mingrone freebsd_committer freebsd_triage 2023-10-02 02:42:25 UTC
I believe this is either fixed (or worked around on 12.4), so I'll close.  Please re-open if necessary.