← Commit list

8d5f465a2

Denys Vlasenko
Denys Vlasenko
2020-09-29
SUCCESS Duration: 149s

Subject

ash: jobs: Fix infinite loop in waitproc

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

shell/ash.c+19 -6
@@ -4453,15 +4453,28 @@ waitone(int block, struct job *job)
static int
dowait(int block, struct job *jp)
{
- int pid = block == DOWAIT_NONBLOCK ? got_sigchld : 1;
+ smallint gotchld = *(volatile smallint *)&got_sigchld;
+ int rpid;
+ int pid;
+
+ if (jp && jp->state != JOBRUNNING)
+ block = DOWAIT_NONBLOCK;
+
+ if (block == DOWAIT_NONBLOCK && !gotchld)
+ return 1;
+
+ rpid = 1;
- while (jp ? jp->state == JOBRUNNING : pid > 0) {
- if (!jp)
- got_sigchld = 0;
+ do {
+ got_sigchld = 0;
pid = waitone(block, jp);
- }
+ rpid &= !!pid;
- return pid;
+ if (!pid || (jp && jp->state != JOBRUNNING))
+ block = DOWAIT_NONBLOCK;
+ } while (pid >= 0);
+
+ return rpid;
}
#if JOBS