klibc-bot for Herbert Xu
2020-Mar-28 21:49 UTC
[klibc] [klibc:update-dash] dash: eval: Reap zombies after built-in commands and functions
Commit-ID: a33ea92e57007317a5c406626441029899e164e0 Gitweb: http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=a33ea92e57007317a5c406626441029899e164e0 Author: Herbert Xu <herbert at gondor.apana.org.au> AuthorDate: Mon, 26 Mar 2018 23:55:50 +0800 Committer: Ben Hutchings <ben at decadent.org.uk> CommitDate: Sat, 28 Mar 2020 21:42:54 +0000 [klibc] dash: eval: Reap zombies after built-in commands and functions [ dash commit 03876c0743a50984b0aae69bba6f5034dc38aec1 ] Currently dash does not reap dead children after built-in commands or functions. This means that if you construct a loop consisting of solely built-in commands and functions, then zombies can hang around indefinitely. This patch fixes this by reaping when necessary after each built-in command and function. Reported-by: Denys Vlasenko <vda.linux at googlemail.com> Signed-off-by: Herbert Xu <herbert at gondor.apana.org.au> Signed-off-by: Ben Hutchings <ben at decadent.org.uk> --- usr/dash/eval.c | 11 ++++++----- usr/dash/jobs.c | 8 +++++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/usr/dash/eval.c b/usr/dash/eval.c index a679ba31..26055493 100644 --- a/usr/dash/eval.c +++ b/usr/dash/eval.c @@ -848,6 +848,8 @@ bail: goto out; } + jp = NULL; + /* Execute the command. */ switch (cmdentry.cmdtype) { default: @@ -856,7 +858,6 @@ bail: INTOFF; jp = makejob(cmd, 1); if (forkshell(jp, cmd, FORK_FG) != 0) { - status = waitforjob(jp); INTON; break; } @@ -875,22 +876,22 @@ bail: if (evalbltin(cmdentry.u.cmd, argc, argv, flags)) { if (exception == EXERROR && spclbltin <= 0) { FORCEINTON; - goto readstatus; + break; } raise: longjmp(handler->loc, 1); } - goto readstatus; + break; case CMDFUNCTION: poplocalvars(1); if (evalfun(cmdentry.u.func, argc, argv, flags)) goto raise; -readstatus: - status = exitstatus; break; } + status = waitforjob(jp); + out: if (cmd->ncmd.redirect) popredir(execcmd); diff --git a/usr/dash/jobs.c b/usr/dash/jobs.c index 333a2a22..3ea7e122 100644 --- a/usr/dash/jobs.c +++ b/usr/dash/jobs.c @@ -53,6 +53,7 @@ #include <termios.h> #undef CEOF /* syntax.h redefines this */ #endif +#include "eval.h" #include "redir.h" #include "show.h" #include "main.h" @@ -972,10 +973,11 @@ waitforjob(struct job *jp) { int st; - TRACE(("waitforjob(%%%d) called\n", jobno(jp))); - while (jp->state == JOBRUNNING) { + TRACE(("waitforjob(%%%d) called\n", jp ? jobno(jp) : 0)); + while ((jp && jp->state == JOBRUNNING) || gotsigchld) dowait(DOWAIT_BLOCK, jp); - } + if (!jp) + return exitstatus; st = getstatus(jp); #if JOBS if (jp->jobctl) {
Apparently Analagous Threads
- [klibc:update-dash] eval: Reap zombies after built-in commands and functions
- [klibc:update-dash] dash: jobs - Do not block when waiting on SIGCHLD
- [klibc:update-dash] jobs - Do not block when waiting on SIGCHLD
- [klibc:update-dash] dash: eval: Return status in eval functions
- [klibc:update-dash] dash: jobs: Only clear gotsigchld when waiting for everything