diff mbox series

[OpenWrt-Devel,ucert,09/13] usign-exec: close writing end of pipe early in parent process

Message ID 077feb5b5824beb3af28385d350e2398ffe46f27.1589663193.git.mschiffer@universe-factory.net
State Accepted
Delegated to: Matthias Schiffer
Headers show
Series ucert fixes and cleanup | expand

Commit Message

Matthias Schiffer May 16, 2020, 9:13 p.m. UTC
When the child process exited without producing output (for example
because usign was not found), the parent process would hang forever in
read(). By closing the writing end early in the parent process, read
will return as soon as no writing FDs are left - that is, when the child
process has exited.

Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
---
 usign-exec.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/usign-exec.c b/usign-exec.c
index c9aecf99f9c0..0dde81ed647b 100644
--- a/usign-exec.c
+++ b/usign-exec.c
@@ -136,6 +136,8 @@  static int usign_f(char fingerprint[17], const char *pubkeyfile, const char *sec
 		_exit(1);
 	}
 
+	close(fds[1]);
+
 	waitpid(pid, &status, 0);
 	status = WEXITSTATUS(status);
 	if (fingerprint && !WEXITSTATUS(status)) {
@@ -149,7 +151,6 @@  static int usign_f(char fingerprint[17], const char *pubkeyfile, const char *sec
 
 	}
 	close(fds[0]);
-	close(fds[1]);
 	return status;
 }