aboutsummaryrefslogtreecommitdiff
path: root/toys/other
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2019-09-13 15:33:04 -0700
committerRob Landley <rob@landley.net>2019-09-13 21:11:45 -0500
commit38509d0e217d57d9b7fb18727bd02277cd205566 (patch)
tree500d34b67fe16b9473bd042e1486b2e0006abd85 /toys/other
parentdd155a3ba5aae70c0bc0590fd82ed5d7e3a76a22 (diff)
downloadtoybox-38509d0e217d57d9b7fb18727bd02277cd205566.tar.gz
timeout: fix exit status for sneaky subprocesses.
There's nothing to stop a subprocess from catching our SIGTERM on timeout and exiting, causing us to incorrectly report that it didn't time out. Android's ART has a utility that does exactly this. Explicitly catch this case, and add corresponding tests. Bug: http://b/141007616
Diffstat (limited to 'toys/other')
-rw-r--r--toys/other/timeout.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/toys/other/timeout.c b/toys/other/timeout.c
index dc48f55b..69b4995b 100644
--- a/toys/other/timeout.c
+++ b/toys/other/timeout.c
@@ -35,6 +35,7 @@ GLOBALS(
pid_t pid;
struct timeval ktv;
struct itimerval itv;
+ int signaled;
)
static void handler(int i)
@@ -43,6 +44,7 @@ static void handler(int i)
fprintf(stderr, "timeout pid %d signal %d\n", TT.pid, TT.nextsig);
kill(TT.pid, TT.nextsig);
+ if (TT.nextsig != SIGKILL) TT.signaled++;
if (TT.k) {
TT.k = 0;
@@ -88,5 +90,8 @@ void timeout_main(void)
if (WIFEXITED(status)) toys.exitval = WEXITSTATUS(status);
else if (WTERMSIG(status)==SIGKILL) toys.exitval = 137;
else toys.exitval = FLAG(preserve_status) ? 128+WTERMSIG(status) : 124;
+
+ // This is visible if the subprocess catches our timeout signal and exits.
+ if (TT.signaled && !FLAG(preserve_status)) toys.exitval = 124;
}
}