ash: code readability enhancements, no real code changes
This commit is contained in:
parent
ddd42cb064
commit
36fc3cd8bc
56
shell/ash.c
56
shell/ash.c
@ -229,7 +229,7 @@ static struct globals_misc *const ptr_to_globals_misc __attribute__ ((section ("
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* These macros allow the user to suspend the handling of interrupt signals
|
* These macros allow the user to suspend the handling of interrupt signals
|
||||||
* over a period of time. This is similar to SIGHOLD to or sigblock, but
|
* over a period of time. This is similar to SIGHOLD or to sigblock, but
|
||||||
* much more efficient and portable. (But hacking the kernel is so much
|
* much more efficient and portable. (But hacking the kernel is so much
|
||||||
* more fun than worrying about efficiency and portability. :-))
|
* more fun than worrying about efficiency and portability. :-))
|
||||||
*/
|
*/
|
||||||
@ -272,10 +272,10 @@ raise_interrupt(void)
|
|||||||
sigset_t mask;
|
sigset_t mask;
|
||||||
|
|
||||||
intpending = 0;
|
intpending = 0;
|
||||||
/* Signal is not automatically re-enabled after it is raised,
|
/* Signal is not automatically unmasked after it is raised,
|
||||||
* do it ourself */
|
* do it ourself - unmask all signals */
|
||||||
sigemptyset(&mask);
|
sigemptyset(&mask);
|
||||||
sigprocmask(SIG_SETMASK, &mask, 0);
|
sigprocmask(SIG_SETMASK, &mask, NULL);
|
||||||
/* pendingsig = 0; - now done in onsig() */
|
/* pendingsig = 0; - now done in onsig() */
|
||||||
|
|
||||||
i = EXSIG;
|
i = EXSIG;
|
||||||
@ -3337,8 +3337,8 @@ setsignal(int signo)
|
|||||||
#define CUR_STOPPED 0
|
#define CUR_STOPPED 0
|
||||||
|
|
||||||
/* mode flags for dowait */
|
/* mode flags for dowait */
|
||||||
#define DOWAIT_NORMAL 0
|
#define DOWAIT_NONBLOCK WNOHANG
|
||||||
#define DOWAIT_BLOCK 1
|
#define DOWAIT_BLOCK 0
|
||||||
|
|
||||||
#if JOBS
|
#if JOBS
|
||||||
/* pgrp of shell on invocation */
|
/* pgrp of shell on invocation */
|
||||||
@ -3584,7 +3584,7 @@ setjobctl(int on)
|
|||||||
fd = ttyfd;
|
fd = ttyfd;
|
||||||
pgrp = initialpgrp;
|
pgrp = initialpgrp;
|
||||||
/* was xtcsetpgrp, but this can make exiting ash
|
/* was xtcsetpgrp, but this can make exiting ash
|
||||||
* with pty already deleted loop forever */
|
* loop forever if pty is already deleted */
|
||||||
tcsetpgrp(fd, pgrp);
|
tcsetpgrp(fd, pgrp);
|
||||||
setpgid(0, pgrp);
|
setpgid(0, pgrp);
|
||||||
setsignal(SIGTSTP);
|
setsignal(SIGTSTP);
|
||||||
@ -3757,24 +3757,20 @@ sprint_status(char *s, int status, int sigonly)
|
|||||||
* and the jobs command may give out of date information.
|
* and the jobs command may give out of date information.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
waitproc(int block, int *status)
|
waitproc(int wait_flags, int *status)
|
||||||
{
|
{
|
||||||
int flags = 0;
|
|
||||||
|
|
||||||
#if JOBS
|
#if JOBS
|
||||||
if (jobctl)
|
if (jobctl)
|
||||||
flags |= WUNTRACED;
|
wait_flags |= WUNTRACED;
|
||||||
#endif
|
#endif
|
||||||
if (block == 0)
|
return waitpid(-1, status, wait_flags); // safe_waitpid?
|
||||||
flags |= WNOHANG;
|
|
||||||
return waitpid(-1, status, flags); // safe_waitpid?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Wait for a process to terminate.
|
* Wait for a process to terminate.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
dowait(int block, struct job *job)
|
dowait(int wait_flags, struct job *job)
|
||||||
{
|
{
|
||||||
int pid;
|
int pid;
|
||||||
int status;
|
int status;
|
||||||
@ -3782,9 +3778,9 @@ dowait(int block, struct job *job)
|
|||||||
struct job *thisjob;
|
struct job *thisjob;
|
||||||
int state;
|
int state;
|
||||||
|
|
||||||
TRACE(("dowait(%d) called\n", block));
|
TRACE(("dowait(%d) called\n", wait_flags));
|
||||||
pid = waitproc(block, &status);
|
pid = waitproc(wait_flags, &status);
|
||||||
TRACE(("wait returns pid %d, status=%d\n", pid, status));
|
TRACE(("wait returns pid=%d, status=%d\n", pid, status));
|
||||||
if (pid <= 0)
|
if (pid <= 0)
|
||||||
return pid;
|
return pid;
|
||||||
INT_OFF;
|
INT_OFF;
|
||||||
@ -3822,7 +3818,6 @@ dowait(int block, struct job *job)
|
|||||||
#if JOBS
|
#if JOBS
|
||||||
if (!WIFSTOPPED(status))
|
if (!WIFSTOPPED(status))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
jobless--;
|
jobless--;
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
@ -3852,7 +3847,7 @@ dowait(int block, struct job *job)
|
|||||||
len = sprint_status(s, status, 1);
|
len = sprint_status(s, status, 1);
|
||||||
if (len) {
|
if (len) {
|
||||||
s[len] = '\n';
|
s[len] = '\n';
|
||||||
s[len + 1] = 0;
|
s[len + 1] = '\0';
|
||||||
out2str(s);
|
out2str(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3938,8 +3933,8 @@ showjobs(FILE *out, int mode)
|
|||||||
|
|
||||||
TRACE(("showjobs(%x) called\n", mode));
|
TRACE(("showjobs(%x) called\n", mode));
|
||||||
|
|
||||||
/* If not even one one job changed, there is nothing to do */
|
/* If not even one job changed, there is nothing to do */
|
||||||
while (dowait(DOWAIT_NORMAL, NULL) > 0)
|
while (dowait(DOWAIT_NONBLOCK, NULL) > 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (jp = curjob; jp; jp = jp->prev_job) {
|
for (jp = curjob; jp; jp = jp->prev_job) {
|
||||||
@ -4029,7 +4024,7 @@ waitcmd(int argc, char **argv)
|
|||||||
jp->waited = 1;
|
jp->waited = 1;
|
||||||
jp = jp->prev_job;
|
jp = jp->prev_job;
|
||||||
}
|
}
|
||||||
dowait(DOWAIT_BLOCK, 0);
|
dowait(DOWAIT_BLOCK, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4038,20 +4033,18 @@ waitcmd(int argc, char **argv)
|
|||||||
if (**argv != '%') {
|
if (**argv != '%') {
|
||||||
pid_t pid = number(*argv);
|
pid_t pid = number(*argv);
|
||||||
job = curjob;
|
job = curjob;
|
||||||
goto start;
|
while (1) {
|
||||||
do {
|
if (!job)
|
||||||
|
goto repeat;
|
||||||
if (job->ps[job->nprocs - 1].pid == pid)
|
if (job->ps[job->nprocs - 1].pid == pid)
|
||||||
break;
|
break;
|
||||||
job = job->prev_job;
|
job = job->prev_job;
|
||||||
start:
|
}
|
||||||
if (!job)
|
|
||||||
goto repeat;
|
|
||||||
} while (1);
|
|
||||||
} else
|
} else
|
||||||
job = getjob(*argv, 0);
|
job = getjob(*argv, 0);
|
||||||
/* loop until process terminated or stopped */
|
/* loop until process terminated or stopped */
|
||||||
while (job->state == JOBRUNNING)
|
while (job->state == JOBRUNNING)
|
||||||
dowait(DOWAIT_BLOCK, 0);
|
dowait(DOWAIT_BLOCK, NULL);
|
||||||
job->waited = 1;
|
job->waited = 1;
|
||||||
retval = getstatus(job);
|
retval = getstatus(job);
|
||||||
repeat:
|
repeat:
|
||||||
@ -4526,7 +4519,8 @@ forkparent(struct job *jp, union node *n, int mode, pid_t pid)
|
|||||||
{
|
{
|
||||||
TRACE(("In parent shell: child = %d\n", pid));
|
TRACE(("In parent shell: child = %d\n", pid));
|
||||||
if (!jp) {
|
if (!jp) {
|
||||||
while (jobless && dowait(DOWAIT_NORMAL, 0) > 0);
|
while (jobless && dowait(DOWAIT_NONBLOCK, NULL) > 0)
|
||||||
|
continue;
|
||||||
jobless++;
|
jobless++;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user