Blame SOURCES/0008-hugeutils-Make-writing-a-ulong-to-a-file-more-reliab.patch

0dfa60
From 4ba60a2f5c3f5405c599caddc5a124c5781c9beb Mon Sep 17 00:00:00 2001
0dfa60
Message-Id: <4ba60a2f5c3f5405c599caddc5a124c5781c9beb.1566225007.git.aquini@redhat.com>
0dfa60
In-Reply-To: <d42f467a923dfc09309acb7a83b42e3285fbd8f4.1566225007.git.aquini@redhat.com>
0dfa60
References: <d42f467a923dfc09309acb7a83b42e3285fbd8f4.1566225007.git.aquini@redhat.com>
0dfa60
From: Sandipan Das <sandipan@linux.ibm.com>
0dfa60
Date: Thu, 15 Aug 2019 13:08:35 +0530
0dfa60
Subject: [RHEL7 PATCH 08/31] hugeutils: Make writing a ulong to a file more
0dfa60
 reliable
0dfa60
0dfa60
This makes file_write_ulong() more reliable in terms of error
0dfa60
detection for certain cases like writing an invalid value to
0dfa60
a file under procfs or sysfs. Also, using fprintf() does not
0dfa60
guarantee that errno would be set under such circumstances.
0dfa60
0dfa60
Signed-off-by: Sandipan Das <sandipan@linux.ibm.com>
0dfa60
Signed-off-by: Eric B Munson <emunson@mgebm.net>
0dfa60
Signed-off-by: Rafael Aquini <aquini@redhat.com>
0dfa60
---
0dfa60
 hugeutils.c | 13 +++++++------
0dfa60
 1 file changed, 7 insertions(+), 6 deletions(-)
0dfa60
0dfa60
diff --git a/hugeutils.c b/hugeutils.c
0dfa60
index 60488e8..fc64946 100644
0dfa60
--- a/hugeutils.c
0dfa60
+++ b/hugeutils.c
0dfa60
@@ -219,17 +219,18 @@ long file_read_ulong(char *file, const char *tag)
0dfa60
 
0dfa60
 int file_write_ulong(char *file, unsigned long val)
0dfa60
 {
0dfa60
-	FILE *f;
0dfa60
-	int ret;
0dfa60
+	int fd, ret, buflen;
0dfa60
+	char buf[20];
0dfa60
 
0dfa60
-	f = fopen(file, "w");
0dfa60
-	if (!f) {
0dfa60
+	fd = open(file, O_WRONLY);
0dfa60
+	if (fd < 0) {
0dfa60
 		ERROR("Couldn't open %s: %s\n", file, strerror(errno));
0dfa60
 		return -1;
0dfa60
 	}
0dfa60
 
0dfa60
-	ret = fprintf(f, "%lu", val);
0dfa60
-	fclose(f);
0dfa60
+	buflen = sprintf(buf, "%lu", val);
0dfa60
+	ret = write(fd, buf, buflen);
0dfa60
+	close(fd);
0dfa60
 	return ret > 0 ? 0 : -1;
0dfa60
 }
0dfa60
 
0dfa60
-- 
0dfa60
1.8.3.1
0dfa60