~ubuntu-branches/ubuntu/raring/findutils/raring

« back to all changes in this revision

Viewing changes to xargs/xargs.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2008-05-06 11:32:24 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 23.
  • Revision ID: james.westby@ubuntu.com-20080506113224-gy4ecmxu48tnvva4
Tags: upstream-4.4.0
ImportĀ upstreamĀ versionĀ 4.4.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* xargs -- build and execute command lines from standard input
2
 
   Copyright (C) 1990, 91, 92, 93, 94, 2000, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
 
2
   Copyright (C) 1990, 91, 92, 93, 94, 2000, 2003, 2004, 2005, 2006,
 
3
   2007, 2008 Free Software Foundation, Inc.
3
4
 
4
5
   This program is free software: you can redistribute it and/or modify
5
6
   it under the terms of the GNU General Public License as published by
16
17
*/
17
18
 
18
19
/* Written by Mike Rendell <michael@cs.mun.ca>
19
 
   and David MacKenzie <djm@gnu.org>.
20
 
   Modifications by
21
 
        James Youngman
 
20
   and David MacKenzie <djm@gnu.org>.  
 
21
   Modifications by 
 
22
        James Youngman
22
23
        Dmitry V. Levin
23
24
*/
24
25
 
56
57
#include <getopt.h>
57
58
#include <fcntl.h>
58
59
 
59
 
#if defined(STDC_HEADERS)
 
60
#if defined STDC_HEADERS
60
61
#include <assert.h>
61
62
#endif
62
63
 
63
 
#if defined(HAVE_STRING_H) || defined(STDC_HEADERS)
 
64
#if defined HAVE_STRING_H || defined STDC_HEADERS
64
65
#include <string.h>
65
 
#if !defined(STDC_HEADERS)
 
66
#if !defined STDC_HEADERS
66
67
#include <memory.h>
67
68
#endif
68
69
#else
93
94
#define SIGCHLD SIGCLD
94
95
#endif
95
96
 
 
97
#include "verify.h"
96
98
#include "wait.h"
 
99
#include "quotearg.h"
 
100
#include "findutils-version.h"
97
101
 
98
 
/* States for read_line. */
99
 
#define NORM 0
100
 
#define SPACE 1
101
 
#define QUOTE 2
102
 
#define BACKSLASH 3
103
102
 
104
103
#ifdef STDC_HEADERS
105
104
#include <stdlib.h>
188
187
static struct buildcmd_state bc_state;
189
188
static struct buildcmd_control bc_ctl;
190
189
 
 
190
/* Did we already complain about NUL characters in the input? */
 
191
static int nullwarning_given = 0;
 
192
 
191
193
 
192
194
/* If nonzero, when this string is read on stdin it is treated as
193
195
   end of file.
204
206
 
205
207
/* If nonzero, the maximum number of child processes that can be running
206
208
   at once.  */
207
 
static int proc_max = 1;
 
209
static unsigned long int proc_max = 1uL;
208
210
 
209
 
/* Total number of child processes that have been executed.  */
210
 
static int procs_executed = 0;
 
211
/* Did we fork a child yet? */
 
212
static boolean procs_executed = false;
211
213
 
212
214
/* The number of elements in `pids'.  */
213
 
static int procs_executing = 0;
 
215
static unsigned long int procs_executing = 0uL;
214
216
 
215
217
/* List of child processes currently executing.  */
216
218
static pid_t *pids = NULL;
217
219
 
218
220
/* The number of allocated elements in `pids'. */
219
 
static int pids_alloc = 0;
 
221
static size_t pids_alloc = 0u;
220
222
 
221
223
/* Exit status; nonzero if any child process exited with a
222
224
   status of 1-125.  */
265
267
static int xargs_do_exec (const struct buildcmd_control *cl, struct buildcmd_state *state);
266
268
static void exec_if_possible PARAMS ((void));
267
269
static void add_proc PARAMS ((pid_t pid));
268
 
static void wait_for_proc PARAMS ((boolean all));
 
270
static void wait_for_proc PARAMS ((boolean all, unsigned int minreap));
269
271
static void wait_for_proc_all PARAMS ((void));
270
272
static long parse_num PARAMS ((char *str, int option, long min, long max, int fatal));
271
273
static void usage PARAMS ((FILE * stream));
280
282
  unsigned long val;
281
283
  char *endp;
282
284
 
283
 
  assert('\\' == s[0]);
 
285
  assert ('\\' == s[0]);
284
286
  
285
287
  if ('x' == s[1])
286
288
    {
296
298
    }
297
299
  else
298
300
    {
 
301
      p = NULL;                 /* Silence compiler warning. */
299
302
      error(1, 0,
300
303
            _("Invalid escape sequence %s in input delimiter specification."),
301
304
            s);
377
380
          error(1, 0,
378
381
                _("Invalid input delimiter specification %s: the delimiter must be either a single character or an escape sequence starting with \\."),
379
382
                s);
380
 
          abort ();
 
383
          /*NOTREACHED*/
 
384
          return 0;
381
385
        }
382
386
    }
383
387
}
406
410
  int (*read_args) PARAMS ((void)) = read_line;
407
411
  void (*act_on_init_result)(void) = noop;
408
412
  enum BC_INIT_STATUS bcstatus;
409
 
 
 
413
  enum { XARGS_POSIX_HEADROOM = 2048u };
 
414
  
410
415
  program_name = argv[0];
411
416
  original_exit_value = 0;
412
417
  
418
423
  atexit (close_stdin);
419
424
  atexit (wait_for_proc_all);
420
425
 
421
 
  bcstatus = bc_init_controlinfo(&bc_ctl);
 
426
  /* xargs is required by POSIX to allow 2048 bytes of headroom 
 
427
   * for extra environment variables (that perhaps the utliity might 
 
428
   * want to set before execing something else).
 
429
   */
 
430
  bcstatus = bc_init_controlinfo(&bc_ctl, XARGS_POSIX_HEADROOM);
 
431
  
422
432
  /* The bc_init_controlinfo call may have determined that the 
423
433
   * environment is too big.  In that case, we will fail with 
424
434
   * an error message after processing the command-line options,
433
443
    {
434
444
      act_on_init_result = fail_due_to_env_size;
435
445
    }
 
446
  else if (BC_INIT_CANNOT_ACCOMODATE_HEADROOM == bcstatus)
 
447
    {
 
448
      /* All POSIX systems are required to support ARG_MAX of at least
 
449
       * 4096.  For everything to work the total of (command line +
 
450
       * headroom + environment) must fit into this.  POSIX requires
 
451
       * that we use a headroom of 2048 bytes.  The user is in control
 
452
       * of the size of the environment.  
 
453
       *
 
454
       * In general if bc_init_controlinfo() returns
 
455
       * BC_INIT_CANNOT_ACCOMODATE_HEADROOM, its caller can try again
 
456
       * with a smaller headroom.  However, in the case of xargs, this
 
457
       * would not be POSIX-compliant.
 
458
       */
 
459
      act_on_init_result = fail_due_to_env_size;
 
460
    }
436
461
  else
437
462
    {
438
463
      /* IEEE Std 1003.1, 2003 specifies that the combined argument and 
439
464
       * environment list shall not exceed {ARG_MAX}-2048 bytes.  It also 
440
465
       * specifies that it shall be at least LINE_MAX.
441
466
       */
442
 
#if defined(ARG_MAX)
443
 
      assert(bc_ctl.arg_max <= (ARG_MAX-2048));
 
467
#ifdef _SC_ARG_MAX  
 
468
      long val = sysconf(_SC_ARG_MAX);
 
469
      if (val > 0)
 
470
        {
 
471
          /* Note that val can in fact be greater than ARG_MAX
 
472
           * and bc_ctl.arg_max can also be greater than ARG_MAX.
 
473
           */
 
474
          assert (bc_ctl.arg_max <= (val-XARGS_POSIX_HEADROOM));
 
475
        }
 
476
      else
 
477
        {
 
478
# if defined ARG_MAX
 
479
          assert (bc_ctl.arg_max <= (ARG_MAX-XARGS_POSIX_HEADROOM));
 
480
# endif
 
481
        }
 
482
#else
 
483
      /* No _SC_ARG_MAX */
 
484
      assert (bc_ctl.arg_max <= (ARG_MAX-XARGS_POSIX_HEADROOM));
444
485
#endif
 
486
 
 
487
 
445
488
#ifdef LINE_MAX
446
 
      assert(bc_ctl.arg_max >= LINE_MAX);
 
489
      /* This assertion ensures that this xargs implementation
 
490
       * conforms to the POSIX requirement that the default command
 
491
       * line length shall be at least LINE_MAX.
 
492
       */
 
493
      assert (bc_ctl.arg_max >= LINE_MAX);
447
494
#endif
448
495
      
449
496
      bc_ctl.exec_callback = xargs_do_exec;
533
580
            if (arg_size > bc_ctl.posix_arg_size_max)
534
581
              {
535
582
                error (0, 0,
536
 
                       _("warning: value %ld for -s option is too large, "
 
583
                       _("Warning: value %ld for -s option is too large, "
537
584
                         "using %ld instead"),
538
585
                       arg_size, bc_ctl.posix_arg_size_max);
539
586
                arg_size = bc_ctl.posix_arg_size_max;
564
611
          break;
565
612
 
566
613
        case 'P':
567
 
          proc_max = parse_num (optarg, 'P', 0L, -1L, 1);
 
614
          /* Allow only up to LONG_MAX child processes. */
 
615
          proc_max = parse_num (optarg, 'P', 0L, LONG_MAX, 1);
568
616
          break;
569
617
 
570
618
        case 'a':
572
620
          break;
573
621
 
574
622
        case 'v':
575
 
          printf (_("GNU xargs version %s\n"), version_string);
576
 
          printf (_("Built using GNU gnulib version %s\n"), gnulib_version);
 
623
          display_findutils_version("xargs");
577
624
          return 0;
578
625
 
579
626
        default:
590
637
   * the environment is too large. 
591
638
   */
592
639
  act_on_init_result();
593
 
  assert(BC_INIT_OK == bcstatus);
 
640
  assert (BC_INIT_OK == bcstatus);
594
641
 
595
642
  if (0 == strcmp (input_file, "-"))
596
643
    {
603
650
      if (NULL == input_stream)
604
651
        {
605
652
          error (1, errno,
606
 
                 _("Cannot open input file `%s'"),
607
 
                 input_file);
 
653
                 _("Cannot open input file %s"),
 
654
                 quotearg_n_style(0, locale_quoting_style, input_file));
608
655
        }
609
656
    }
610
657
 
625
672
   * special C99 ways to print such values.  Unfortunately this
626
673
   * program tries to work on both C89 and C99 systems.
627
674
   */
628
 
#if defined(SIZE_MAX)
 
675
#if defined SIZE_MAX
629
676
# if SIZE_MAX > ULONG_MAX
630
677
# error "I'm not sure how to print size_t values on your system"
631
678
# endif
633
680
  /* Without SIZE_MAX (i.e. limits.h) this is probably 
634
681
   * close to the best we can do.
635
682
   */
636
 
  assert(sizeof(size_t) <= sizeof(unsigned long));
 
683
  verify_true (sizeof(size_t) <= sizeof(unsigned long));
637
684
#endif
638
 
 
 
685
  
639
686
  if (show_limits)
640
687
    {
641
688
      fprintf(stderr,
642
689
              _("Your environment variables take up %lu bytes\n"),
643
690
              (unsigned long)bc_size_of_environment());
644
691
      fprintf(stderr,
645
 
              _("POSIX lower and upper limits on argument length: %lu, %lu\n"),
646
 
              (unsigned long)bc_ctl.posix_arg_size_min,
 
692
              _("POSIX upper limit on argument length (this system): %lu\n"),
647
693
              (unsigned long)bc_ctl.posix_arg_size_max);
648
694
      fprintf(stderr,
 
695
              _("POSIX smallest allowable upper limit on argument length (all systems): %lu\n"),
 
696
              (unsigned long)bc_ctl.posix_arg_size_min);
 
697
      fprintf(stderr,
649
698
              _("Maximum length of command we could actually use: %ld\n"),
650
699
              (unsigned long)(bc_ctl.posix_arg_size_max -
651
700
                              bc_size_of_environment()));
652
701
      fprintf(stderr,
653
702
              _("Size of command buffer we are actually using: %lu\n"),
654
703
              (unsigned long)bc_ctl.arg_max);
655
 
 
 
704
      
656
705
      if (isatty(STDIN_FILENO))
657
706
        {
658
707
          fprintf(stderr,
659
 
                  "\n"
660
 
                  "Execution of xargs will continue now, and it will "
661
 
                  "try to read its input and run commands; if this is "
662
 
                  "not what you wanted to happen, please type the "
663
 
                  "end-of-file keystroke.\n");
 
708
                  _("\n"
 
709
                    "Execution of xargs will continue now, and it will "
 
710
                    "try to read its input and run commands; if this is "
 
711
                    "not what you wanted to happen, please type the "
 
712
                    "end-of-file keystroke.\n"));
 
713
          if (always_run_command)
 
714
            {
 
715
              fprintf(stderr,
 
716
                      _("Warning: %s will be run at least once.  "
 
717
                        "If you do not want that to happen, then press "
 
718
                        "the interrupt keystroke.\n"),
 
719
                      argv[optind]);
 
720
            }
664
721
        }
665
722
    }
666
723
  
667
 
  linebuf = (char *) xmalloc (bc_ctl.arg_max + 1);
668
 
  bc_state.argbuf = (char *) xmalloc (bc_ctl.arg_max + 1);
 
724
  linebuf = xmalloc (bc_ctl.arg_max + 1);
 
725
  bc_state.argbuf = xmalloc (bc_ctl.arg_max + 1);
669
726
 
670
727
  /* Make sure to listen for the kids.  */
671
728
  signal (SIGCHLD, SIG_DFL);
691
748
      /* SYSV xargs seems to do at least one exec, even if the
692
749
         input is empty.  */
693
750
      if (bc_state.cmd_argc != bc_ctl.initial_argc
694
 
          || (always_run_command && procs_executed == 0))
 
751
          || (always_run_command && !procs_executed))
695
752
        xargs_do_exec (&bc_ctl, &bc_state);
696
753
 
697
754
    }
699
756
    {
700
757
      int i;
701
758
      size_t len;
702
 
      size_t *arglen = (size_t *) xmalloc (sizeof (size_t) * argc);
 
759
      size_t *arglen = xmalloc (sizeof (size_t) * argc);
703
760
 
704
761
      for (i = optind; i < argc; i++)
705
762
        arglen[i] = strlen(argv[i]);
742
799
static int
743
800
read_line (void)
744
801
{
 
802
/* States for read_line. */
 
803
  enum read_line_state 
 
804
    {
 
805
      NORM = 0,
 
806
      SPACE = 1,
 
807
      QUOTE = 2,
 
808
      BACKSLASH = 3
 
809
    };
745
810
  static boolean eof = false;
746
811
  /* Start out in mode SPACE to always strip leading spaces (even with -i).  */
747
 
  int state = SPACE;            /* The type of character we last read.  */
 
812
  enum read_line_state state = SPACE; /* The type of character we last read.  */
748
813
  int prevc;                    /* The previous value of c.  */
749
814
  int quotc = 0;                /* The last quote character read.  */
750
815
  int c = EOF;
751
816
  boolean first = true;         /* true if reading first arg on line.  */
 
817
  boolean seen_arg = false;      /* true if we have seen any arg (or part of one) yet */
752
818
  int len;
753
819
  char *p = linebuf;
754
820
  /* Including the NUL, the args must not grow past this point.  */
755
821
  char *endbuf = linebuf + bc_ctl.arg_max - bc_state.cmd_initial_argv_chars - 1;
756
 
 
 
822
  
757
823
  if (eof)
758
824
    return -1;
759
825
  while (1)
760
826
    {
761
827
      prevc = c;
762
828
      c = getc (input_stream);
 
829
      
763
830
      if (c == EOF)
764
831
        {
765
832
          /* COMPAT: SYSV seems to ignore stuff on a line that
799
866
                lineno++;       /* For -l.  */
800
867
              if (p == linebuf)
801
868
                {
802
 
                  /* Blank line.  */
803
 
                  state = SPACE;
804
 
                  continue;
 
869
                  if (seen_arg)
 
870
                    {
 
871
                      /* An empty argument, add it to the list as normal. */
 
872
                    }
 
873
                  else
 
874
                    {
 
875
                      /* Blank line.  */
 
876
                      state = SPACE;
 
877
                      continue;
 
878
                    }
805
879
                }
806
880
              *p++ = '\0';
807
881
              len = p - linebuf;
817
891
                             initial_args);
818
892
              return len;
819
893
            }
820
 
          if (!bc_ctl.replace_pat && ISSPACE (c))
 
894
          seen_arg = true;
 
895
 
 
896
          /* POSIX: In the POSIX locale, the separators are <SPC> and
 
897
           * <TAB>, but not <FF> or <VT>. 
 
898
           */
 
899
          if (!bc_ctl.replace_pat && ISBLANK (c))
821
900
            {
822
901
              *p++ = '\0';
823
902
              len = p - linebuf;
859
938
          if (c == quotc)
860
939
            {
861
940
              state = NORM;
 
941
              seen_arg = true; /* Makes a difference for e.g. just '' or "" as the first arg on a line */
862
942
              continue;
863
943
            }
864
944
          break;
867
947
          state = NORM;
868
948
          break;
869
949
        }
 
950
      
 
951
      if ( (0 == c) && !nullwarning_given )
 
952
        {
 
953
          /* This is just a warning message.  We only issue it once. */
 
954
          error (0, 0,
 
955
                 _("Warning: a NUL character occurred in the input.  "
 
956
                   "It cannot be passed through in the argument list.  "
 
957
                   "Did you mean to use the --null option?"));
 
958
          nullwarning_given = 1;
 
959
        }
 
960
 
870
961
#if 1
871
962
      if (p >= endbuf)
872
963
        {
991
1082
           * stdin is almost as good as executing it
992
1083
           * with its stdin attached to /dev/null.
993
1084
           */
994
 
          error (0, errno, "%s", inputfile);
 
1085
          error (0, errno, "%s", quotearg_n_style(0, locale_quoting_style, inputfile));
995
1086
        }
996
1087
    }
997
1088
}
1005
1096
{
1006
1097
  pid_t child;
1007
1098
 
 
1099
  (void) ctl;
 
1100
  (void) state;
 
1101
  
1008
1102
  bc_push_arg (&bc_ctl, &bc_state,
1009
1103
               (char *) NULL, 0,
1010
1104
               NULL, 0,
1012
1106
  
1013
1107
  if (!query_before_executing || print_args (true))
1014
1108
    {
1015
 
      if (proc_max && procs_executing >= proc_max)
1016
 
        wait_for_proc (false);
 
1109
      if (proc_max)
 
1110
        {
 
1111
          if (procs_executing >= proc_max)
 
1112
            wait_for_proc (false, proc_max - procs_executing + 1);
 
1113
          assert (procs_executing < proc_max);
 
1114
        }
1017
1115
      if (!query_before_executing && print_command)
1018
1116
        print_args (false);
 
1117
 
 
1118
      /* Before forking, reap any already-exited child. We do this so
 
1119
         that we don't leave unreaped children around while we build a
 
1120
         new command line.  For example this command will spend most
 
1121
         of its time waiting for sufficient arguments to launch
 
1122
         another command line:
 
1123
 
 
1124
         seq 1 1000 | fmt | while read x ; do echo $x; sleep 1 ; done | 
 
1125
         ./xargs -P 200 -n 20  sh -c 'echo "$@"; sleep $((1 + $RANDOM % 5))' sleeper
 
1126
      */
 
1127
      wait_for_proc (false, 0u);
 
1128
 
1019
1129
      /* If we run out of processes, wait for a child to return and
1020
1130
         try again.  */
1021
1131
      while ((child = fork ()) < 0 && errno == EAGAIN && procs_executing)
1022
 
        wait_for_proc (false);
 
1132
        wait_for_proc (false, 1u);
 
1133
 
1023
1134
      switch (child)
1024
1135
        {
1025
1136
        case -1:
1056
1167
static void
1057
1168
add_proc (pid_t pid)
1058
1169
{
1059
 
  int i;
 
1170
  unsigned int i, j;
1060
1171
 
1061
1172
  /* Find an empty slot.  */
1062
1173
  for (i = 0; i < pids_alloc && pids[i]; i++)
1063
1174
    ;
 
1175
 
 
1176
  /* Extend the array if we failed. */
1064
1177
  if (i == pids_alloc)
1065
1178
    {
1066
 
      if (pids_alloc == 0)
1067
 
        {
1068
 
          pids_alloc = proc_max ? proc_max : 64;
1069
 
          pids = (pid_t *) xmalloc (sizeof (pid_t) * pids_alloc);
1070
 
        }
1071
 
      else
1072
 
        {
1073
 
          pids_alloc *= 2;
1074
 
          pids = (pid_t *) xrealloc (pids,
1075
 
                                     sizeof (pid_t) * pids_alloc);
1076
 
        }
1077
 
      memset (&pids[i], '\0', sizeof (pid_t) * (pids_alloc - i));
 
1179
      pids = x2nrealloc (pids, &pids_alloc, sizeof *pids);
 
1180
 
 
1181
      /* Zero out the new slots. */
 
1182
      for (j=i; j<pids_alloc; ++j)
 
1183
        pids[j] = (pid_t)0;
1078
1184
    }
 
1185
  /* Verify that we are not destroying the record of some existing child. */
 
1186
  assert (0 == pids[i]);
 
1187
 
 
1188
  /* Remember the child. */
1079
1189
  pids[i] = pid;
1080
1190
  procs_executing++;
1081
 
  procs_executed++;
 
1191
  procs_executed = true;
1082
1192
}
1083
1193
 
 
1194
 
1084
1195
/* If ALL is true, wait for all child processes to finish;
1085
 
   otherwise, wait for one child process to finish.
 
1196
   otherwise, wait for at least MINREAP child processes to finish.
1086
1197
   Remove the processes that finish from the list of executing processes.  */
1087
1198
 
1088
1199
static void
1089
 
wait_for_proc (boolean all)
 
1200
wait_for_proc (boolean all, unsigned int minreap)
1090
1201
{
 
1202
  unsigned int reaped = 0;
 
1203
 
1091
1204
  while (procs_executing)
1092
1205
    {
1093
 
      int i, status;
 
1206
      unsigned int i;
 
1207
      int status;
 
1208
      pid_t pid;
 
1209
      int wflags = 0;
 
1210
 
 
1211
      if (!all)
 
1212
        {
 
1213
          if (reaped >= minreap)
 
1214
            {
 
1215
              /* We already reaped enough children.  To save system
 
1216
               * resources, reap any dead children anyway, but do not
 
1217
               * wait for any currently executing children to exit.
 
1218
               
 
1219
               */
 
1220
              wflags = WNOHANG;
 
1221
            }
 
1222
        }
1094
1223
 
1095
1224
      do
1096
1225
        {
1097
 
          pid_t pid;
1098
 
 
1099
 
          while ((pid = wait (&status)) == (pid_t) -1)
1100
 
            if (errno != EINTR)
1101
 
              error (1, errno, _("error waiting for child process"));
1102
 
 
 
1226
          /* Wait for any child.   We used to use wait() here, but it's 
 
1227
           * unlikely that that offers any portability advantage over 
 
1228
           * wait these days.
 
1229
           */
 
1230
          while ((pid = waitpid (-1, &status, wflags)) == (pid_t) -1)
 
1231
            {
 
1232
              if (errno != EINTR)
 
1233
                error (1, errno, _("error waiting for child process"));
 
1234
            }
 
1235
          
1103
1236
          /* Find the entry in `pids' for the child process
1104
1237
             that exited.  */
1105
 
          for (i = 0; i < pids_alloc && pid != pids[i]; i++)
1106
 
            ;
 
1238
          if (pid)
 
1239
            {
 
1240
              for (i = 0; i < pids_alloc && pid != pids[i]; i++)
 
1241
                ;
 
1242
            }
1107
1243
        }
1108
 
      while (i == pids_alloc);  /* A child died that we didn't start? */
 
1244
      while (pid && i == pids_alloc);   /* A child died that we didn't start? */
1109
1245
 
 
1246
      if (!pid)
 
1247
        {
 
1248
          if (!(wflags & WNOHANG))
 
1249
            {
 
1250
              /* Nothing remained to be reaped.  This should not
 
1251
               * happen, because procs_executing should contain the
 
1252
               * number of child processes still executing, so the
 
1253
               * loop should have terminated.
 
1254
               */
 
1255
              error (0, 0, _("Warning: Lost track of %d child processes"),
 
1256
                     procs_executing);
 
1257
            }
 
1258
          else
 
1259
            {
 
1260
              /* Children are (probably) executing but are not ready
 
1261
               * to be reaped at the moment.
 
1262
               */
 
1263
            }
 
1264
          break;
 
1265
        }
 
1266
      
1110
1267
      /* Remove the child from the list.  */
1111
1268
      pids[i] = 0;
1112
1269
      procs_executing--;
 
1270
      reaped++;
1113
1271
 
1114
1272
      if (WEXITSTATUS (status) == 126 || WEXITSTATUS (status) == 127)
1115
1273
        exit (WEXITSTATUS (status));    /* Can't find or run the command.  */
1121
1279
        error (125, 0, _("%s: terminated by signal %d"), bc_state.cmd_argv[0], WTERMSIG (status));
1122
1280
      if (WEXITSTATUS (status) != 0)
1123
1281
        child_error = 123;
1124
 
 
1125
 
      if (!all)
1126
 
        break;
1127
1282
    }
1128
1283
}
1129
1284
 
1138
1293
    return;
1139
1294
 
1140
1295
  waiting = true;
1141
 
  wait_for_proc (true);
 
1296
  wait_for_proc (true, 0u);
1142
1297
  waiting = false;
1143
1298
  
1144
1299
  if (original_exit_value != child_error)
1207
1362
  return val;
1208
1363
}
1209
1364
 
1210
 
/* Return how much of ARG_MAX is used by the environment.  */
1211
 
 
1212
1365
static void
1213
1366
usage (FILE *stream)
1214
1367
{