about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2017-11-03 23:07:27 +0100
committerLeah Neukirchen <leah@vuxu.org>2017-11-03 23:07:27 +0100
commitc77fd48024d6de425e890f74cc11142085e4b5b8 (patch)
tree11af154c265da33514a07c7f81427be290676a8d
parent8c499789196b79a8e681b22e19065d37eb76a309 (diff)
downloadxe-c77fd48024d6de425e890f74cc11142085e4b5b8.tar.gz
xe-c77fd48024d6de425e890f74cc11142085e4b5b8.tar.xz
xe-c77fd48024d6de425e890f74cc11142085e4b5b8.zip
run: close fd 0 if dup'ing /dev/null fails
-rw-r--r--xe.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/xe.c b/xe.c
index 4cc416c..018ee3b 100644
--- a/xe.c
+++ b/xe.c
@@ -233,12 +233,15 @@ run()
 		snprintf(iter, sizeof iter, "%ld", iterations);
 		setenv("ITER", iter, 1);
 		// redirect stdin to /dev/null when we read arguments from it
+		// just close it if this fails
 		if (input == stdin) {
 			int fd = open("/dev/null", O_RDONLY);
 			if (fd >= 0) {
 				if (dup2(fd, 0) != 0)
-					exit(1);
+					close(0);
 				close(fd);
+			} else {
+				close(0);
 			}
 		}