summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBert Münnich <ber.t@posteo.de>2017-10-27 19:30:09 +0200
committerBert Münnich <ber.t@posteo.de>2017-10-27 20:22:21 +0200
commit775b775240d09fe665efaecf2432d590567e68ef (patch)
treebf0f8b32c386fd7670c52623022a8ef576540c21
parent7dc3033c862c30d8998ed3e4c98c056286f31401 (diff)
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.
-rw-r--r--glom.c2
-rw-r--r--rc.h1
-rw-r--r--status.c6
3 files changed, 5 insertions, 4 deletions
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;
diff --git a/rc.h b/rc.h
index 2912e60..68d338d 100644
--- a/rc.h
+++ b/rc.h
@@ -347,7 +347,6 @@ extern void set(bool);
extern void setstatus(pid_t, int);
extern List *sgetstatus(void);
extern void setpipestatus(int [], int);
-extern void statprint(pid_t, int);
extern void ssetstatus(char **);
extern char *strstatus(int s);
diff --git a/status.c b/status.c
index 5b37aa5..b4e6a05 100644
--- a/status.c
+++ b/status.c
@@ -7,6 +7,8 @@
/* status == the wait() value of the last command in the pipeline, or the last command */
+static void statprint(pid_t, int);
+
static int statuses[512];
static int pipelength = 1;
@@ -49,8 +51,8 @@ extern void set(bool code) {
extern void setpipestatus(int stats[], int num) {
int i;
for (i = 0; i < (pipelength = num); i++) {
- statprint(-1, stats[i]);
statuses[i] = stats[i];
+ statprint(-1, stats[i]);
}
}
@@ -64,7 +66,7 @@ extern void setstatus(pid_t pid, int i) {
/* print a message if termination was with a signal, and if the child dumped core. exit on error if -e is set */
-extern void statprint(pid_t pid, int i) {
+static void statprint(pid_t pid, int i) {
if (WIFSIGNALED(i)) {
int t = WTERMSIG(i);
char *msg = ((t > 0) && (t < NUMOFSIGNALS) ? signals[WTERMSIG(i)].msg : "");