diff options
| author | Ed Maste <emaste@FreeBSD.org> | 2021-05-25 18:25:18 +0000 |
|---|---|---|
| committer | Ed Maste <emaste@FreeBSD.org> | 2021-12-12 18:58:23 +0000 |
| commit | e048bd5c0954814f72e04df8b7b7ff183da45a19 (patch) | |
| tree | fd036a3649f5cf47b01f5d54102d465e666c588b | |
| parent | ef2ecd0483392ac878a73afd5904020bf84ec5df (diff) | |
elfctl: avoid touching file if no change made
Suggested by: brooks
Reviewed by: brooks, markj
MFC after: 1 week
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D30452
(cherry picked from commit 3f2508b7f3855102abed99b846e30e728ba3d04d)
(cherry picked from commit 5ceb90aa667afbd0941f045073d54aea35d40f1b)
| -rw-r--r-- | usr.bin/elfctl/elfctl.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/usr.bin/elfctl/elfctl.c b/usr.bin/elfctl/elfctl.c index 205be39fadc7..6f23b6a94501 100644 --- a/usr.bin/elfctl/elfctl.c +++ b/usr.bin/elfctl/elfctl.c @@ -290,7 +290,7 @@ convert_to_feature_val(char *feature_str, uint32_t *feature_val) static bool edit_file_features(Elf *elf, int phcount, int fd, char *val) { - uint32_t features; + uint32_t features, prev_features; uint64_t off; if (!get_file_features(elf, phcount, fd, &features, &off)) { @@ -298,8 +298,12 @@ edit_file_features(Elf *elf, int phcount, int fd, char *val) return (false); } + prev_features = features; if (!convert_to_feature_val(val, &features)) return (false); + /* Avoid touching file if no change. */ + if (features == prev_features) + return (true); if (lseek(fd, off, SEEK_SET) == -1 || write(fd, &features, sizeof(features)) < |
