X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;ds=inline;f=hush.c;h=134404251d4cf4cc142fc70ae59b6c8936821496;hb=c126f8ffb6143f1455bea63dad21b2832ddb8b3c;hp=b0637f806fa12b6142f3245497ec872ef9cc9585;hpb=6c947d289fde9468092a23ed686632c81f99dcac;p=oweals%2Fbusybox.git diff --git a/hush.c b/hush.c index b0637f806..134404251 100644 --- a/hush.c +++ b/hush.c @@ -237,10 +237,6 @@ unsigned int global_argc; unsigned int last_return_code; extern char **environ; /* This is in , but protected with __USE_GNU */ -/* Variables we export */ -unsigned int shell_context; /* Used in cmdedit.c to reset the - * context when someone hits ^C */ - /* "globals" within this file */ static char *ifs; static char map[256]; @@ -395,7 +391,6 @@ static void remove_bg_job(struct pipe *pi); static char *get_local_var(const char *var); static void unset_local_var(const char *name); static int set_local_var(const char *s, int flg_export); -static void sigchld_handler(int sig); /* Table of built-in functions. They can be forked or not, depending on * context: within pipes, they fork. As simple commands, they do not. @@ -569,17 +564,21 @@ static int builtin_fg_bg(struct child_prog *child) } if (*child->argv[0] == 'f') { - /* Make this job the foreground job */ - /* suppress messages when run from /linuxrc mag@sysgo.de */ - if (tcsetpgrp(shell_terminal, pi->pgrp) && errno != ENOTTY) - perror_msg("tcsetpgrp-1"); + /* Put the job into the foreground. */ + tcsetpgrp(shell_terminal, pi->pgrp); } /* Restart the processes in the job */ for (i = 0; i < pi->num_progs; i++) pi->progs[i].is_stopped = 0; - kill(-pi->pgrp, SIGCONT); + if ( (i=kill(- pi->pgrp, SIGCONT)) < 0) { + if (i == ESRCH) { + remove_bg_job(pi); + } else { + perror_msg("kill (SIGCONT)"); + } + } pi->stopped_progs = 0; return EXIT_SUCCESS; @@ -861,7 +860,7 @@ static inline void setup_prompt_string(int promptmode, char **prompt_str) *prompt_str = PS2; } #else - *prompt_str = (promptmode==0)? PS1 : PS2; + *prompt_str = (promptmode==1)? PS1 : PS2; #endif debug_printf("result %s\n",*prompt_str); } @@ -880,7 +879,6 @@ static void get_user_input(struct in_str *i) ** child processes (rob@sysgo.de) */ cmdedit_read_input(prompt_str, the_command); - cmdedit_terminate(); #else fputs(prompt_str, stdout); fflush(stdout); @@ -1185,6 +1183,11 @@ static void remove_bg_job(struct pipe *pi) prev_pipe = prev_pipe->next; prev_pipe->next = pi->next; } + if (job_list) + last_jobid = job_list->jobid; + else + last_jobid = 0; + pi->stopped_progs = 0; free_pipe(pi, 0); free(pi); @@ -1261,8 +1264,8 @@ static int checkjobs(struct pipe* fg_pipe) perror_msg("waitpid"); /* move the shell to the foreground */ - if (interactive && tcsetpgrp(shell_terminal, getpgid(0))) - perror_msg("tcsetpgrp-2"); + //if (interactive && tcsetpgrp(shell_terminal, getpgid(0))) + // perror_msg("tcsetpgrp-2"); return -1; } @@ -1403,6 +1406,7 @@ static int run_pipe_real(struct pipe *pi) /* Set the handling for job control signals back to the default. */ signal(SIGINT, SIG_DFL); signal(SIGQUIT, SIG_DFL); + signal(SIGTERM, SIG_DFL); signal(SIGTSTP, SIG_DFL); signal(SIGTTIN, SIG_DFL); signal(SIGTTOU, SIG_DFL); @@ -1508,8 +1512,8 @@ static int run_list_real(struct pipe *pi) if ( (rcode==EXIT_SUCCESS && pi->followup==PIPE_OR) || (rcode!=EXIT_SUCCESS && pi->followup==PIPE_AND) ) skip_more_in_this_rmode=rmode; + checkjobs(NULL); } - checkjobs(NULL); return rcode; } @@ -2530,12 +2534,6 @@ static int parse_file_outer(FILE *f) return rcode; } -static void sigchld_handler(int sig) -{ - checkjobs(NULL); - signal(SIGCHLD, sigchld_handler); -} - /* Make sure we have a controlling tty. If we get started under a job * aware app (like bash for example), make sure we are now in charge so * we don't fight over who gets the foreground */ @@ -2549,16 +2547,16 @@ static void setup_job_control() /* Ignore interactive and job-control signals. */ signal(SIGINT, SIG_IGN); signal(SIGQUIT, SIG_IGN); + signal(SIGTERM, SIG_IGN); signal(SIGTSTP, SIG_IGN); signal(SIGTTIN, SIG_IGN); signal(SIGTTOU, SIG_IGN); - signal(SIGCHLD, sigchld_handler); + signal(SIGCHLD, SIG_IGN); /* Put ourselves in our own process group. */ + setsid(); shell_pgrp = getpid (); - if (setpgid (shell_pgrp, shell_pgrp) < 0) { - perror_msg_and_die("Couldn't put the shell in its own process group"); - } + setpgid (shell_pgrp, shell_pgrp); /* Grab control of the terminal. */ tcsetpgrp(shell_terminal, shell_pgrp); @@ -2607,11 +2605,12 @@ int shell_main(int argc, char **argv) if (argv[0] && argv[0][0] == '-') { debug_printf("\nsourcing /etc/profile\n"); - input = xfopen("/etc/profile", "r"); - mark_open(fileno(input)); - parse_file_outer(input); - mark_closed(fileno(input)); - fclose(input); + if ((input = fopen("/etc/profile", "r")) != NULL) { + mark_open(fileno(input)); + parse_file_outer(input); + mark_closed(fileno(input)); + fclose(input); + } } input=stdin;