Menu

#597 Create tempfiles in source dir for in-place elfcopy operations

RELEASE_1_0
closed
None
fixed
2021-04-04
2020-11-06
No

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.

1 Attachments

Discussion

  • Joseph Koshy

    Joseph Koshy - 2020-11-07

    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
  • Dimitry Andric

    Dimitry Andric - 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?

     
  • Joseph Koshy

    Joseph Koshy - 2020-11-07

    Even if the destination directory is unwriteable, the file being replaced could still be writeable.

     
  • Dimitry Andric

    Dimitry Andric - 2020-11-08

    Okay, let's try this other approach then. This version now retries with ${TMPDIR:-/tmp} if it gets EACCES when mkstemp() fails in the source dir. I also had to patch up copy_from_tempfile() to make it correctly work, otherwise you would still get EACCES on either the rename() or the unlink(). (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:

    mkdir foo
    cp abritrary.o foo
    chmod -w foo
    elfcopy foo/arbitrary.o
    
     
  • Joseph Koshy

    Joseph Koshy - 2020-11-09
    • status: new --> accepted
    • assigned_to: Joseph Koshy
     
  • Dimitry Andric

    Dimitry Andric - 2020-11-16

    Hi Joseph, any progress on this? I'd like to fix up FreeBSD's version of elftoolchain but rather not deviate from upstream. :)

     
    • Joseph Koshy

      Joseph Koshy - 2020-11-21

      Thanks for the patch. I will look at it this weekend. It should hopefully work fine on our other supported OSes.

       
  • Ed Maste

    Ed Maste - 2020-11-18
     
  • crees

    crees - 2021-02-15

    Rebased diff on trunk.

     
  • Joseph Koshy

    Joseph Koshy - 2021-02-19

    Fixed in [r3919]. I reworked the patch(es) a bit to make the code a little clearer.

     

    Related

    Commit: [r3919]

  • Joseph Koshy

    Joseph Koshy - 2021-04-04
    • status: accepted --> closed
    • Resolution: --> fixed
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.