/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to plugin-runner.c

  • Committer: Teddy Hogeborn
  • Date: 2009-09-23 08:52:09 UTC
  • Revision ID: teddy@fukt.bsnet.se-20090923085209-n6nx3i86rvokwfq6
* plugin-runner.c (main): Use the O_CLOEXEC flag, if available, when
                          opening the plugin directory.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*  -*- coding: utf-8 -*- */
 
1
/*  -*- coding: utf-8; mode: c; mode: orgtbl -*- */
2
2
/*
3
3
 * Mandos plugin runner - Run Mandos plugins
4
4
 *
23
23
 */
24
24
 
25
25
#define _GNU_SOURCE             /* TEMP_FAILURE_RETRY(), getline(),
26
 
                                   asprintf() */
 
26
                                   asprintf(), O_CLOEXEC */
27
27
#include <stddef.h>             /* size_t, NULL */
28
28
#include <stdlib.h>             /* malloc(), exit(), EXIT_FAILURE,
29
29
                                   EXIT_SUCCESS, realloc() */
30
30
#include <stdbool.h>            /* bool, true, false */
31
31
#include <stdio.h>              /* perror, fileno(), fprintf(),
32
32
                                   stderr, STDOUT_FILENO */
33
 
#include <sys/types.h>          /* DIR, opendir(), stat(), struct
 
33
#include <sys/types.h>          /* DIR, fdopendir(), stat(), struct
34
34
                                   stat, waitpid(), WIFEXITED(),
35
35
                                   WEXITSTATUS(), wait(), pid_t,
36
36
                                   uid_t, gid_t, getuid(), getgid(),
38
38
#include <sys/select.h>         /* fd_set, select(), FD_ZERO(),
39
39
                                   FD_SET(), FD_ISSET(), FD_CLR */
40
40
#include <sys/wait.h>           /* wait(), waitpid(), WIFEXITED(),
41
 
                                   WEXITSTATUS() */
 
41
                                   WEXITSTATUS(), WTERMSIG(),
 
42
                                   WCOREDUMP() */
42
43
#include <sys/stat.h>           /* struct stat, stat(), S_ISREG() */
43
44
#include <iso646.h>             /* and, or, not */
44
 
#include <dirent.h>             /* DIR, struct dirent, opendir(),
 
45
#include <dirent.h>             /* DIR, struct dirent, fdopendir(),
45
46
                                   readdir(), closedir(), dirfd() */
46
47
#include <unistd.h>             /* struct stat, stat(), S_ISREG(),
47
48
                                   fcntl(), setuid(), setgid(),
52
53
                                   close() */
53
54
#include <fcntl.h>              /* fcntl(), F_GETFD, F_SETFD,
54
55
                                   FD_CLOEXEC */
55
 
#include <string.h>             /* strsep, strlen(), asprintf() */
 
56
#include <string.h>             /* strsep, strlen(), asprintf(),
 
57
                                   strsignal() */
56
58
#include <errno.h>              /* errno */
57
59
#include <argp.h>               /* struct argp_option, struct
58
60
                                   argp_state, struct argp,
65
67
                                   SIG_UNBLOCK, kill(), sig_atomic_t
66
68
                                */
67
69
#include <errno.h>              /* errno, EBADF */
68
 
#include <inttypes.h>           /* intmax_t, SCNdMAX, PRIdMAX,  */
 
70
#include <inttypes.h>           /* intmax_t, PRIdMAX, strtoimax() */
69
71
 
70
72
#define BUFFER_SIZE 256
71
73
 
82
84
  char **environ;
83
85
  int envc;
84
86
  bool disabled;
85
 
 
 
87
  
86
88
  /* Variables used for running processes*/
87
89
  pid_t pid;
88
90
  int fd;
108
110
    }
109
111
  }
110
112
  /* Create a new plugin */
111
 
  plugin *new_plugin = malloc(sizeof(plugin));
 
113
  plugin *new_plugin = NULL;
 
114
  do {
 
115
    new_plugin = malloc(sizeof(plugin));
 
116
  } while(new_plugin == NULL and errno == EINTR);
112
117
  if(new_plugin == NULL){
113
118
    return NULL;
114
119
  }
115
120
  char *copy_name = NULL;
116
121
  if(name != NULL){
117
 
    copy_name = strdup(name);
 
122
    do {
 
123
      copy_name = strdup(name);
 
124
    } while(copy_name == NULL and errno == EINTR);
118
125
    if(copy_name == NULL){
119
126
      free(new_plugin);
120
127
      return NULL;
126
133
                          .disabled = false,
127
134
                          .next = plugin_list };
128
135
  
129
 
  new_plugin->argv = malloc(sizeof(char *) * 2);
 
136
  do {
 
137
    new_plugin->argv = malloc(sizeof(char *) * 2);
 
138
  } while(new_plugin->argv == NULL and errno == EINTR);
130
139
  if(new_plugin->argv == NULL){
131
140
    free(copy_name);
132
141
    free(new_plugin);
135
144
  new_plugin->argv[0] = copy_name;
136
145
  new_plugin->argv[1] = NULL;
137
146
  
138
 
  new_plugin->environ = malloc(sizeof(char *));
 
147
  do {
 
148
    new_plugin->environ = malloc(sizeof(char *));
 
149
  } while(new_plugin->environ == NULL and errno == EINTR);
139
150
  if(new_plugin->environ == NULL){
140
151
    free(copy_name);
141
152
    free(new_plugin->argv);
153
164
static bool add_to_char_array(const char *new, char ***array,
154
165
                              int *len){
155
166
  /* Resize the pointed-to array to hold one more pointer */
156
 
  *array = realloc(*array, sizeof(char *)
157
 
                   * (size_t) ((*len) + 2));
 
167
  do {
 
168
    *array = realloc(*array, sizeof(char *)
 
169
                     * (size_t) ((*len) + 2));
 
170
  } while(*array == NULL and errno == EINTR);
158
171
  /* Malloc check */
159
172
  if(*array == NULL){
160
173
    return false;
161
174
  }
162
175
  /* Make a copy of the new string */
163
 
  char *copy = strdup(new);
 
176
  char *copy;
 
177
  do {
 
178
    copy = strdup(new);
 
179
  } while(copy == NULL and errno == EINTR);
164
180
  if(copy == NULL){
165
181
    return false;
166
182
  }
192
208
    if(strncmp(*e, def, namelen + 1) == 0){
193
209
      /* It already exists */
194
210
      if(replace){
195
 
        char *new = realloc(*e, strlen(def) + 1);
 
211
        char *new;
 
212
        do {
 
213
          new = realloc(*e, strlen(def) + 1);
 
214
        } while(new == NULL and errno == EINTR);
196
215
        if(new == NULL){
197
216
          return false;
198
217
        }
208
227
/*
209
228
 * Based on the example in the GNU LibC manual chapter 13.13 "File
210
229
 * Descriptor Flags".
211
 
 * *Note File Descriptor Flags:(libc)Descriptor Flags.
 
230
 | [[info:libc:Descriptor%20Flags][File Descriptor Flags]] |
212
231
 */
213
232
static int set_cloexec_flag(int fd){
214
 
  int ret = fcntl(fd, F_GETFD, 0);
 
233
  int ret = (int)TEMP_FAILURE_RETRY(fcntl(fd, F_GETFD, 0));
215
234
  /* If reading the flags failed, return error indication now. */
216
235
  if(ret < 0){
217
236
    return ret;
218
237
  }
219
238
  /* Store modified flag word in the descriptor. */
220
 
  return fcntl(fd, F_SETFD, ret | FD_CLOEXEC);
 
239
  return (int)TEMP_FAILURE_RETRY(fcntl(fd, F_SETFD,
 
240
                                       ret | FD_CLOEXEC));
221
241
}
222
242
 
223
243
 
280
300
  }
281
301
  free(plugin_node->environ);
282
302
  free(plugin_node->buffer);
283
 
 
 
303
  
284
304
  /* Removes the plugin from the singly-linked list */
285
305
  if(plugin_node == plugin_list){
286
306
    /* First one - simple */
313
333
  struct dirent *dirst;
314
334
  struct stat st;
315
335
  fd_set rfds_all;
316
 
  int ret, numchars, maxfd = 0;
 
336
  int ret, maxfd = 0;
317
337
  ssize_t sret;
318
 
  intmax_t tmpmax;
319
338
  uid_t uid = 65534;
320
339
  gid_t gid = 65534;
321
340
  bool debug = false;
381
400
  error_t parse_opt(int key, char *arg, __attribute__((unused))
382
401
                    struct argp_state *state){
383
402
    switch(key){
 
403
      char *tmp;
 
404
      intmax_t tmpmax;
384
405
    case 'g':                   /* --global-options */
385
406
      if(arg != NULL){
386
407
        char *plugin_option;
456
477
      plugindir = strdup(arg);
457
478
      if(plugindir == NULL){
458
479
        perror("strdup");
459
 
      }      
 
480
      }
460
481
      break;
461
482
    case 129:                   /* --config-file */
462
483
      /* This is already done by parse_opt_config_file() */
463
484
      break;
464
485
    case 130:                   /* --userid */
465
 
      ret = sscanf(arg, "%" SCNdMAX "%n", &tmpmax, &numchars);
466
 
      if(ret < 1 or tmpmax != (uid_t)tmpmax
467
 
         or arg[numchars] != '\0'){
 
486
      errno = 0;
 
487
      tmpmax = strtoimax(arg, &tmp, 10);
 
488
      if(errno != 0 or tmp == arg or *tmp != '\0'
 
489
         or tmpmax != (uid_t)tmpmax){
468
490
        fprintf(stderr, "Bad user ID number: \"%s\", using %"
469
491
                PRIdMAX "\n", arg, (intmax_t)uid);
470
492
      } else {
472
494
      }
473
495
      break;
474
496
    case 131:                   /* --groupid */
475
 
      ret = sscanf(arg, "%" SCNdMAX "%n", &tmpmax, &numchars);
476
 
      if(ret < 1 or tmpmax != (gid_t)tmpmax
477
 
         or arg[numchars] != '\0'){
 
497
      errno = 0;
 
498
      tmpmax = strtoimax(arg, &tmp, 10);
 
499
      if(errno != 0 or tmp == arg or *tmp != '\0'
 
500
         or tmpmax != (gid_t)tmpmax){
478
501
        fprintf(stderr, "Bad group ID number: \"%s\", using %"
479
502
                PRIdMAX "\n", arg, (intmax_t)gid);
480
503
      } else {
524
547
      if(argfile == NULL){
525
548
        perror("strdup");
526
549
      }
527
 
      break;      
 
550
      break;
528
551
    case 130:                   /* --userid */
529
552
    case 131:                   /* --groupid */
530
553
    case 132:                   /* --debug */
559
582
    conffp = fopen(AFILE, "r");
560
583
  } else {
561
584
    conffp = fopen(argfile, "r");
562
 
  }  
 
585
  }
563
586
  if(conffp != NULL){
564
587
    char *org_line = NULL;
565
588
    char *p, *arg, *new_arg, *line;
566
589
    size_t size = 0;
567
590
    const char whitespace_delims[] = " \r\t\f\v\n";
568
591
    const char comment_delim[] = "#";
569
 
 
 
592
    
570
593
    custom_argc = 1;
571
594
    custom_argv = malloc(sizeof(char*) * 2);
572
595
    if(custom_argv == NULL){
576
599
    }
577
600
    custom_argv[0] = argv[0];
578
601
    custom_argv[1] = NULL;
579
 
 
 
602
    
580
603
    /* for each line in the config file, strip whitespace and ignore
581
604
       commented text */
582
605
    while(true){
584
607
      if(sret == -1){
585
608
        break;
586
609
      }
587
 
 
 
610
      
588
611
      line = org_line;
589
612
      arg = strsep(&line, comment_delim);
590
613
      while((p = strsep(&arg, whitespace_delims)) != NULL){
609
632
          goto fallback;
610
633
        }
611
634
        custom_argv[custom_argc-1] = new_arg;
612
 
        custom_argv[custom_argc] = NULL;        
 
635
        custom_argv[custom_argc] = NULL;
613
636
      }
614
637
    }
 
638
    do {
 
639
      ret = fclose(conffp);
 
640
    } while(ret == EOF and errno == EINTR);
 
641
    if(ret == EOF){
 
642
      perror("fclose");
 
643
      exitstatus = EXIT_FAILURE;
 
644
      goto fallback;
 
645
    }
615
646
    free(org_line);
616
647
  } else {
617
648
    /* Check for harmful errors and go to fallback. Other errors might
667
698
    perror("setuid");
668
699
  }
669
700
  
670
 
  if(plugindir == NULL){
671
 
    dir = opendir(PDIR);
672
 
  } else {
673
 
    dir = opendir(plugindir);
674
 
  }
675
 
  
676
 
  if(dir == NULL){
677
 
    perror("Could not open plugin dir");
678
 
    exitstatus = EXIT_FAILURE;
679
 
    goto fallback;
680
 
  }
681
 
  
682
 
  /* Set the FD_CLOEXEC flag on the directory, if possible */
 
701
  /* Open plugin directory with close_on_exec flag */
683
702
  {
684
 
    int dir_fd = dirfd(dir);
685
 
    if(dir_fd >= 0){
686
 
      ret = set_cloexec_flag(dir_fd);
687
 
      if(ret < 0){
688
 
        perror("set_cloexec_flag");
689
 
        exitstatus = EXIT_FAILURE;
690
 
        goto fallback;
691
 
      }
 
703
    int dir_fd = -1;
 
704
    if(plugindir == NULL){
 
705
      dir_fd = open(PDIR, O_RDONLY |
 
706
#ifdef O_CLOEXEC
 
707
                    O_CLOEXEC
 
708
#else  /* not O_CLOEXEC */
 
709
                    0
 
710
#endif  /* not O_CLOEXEC */
 
711
                    );
 
712
    } else {
 
713
      dir_fd = open(plugindir, O_RDONLY |
 
714
#ifdef O_CLOEXEC
 
715
                    O_CLOEXEC
 
716
#else  /* not O_CLOEXEC */
 
717
                    0
 
718
#endif  /* not O_CLOEXEC */
 
719
                    );
 
720
    }
 
721
    if(dir_fd == -1){
 
722
      perror("Could not open plugin dir");
 
723
      exitstatus = EXIT_FAILURE;
 
724
      goto fallback;
 
725
    }
 
726
    
 
727
#ifndef O_CLOEXEC
 
728
  /* Set the FD_CLOEXEC flag on the directory */
 
729
    ret = set_cloexec_flag(dir_fd);
 
730
    if(ret < 0){
 
731
      perror("set_cloexec_flag");
 
732
      TEMP_FAILURE_RETRY(close(dir_fd));
 
733
      exitstatus = EXIT_FAILURE;
 
734
      goto fallback;
 
735
    }
 
736
#endif  /* O_CLOEXEC */
 
737
    
 
738
    dir = fdopendir(dir_fd);
 
739
    if(dir == NULL){
 
740
      perror("Could not open plugin dir");
 
741
      TEMP_FAILURE_RETRY(close(dir_fd));
 
742
      exitstatus = EXIT_FAILURE;
 
743
      goto fallback;
692
744
    }
693
745
  }
694
746
  
696
748
  
697
749
  /* Read and execute any executable in the plugin directory*/
698
750
  while(true){
699
 
    dirst = readdir(dir);
 
751
    do {
 
752
      dirst = readdir(dir);
 
753
    } while(dirst == NULL and errno == EINTR);
700
754
    
701
755
    /* All directory entries have been processed */
702
756
    if(dirst == NULL){
753
807
        continue;
754
808
      }
755
809
    }
756
 
 
 
810
    
757
811
    char *filename;
758
812
    if(plugindir == NULL){
759
 
      ret = asprintf(&filename, PDIR "/%s", dirst->d_name);
 
813
      ret = (int)TEMP_FAILURE_RETRY(asprintf(&filename, PDIR "/%s",
 
814
                                             dirst->d_name));
760
815
    } else {
761
 
      ret = asprintf(&filename, "%s/%s", plugindir, dirst->d_name);
 
816
      ret = (int)TEMP_FAILURE_RETRY(asprintf(&filename, "%s/%s",
 
817
                                             plugindir,
 
818
                                             dirst->d_name));
762
819
    }
763
820
    if(ret < 0){
764
821
      perror("asprintf");
765
822
      continue;
766
823
    }
767
824
    
768
 
    ret = stat(filename, &st);
 
825
    ret = (int)TEMP_FAILURE_RETRY(stat(filename, &st));
769
826
    if(ret == -1){
770
827
      perror("stat");
771
828
      free(filename);
772
829
      continue;
773
830
    }
774
 
 
 
831
    
775
832
    /* Ignore non-executable files */
776
 
    if(not S_ISREG(st.st_mode) or (access(filename, X_OK) != 0)){
 
833
    if(not S_ISREG(st.st_mode)
 
834
       or (TEMP_FAILURE_RETRY(access(filename, X_OK)) != 0)){
777
835
      if(debug){
778
836
        fprintf(stderr, "Ignoring plugin dir entry \"%s\""
779
837
                " with bad type or mode\n", filename);
825
883
    }
826
884
    
827
885
    int pipefd[2];
828
 
    ret = pipe(pipefd);
 
886
    ret = (int)TEMP_FAILURE_RETRY(pipe(pipefd));
829
887
    if(ret == -1){
830
888
      perror("pipe");
831
889
      exitstatus = EXIT_FAILURE;
845
903
      goto fallback;
846
904
    }
847
905
    /* Block SIGCHLD until process is safely in process list */
848
 
    ret = sigprocmask(SIG_BLOCK, &sigchld_action.sa_mask, NULL);
 
906
    ret = (int)TEMP_FAILURE_RETRY(sigprocmask(SIG_BLOCK,
 
907
                                              &sigchld_action.sa_mask,
 
908
                                              NULL));
849
909
    if(ret < 0){
850
910
      perror("sigprocmask");
851
911
      exitstatus = EXIT_FAILURE;
852
912
      goto fallback;
853
913
    }
854
914
    /* Starting a new process to be watched */
855
 
    pid_t pid = fork();
 
915
    pid_t pid;
 
916
    do {
 
917
      pid = fork();
 
918
    } while(pid == -1 and errno == EINTR);
856
919
    if(pid == -1){
857
920
      perror("fork");
858
921
      exitstatus = EXIT_FAILURE;
896
959
      /* no return */
897
960
    }
898
961
    /* Parent process */
899
 
    close(pipefd[1]);           /* Close unused write end of pipe */
 
962
    TEMP_FAILURE_RETRY(close(pipefd[1])); /* Close unused write end of
 
963
                                             pipe */
900
964
    free(filename);
901
965
    plugin *new_plugin = getplugin(dirst->d_name);
902
966
    if(new_plugin == NULL){
903
967
      perror("getplugin");
904
 
      ret = sigprocmask(SIG_UNBLOCK, &sigchld_action.sa_mask, NULL);
 
968
      ret = (int)(TEMP_FAILURE_RETRY
 
969
                  (sigprocmask(SIG_UNBLOCK, &sigchld_action.sa_mask,
 
970
                               NULL)));
905
971
      if(ret < 0){
906
972
        perror("sigprocmask");
907
973
      }
914
980
    
915
981
    /* Unblock SIGCHLD so signal handler can be run if this process
916
982
       has already completed */
917
 
    ret = sigprocmask(SIG_UNBLOCK, &sigchld_action.sa_mask, NULL);
 
983
    ret = (int)TEMP_FAILURE_RETRY(sigprocmask(SIG_UNBLOCK,
 
984
                                              &sigchld_action.sa_mask,
 
985
                                              NULL));
918
986
    if(ret < 0){
919
987
      perror("sigprocmask");
920
988
      exitstatus = EXIT_FAILURE;
921
989
      goto fallback;
922
990
    }
923
991
    
924
 
    FD_SET(new_plugin->fd, &rfds_all);
 
992
    FD_SET(new_plugin->fd, &rfds_all); /* Spurious warning from
 
993
                                          -Wconversion */
925
994
    
926
995
    if(maxfd < new_plugin->fd){
927
996
      maxfd = new_plugin->fd;
928
997
    }
929
998
  }
930
999
  
931
 
  closedir(dir);
 
1000
  TEMP_FAILURE_RETRY(closedir(dir));
932
1001
  dir = NULL;
933
1002
  free_plugin(getplugin(NULL));
934
1003
  
947
1016
  while(plugin_list){
948
1017
    fd_set rfds = rfds_all;
949
1018
    int select_ret = select(maxfd+1, &rfds, NULL, NULL, NULL);
950
 
    if(select_ret == -1){
 
1019
    if(select_ret == -1 and errno != EINTR){
951
1020
      perror("select");
952
1021
      exitstatus = EXIT_FAILURE;
953
1022
      goto fallback;
961
1030
        if(not WIFEXITED(proc->status)
962
1031
           or WEXITSTATUS(proc->status) != 0){
963
1032
          /* Bad exit by plugin */
964
 
 
 
1033
          
965
1034
          if(debug){
966
1035
            if(WIFEXITED(proc->status)){
967
1036
              fprintf(stderr, "Plugin %s [%" PRIdMAX "] exited with"
970
1039
                      WEXITSTATUS(proc->status));
971
1040
            } else if(WIFSIGNALED(proc->status)){
972
1041
              fprintf(stderr, "Plugin %s [%" PRIdMAX "] killed by"
973
 
                      " signal %d\n", proc->name,
 
1042
                      " signal %d: %s\n", proc->name,
974
1043
                      (intmax_t) (proc->pid),
975
 
                      WTERMSIG(proc->status));
 
1044
                      WTERMSIG(proc->status),
 
1045
                      strsignal(WTERMSIG(proc->status)));
976
1046
            } else if(WCOREDUMP(proc->status)){
977
1047
              fprintf(stderr, "Plugin %s [%" PRIdMAX "] dumped"
978
1048
                      " core\n", proc->name, (intmax_t) (proc->pid));
980
1050
          }
981
1051
          
982
1052
          /* Remove the plugin */
983
 
          FD_CLR(proc->fd, &rfds_all);
984
 
 
 
1053
          FD_CLR(proc->fd, &rfds_all); /* Spurious warning from
 
1054
                                          -Wconversion */
 
1055
          
985
1056
          /* Block signal while modifying process_list */
986
 
          ret = sigprocmask(SIG_BLOCK, &sigchld_action.sa_mask, NULL);
 
1057
          ret = (int)TEMP_FAILURE_RETRY(sigprocmask
 
1058
                                        (SIG_BLOCK,
 
1059
                                         &sigchld_action.sa_mask,
 
1060
                                         NULL));
987
1061
          if(ret < 0){
988
1062
            perror("sigprocmask");
989
1063
            exitstatus = EXIT_FAILURE;
995
1069
          proc = next_plugin;
996
1070
          
997
1071
          /* We are done modifying process list, so unblock signal */
998
 
          ret = sigprocmask(SIG_UNBLOCK, &sigchld_action.sa_mask,
999
 
                            NULL);
 
1072
          ret = (int)(TEMP_FAILURE_RETRY
 
1073
                      (sigprocmask(SIG_UNBLOCK,
 
1074
                                   &sigchld_action.sa_mask, NULL)));
1000
1075
          if(ret < 0){
1001
1076
            perror("sigprocmask");
1002
1077
            exitstatus = EXIT_FAILURE;
1022
1097
      }
1023
1098
      
1024
1099
      /* This process has not completed.  Does it have any output? */
1025
 
      if(proc->eof or not FD_ISSET(proc->fd, &rfds)){
 
1100
      if(proc->eof or not FD_ISSET(proc->fd, &rfds)){ /* Spurious
 
1101
                                                         warning from
 
1102
                                                         -Wconversion */
1026
1103
        /* This process had nothing to say at this time */
1027
1104
        proc = proc->next;
1028
1105
        continue;
1039
1116
        proc->buffer_size += BUFFER_SIZE;
1040
1117
      }
1041
1118
      /* Read from the process */
1042
 
      sret = read(proc->fd, proc->buffer + proc->buffer_length,
1043
 
                  BUFFER_SIZE);
 
1119
      sret = TEMP_FAILURE_RETRY(read(proc->fd,
 
1120
                                     proc->buffer
 
1121
                                     + proc->buffer_length,
 
1122
                                     BUFFER_SIZE));
1044
1123
      if(sret < 0){
1045
1124
        /* Read error from this process; ignore the error */
1046
1125
        proc = proc->next;
1054
1133
      }
1055
1134
    }
1056
1135
  }
1057
 
 
1058
 
 
 
1136
  
 
1137
  
1059
1138
 fallback:
1060
1139
  
1061
1140
  if(plugin_list == NULL or exitstatus != EXIT_SUCCESS){
1108
1187
  }
1109
1188
  
1110
1189
  /* Wait for any remaining child processes to terminate */
1111
 
  do{
 
1190
  do {
1112
1191
    ret = wait(NULL);
1113
1192
  } while(ret >= 0);
1114
1193
  if(errno != ECHILD){