aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2015-10-09 15:40:13 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2015-10-09 15:40:13 +0200
commit4700fb5bead95d6457b943351b7dc6f49a09683e (patch)
tree0404ca4516d152f92e5655cf5ef4eeb9d78413d1
parente1603156ff96672375970f460716d37a50c63fae (diff)
downloadbusybox-w32-4700fb5bead95d6457b943351b7dc6f49a09683e.tar.gz
busybox-w32-4700fb5bead95d6457b943351b7dc6f49a09683e.tar.bz2
busybox-w32-4700fb5bead95d6457b943351b7dc6f49a09683e.zip
ash: make dowait() a bit more readable. Logic is unchanged
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--shell/ash.c58
1 files changed, 27 insertions, 31 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 7d20b8860..38ff4b62e 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -3919,19 +3919,15 @@ sprint_status48(char *s, int status, int sigonly)
3919 3919
3920 col = 0; 3920 col = 0;
3921 if (!WIFEXITED(status)) { 3921 if (!WIFEXITED(status)) {
3922#if JOBS 3922 if (JOBS && WIFSTOPPED(status))
3923 if (WIFSTOPPED(status))
3924 st = WSTOPSIG(status); 3923 st = WSTOPSIG(status);
3925 else 3924 else
3926#endif
3927 st = WTERMSIG(status); 3925 st = WTERMSIG(status);
3928 if (sigonly) { 3926 if (sigonly) {
3929 if (st == SIGINT || st == SIGPIPE) 3927 if (st == SIGINT || st == SIGPIPE)
3930 goto out; 3928 goto out;
3931#if JOBS 3929 if (JOBS && WIFSTOPPED(status))
3932 if (WIFSTOPPED(status))
3933 goto out; 3930 goto out;
3934#endif
3935 } 3931 }
3936 st &= 0x7f; 3932 st &= 0x7f;
3937//TODO: use bbox's get_signame? strsignal adds ~600 bytes to text+rodata 3933//TODO: use bbox's get_signame? strsignal adds ~600 bytes to text+rodata
@@ -3955,7 +3951,6 @@ dowait(int wait_flags, struct job *job)
3955 int status; 3951 int status;
3956 struct job *jp; 3952 struct job *jp;
3957 struct job *thisjob; 3953 struct job *thisjob;
3958 int state;
3959 3954
3960 TRACE(("dowait(0x%x) called\n", wait_flags)); 3955 TRACE(("dowait(0x%x) called\n", wait_flags));
3961 3956
@@ -3973,11 +3968,12 @@ dowait(int wait_flags, struct job *job)
3973 INT_OFF; 3968 INT_OFF;
3974 thisjob = NULL; 3969 thisjob = NULL;
3975 for (jp = curjob; jp; jp = jp->prev_job) { 3970 for (jp = curjob; jp; jp = jp->prev_job) {
3971 int jobstate;
3976 struct procstat *ps; 3972 struct procstat *ps;
3977 struct procstat *psend; 3973 struct procstat *psend;
3978 if (jp->state == JOBDONE) 3974 if (jp->state == JOBDONE)
3979 continue; 3975 continue;
3980 state = JOBDONE; 3976 jobstate = JOBDONE;
3981 ps = jp->ps; 3977 ps = jp->ps;
3982 psend = ps + jp->nprocs; 3978 psend = ps + jp->nprocs;
3983 do { 3979 do {
@@ -3989,41 +3985,41 @@ dowait(int wait_flags, struct job *job)
3989 thisjob = jp; 3985 thisjob = jp;
3990 } 3986 }
3991 if (ps->ps_status == -1) 3987 if (ps->ps_status == -1)
3992 state = JOBRUNNING; 3988 jobstate = JOBRUNNING;
3993#if JOBS 3989#if JOBS
3994 if (state == JOBRUNNING) 3990 if (jobstate == JOBRUNNING)
3995 continue; 3991 continue;
3996 if (WIFSTOPPED(ps->ps_status)) { 3992 if (WIFSTOPPED(ps->ps_status)) {
3997 jp->stopstatus = ps->ps_status; 3993 jp->stopstatus = ps->ps_status;
3998 state = JOBSTOPPED; 3994 jobstate = JOBSTOPPED;
3999 } 3995 }
4000#endif 3996#endif
4001 } while (++ps < psend); 3997 } while (++ps < psend);
4002 if (thisjob) 3998 if (!thisjob)
4003 goto gotjob; 3999 continue;
4004 }
4005#if JOBS
4006 if (!WIFSTOPPED(status))
4007#endif
4008 jobless--;
4009 goto out;
4010
4011 gotjob:
4012 if (state != JOBRUNNING) {
4013 thisjob->changed = 1;
4014 4000
4015 if (thisjob->state != state) { 4001 /* Found the job where one of its processes changed its state.
4016 TRACE(("Job %d: changing state from %d to %d\n", 4002 * Is there at least one live and running process in this job? */
4017 jobno(thisjob), thisjob->state, state)); 4003 if (jobstate != JOBRUNNING) {
4018 thisjob->state = state; 4004 /* No. All live processes in the job are stopped
4005 * (JOBSTOPPED) or there are no live processes (JOBDONE)
4006 */
4007 thisjob->changed = 1;
4008 if (thisjob->state != jobstate) {
4009 TRACE(("Job %d: changing state from %d to %d\n",
4010 jobno(thisjob), thisjob->state, jobstate));
4011 thisjob->state = jobstate;
4019#if JOBS 4012#if JOBS
4020 if (state == JOBSTOPPED) { 4013 if (jobstate == JOBSTOPPED)
4021 set_curjob(thisjob, CUR_STOPPED); 4014 set_curjob(thisjob, CUR_STOPPED);
4022 }
4023#endif 4015#endif
4016 }
4024 } 4017 }
4018 goto out;
4025 } 4019 }
4026 4020 /* The process wasn't found in job list */
4021 if (JOBS && !WIFSTOPPED(status))
4022 jobless--;
4027 out: 4023 out:
4028 INT_ON; 4024 INT_ON;
4029 4025