From: Herbert Xu <herbert@gondor.apana.org.au>
To: Michael Biebl <biebl@debian.org>
Cc: Andrej Shadura <andrew.shadura@collabora.co.uk>,
dash@vger.kernel.org, 974705@bugs.debian.org
Subject: [PATCH] jobs: Only block in waitcmd on first run
Date: Wed, 2 Dec 2020 16:31:45 +1100 [thread overview]
Message-ID: <20201202053145.GA8074@gondor.apana.org.au> (raw)
In-Reply-To: <20201201232606.GA32382@gondor.apana.org.au>
This patch ensures that waitcmd never blocks unless there are
outstanding jobs. This could otherwise trigger a hang if children
were created prior to the shell coming into existence, or if
there are backgrounded children of other kinds (e.g., a here-
document).
Fixes: 6c691b3e5099 ("jobs: Only clear gotsigchld when waiting...")
Reported-by: Michael Biebl <biebl@debian.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
diff --git a/src/jobs.c b/src/jobs.c
index 3417633..516786f 100644
--- a/src/jobs.c
+++ b/src/jobs.c
@@ -81,6 +81,7 @@
#define DOWAIT_NONBLOCK 0
#define DOWAIT_BLOCK 1
#define DOWAIT_WAITCMD 2
+#define DOWAIT_WAITCMD_ALL 4
/* array of jobs */
static struct job *jobtab;
@@ -615,7 +616,7 @@ waitcmd(int argc, char **argv)
jp->waited = 1;
jp = jp->prev_job;
}
- if (!dowait(DOWAIT_WAITCMD, 0))
+ if (!dowait(DOWAIT_WAITCMD_ALL, 0))
goto sigout;
}
}
@@ -1138,6 +1139,7 @@ static int dowait(int block, struct job *jp)
pid = waitone(block, jp);
rpid &= !!pid;
+ block &= ~DOWAIT_WAITCMD_ALL;
if (!pid || (jp && jp->state != JOBRUNNING))
block = DOWAIT_NONBLOCK;
} while (pid >= 0);
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
next prev parent reply other threads:[~2020-12-02 5:32 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-16 10:29 Changes to job handling cause hangs in wait Andrej Shadura
2020-11-17 3:33 ` Herbert Xu
2020-12-01 5:38 ` Herbert Xu
2020-12-01 5:42 ` Herbert Xu
2020-12-01 6:06 ` Herbert Xu
2020-12-01 6:56 ` Herbert Xu
2020-12-01 23:21 ` Michael Biebl
2020-12-01 23:26 ` Herbert Xu
2020-12-02 5:31 ` Herbert Xu [this message]
2020-12-03 12:27 ` Michael Biebl
2020-12-07 3:55 ` Herbert Xu
2020-12-03 12:49 ` Michael Biebl
2020-12-01 10:14 ` Harald van Dijk
2020-12-01 10:34 ` Herbert Xu
2020-12-01 10:50 ` Harald van Dijk
2020-12-01 10:53 ` Herbert Xu
2020-12-01 10:55 ` Harald van Dijk
2020-12-01 10:56 ` Herbert Xu
2020-12-01 10:59 ` Harald van Dijk
2020-12-01 11:01 ` Herbert Xu
2020-12-01 13:04 ` Michael Biebl
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201202053145.GA8074@gondor.apana.org.au \
--to=herbert@gondor.apana.org.au \
--cc=974705@bugs.debian.org \
--cc=andrew.shadura@collabora.co.uk \
--cc=biebl@debian.org \
--cc=dash@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox