From ca23df457baa1a10fa1c0d9f79169f47d4a2e113 Mon Sep 17 00:00:00 2001
From: Morris Jette <jette@schedmd.com>
Date: Fri, 18 Aug 2017 14:03:49 -0600
Subject: [PATCH] log fcntl error

Coverity CID 44725, 44726, 44747, 44728
---
 src/plugins/jobacct_gather/common/common_jag.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/plugins/jobacct_gather/common/common_jag.c b/src/plugins/jobacct_gather/common/common_jag.c
index 227be22fee2..65c5c6ad5f0 100644
--- a/src/plugins/jobacct_gather/common/common_jag.c
+++ b/src/plugins/jobacct_gather/common/common_jag.c
@@ -141,7 +141,8 @@ static int _get_pss(char *proc_smaps_file, jag_prec_t *prec)
                 return -1;
         }
 
-	fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
+	if (fcntl(fileno(fp), F_SETFD, FD_CLOEXEC) == -1)
+		error("%s: fcntl(%s): %m", __func__, proc_smaps_file);
 	pss = 0;
 
         while (fgets(line,sizeof(line),fp)) {
@@ -202,7 +203,8 @@ static int _get_sys_interface_freq_line(uint32_t cpu, char *filename,
 	if ((sys_fp = fopen(freq_file, "r"))!= NULL) {
 		/* frequency scaling enabled */
 		fd = fileno(sys_fp);
-		fcntl(fd, F_SETFD, FD_CLOEXEC);
+		if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
+			error("%s: fcntl(%s): %m", __func__, freq_file);
 		num_read = read(fd, sbuf, (sizeof(sbuf) - 1));
 		if (num_read > 0) {
 			sbuf[num_read] = '\0';
@@ -395,7 +397,8 @@ static int _remove_share_data(char *proc_stat_file, jag_prec_t *prec)
 	if (!(statm_fp = fopen(proc_statm_file, "r")))
 		return rc;  /* Assume the process went away */
 	fd = fileno(statm_fp);
-	fcntl(fd, F_SETFD, FD_CLOEXEC);
+	if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
+		error("%s: fcntl(%s): %m", __func__, proc_statm_file);
 	rc = _get_process_memory_line(fd, prec);
 	fclose(statm_fp);
 	return rc;
@@ -477,7 +480,8 @@ static void _handle_stats(List prec_list, char *proc_stat_file, char *proc_io_fi
 	 * problem in practice.
 	 */
 	fd = fileno(stat_fp);
-	fcntl(fd, F_SETFD, FD_CLOEXEC);
+	if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
+		error("%s: fcntl(%s): %m", __func__, proc_stat_file);
 
 	prec = try_xmalloc(sizeof(jag_prec_t));
 	if (prec == NULL) {	/* Avoid killing slurmstepd on malloc failure */
-- 
GitLab