bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bg should handle multiple job spec ids


From: llattanzi+bash
Subject: bg should handle multiple job spec ids
Date: Mon, 19 Jul 2004 13:50:34 -0700 (PDT)

Configuration Information [Automatically generated, do not change]:
Machine: powerpc
OS: darwin8.0
Compiler: gcc
Compilation CFLAGS: -arch i386 -arch ppc -g -Os -pipe -no-cpp-precomp -arch i386 -arch ppc -pipe -DPROGRAM='bash' -DCONF_HOSTTYPE='powerpc' -DCONF_OSTYPE='darwin8.0' -DCONF_MACHTYPE='powerpc-apple-darwin8.0' -DCONF_VENDOR='apple' -DSHELL -DHAVE_CONFIG_H -DMACOSX -I. -I/SourceCache/bash/bash-32/bash -I/SourceCache/bash/bash-32/bash/include -I/SourceCache/bash/bash-32/bash/lib -arch i386 -arch ppc -g -Os -pipe -no-cpp-precomp -arch i386 -arch ppc -pipe uname output: Darwin stderr.apple.com 8.0.0b1 Darwin Kernel Version 8.0.0b1: Mon Jul 12 21:41:56 PDT 2004; root:xnu/xnu-638.1.obj~4/RELEASE_PPC Power Macintosh powerpc
Machine Type: powerpc-apple-darwin8.0

Bash Version: 2.05b
Patch Level: 0
Release Status: release

Description:
        bg %1 %2 # should not ignore %2

Repeat-By:
        #Start and stop two jobs
        bg %1 %2
        jobs #is %2 running?

Fix:
Index: bash/bash/builtins/fg_bg.def
diff -u bash/bash/builtins/fg_bg.def:1.1.1.4 bash/bash/builtins/fg_bg.def:1.1.1.4.32.1
--- bash/bash/builtins/fg_bg.def:1.1.1.4        Sat Apr  5 00:00:28 2003
+++ bash/bash/builtins/fg_bg.def        Mon Jul 19 13:50:41 2004
@@ -80,8 +80,8 @@
 $BUILTIN bg
 $FUNCTION bg_builtin
 $DEPENDS_ON JOB_CONTROL
-$SHORT_DOC bg [job_spec]
-Place JOB_SPEC in the background, as if it had been started with
+$SHORT_DOC bg [job_spec ...]
+Place JOB_SPEC(s) in the background, as if it had been started with
 `&'.  If JOB_SPEC is not present, the shell's notion of the current
 job is used.
 $END
@@ -105,55 +105,62 @@
   return (fg_bg (list, 0));
 }

-/* How to put a job into the foreground/background. */
+/* How to put jobs into the foreground/background. */
 static int
 fg_bg (list, foreground)
      WORD_LIST *list;
      int foreground;
 {
   sigset_t set, oset;
-  int job, status, old_async_pid;
+  int job, status, old_async_pid, return_status=-1;

   BLOCK_CHILD (set, oset);
-  job = get_job_spec (list);
+  do {
+       job = get_job_spec (list);

-  if (job < 0 || job >= job_slots || jobs[job] == 0)
-    {
-      if (job != DUP_JOB)
-       sh_badjob (list ? list->word->word : "current");
-
-      goto failure;
-    }
-
-  /* Or if jobs[job]->pgrp == shell_pgrp. */
-  if (IS_JOBCONTROL (job) == 0)
-    {
-      builtin_error ("job %%%d started without job control", job + 1);
-      goto failure;
-    }
-
-  if (foreground == 0)
-    {
-      old_async_pid = last_asynchronous_pid;
- last_asynchronous_pid = jobs[job]->pgrp; /* As per Posix.2 5.4.2 */
-    }
-
-  status = start_job (job, foreground);
-
-  if (status >= 0)
-    {
-    /* win: */
-      UNBLOCK_CHILD (oset);
-      return (status);
-    }
-  else
-    {
-      if (foreground == 0)
-       last_asynchronous_pid = old_async_pid;
-
-    failure:
-      UNBLOCK_CHILD (oset);
-      return (EXECUTION_FAILURE);
-    }
+       if (job < 0 || job >= job_slots || jobs[job] == 0)
+         {
+          if (job != DUP_JOB)
+            sh_badjob (list ? list->word->word : "current");
+
+          goto failure;
+         }
+
+       /* Or if jobs[job]->pgrp == shell_pgrp. */
+       if (IS_JOBCONTROL (job) == 0)
+         {
+          builtin_error ("job %%%d started without job control", job + 1);
+          goto failure;
+         }
+
+       if (foreground == 0)
+         {
+          old_async_pid = last_asynchronous_pid;
+          last_asynchronous_pid = jobs[job]->pgrp;  /* As per Posix.2 5.4.2 */
+         }
+
+       status = start_job (job, foreground);
+
+       if (status < 0)
+         {
+           if (foreground == 0)
+            last_asynchronous_pid = old_async_pid;
+
+         failure:
+          /* Continue processing job ids */
+          return_status = EXECUTION_FAILURE;
+         }
+       else if (return_status == -1)
+        return_status = status;
+       if (list) {
+        list = list->next;
+ if (list && foreground) { /* Only bg takes multiple operands */
+           UNBLOCK_CHILD (oset);
+           return (EX_USAGE);
+         }
+       }
+     } while (list);
+     UNBLOCK_CHILD (oset);
+     return return_status;
 }
 #endif /* JOB_CONTROL */





reply via email to

[Prev in Thread] Current Thread [Next in Thread]