svn commit: trunk/busybox/shell
vda at busybox.net
vda at busybox.net
Tue Jan 29 09:23:50 UTC 2008
Author: vda
Date: 2008-01-29 01:23:49 -0800 (Tue, 29 Jan 2008)
New Revision: 20919
Log:
ash: code readability enhancements, no real code changes
Modified:
trunk/busybox/shell/ash.c
Changeset:
Modified: trunk/busybox/shell/ash.c
===================================================================
--- trunk/busybox/shell/ash.c 2008-01-29 00:59:15 UTC (rev 20918)
+++ trunk/busybox/shell/ash.c 2008-01-29 09:23:49 UTC (rev 20919)
@@ -229,7 +229,7 @@
/*
* 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
* more fun than worrying about efficiency and portability. :-))
*/
@@ -272,10 +272,10 @@
sigset_t mask;
intpending = 0;
- /* Signal is not automatically re-enabled after it is raised,
- * do it ourself */
+ /* Signal is not automatically unmasked after it is raised,
+ * do it ourself - unmask all signals */
sigemptyset(&mask);
- sigprocmask(SIG_SETMASK, &mask, 0);
+ sigprocmask(SIG_SETMASK, &mask, NULL);
/* pendingsig = 0; - now done in onsig() */
i = EXSIG;
@@ -3337,8 +3337,8 @@
#define CUR_STOPPED 0
/* mode flags for dowait */
-#define DOWAIT_NORMAL 0
-#define DOWAIT_BLOCK 1
+#define DOWAIT_NONBLOCK WNOHANG
+#define DOWAIT_BLOCK 0
#if JOBS
/* pgrp of shell on invocation */
@@ -3584,7 +3584,7 @@
fd = ttyfd;
pgrp = initialpgrp;
/* was xtcsetpgrp, but this can make exiting ash
- * with pty already deleted loop forever */
+ * loop forever if pty is already deleted */
tcsetpgrp(fd, pgrp);
setpgid(0, pgrp);
setsignal(SIGTSTP);
@@ -3757,24 +3757,20 @@
* and the jobs command may give out of date information.
*/
static int
-waitproc(int block, int *status)
+waitproc(int wait_flags, int *status)
{
- int flags = 0;
-
#if JOBS
if (jobctl)
- flags |= WUNTRACED;
+ wait_flags |= WUNTRACED;
#endif
- if (block == 0)
- flags |= WNOHANG;
- return waitpid(-1, status, flags); // safe_waitpid?
+ return waitpid(-1, status, wait_flags); // safe_waitpid?
}
/*
* Wait for a process to terminate.
*/
static int
-dowait(int block, struct job *job)
+dowait(int wait_flags, struct job *job)
{
int pid;
int status;
@@ -3782,9 +3778,9 @@
struct job *thisjob;
int state;
- TRACE(("dowait(%d) called\n", block));
- pid = waitproc(block, &status);
- TRACE(("wait returns pid %d, status=%d\n", pid, status));
+ TRACE(("dowait(%d) called\n", wait_flags));
+ pid = waitproc(wait_flags, &status);
+ TRACE(("wait returns pid=%d, status=%d\n", pid, status));
if (pid <= 0)
return pid;
INT_OFF;
@@ -3822,7 +3818,6 @@
#if JOBS
if (!WIFSTOPPED(status))
#endif
-
jobless--;
goto out;
@@ -3852,7 +3847,7 @@
len = sprint_status(s, status, 1);
if (len) {
s[len] = '\n';
- s[len + 1] = 0;
+ s[len + 1] = '\0';
out2str(s);
}
}
@@ -3938,8 +3933,8 @@
TRACE(("showjobs(%x) called\n", mode));
- /* If not even one one job changed, there is nothing to do */
- while (dowait(DOWAIT_NORMAL, NULL) > 0)
+ /* If not even one job changed, there is nothing to do */
+ while (dowait(DOWAIT_NONBLOCK, NULL) > 0)
continue;
for (jp = curjob; jp; jp = jp->prev_job) {
@@ -4029,7 +4024,7 @@
jp->waited = 1;
jp = jp->prev_job;
}
- dowait(DOWAIT_BLOCK, 0);
+ dowait(DOWAIT_BLOCK, NULL);
}
}
@@ -4038,20 +4033,18 @@
if (**argv != '%') {
pid_t pid = number(*argv);
job = curjob;
- goto start;
- do {
+ while (1) {
+ if (!job)
+ goto repeat;
if (job->ps[job->nprocs - 1].pid == pid)
break;
job = job->prev_job;
- start:
- if (!job)
- goto repeat;
- } while (1);
+ }
} else
job = getjob(*argv, 0);
/* loop until process terminated or stopped */
while (job->state == JOBRUNNING)
- dowait(DOWAIT_BLOCK, 0);
+ dowait(DOWAIT_BLOCK, NULL);
job->waited = 1;
retval = getstatus(job);
repeat:
@@ -4526,7 +4519,8 @@
{
TRACE(("In parent shell: child = %d\n", pid));
if (!jp) {
- while (jobless && dowait(DOWAIT_NORMAL, 0) > 0);
+ while (jobless && dowait(DOWAIT_NONBLOCK, NULL) > 0)
+ continue;
jobless++;
return;
}
More information about the busybox-cvs
mailing list