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>
This commit is contained in:
parent
1609629a91
commit
9e55a156f8
27
shell/hush.c
27
shell/hush.c
@ -3527,9 +3527,8 @@ static int reserved_word(o_string *word, struct parse_context *ctx)
|
|||||||
if (r->flag & FLAG_START) {
|
if (r->flag & FLAG_START) {
|
||||||
struct parse_context *old;
|
struct parse_context *old;
|
||||||
|
|
||||||
old = xmalloc(sizeof(*old));
|
old = xmemdup(ctx, sizeof(*ctx));
|
||||||
debug_printf_parse("push stack %p\n", old);
|
debug_printf_parse("push stack %p\n", old);
|
||||||
*old = *ctx; /* physical copy */
|
|
||||||
initialize_context(ctx);
|
initialize_context(ctx);
|
||||||
ctx->stack = old;
|
ctx->stack = old;
|
||||||
} else if (/*ctx->ctx_res_w == RES_NONE ||*/ !(ctx->old_flag & (1 << r->res))) {
|
} 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)
|
|||||||
struct pipe *job, **jobp;
|
struct pipe *job, **jobp;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* Linear search for the ID of the job to use */
|
/* Find the end of the list, and find next job ID to use */
|
||||||
pi->jobid = 1;
|
i = 0;
|
||||||
for (job = G.job_list; job; job = job->next)
|
|
||||||
if (job->jobid >= pi->jobid)
|
|
||||||
pi->jobid = job->jobid + 1;
|
|
||||||
|
|
||||||
/* Add job to the list of running jobs */
|
|
||||||
jobp = &G.job_list;
|
jobp = &G.job_list;
|
||||||
while ((job = *jobp) != NULL)
|
while ((job = *jobp) != NULL) {
|
||||||
|
if (job->jobid > i)
|
||||||
|
i = job->jobid;
|
||||||
jobp = &job->next;
|
jobp = &job->next;
|
||||||
job = *jobp = xmalloc(sizeof(*job));
|
}
|
||||||
|
pi->jobid = i + 1;
|
||||||
|
|
||||||
*job = *pi; /* physical copy */
|
/* Create a new job struct at the end */
|
||||||
|
job = *jobp = xmemdup(pi, sizeof(*pi));
|
||||||
job->next = NULL;
|
job->next = NULL;
|
||||||
job->cmds = xzalloc(sizeof(pi->cmds[0]) * pi->num_cmds);
|
job->cmds = xzalloc(sizeof(pi->cmds[0]) * pi->num_cmds);
|
||||||
/* Cannot copy entire pi->cmds[] vector! This causes double frees */
|
/* Cannot copy entire pi->cmds[] vector! This causes double frees */
|
||||||
@ -7267,7 +7265,6 @@ static void remove_job_from_table(struct pipe *pi)
|
|||||||
G.last_jobid = 0;
|
G.last_jobid = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Remove a backgrounded job */
|
|
||||||
static void delete_finished_job(struct pipe *pi)
|
static void delete_finished_job(struct pipe *pi)
|
||||||
{
|
{
|
||||||
remove_job_from_table(pi);
|
remove_job_from_table(pi);
|
||||||
@ -9904,8 +9901,8 @@ static int FAST_FUNC builtin_wait(char **argv)
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
ret = wait_for_child_or_signal(wait_pipe, 0);
|
ret = wait_for_child_or_signal(wait_pipe, 0);
|
||||||
//bash immediately deletes finished jobs from job table only in interactive mode,
|
//bash immediately deletes finished jobs from job table only in interactive mode,
|
||||||
//we _always_ delete them at once. If we'd start doing that, this (and more)
|
//we _always_ delete them at once. If we'd start keeping some dead jobs, this
|
||||||
//would be necessary to avoid accumulating dead jobs:
|
//(and more) would be necessary to avoid accumulating dead jobs:
|
||||||
# if 0
|
# if 0
|
||||||
else {
|
else {
|
||||||
if (!wait_pipe->alive_cmds)
|
if (!wait_pipe->alive_cmds)
|
||||||
|
Loading…
Reference in New Issue
Block a user