diff mbox

[LEDE-DEV,5/5] initd: fix descriptor leak

Message ID aa6eed3e0de2f4f0d23f3b0eba2a3760634211a7.1463496164.git.jo@mein.io
State Accepted
Headers show

Commit Message

Jo-Philipp Wich May 17, 2016, 3 p.m. UTC
Close the descriptor to /tmp/.preinit returned by creat() in order to avoid
an fd leak in the init process.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
---
 initd/preinit.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/initd/preinit.c b/initd/preinit.c
index 51fde31..729978e 100644
--- a/initd/preinit.c
+++ b/initd/preinit.c
@@ -89,6 +89,7 @@  preinit(void)
 {
 	char *init[] = { "/bin/sh", "/etc/preinit", NULL };
 	char *plug[] = { "/sbin/procd", "-h", "/etc/hotplug-preinit.json", NULL };
+	int fd;
 
 	LOG("- preinit -\n");
 
@@ -106,7 +107,13 @@  preinit(void)
 	uloop_process_add(&plugd_proc);
 
 	setenv("PREINIT", "1", 1);
-	creat("/tmp/.preinit", 0600);
+
+	fd = creat("/tmp/.preinit", 0600);
+
+	if (fd < 0)
+		ERROR("Failed to create sentinel file\n");
+	else
+		close(fd);
 
 	preinit_proc.cb = spawn_procd;
 	preinit_proc.pid = fork();