From f9b855a56b13708e2224efa54060b90539406383 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Tue, 2 Feb 2021 16:59:14 +0000 Subject: Make if propagate failure code --- src/execline/if.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/execline/if.c b/src/execline/if.c index a37ecbc..8820dfa 100644 --- a/src/execline/if.c +++ b/src/execline/if.c @@ -11,12 +11,13 @@ #include #define USAGE "if [ -n ] [ -X ] [ -t | -x exitcode ] { command... }" +#define dieusage() strerr_dieusage(100, USAGE) ; int main (int argc, char const **argv, char const *const *envp) { int argc1, wstat ; pid_t pid ; - int not = 0, flagnormalcrash = 0 ; + int not = 0, fixed = 0, flagnormalcrash = 0 ; unsigned short e = 1 ; PROG = "if" ; { @@ -27,11 +28,11 @@ int main (int argc, char const **argv, char const *const *envp) if (opt == -1) break ; switch (opt) { - case 'n' : not = 1 ; break ; + case 'n' : not = 1 ; fixed = 1 ; break ; case 'X' : flagnormalcrash = 1 ; break ; - case 't' : e = 0 ; break ; - case 'x' : if (ushort_scan(l.arg, &e)) break ; - default : strerr_dieusage(100, USAGE) ; + case 't' : e = 0 ; fixed = 1 ; break ; + case 'x' : if (!ushort_scan(l.arg, &e)) dieusage() ; fixed = 1 ; break ; + default : dieusage() ; } } argc -= l.ind ; argv += l.ind ; @@ -49,6 +50,6 @@ int main (int argc, char const **argv, char const *const *envp) fmt[uint_fmt(fmt, WTERMSIG(wstat))] = 0 ; strerr_dief2x(128 + WTERMSIG(wstat), "child crashed with signal ", fmt) ; } - if (not == !wait_estatus(wstat)) return e ; + if (not == !wait_estatus(wstat)) return fixed ? e : wait_estatus(wstat) ; xexec0_e(argv+argc1+1, envp) ; } -- cgit v1.2.3