Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

patchelf breaks hardlinks #32

Closed
sjackman opened this issue Aug 22, 2014 · 6 comments
Closed

patchelf breaks hardlinks #32

sjackman opened this issue Aug 22, 2014 · 6 comments

Comments

@sjackman
Copy link

Hard links are used extensively by gcc and git. See the example below.

Experiment

$ cc hello.c -o hello
$ ln hello hello2
$ ls -il hello hello2
10099869 -rwxr-xr-x 2 sjackman assembly 7130 Aug 22 13:54 hello
10099869 -rwxr-xr-x 2 sjackman assembly 7130 Aug 22 13:54 hello2
$ patchelf --set-rpath /foo hello

Observed

$ ls -il hello hello2
10099870 -rwxr-xr-x 1 sjackman assembly 11226 Aug 22 13:55 hello
10099869 -rwxr-xr-x 1 sjackman assembly  7130 Aug 22 13:54 hello2

Expected

$ ls -il hello hello2
10099869 -rwxr-xr-x 2 sjackman assembly 11226 Aug 22 13:55 hello
10099869 -rwxr-xr-x 2 sjackman assembly 11226 Aug 22 13:55 hello2
@darealshinji
Copy link
Contributor

patchelf writes the changes in a new temporary file and replaces the original with the new one, that's why this happens.
https://github.com/NixOS/patchelf/blob/master/src/patchelf.cc#L378

@sjackman
Copy link
Author

Breaking hardlinks is rather unexpected behaviour. Can writeFile be changed to write directly to the file, rather than through a temp file?

@darealshinji
Copy link
Contributor

I found the solution! This is what "static void writeFile()" should look like:

static void writeFile(string fileName, mode_t fileMode)
{
    int fd = open(fileName.c_str(), O_TRUNC | O_WRONLY, 0700);
    if (fd == -1)
        error("open");

    if (write(fd, contents, fileSize) != fileSize)
        error("write");

    if (close(fd) != 0)
        error("close");
}

darealshinji@bed9cea

@sjackman
Copy link
Author

Excellent! Thanks. I'll test it soon. Without O_CREAT you can remove , 0700 as it has no effect.

@sjackman
Copy link
Author

@edolstra Can you please merge this patch from @darealshinji to fix this issue? Thanks!
darealshinji@bed9cea

@sjackman
Copy link
Author

Great. Thanks. Will there be a new stable release that includes this fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants