As reported in https://bugs.freebsd.org/250872, elfcopy always creates temporary files in $TMPDIR
or /tmp
. If an in-place operation is taking place and the temporary file system is full, the operation can then fail with "no space left on device", even if the file system containing the source file has plenty of space left.
I propose adding a src
parameter to the create_tempfile()
function in elfcopy, which is used as the base directory for the new temporary file. If the src
parameter is set to NULL
, the behavior is as it was before, e.g. first try $TMPDIR
, and if that is unset, use /tmp
.
If we are considering this change, we should probably fall back to using
${TMPDIR:-'/tmp'}
if the temporary file cannot be created in the destination directory, e.g if the writing process lacks write permission for that directory.Last edit: Joseph Koshy 2020-11-07
That might seem reasonable, but if you can't write into the destination directory, moving/copying the temporary file to the destination will also fail, but later, and all work to write the temporary file will have been for nothing. Maybe it is better to fail early?
Even if the destination directory is unwriteable, the file being replaced could still be writeable.
Okay, let's try this other approach then. This version now retries with
${TMPDIR:-/tmp}
if it getsEACCES
whenmkstemp()
fails in the source dir. I also had to patch upcopy_from_tempfile()
to make it correctly work, otherwise you would still getEACCES
on either therename()
or theunlink()
. (All this in case the temp dir is on the same file system; if they are on different ones this does not apply.)A good test case is:
Hi Joseph, any progress on this? I'd like to fix up FreeBSD's version of elftoolchain but rather not deviate from upstream. :)
Thanks for the patch. I will look at it this weekend. It should hopefully work fine on our other supported OSes.
Committed to FreeBSD as https://svnweb.freebsd.org/changeset/base/367809
Rebased diff on trunk.
Fixed in [r3919]. I reworked the patch(es) a bit to make the code a little clearer.
Related
Commit: [r3919]