summaryrefslogtreecommitdiffhomepage
path: root/shell/ash.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-07-14 18:45:37 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-07-14 18:45:37 +0000
commitfcfaf2e18aba06dd90b16958ecfbfcfbf59ceb02 (patch)
treec77e8166667f208fb5a106ea0dff7052831b1fa6 /shell/ash.c
parent8fdc4b7b06ada63a2572f8aff92e8810e52ae841 (diff)
ash: small size optimization
function old new delta makejob 263 270 +7 setjobctl 328 332 +4 jobscmd 96 94 -2 stoppedjobs 53 50 -3 jobctl 4 1 -3 job_warning 4 1 -3 forkshell 644 641 -3 cmdloop 422 409 -13 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/6 up/down: 11/-27) Total: -16 bytes text data bss dec hex filename 675392 2740 13968 692100 a8f84 busybox_old 675380 2740 13968 692088 a8f78 busybox_unstripped
Diffstat (limited to 'shell/ash.c')
-rw-r--r--shell/ash.c66
1 files changed, 33 insertions, 33 deletions
diff --git a/shell/ash.c b/shell/ash.c
index ccb1e1a58..6173a2505 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -3141,20 +3141,18 @@ struct job {
};
static pid_t backgndpid; /* pid of last background process */
-static int job_warning; /* user was warned about stopped jobs */
-#if JOBS
-static int jobctl; /* true if doing job control */
-#endif
+static smallint job_warning; /* user was warned about stopped jobs (can be 2, 1 or 0). */
static struct job *makejob(union node *, int);
static int forkshell(struct job *, union node *, int);
static int waitforjob(struct job *);
-#if ! JOBS
-#define setjobctl(on) /* do nothing */
+#if !JOBS
+enum { jobctl = 0 };
+#define setjobctl(on) do {} while (0)
#else
+static smallint jobctl; /* true if doing job control */
static void setjobctl(int);
-static void showjobs(FILE *, int);
#endif
/*
@@ -3836,11 +3834,32 @@ showjob(FILE *out, struct job *jp, int mode)
}
}
+/*
+ * Print a list of jobs. If "change" is nonzero, only print jobs whose
+ * statuses have changed since the last call to showjobs.
+ */
+static void
+showjobs(FILE *out, int mode)
+{
+ struct job *jp;
+
+ TRACE(("showjobs(%x) called\n", mode));
+
+ /* If not even one one job changed, there is nothing to do */
+ while (dowait(DOWAIT_NORMAL, NULL) > 0)
+ continue;
+
+ for (jp = curjob; jp; jp = jp->prev_job) {
+ if (!(mode & SHOW_CHANGED) || jp->changed) {
+ showjob(out, jp, mode);
+ }
+ }
+}
+
static int
jobscmd(int argc, char **argv)
{
int mode, m;
- FILE *out;
mode = 0;
while ((m = nextopt("lp"))) {
@@ -3850,38 +3869,16 @@ jobscmd(int argc, char **argv)
mode = SHOW_PGID;
}
- out = stdout;
argv = argptr;
if (*argv) {
do
- showjob(out, getjob(*argv,0), mode);
+ showjob(stdout, getjob(*argv,0), mode);
while (*++argv);
} else
- showjobs(out, mode);
+ showjobs(stdout, mode);
return 0;
}
-
-/*
- * Print a list of jobs. If "change" is nonzero, only print jobs whose
- * statuses have changed since the last call to showjobs.
- */
-static void
-showjobs(FILE *out, int mode)
-{
- struct job *jp;
-
- TRACE(("showjobs(%x) called\n", mode));
-
- /* If not even one one job changed, there is nothing to do */
- while (dowait(DOWAIT_NORMAL, NULL) > 0)
- continue;
-
- for (jp = curjob; jp; jp = jp->prev_job) {
- if (!(mode & SHOW_CHANGED) || jp->changed)
- showjob(out, jp, mode);
- }
-}
#endif /* JOBS */
static int
@@ -4043,6 +4040,8 @@ makejob(union node *node, int nprocs)
}
memset(jp, 0, sizeof(*jp));
#if JOBS
+ /* jp->jobctl is a bitfield.
+ * "jp->jobctl |= jobctl" likely to give awful code */
if (jobctl)
jp->jobctl = 1;
#endif
@@ -10883,7 +10882,8 @@ cmdloop(int top)
}
numeof++;
} else if (nflag == 0) {
- job_warning = (job_warning == 2) ? 1 : 0;
+ /* job_warning can only be 2,1,0. Here 2->1, 1/0->0 */
+ job_warning >>= 1;
numeof = 0;
evaltree(n, 0);
}