Imported from ../bash-2.05a.tar.gz.
[platform/upstream/bash.git] / builtins / jobs.def
index 2c818af..f8a2b00 100644 (file)
@@ -7,7 +7,7 @@ This file is part of GNU Bash, the Bourne Again SHell.
 
 Bash is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 1, or (at your option) any later
+Software Foundation; either version 2, or (at your option) any later
 version.
 
 Bash is distributed in the hope that it will be useful, but WITHOUT ANY
@@ -17,7 +17,7 @@ for more details.
 
 You should have received a copy of the GNU General Public License along
 with Bash; see the file COPYING.  If not, write to the Free Software
-Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
 
 $PRODUCES jobs.c
 
@@ -57,8 +57,7 @@ $END
 #define JSTATE_RUNNING 0x1
 #define JSTATE_STOPPED 0x2
 
-extern int job_control, interactive_shell;
-static int execute_list_with_replacements ();
+static int execute_list_with_replacements __P((WORD_LIST *));
 
 /* The `jobs' command.  Prints outs a list of active jobs.  If the
    argument `-l' is given, then the process id's are printed also.
@@ -205,11 +204,12 @@ execute_list_with_replacements (list)
 $BUILTIN disown
 $FUNCTION disown_builtin
 $DEPENDS_ON JOB_CONTROL
-$SHORT_DOC disown [-h] [jobspec ...]
+$SHORT_DOC disown [-h] [-ar] [jobspec ...]
 By default, removes each JOBSPEC argument from the table of active jobs.
 If the -h option is given, the job is not removed from the table, but is
 marked so that SIGHUP is not sent to the job if the shell receives a
-SIGHUP.
+SIGHUP.  The -a option, when JOBSPEC is not supplied, means to remove all
+jobs from the job table; the -r option means to remove only running jobs.
 $END
 
 #if defined (JOB_CONTROL)
@@ -217,18 +217,25 @@ int
 disown_builtin (list)
      WORD_LIST *list;
 {
-  int opt, job, retval, nohup_only;
+  int opt, job, retval, nohup_only, running_jobs, all_jobs;
   sigset_t set, oset;
+  long pid_value;
 
-  nohup_only = 0;
+  nohup_only = running_jobs = all_jobs = 0;
   reset_internal_getopt ();
-  while ((opt = internal_getopt (list, "h")) != -1)
+  while ((opt = internal_getopt (list, "ahr")) != -1)
     {
       switch (opt)
        {
+       case 'a':
+         all_jobs = 1;
+         break;
        case 'h':
          nohup_only = 1;
          break;
+       case 'r':
+         running_jobs = 1;
+         break;
        default:
          builtin_usage ();
          return (EX_USAGE);
@@ -237,26 +244,24 @@ disown_builtin (list)
   list = loptend;
   retval = EXECUTION_SUCCESS;
 
-#if 0
-  /* For the future `disown -a' */
-  if (list == 0)
+  /* `disown -a' or `disown -r' */
+  if (list == 0 && (all_jobs || running_jobs))
     {
       if (nohup_only)
-       nohup_all_jobs ();
+       nohup_all_jobs (running_jobs);
       else
-       delete_all_jobs ();
+       delete_all_jobs (running_jobs);
       return (EXECUTION_SUCCESS);
     }
-#endif
 
   do
     {
       BLOCK_CHILD (set, oset);
-      job = (list && all_digits(list->word->word))
-               ? get_job_by_pid (atoi(list->word->word), 0)
+      job = (list && legal_number (list->word->word, &pid_value) && pid_value == (pid_t) pid_value)
+               ? get_job_by_pid ((pid_t) pid_value, 0)
                : get_job_spec (list);
 
-      if (job == NO_JOB || jobs == 0 || jobs[job] == 0)
+      if (job == NO_JOB || jobs == 0 || job < 0 || job >= job_slots || jobs[job] == 0)
        {
          builtin_error ("%s: no such job", list ? list->word->word : "current");
          retval = EXECUTION_FAILURE;
@@ -264,7 +269,7 @@ disown_builtin (list)
       else if (nohup_only)
        nohup_job (job);
       else
-       delete_job (job);
+       delete_job (job, 1);
       UNBLOCK_CHILD (oset);
 
       if (list)