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 /libelf | |
| 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 'libelf')
| -rw-r--r-- | libelf/ChangeLog | 5 | ||||
| -rw-r--r-- | libelf/elf_update.c | 4 |
2 files changed, 9 insertions, 0 deletions
diff --git a/libelf/ChangeLog b/libelf/ChangeLog index 0a5200f4..fd20ebb7 100644 --- a/libelf/ChangeLog +++ b/libelf/ChangeLog @@ -1,3 +1,8 @@ +2017-05-04 Ulf Hermann <[email protected]> + + * elf_update.c: Don't try to posix_fallocate on systems where it isn't + available. Don't fchmod the output file if there is no fchmod. + 2017-02-28 Ulf Hermann <[email protected]> * Makefile.am: Use the predefined common library names rather than diff --git a/libelf/elf_update.c b/libelf/elf_update.c index 8ce07829..b6014cdb 100644 --- a/libelf/elf_update.c +++ b/libelf/elf_update.c @@ -80,6 +80,7 @@ write_file (Elf *elf, off_t size, int change_bo, size_t shnum) if (elf->map_address != NULL) { +#if HAVE_DECL_POSIX_FALLOCATE /* When using mmap we want to make sure the file content is really there. Only using ftruncate might mean the file is extended, but space isn't allocated yet. This might cause a @@ -100,6 +101,7 @@ write_file (Elf *elf, off_t size, int change_bo, size_t shnum) __libelf_seterrno (ELF_E_WRITE_ERROR); return -1; } +#endif /* The file is mmaped. */ if ((class == ELFCLASS32 @@ -129,6 +131,7 @@ write_file (Elf *elf, off_t size, int change_bo, size_t shnum) size = -1; } +#if HAVE_DECL_FCHMOD /* POSIX says that ftruncate and write may clear the S_ISUID and S_ISGID mode bits. So make sure we restore them afterwards if they were set. This is not atomic if someone else chmod's the file while we operate. */ @@ -140,6 +143,7 @@ write_file (Elf *elf, off_t size, int change_bo, size_t shnum) __libelf_seterrno (ELF_E_WRITE_ERROR); size = -1; } +#endif if (size != -1 && elf->parent == NULL) elf->maximum_size = size; |
