From cdaff25ff6dd46b1bb1973ff955602076d305704 Mon Sep 17 00:00:00 2001
From: Morris Jette <jette@schedmd.com>
Date: Wed, 16 Aug 2017 16:18:45 -0600
Subject: [PATCH] Add chmod error checks

Coverity CID 44678
---
 .../filetxt/filetxt_jobacct_process.c         | 26 ++++++++++++-------
 1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/src/plugins/accounting_storage/filetxt/filetxt_jobacct_process.c b/src/plugins/accounting_storage/filetxt/filetxt_jobacct_process.c
index 7c328d7fe00..7927956fdc1 100644
--- a/src/plugins/accounting_storage/filetxt/filetxt_jobacct_process.c
+++ b/src/plugins/accounting_storage/filetxt/filetxt_jobacct_process.c
@@ -1286,10 +1286,12 @@ extern int filetxt_jobacct_process_archive(slurmdb_archive_cond_t *arch_cond)
 	}
 
 	if (new_file) {  /* By default, the expired file looks like the log */
-		chmod(logfile_name, prot);
-		if (chown(logfile_name, uid, gid) == -1)
-			error("Couldn't change ownership of %s to %u:%u",
-			      logfile_name, uid, gid);
+		if (chmod(logfile_name, prot) == -1)
+			error("%s: chmod(%s): %m", __func__, logfile_name);
+		if (chown(logfile_name, uid, gid) == -1) {
+			error("%s(1): chown(%s, %u, %u)",
+			      __func__, logfile_name, uid, gid);
+		}
 	}
 	xfree(logfile_name);
 
@@ -1301,12 +1303,16 @@ extern int filetxt_jobacct_process_archive(slurmdb_archive_cond_t *arch_cond)
 		fclose(expired_logfile);
 		goto finished;
 	}
-	chmod(logfile_name, prot);     /* preserve file protection */
-	if (chown(logfile_name, uid, gid) == -1)/* and ownership */
-		error("2 Couldn't change ownership of %s to %u:%u",
-		      logfile_name, uid, gid);
-	/* Use line buffering to allow us to safely write
-	 * to the log file at the same time as slurmctld. */
+	if (chmod(logfile_name, prot) == -1)
+		error("%s(2): chmod(%s): %m", __func__, logfile_name);
+	if (chown(logfile_name, uid, gid) == -1) {
+		error("%s(2): chown(%s, %u, %u)",
+		      __func__, logfile_name, uid, gid);
+	}
+	/*
+	 * Use line buffering to allow us to safely write
+	 * to the log file at the same time as slurmctld.
+	 */
 	if (setvbuf(new_logfile, NULL, _IOLBF, 0)) {
 		perror("setvbuf()");
 		fclose(expired_logfile);
-- 
GitLab