From 775b775240d09fe665efaecf2432d590567e68ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bert=20M=C3=BCnnich?= Date: Fri, 27 Oct 2017 19:30:09 +0200 Subject: Fix exit value for -e with failed backquote or pipeline This fixes rakitzis/rc issue #40. Both cases suffered from a misconception of statprint() in which the necessary check for -e happens. The checked status value gets passed to statprint() as an argument but the corresponding value passed to rc_exit() in case the status is non-zero comes from getstatus(), which requires that the checked status is written to statuses[] first. For pipelines this happened in the wrong order and for backquotes the status value was not put into statuses[] at all. Making statprint() a static helper function prevents this mistake by only leaving the setstatus family of functions to handle status codes. --- glom.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'glom.c') diff --git a/glom.c b/glom.c index c44f0d5..7f90d9d 100644 --- a/glom.c +++ b/glom.c @@ -266,7 +266,7 @@ static List *backq(Node *ifs, Node *n) { bq = bqinput(glom(ifs), p[0]); close(p[0]); rc_wait4(pid, &sp, TRUE); - statprint(-1, sp); + setstatus(-1, sp); varassign("bqstatus", word(strstatus(sp), NULL), FALSE); sigchk(); return bq; -- cgit v1.2.3