diff options
author | Ulf Hermann <[email protected]> | 2017-03-27 16:33:52 +0200 |
---|---|---|
committer | Ulf Hermann <[email protected]> | 2017-05-04 16:12:05 +0000 |
commit | 5e738a2deec976ffac6c313327f407d7e4760076 (patch) | |
tree | 443eb2e8617f8198ea21e085e099d9104f71de4a /src/ar.c | |
parent | 741248144e6361548359ad7d9e394144a0312ecf (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/ar.c')
-rw-r--r-- | src/ar.c | 59 |
1 files changed, 39 insertions, 20 deletions
@@ -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: |