aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-07-10 10:01:12 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-07-10 10:01:12 +0200
commit9e55a156f8a07297f620466e8173040336a7c48c (patch)
tree5fa21ca9eb7c73ec7fa59ef31862e4028c2895a1
parent1609629a918f0e5c8813a113447347db61be7b74 (diff)
downloadbusybox-w32-9e55a156f8a07297f620466e8173040336a7c48c.tar.gz
busybox-w32-9e55a156f8a07297f620466e8173040336a7c48c.tar.bz2
busybox-w32-9e55a156f8a07297f620466e8173040336a7c48c.zip
hush: simplify insert_job_into_table() a bit
function old new delta done_word 767 761 -6 insert_job_into_table 325 264 -61 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 59/-126) Total: -67 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--shell/hush.c27
1 files changed, 12 insertions, 15 deletions
diff --git a/shell/hush.c b/shell/hush.c
index 3533dfaa4..8223cdbc5 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -3527,9 +3527,8 @@ static int reserved_word(o_string *word, struct parse_context *ctx)
3527 if (r->flag & FLAG_START) { 3527 if (r->flag & FLAG_START) {
3528 struct parse_context *old; 3528 struct parse_context *old;
3529 3529
3530 old = xmalloc(sizeof(*old)); 3530 old = xmemdup(ctx, sizeof(*ctx));
3531 debug_printf_parse("push stack %p\n", old); 3531 debug_printf_parse("push stack %p\n", old);
3532 *old = *ctx; /* physical copy */
3533 initialize_context(ctx); 3532 initialize_context(ctx);
3534 ctx->stack = old; 3533 ctx->stack = old;
3535 } else if (/*ctx->ctx_res_w == RES_NONE ||*/ !(ctx->old_flag & (1 << r->res))) { 3534 } else if (/*ctx->ctx_res_w == RES_NONE ||*/ !(ctx->old_flag & (1 << r->res))) {
@@ -7222,19 +7221,18 @@ static void insert_job_into_table(struct pipe *pi)
7222 struct pipe *job, **jobp; 7221 struct pipe *job, **jobp;
7223 int i; 7222 int i;
7224 7223
7225 /* Linear search for the ID of the job to use */ 7224 /* Find the end of the list, and find next job ID to use */
7226 pi->jobid = 1; 7225 i = 0;
7227 for (job = G.job_list; job; job = job->next)
7228 if (job->jobid >= pi->jobid)
7229 pi->jobid = job->jobid + 1;
7230
7231 /* Add job to the list of running jobs */
7232 jobp = &G.job_list; 7226 jobp = &G.job_list;
7233 while ((job = *jobp) != NULL) 7227 while ((job = *jobp) != NULL) {
7228 if (job->jobid > i)
7229 i = job->jobid;
7234 jobp = &job->next; 7230 jobp = &job->next;
7235 job = *jobp = xmalloc(sizeof(*job)); 7231 }
7232 pi->jobid = i + 1;
7236 7233
7237 *job = *pi; /* physical copy */ 7234 /* Create a new job struct at the end */
7235 job = *jobp = xmemdup(pi, sizeof(*pi));
7238 job->next = NULL; 7236 job->next = NULL;
7239 job->cmds = xzalloc(sizeof(pi->cmds[0]) * pi->num_cmds); 7237 job->cmds = xzalloc(sizeof(pi->cmds[0]) * pi->num_cmds);
7240 /* Cannot copy entire pi->cmds[] vector! This causes double frees */ 7238 /* Cannot copy entire pi->cmds[] vector! This causes double frees */
@@ -7267,7 +7265,6 @@ static void remove_job_from_table(struct pipe *pi)
7267 G.last_jobid = 0; 7265 G.last_jobid = 0;
7268} 7266}
7269 7267
7270/* Remove a backgrounded job */
7271static void delete_finished_job(struct pipe *pi) 7268static void delete_finished_job(struct pipe *pi)
7272{ 7269{
7273 remove_job_from_table(pi); 7270 remove_job_from_table(pi);
@@ -9904,8 +9901,8 @@ static int FAST_FUNC builtin_wait(char **argv)
9904 if (ret < 0) 9901 if (ret < 0)
9905 ret = wait_for_child_or_signal(wait_pipe, 0); 9902 ret = wait_for_child_or_signal(wait_pipe, 0);
9906//bash immediately deletes finished jobs from job table only in interactive mode, 9903//bash immediately deletes finished jobs from job table only in interactive mode,
9907//we _always_ delete them at once. If we'd start doing that, this (and more) 9904//we _always_ delete them at once. If we'd start keeping some dead jobs, this
9908//would be necessary to avoid accumulating dead jobs: 9905//(and more) would be necessary to avoid accumulating dead jobs:
9909# if 0 9906# if 0
9910 else { 9907 else {
9911 if (!wait_pipe->alive_cmds) 9908 if (!wait_pipe->alive_cmds)