about summary refs log tree commit diff
path: root/xe.c
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2016-02-10 21:09:48 +0100
committerChristian Neukirchen <chneukirchen@gmail.com>2016-02-10 21:09:48 +0100
commitdfb94adb2574b60e7eb403f00789ab6576960435 (patch)
tree9a4436efa892cbe1eace6a909fdfc0ae37d40c51 /xe.c
parent86fa5ec3d5bd08d5ea5282aafb8a1d02917a088b (diff)
downloadxe-dfb94adb2574b60e7eb403f00789ab6576960435.tar.gz
xe-dfb94adb2574b60e7eb403f00789ab6576960435.tar.xz
xe-dfb94adb2574b60e7eb403f00789ab6576960435.zip
only close stdin when we read arguments from it
Diffstat (limited to 'xe.c')
-rw-r--r--xe.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/xe.c b/xe.c
index 77acdd7..c4b6292 100644
--- a/xe.c
+++ b/xe.c
@@ -205,14 +205,16 @@ run()
 		char iter[32];
 		snprintf(iter, sizeof iter, "%ld", iterations);
 		setenv("ITER", iter, 1);
-		// redirect stdin to /dev/null
-		int fd = open("/dev/null", O_RDONLY);
-		if (fd >= 0) {
-			if (dup2(fd, 0) != 0)
-				exit(1);
-			close(fd);
-			execvp(args[0], args);
+		// redirect stdin to /dev/null when we read arguments from it
+		if (!(aflag || Aflag)) {
+			int fd = open("/dev/null", O_RDONLY);
+			if (fd >= 0) {
+				if (dup2(fd, 0) != 0)
+					exit(1);
+				close(fd);
+			}
 		}
+		execvp(args[0], args);
 		fprintf(stderr, "xe: %s: %s\n", args[0], strerror(errno));
 		exit(errno == ENOENT ? 127 : 126);
 	}