File s390-tools-sles15sp1-07-zpcictl-Use-fopen-instead-of-open-for-writes.patch of Package s390-tools.14690

Subject: zpcictl: Use fopen() instead of open() for writes
From: Jan Hoeppner <jan.hoeppner@de.ibm.com>

Summary:     zpcictl: Add tool to manage PCI devices
Description: Use the zpcictl tool to manage PCI devices on the IBM Z
             platform.  Initial functions include generating firmware
             error logs, resetting PCI devices, and preparing a device
             for further repair actions.
Upstream-ID: 8f0496b26aae88e206ac9a95b317043e78d147b8
Problem-ID:  RAS1703

Upstream-Description:

             zpcictl: Use fopen() instead of open() for writes

             Be consistent with the rest of the code and use fopen() rather than
             open().

             Reviewed-by: Hendrik Brueckner <brueckner@linux.ibm.com>
             Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>


Signed-off-by: Jan Hoeppner <jan.hoeppner@de.ibm.com>
---
 zpcictl/zpcictl.c |   14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

--- a/zpcictl/zpcictl.c
+++ b/zpcictl/zpcictl.c
@@ -155,17 +155,19 @@ static unsigned int sysfs_read_value(str
 
 static void sysfs_write_data(struct zpci_report_error *report, char *slot)
 {
+	size_t r_size;
 	char *path;
-	int fd, rc;
+	FILE *fp;
+
+	r_size = sizeof(*report);
 
 	path = util_path_sysfs("bus/pci/devices/%s/report_error", slot);
-	fd = open(path, O_WRONLY);
-	if (!fd)
+	fp = fopen(path, "w");
+	if (!fp)
 		fopen_err(path);
-	rc = write(fd, report, sizeof(*report));
-	if (rc == -1)
+	if (fwrite(report, 1, r_size, fp) != r_size)
 		warnx("Could not write to file: %s: %s", path, strerror(errno));
-	if (close(fd))
+	if (fclose(fp))
 		warnx("Could not close file: %s: %s", path, strerror(errno));
 	free(path);
 }
openSUSE Build Service is sponsored by