From b4a3e45856da6f4755943c190c712ce7fcf92dc0 Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Fri, 3 Nov 2017 23:12:59 +0100 Subject: run: bail out early when there is no command to run --- xe.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/xe.c b/xe.c index 018ee3b..30231eb 100644 --- a/xe.c +++ b/xe.c @@ -215,6 +215,11 @@ run() scanargs(); + if (!args[0]) { + fprintf(stderr, "xe: no command\n"); + exit(126); + } + if (nflag) { trace(); runjobs--; @@ -252,10 +257,6 @@ run() close(pipefd[1]); } - if (!args[0]) { - fprintf(stderr, "xe: no command\n"); - exit(126); - } if (qflag) { int fd = open("/dev/null", O_RDONLY); if (fd >= 0) { @@ -264,7 +265,9 @@ run() close(fd); } } + execvp(args[0], args); + int status = (errno == ENOENT ? 127 : 126); fprintf(stderr, "xe: %s: %s\n", args[0], strerror(errno)); exit(status); -- cgit 1.4.1