diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-01-29 09:23:49 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-01-29 09:23:49 +0000 |
commit | 36fc3cd8bc4c09b3c4e7008eee093c9263c438a5 (patch) | |
tree | a851d97b0bcbc4eecd62b754aa09ed0915791389 /shell/ash.c | |
parent | ddd42cb064b157a2a5d61a922a6ce95ea2f3e4be (diff) | |
download | busybox-w32-36fc3cd8bc4c09b3c4e7008eee093c9263c438a5.tar.gz busybox-w32-36fc3cd8bc4c09b3c4e7008eee093c9263c438a5.tar.bz2 busybox-w32-36fc3cd8bc4c09b3c4e7008eee093c9263c438a5.zip |
ash: code readability enhancements, no real code changes
Diffstat (limited to 'shell/ash.c')
-rw-r--r-- | shell/ash.c | 56 |
1 files changed, 25 insertions, 31 deletions
diff --git a/shell/ash.c b/shell/ash.c index 2a9e96a35..ffa401936 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -229,7 +229,7 @@ static struct globals_misc *const ptr_to_globals_misc __attribute__ ((section (" | |||
229 | 229 | ||
230 | /* | 230 | /* |
231 | * These macros allow the user to suspend the handling of interrupt signals | 231 | * These macros allow the user to suspend the handling of interrupt signals |
232 | * over a period of time. This is similar to SIGHOLD to or sigblock, but | 232 | * over a period of time. This is similar to SIGHOLD or to sigblock, but |
233 | * much more efficient and portable. (But hacking the kernel is so much | 233 | * much more efficient and portable. (But hacking the kernel is so much |
234 | * more fun than worrying about efficiency and portability. :-)) | 234 | * more fun than worrying about efficiency and portability. :-)) |
235 | */ | 235 | */ |
@@ -272,10 +272,10 @@ raise_interrupt(void) | |||
272 | sigset_t mask; | 272 | sigset_t mask; |
273 | 273 | ||
274 | intpending = 0; | 274 | intpending = 0; |
275 | /* Signal is not automatically re-enabled after it is raised, | 275 | /* Signal is not automatically unmasked after it is raised, |
276 | * do it ourself */ | 276 | * do it ourself - unmask all signals */ |
277 | sigemptyset(&mask); | 277 | sigemptyset(&mask); |
278 | sigprocmask(SIG_SETMASK, &mask, 0); | 278 | sigprocmask(SIG_SETMASK, &mask, NULL); |
279 | /* pendingsig = 0; - now done in onsig() */ | 279 | /* pendingsig = 0; - now done in onsig() */ |
280 | 280 | ||
281 | i = EXSIG; | 281 | i = EXSIG; |
@@ -3337,8 +3337,8 @@ setsignal(int signo) | |||
3337 | #define CUR_STOPPED 0 | 3337 | #define CUR_STOPPED 0 |
3338 | 3338 | ||
3339 | /* mode flags for dowait */ | 3339 | /* mode flags for dowait */ |
3340 | #define DOWAIT_NORMAL 0 | 3340 | #define DOWAIT_NONBLOCK WNOHANG |
3341 | #define DOWAIT_BLOCK 1 | 3341 | #define DOWAIT_BLOCK 0 |
3342 | 3342 | ||
3343 | #if JOBS | 3343 | #if JOBS |
3344 | /* pgrp of shell on invocation */ | 3344 | /* pgrp of shell on invocation */ |
@@ -3584,7 +3584,7 @@ setjobctl(int on) | |||
3584 | fd = ttyfd; | 3584 | fd = ttyfd; |
3585 | pgrp = initialpgrp; | 3585 | pgrp = initialpgrp; |
3586 | /* was xtcsetpgrp, but this can make exiting ash | 3586 | /* was xtcsetpgrp, but this can make exiting ash |
3587 | * with pty already deleted loop forever */ | 3587 | * loop forever if pty is already deleted */ |
3588 | tcsetpgrp(fd, pgrp); | 3588 | tcsetpgrp(fd, pgrp); |
3589 | setpgid(0, pgrp); | 3589 | setpgid(0, pgrp); |
3590 | setsignal(SIGTSTP); | 3590 | setsignal(SIGTSTP); |
@@ -3757,24 +3757,20 @@ sprint_status(char *s, int status, int sigonly) | |||
3757 | * and the jobs command may give out of date information. | 3757 | * and the jobs command may give out of date information. |
3758 | */ | 3758 | */ |
3759 | static int | 3759 | static int |
3760 | waitproc(int block, int *status) | 3760 | waitproc(int wait_flags, int *status) |
3761 | { | 3761 | { |
3762 | int flags = 0; | ||
3763 | |||
3764 | #if JOBS | 3762 | #if JOBS |
3765 | if (jobctl) | 3763 | if (jobctl) |
3766 | flags |= WUNTRACED; | 3764 | wait_flags |= WUNTRACED; |
3767 | #endif | 3765 | #endif |
3768 | if (block == 0) | 3766 | return waitpid(-1, status, wait_flags); // safe_waitpid? |
3769 | flags |= WNOHANG; | ||
3770 | return waitpid(-1, status, flags); // safe_waitpid? | ||
3771 | } | 3767 | } |
3772 | 3768 | ||
3773 | /* | 3769 | /* |
3774 | * Wait for a process to terminate. | 3770 | * Wait for a process to terminate. |
3775 | */ | 3771 | */ |
3776 | static int | 3772 | static int |
3777 | dowait(int block, struct job *job) | 3773 | dowait(int wait_flags, struct job *job) |
3778 | { | 3774 | { |
3779 | int pid; | 3775 | int pid; |
3780 | int status; | 3776 | int status; |
@@ -3782,9 +3778,9 @@ dowait(int block, struct job *job) | |||
3782 | struct job *thisjob; | 3778 | struct job *thisjob; |
3783 | int state; | 3779 | int state; |
3784 | 3780 | ||
3785 | TRACE(("dowait(%d) called\n", block)); | 3781 | TRACE(("dowait(%d) called\n", wait_flags)); |
3786 | pid = waitproc(block, &status); | 3782 | pid = waitproc(wait_flags, &status); |
3787 | TRACE(("wait returns pid %d, status=%d\n", pid, status)); | 3783 | TRACE(("wait returns pid=%d, status=%d\n", pid, status)); |
3788 | if (pid <= 0) | 3784 | if (pid <= 0) |
3789 | return pid; | 3785 | return pid; |
3790 | INT_OFF; | 3786 | INT_OFF; |
@@ -3822,7 +3818,6 @@ dowait(int block, struct job *job) | |||
3822 | #if JOBS | 3818 | #if JOBS |
3823 | if (!WIFSTOPPED(status)) | 3819 | if (!WIFSTOPPED(status)) |
3824 | #endif | 3820 | #endif |
3825 | |||
3826 | jobless--; | 3821 | jobless--; |
3827 | goto out; | 3822 | goto out; |
3828 | 3823 | ||
@@ -3852,7 +3847,7 @@ dowait(int block, struct job *job) | |||
3852 | len = sprint_status(s, status, 1); | 3847 | len = sprint_status(s, status, 1); |
3853 | if (len) { | 3848 | if (len) { |
3854 | s[len] = '\n'; | 3849 | s[len] = '\n'; |
3855 | s[len + 1] = 0; | 3850 | s[len + 1] = '\0'; |
3856 | out2str(s); | 3851 | out2str(s); |
3857 | } | 3852 | } |
3858 | } | 3853 | } |
@@ -3938,8 +3933,8 @@ showjobs(FILE *out, int mode) | |||
3938 | 3933 | ||
3939 | TRACE(("showjobs(%x) called\n", mode)); | 3934 | TRACE(("showjobs(%x) called\n", mode)); |
3940 | 3935 | ||
3941 | /* If not even one one job changed, there is nothing to do */ | 3936 | /* If not even one job changed, there is nothing to do */ |
3942 | while (dowait(DOWAIT_NORMAL, NULL) > 0) | 3937 | while (dowait(DOWAIT_NONBLOCK, NULL) > 0) |
3943 | continue; | 3938 | continue; |
3944 | 3939 | ||
3945 | for (jp = curjob; jp; jp = jp->prev_job) { | 3940 | for (jp = curjob; jp; jp = jp->prev_job) { |
@@ -4029,7 +4024,7 @@ waitcmd(int argc, char **argv) | |||
4029 | jp->waited = 1; | 4024 | jp->waited = 1; |
4030 | jp = jp->prev_job; | 4025 | jp = jp->prev_job; |
4031 | } | 4026 | } |
4032 | dowait(DOWAIT_BLOCK, 0); | 4027 | dowait(DOWAIT_BLOCK, NULL); |
4033 | } | 4028 | } |
4034 | } | 4029 | } |
4035 | 4030 | ||
@@ -4038,20 +4033,18 @@ waitcmd(int argc, char **argv) | |||
4038 | if (**argv != '%') { | 4033 | if (**argv != '%') { |
4039 | pid_t pid = number(*argv); | 4034 | pid_t pid = number(*argv); |
4040 | job = curjob; | 4035 | job = curjob; |
4041 | goto start; | 4036 | while (1) { |
4042 | do { | 4037 | if (!job) |
4038 | goto repeat; | ||
4043 | if (job->ps[job->nprocs - 1].pid == pid) | 4039 | if (job->ps[job->nprocs - 1].pid == pid) |
4044 | break; | 4040 | break; |
4045 | job = job->prev_job; | 4041 | job = job->prev_job; |
4046 | start: | 4042 | } |
4047 | if (!job) | ||
4048 | goto repeat; | ||
4049 | } while (1); | ||
4050 | } else | 4043 | } else |
4051 | job = getjob(*argv, 0); | 4044 | job = getjob(*argv, 0); |
4052 | /* loop until process terminated or stopped */ | 4045 | /* loop until process terminated or stopped */ |
4053 | while (job->state == JOBRUNNING) | 4046 | while (job->state == JOBRUNNING) |
4054 | dowait(DOWAIT_BLOCK, 0); | 4047 | dowait(DOWAIT_BLOCK, NULL); |
4055 | job->waited = 1; | 4048 | job->waited = 1; |
4056 | retval = getstatus(job); | 4049 | retval = getstatus(job); |
4057 | repeat: | 4050 | repeat: |
@@ -4526,7 +4519,8 @@ forkparent(struct job *jp, union node *n, int mode, pid_t pid) | |||
4526 | { | 4519 | { |
4527 | TRACE(("In parent shell: child = %d\n", pid)); | 4520 | TRACE(("In parent shell: child = %d\n", pid)); |
4528 | if (!jp) { | 4521 | if (!jp) { |
4529 | while (jobless && dowait(DOWAIT_NORMAL, 0) > 0); | 4522 | while (jobless && dowait(DOWAIT_NONBLOCK, NULL) > 0) |
4523 | continue; | ||
4530 | jobless++; | 4524 | jobless++; |
4531 | return; | 4525 | return; |
4532 | } | 4526 | } |