From 8eb28c00b6a78928cfa91728b1eba911a4ef49c1 Mon Sep 17 00:00:00 2001 From: darealshinji Date: Mon, 13 Jul 2015 18:54:57 +0200 Subject: Don't create a temporary copy to not break hardlinks (fixes #32) --- src/patchelf.cc | 39 +++++++++------------------------------ 1 file changed, 9 insertions(+), 30 deletions(-) diff --git a/src/patchelf.cc b/src/patchelf.cc index df75593..80b2aa0 100644 --- a/src/patchelf.cc +++ b/src/patchelf.cc @@ -17,16 +17,6 @@ #include #include -#ifdef HAVE_ATTR_LIBATTR_H -# include -#endif -#ifdef HAVE_SYS_ACL_H -# include -#endif -#ifdef HAVE_ACL_LIBACL_H -# include -#endif - #include "elf.h" using namespace std; @@ -378,28 +368,17 @@ void ElfFile::sortShdrs() } -static void writeFile(string fileName, mode_t fileMode) +static void writeFile(string fileName) { - string fileName2 = fileName + "_patchelf_tmp"; - - int fd = open(fileName2.c_str(), - O_CREAT | O_TRUNC | O_WRONLY, 0700); - if (fd == -1) error("open"); + int fd = open(fileName.c_str(), O_TRUNC | O_WRONLY); + if (fd == -1) + error("open"); - if (write(fd, contents, fileSize) != fileSize) error("write"); - - if (close(fd) != 0) error("close"); - -#if defined(HAVE_ATTR_COPY_FILE) - if (attr_copy_file(fileName.c_str(), fileName2.c_str(), 0, 0) != 0) error("attr_copy_file"); -#endif -#if defined(HAVE_PERM_COPY_FILE) - if (perm_copy_file(fileName.c_str(), fileName2.c_str(), 0) != 0) error("perm_copy_file"); -#else - if (chmod(fileName2.c_str(), fileMode) != 0) error("chmod"); -#endif + if (write(fd, contents, fileSize) != fileSize) + error("write"); - if (rename(fileName2.c_str(), fileName.c_str()) != 0) error("rename"); + if (close(fd) != 0) + error("close"); } @@ -1376,7 +1355,7 @@ static void patchElf2(ElfFile & elfFile, mode_t fileMode) if (elfFile.isChanged()){ elfFile.rewriteSections(); - writeFile(fileName, fileMode); + writeFile(fileName); } } -- cgit v0.12 From 80e25cdfa99ef90b6c89255942675f37f20974d6 Mon Sep 17 00:00:00 2001 From: darealshinji Date: Mon, 13 Jul 2015 18:56:15 +0200 Subject: Don't need libattr and libacl anymore --- configure.ac | 8 -------- 1 file changed, 8 deletions(-) diff --git a/configure.ac b/configure.ac index 8ca9ad4..bdda1a6 100644 --- a/configure.ac +++ b/configure.ac @@ -6,13 +6,5 @@ AM_INIT_AUTOMAKE([-Wall -Werror dist-bzip2 foreign color-tests parallel-tests]) AM_PROG_CC_C_O AC_PROG_CXX -AC_CHECK_HEADERS([attr/libattr.h attr/error_context.h]) -AC_SEARCH_LIBS(attr_copy_file, attr) -AC_CHECK_FUNCS([attr_copy_file]) - -AC_CHECK_HEADERS([sys/acl.h acl/libacl.h]) -AC_SEARCH_LIBS(perm_copy_file, acl) -AC_CHECK_FUNCS([perm_copy_file]) - AC_CONFIG_FILES([Makefile src/Makefile tests/Makefile patchelf.spec]) AC_OUTPUT -- cgit v0.12