diff options
Diffstat (limited to 'builtins/fg_bg.def')
-rw-r--r-- | builtins/fg_bg.def | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/builtins/fg_bg.def b/builtins/fg_bg.def index e48af386..49d0200b 100644 --- a/builtins/fg_bg.def +++ b/builtins/fg_bg.def @@ -30,10 +30,18 @@ JOB_SPEC is not present, the shell's notion of the current job is used. $END +#include <config.h> + #include <sys/types.h> #include <signal.h> + +#if defined (HAVE_UNISTD_H) +# include <unistd.h> +#endif + #include "../shell.h" #include "../jobs.h" +#include "common.h" #if defined (JOB_CONTROL) extern char *this_command_name; @@ -45,23 +53,23 @@ int fg_builtin (list) WORD_LIST *list; { - int fg_bit = 1; - register WORD_LIST *t = list; + int fg_bit; + register WORD_LIST *t; - if (!job_control) + if (job_control == 0) { builtin_error ("no job control"); return (EXECUTION_FAILURE); } + if (no_options (list)) + return (EX_USAGE); + /* If the last arg on the line is '&', then start this job in the background. Else, fg the job. */ - - while (t && t->next) - t = t->next; - - if (t && t->word->word[0] == '&' && !t->word->word[1]) - fg_bit = 0; + for (t = list; t && t->next; t = t->next) + ; + fg_bit = (t && t->word->word[0] == '&' && t->word->word[1] == '\0') == 0; return (fg_bg (list, fg_bit)); } @@ -82,12 +90,15 @@ int bg_builtin (list) WORD_LIST *list; { - if (!job_control) + if (job_control == 0) { builtin_error ("no job control"); return (EXECUTION_FAILURE); } + if (no_options (list)) + return (EX_USAGE); + return (fg_bg (list, 0)); } @@ -98,27 +109,27 @@ fg_bg (list, foreground) int foreground; { sigset_t set, oset; - int job, status = EXECUTION_SUCCESS, old_async_pid; + int job, status, old_async_pid; BLOCK_CHILD (set, oset); job = get_job_spec (list); - if (job < 0 || job >= job_slots || !jobs[job]) + if (job < 0 || job >= job_slots || jobs[job] == 0) { if (job != DUP_JOB) - builtin_error ("No such job %s", list ? list->word->word : ""); + builtin_error ("%s: no such job", list ? list->word->word : "current"); goto failure; } /* Or if jobs[job]->pgrp == shell_pgrp. */ - if (!(jobs[job]->flags & J_JOBCONTROL)) + if (IS_JOBCONTROL (job) == 0) { builtin_error ("job %%%d started without job control", job + 1); goto failure; } - if (!foreground) + if (foreground == 0) { old_async_pid = last_asynchronous_pid; last_asynchronous_pid = jobs[job]->pgrp; /* As per Posix.2 5.4.2 */ @@ -134,7 +145,7 @@ fg_bg (list, foreground) } else { - if (!foreground) + if (foreground == 0) last_asynchronous_pid = old_async_pid; failure: |