git: 5ceb90aa667a - stable/13 - elfctl: avoid touching file if no change made

Ed Maste emaste at FreeBSD.org
Wed Jun 2 02:09:30 UTC 2021


The branch stable/13 has been updated by emaste:

URL: https://cgit.FreeBSD.org/src/commit/?id=5ceb90aa667afbd0941f045073d54aea35d40f1b

commit 5ceb90aa667afbd0941f045073d54aea35d40f1b
Author:     Ed Maste <emaste at FreeBSD.org>
AuthorDate: 2021-05-25 18:25:18 +0000
Commit:     Ed Maste <emaste at FreeBSD.org>
CommitDate: 2021-06-02 02:08:54 +0000

    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)
---
 usr.bin/elfctl/elfctl.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/usr.bin/elfctl/elfctl.c b/usr.bin/elfctl/elfctl.c
index bcdd1be394a9..04719b487613 100644
--- a/usr.bin/elfctl/elfctl.c
+++ b/usr.bin/elfctl/elfctl.c
@@ -288,7 +288,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)) {
@@ -296,8 +296,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)) <


More information about the dev-commits-src-all mailing list