Blob Blame History Raw
From 38952aa277df116da0b7ef389440de34a3e61cd0 Mon Sep 17 00:00:00 2001
From: Scott Moser <smoser@brickies.net>
Date: Wed, 19 Sep 2018 17:21:48 -0400
Subject: [PATCH] Close file handles when writing pid files.

The file descriptors used for writing to the pid file were
not being closed.  Just be more clean and close them.

Also fix a debug message that said 'lock file' rather than 'pid file'.
---
 iscsiuio/src/unix/main.c | 3 ++-
 usr/iscsid.c             | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/iscsiuio/src/unix/main.c b/iscsiuio/src/unix/main.c
index 5cccc76ed220..457ebe340b7d 100644
--- a/iscsiuio/src/unix/main.c
+++ b/iscsiuio/src/unix/main.c
@@ -346,8 +346,9 @@ int main(int argc, char *argv[])
 		sprintf(buf, "%d\n", getpid());
 		written_bytes = write(fd, buf, strlen(buf));
 		if (written_bytes == -1)
-			printf("Could not write lock file [%s]",
+			printf("Could not write pid file [%s]",
 			       strerror(errno));
+		close(fd);
 
 		daemon_init();
 	}
diff --git a/usr/iscsid.c b/usr/iscsid.c
index b95917df3bc5..7d6032252d00 100644
--- a/usr/iscsid.c
+++ b/usr/iscsid.c
@@ -467,6 +467,7 @@ int main(int argc, char *argv[])
 				exit(ISCSI_ERR);
 			}
 		}
+		close(fd);
 
 		daemon_init();
 	} else {
-- 
2.17.2