]> git.ipfire.org Git - thirdparty/bash.git/commitdiff
commit bash-20070920 snapshot
authorChet Ramey <chet.ramey@case.edu>
Wed, 7 Dec 2011 14:13:02 +0000 (09:13 -0500)
committerChet Ramey <chet.ramey@case.edu>
Wed, 7 Dec 2011 14:13:02 +0000 (09:13 -0500)
CWRU/CWRU.chlog
builtins/fc.def
doc/bash.1
doc/bashref.texi
jobs.c
jobs.h
nojobs.c

index 73707c365b849bea43918352fa28697c4c2073f5..292ac7fa0bc82580b3f91dcd205707d714846312 100644 (file)
@@ -14893,3 +14893,10 @@ builtins/common.c
        - if DONT_REPORT_BROKEN_PIPE_WRITE_ERRORS is defined, don't print an
          error message from sh_wrerror if errno == EPIPE.  Suggestion from
          Petr Sumbera <petr.sumbera@sun.com>
+
+                                  9/19
+                                  ----
+{jobs,nojobs}.c,jobs.h
+       - add code to retry fork() after EAGAIN, with a progressively longer
+         sleep between attempts, up to FORKSLEEP_MAX (16) seconds.  Suggested
+         by Martin Koeppe <mkoeppe@gmx.de>
index 5d6d530ea035290a9b5a12a5c6e667cff3ecfc6a..4ea703077f8145c90424fb24e5290633512c518a 100644 (file)
@@ -290,7 +290,7 @@ fc_builtin (list)
      line was actually added (HISTIGNORE may have caused it to not be),
      so we check hist_last_line_added. */
 
-  /* "When not  listing, he fc command that caused the editing shall not be
+  /* "When not  listing, the fc command that caused the editing shall not be
      entered into the history list." */
   if (listing == 0 && hist_last_line_added)
     delete_last_history ();
index 86596ebac6792e08c1ac39cbf317e5434d3f81f7..35cbd3833893b4c1474f43d1880f18dd951ef394 100644 (file)
@@ -8595,8 +8595,9 @@ none are found.
 Provides control over the resources available to the shell and to
 processes started by it, on systems that allow such control.
 The \fB\-H\fP and \fB\-S\fP options specify that the hard or soft limit is
-set for the given resource.  A hard limit cannot be increased once it
-is set; a soft limit may be increased up to the value of the hard limit.
+set for the given resource.
+A hard limit cannot be increased by a non-root user once it is set;
+a soft limit may be increased up to the value of the hard limit.
 If neither \fB\-H\fP nor \fB\-S\fP is specified, both the soft and hard
 limits are set.
 The value of
index 7a0c8282a90f6afece5b0eedc7cce55c391a5583..d34f6370f3f51b97d1ccca8e0d5df1eb5a9c529e 100644 (file)
@@ -3655,6 +3655,8 @@ If @var{limit} is given, it is the new value of the specified resource;
 the special @var{limit} values @code{hard}, @code{soft}, and
 @code{unlimited} stand for the current hard limit, the current soft limit,
 and no limit, respectively.
+A hard limit cannot be increased by a non-root user once it is set;
+a soft limit may be increased up to the value of the hard limit.
 Otherwise, the current value of the soft limit for the specified resource
 is printed, unless the @option{-H} option is supplied.
 When setting new limits, if neither @option{-H} nor @option{-S} is supplied,
diff --git a/jobs.c b/jobs.c
index d94cc5fa3ad8510363eb99b328e62f8f2ba4e2ae..82a6b488d10c0cf3d10a2906e2dd5cb1e0de0ad1 100644 (file)
--- a/jobs.c
+++ b/jobs.c
@@ -1674,6 +1674,7 @@ make_child (command, async_p)
      char *command;
      int async_p;
 {
+  int forksleep;
   sigset_t set, oset;
   pid_t pid;
 
@@ -1695,8 +1696,16 @@ make_child (command, async_p)
     sync_buffered_stream (default_buffered_input);
 #endif /* BUFFERED_INPUT */
 
-  /* Create the child, handle severe errors. */
-  if ((pid = fork ()) < 0)
+  /* Create the child, handle severe errors.  Retry on EAGAIN. */
+  while ((pid = fork ()) < 0 && errno == EAGAIN && forksleep < FORKSLEEP_MAX)
+    {
+      sys_error ("fork: retry");
+      if (sleep (forksleep) != 0)
+       break;
+      forksleep <<= 1;
+    }
+
+  if (pid < 0)
     {
       sys_error ("fork");
 
diff --git a/jobs.h b/jobs.h
index 17f0387989a6b9901471f4602f091b5d2dc46725..91dfa03e3973590db5e1462189294136fe3d3ae9 100644 (file)
--- a/jobs.h
+++ b/jobs.h
@@ -38,6 +38,9 @@
 /* I looked it up.  For pretty_print_job ().  The real answer is 24. */
 #define LONGEST_SIGNAL_DESC 24
 
+/* The max time to sleep while retrying fork() on EAGAIN failure */
+#define FORKSLEEP_MAX  16
+
 /* We keep an array of jobs.  Each entry in the array is a linked list
    of processes that are piped together.  The first process encountered is
    the group leader. */
index e626b2c7a32a0b671b89fca0043f00bc4c122e92..059c89acef07fceb7a6ce35f23b90537874fbef8 100644 (file)
--- a/nojobs.c
+++ b/nojobs.c
@@ -465,9 +465,7 @@ make_child (command, async_p)
      int async_p;
 {
   pid_t pid;
-#if defined (HAVE_WAITPID)
-  int retry = 1;
-#endif /* HAVE_WAITPID */
+  int forksleep;
 
   /* Discard saved memory. */
   if (command)
@@ -484,26 +482,27 @@ make_child (command, async_p)
     sync_buffered_stream (default_buffered_input);
 #endif /* BUFFERED_INPUT */
 
-  /* Create the child, handle severe errors. */
-#if defined (HAVE_WAITPID)
-  retry_fork:
-#endif /* HAVE_WAITPID */
-
-  if ((pid = fork ()) < 0)
+  /* Create the child, handle severe errors.  Retry on EAGAIN. */
+  forksleep = 1;
+  while ((pid = fork ()) < 0 && errno == EAGAIN && forksleep < FORKSLEEP_MAX)
     {
+      sys_error ("fork: retry");
 #if defined (HAVE_WAITPID)
       /* Posix systems with a non-blocking waitpid () system call available
         get another chance after zombies are reaped. */
-      if (errno == EAGAIN && retry)
-       {
-         reap_zombie_children ();
-         retry = 0;
-         goto retry_fork;
-       }
+      reap_zombie_children ();
+      if (forksleep > 1 && sleep (forksleep) != 0)
+        break;
+#else
+      if (sleep (forksleep) != 0)
+       break;
 #endif /* HAVE_WAITPID */
+      forksleep <<= 1;
+    }
 
+  if (pid < 0)
+    {
       sys_error ("fork");
-
       throw_to_top_level ();
     }