Skip to content

Why hard links ? #1067

Closed
Closed

Description

@SaavdhaanCyber

os.link is necessary ? Can os.symlink can be used (I think easily ) but I want to know from you

Activity

  1. mnaberez commented on Mar 3, 2018

    @mnaberez
    Member

    Some context would be useful, such as the file/line you're asking about.

  2. FAKERINHEART commented on Mar 3, 2018

    @FAKERINHEART

    @lkdevil @mnaberez The system hard link of socket codes in supervisord, which are referenced by @lkdevil, are the reason that partially result in the failure of the overylay fs system (docker uses) using supervisord. moby/moby#12080
    and
    https://github.com/analytically/docker-overlayfs-bug

  3. rqcy commented on Jul 24, 2018

    @rqcy

    Yes, please merge the PR #1069 !

    1. os.rename is cleaner, shorter and easier to understand in code than os.link/os.unlink, unless there's some good reason to use the later one. For reference: https://stackoverflow.com/questions/18653112/which-is-costlier-rename-or-link-and-unlink-in-c

    2. I've recently installed supervisor in Termux on Android and Python there does not support os.link, but does support rename. After this change, I could use supervisor in Termux via pip.

    Thanks for your work!

  4. mnaberez commented on Dec 11, 2021

    @mnaberez
    Member

    os.link()

    $ touch foo
    $ touch bar
    $ python -c "import os; os.link('foo', 'bar')"
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
    OSError: [Errno 17] File exists
    $
    

    os.rename()

    $ touch foo
    $ touch bar
    $ python -c "import os; os.rename('foo', 'bar')"
    $ ls
    bar
    

    os.link() guarantees the destination filename does not exist. os.rename() overwrites it. Changing from os.link() to os.rename() would no longer have the guarantee that the socket file does not exist. A check like os.path.exists() would need to be added before it, and then the code would no longer be atomic. A race condition would then be possible, which likely has security implications.

    I'd rather not change anything here. Supporting systems without hard links is not a goal of this project, sorry. supervisorctl can communicate with supervisord over both a UNIX domain socket (what this code is for) or over a TCP socket. Perhaps a TCP socket bound to localhost could be used instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions