Re: [GIT PULL] scripts: recordmcount: break hardlinks

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 15 Dec 2015 15:10:04 -0500
Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:

> I can write a patch on top of this one that does just that. I'll have
> to run it through all my tests before I push it to you. Expect
> something by tomorrow.

Russell,

Can you apply this on top of your patch and make sure everything still
works. I built and booted it, and now I'm going to run it through my
tests.

Thanks!

-- Steve

diff --git a/scripts/recordmcount.c b/scripts/recordmcount.c
index 91705ef30402..038a11aa0865 100644
--- a/scripts/recordmcount.c
+++ b/scripts/recordmcount.c
@@ -211,20 +211,24 @@ static void *mmap_file(char const *fname)
 		addr = umalloc(sb.st_size);
 		uread(fd_map, addr, sb.st_size);
 	}
-	if (sb.st_nlink != 1) {
-		/* file is hard-linked, break the hard link */
-		close(fd_map);
-		if (unlink(fname) < 0) {
-			perror(fname);
-			fail_file();
-		}
-		fd_map = open(fname, O_RDWR | O_CREAT, sb.st_mode);
-		if (fd_map < 0) {
-			perror(fname);
-			fail_file();
-		}
-		uwrite(fd_map, addr, sb.st_size);
+
+	/*
+	 * After reading the entire file into memory, delete it
+	 * and write it back, to prevent weird side effects of modifying
+	 * an object file in place.
+	 */
+	close(fd_map);
+	if (unlink(fname) < 0) {
+		perror(fname);
+		fail_file();
+	}
+	fd_map = open(fname, O_RDWR | O_CREAT, sb.st_mode);
+	if (fd_map < 0) {
+		perror(fname);
+		fail_file();
 	}
+	uwrite(fd_map, addr, sb.st_size);
+
 	return addr;
 }
 
--
To unsubscribe from this list: send the line "unsubscribe stable" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel]     [Kernel Development Newbies]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]