summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorUlf Hermann <[email protected]>2017-03-27 16:33:52 +0200
committerUlf Hermann <[email protected]>2017-05-04 16:12:05 +0000
commit5e738a2deec976ffac6c313327f407d7e4760076 (patch)
tree443eb2e8617f8198ea21e085e099d9104f71de4a /src
parent741248144e6361548359ad7d9e394144a0312ecf (diff)
Skip fchown, fchmod, fadvise, fallocate if functions are unavailable
If fchmod or fchown are unavailable, then the file permission model is likely to be different from what we expect there. posix_fallocate is a rather fragile affair already on linux, and not guaranteed to do anything useful. If it's not available, the result will be the same as when it's available and unreliable. fadvise is an optimization. Change-Id: I28a77e976a0198cf80397b45eb1bc8cfb30664f5 Reviewed-by: Christian Kandeler <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog9
-rw-r--r--src/ar.c59
-rw-r--r--src/elfcompress.c4
-rw-r--r--src/ranlib.c21
-rw-r--r--src/strings.c2
-rw-r--r--src/strip.c5
6 files changed, 71 insertions, 29 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 4a32604f..e0df2e13 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,14 @@
2017-05-04 Ulf Hermann <[email protected]>
+ * ar.c: Don't fchmod or fchown the output file if fchmod or fchown
+ don't exist.
+ * elfcompress.c: Likewise.
+ * ranlib.c: Likewise.
+ * strip.c: Likewise.
+ * strings.c: Skip posix_fadvise if it doesn't exist.
+
+2017-05-04 Ulf Hermann <[email protected]>
+
* strings.c: If roundup() is not defined, define it.
2017-04-28 Ulf Hermann <[email protected]>
diff --git a/src/ar.c b/src/ar.c
index ec32cee5..45b219ac 100644
--- a/src/ar.c
+++ b/src/ar.c
@@ -655,6 +655,7 @@ do_oper_extract (int oper, const char *arfname, char **argv, int argc,
if (oper != oper_print)
{
+#if HAVE_DECL_FCHMOD
/* Fix up the mode. */
if (unlikely (fchmod (xfd, arhdr->ar_mode) != 0))
{
@@ -662,6 +663,7 @@ do_oper_extract (int oper, const char *arfname, char **argv, int argc,
arhdr->ar_name);
status = 0;
}
+#endif
if (preserve_dates)
{
@@ -788,20 +790,25 @@ cannot rename temporary file to %.*s"),
!= (ssize_t) symtab.symsofflen)
|| (write_retry (newfd, symtab.symsname,
symtab.symsnamelen)
- != (ssize_t) symtab.symsnamelen)))
+ != (ssize_t) symtab.symsnamelen))) ||
/* Even if the original file had content before the
symbol table, we write it in the correct order. */
- || (index_off != SARMAG
- && copy_content (elf, newfd, SARMAG, index_off - SARMAG))
- || copy_content (elf, newfd, rest_off, st.st_size - rest_off)
+ (index_off != SARMAG
+ && copy_content (elf, newfd, SARMAG, index_off - SARMAG)) ||
+ copy_content (elf, newfd, rest_off, st.st_size - rest_off) ||
+#if HAVE_DECL_FCHMOD
/* Set the mode of the new file to the same values the
original file has. */
- || fchmod (newfd, st.st_mode & ALLPERMS) != 0
+ fchmod (newfd, st.st_mode & ALLPERMS) != 0 ||
+#endif
+ (
+#if HAVE_DECL_FCHOWN
/* Never complain about fchown failing. */
- || (({asm ("" :: "r" (fchown (newfd, st.st_uid,
+ ({asm ("" :: "r" (fchown (newfd, st.st_uid,
st.st_gid))); }),
- close (newfd) != 0)
- || (newfd = -1, rename (tmpfname, arfname) != 0))
+#endif
+ close (newfd) != 0) ||
+ (newfd = -1, rename (tmpfname, arfname) != 0))
goto nonew_unlink;
}
}
@@ -1046,13 +1053,19 @@ do_oper_delete (const char *arfname, char **argv, int argc,
goto nonew_unlink;
}
- /* Set the mode of the new file to the same values the original file
- has. */
- if (fchmod (newfd, st.st_mode & ALLPERMS) != 0
+ if (
+#if HAVE_DECL_FCHMOD
+ /* Set the mode of the new file to the same values the original file
+ has. */
+ fchmod (newfd, st.st_mode & ALLPERMS) != 0 ||
+#endif
+ (
+#if HAVE_DECL_FCHOWN
/* Never complain about fchown failing. */
- || (({asm ("" :: "r" (fchown (newfd, st.st_uid, st.st_gid))); }),
- close (newfd) != 0)
- || (newfd = -1, rename (tmpfname, arfname) != 0))
+ ({asm ("" :: "r" (fchown (newfd, st.st_uid, st.st_gid))); }),
+#endif
+ close (newfd) != 0) ||
+ (newfd = -1, rename (tmpfname, arfname) != 0))
goto nonew_unlink;
errout:
@@ -1503,14 +1516,20 @@ do_oper_insert (int oper, const char *arfname, char **argv, int argc,
goto nonew_unlink;
}
- /* Set the mode of the new file to the same values the original file
- has. */
if (fd != -1
- && (fchmod (newfd, st.st_mode & ALLPERMS) != 0
+ && (
+#if HAVE_DECL_FCHMOD
+ /* Set the mode of the new file to the same values the original file
+ has. */
+ fchmod (newfd, st.st_mode & ALLPERMS) != 0 ||
+#endif
+ (
+#if HAVE_DECL_FCHOWN
/* Never complain about fchown failing. */
- || (({asm ("" :: "r" (fchown (newfd, st.st_uid, st.st_gid))); }),
- close (newfd) != 0)
- || (newfd = -1, rename (tmpfname, arfname) != 0)))
+ ({asm ("" :: "r" (fchown (newfd, st.st_uid, st.st_gid))); }),
+#endif
+ close (newfd) != 0) ||
+ (newfd = -1, rename (tmpfname, arfname) != 0)))
goto nonew_unlink;
errout:
diff --git a/src/elfcompress.c b/src/elfcompress.c
index 8e0d5c55..e092e136 100644
--- a/src/elfcompress.c
+++ b/src/elfcompress.c
@@ -1235,13 +1235,17 @@ process_file (const char *fname)
elf_end (elfnew);
elfnew = NULL;
+#if HAVE_DECL_FCHMOD
/* Try to match mode and owner.group of the original file. */
if (fchmod (fdnew, st.st_mode & ALLPERMS) != 0)
if (verbose >= 0)
error (0, errno, "Couldn't fchmod %s", fnew);
+#endif
+#if HAVE_DECL_FCHOWN
if (fchown (fdnew, st.st_uid, st.st_gid) != 0)
if (verbose >= 0)
error (0, errno, "Couldn't fchown %s", fnew);
+#endif
/* Finally replace the old file with the new file. */
if (foutput == NULL)
diff --git a/src/ranlib.c b/src/ranlib.c
index cc0ee233..ecaeb55a 100644
--- a/src/ranlib.c
+++ b/src/ranlib.c
@@ -252,19 +252,24 @@ handle_file (const char *fname)
!= (ssize_t) symtab.symsofflen)
|| (write_retry (newfd, symtab.symsname,
symtab.symsnamelen)
- != (ssize_t) symtab.symsnamelen)))
+ != (ssize_t) symtab.symsnamelen))) ||
/* Even if the original file had content before the
symbol table, we write it in the correct order. */
- || (index_off > SARMAG
- && copy_content (arelf, newfd, SARMAG, index_off - SARMAG))
- || copy_content (arelf, newfd, rest_off, st.st_size - rest_off)
+ (index_off > SARMAG
+ && copy_content (arelf, newfd, SARMAG, index_off - SARMAG)) ||
+ copy_content (arelf, newfd, rest_off, st.st_size - rest_off) ||
+#if HAVE_DECL_FCHMOD
/* Set the mode of the new file to the same values the
original file has. */
- || fchmod (newfd, st.st_mode & ALLPERMS) != 0
+ fchmod (newfd, st.st_mode & ALLPERMS) != 0 ||
+#endif
+ (
+#if HAVE_DECL_FCHOWN
/* Never complain about fchown failing. */
- || (({asm ("" :: "r" (fchown (newfd, st.st_uid, st.st_gid))); }),
- close (newfd) != 0)
- || (newfd = -1, rename (tmpfname, fname) != 0))
+ ({asm ("" :: "r" (fchown (newfd, st.st_uid, st.st_gid))); }),
+#endif
+ close (newfd) != 0) ||
+ (newfd = -1, rename (tmpfname, fname) != 0))
goto nonew_unlink;
}
}
diff --git a/src/strings.c b/src/strings.c
index 22cbfaca..46b23560 100644
--- a/src/strings.c
+++ b/src/strings.c
@@ -574,9 +574,11 @@ read_block (int fd, const char *fname, off_t fdlen, off_t from, off_t to)
elfmap_off = from & ~(ps - 1);
elfmap_base = elfmap = map_file (fd, elfmap_off, fdlen, &elfmap_size);
+#if HAVE_DECL_POSIX_FADVISE
if (unlikely (elfmap == MAP_FAILED))
/* Let the kernel know we are going to read everything in sequence. */
(void) posix_fadvise (fd, 0, 0, POSIX_FADV_SEQUENTIAL);
+#endif
}
if (unlikely (elfmap == MAP_FAILED))
diff --git a/src/strip.c b/src/strip.c
index f7474418..f5920812 100644
--- a/src/strip.c
+++ b/src/strip.c
@@ -2007,7 +2007,10 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
/* Create the real output file. First rename, then change the
mode. */
if (rename (tmp_debug_fname, debug_fname) != 0
- || fchmod (debug_fd, mode) != 0)
+#if HAVE_DECL_FCHMOD
+ || fchmod (debug_fd, mode) != 0
+#endif
+ )
{
error (0, errno, gettext ("while creating '%s'"), debug_fname);
result = 1;