/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

todo

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
 *
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
45
#include <dirent.h>             /* DIR, struct dirent, opendir(),
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(), strcmp(), strncmp() */
56
58
#include <errno.h>              /* errno */
57
59
#include <argp.h>               /* struct argp_option, struct
58
60
                                   argp_state, struct argp,
62
64
#include <signal.h>             /* struct sigaction, sigemptyset(),
63
65
                                   sigaddset(), sigaction(),
64
66
                                   sigprocmask(), SIG_BLOCK, SIGCHLD,
65
 
                                   SIG_UNBLOCK, kill() */
 
67
                                   SIG_UNBLOCK, kill(), sig_atomic_t
 
68
                                */
66
69
#include <errno.h>              /* errno, EBADF */
67
 
#include <inttypes.h>           /* intmax_t, SCNdMAX, PRIdMAX,  */
 
70
#include <inttypes.h>           /* intmax_t, PRIdMAX, strtoimax() */
68
71
 
69
72
#define BUFFER_SIZE 256
70
73
 
81
84
  char **environ;
82
85
  int envc;
83
86
  bool disabled;
84
 
 
 
87
  
85
88
  /* Variables used for running processes*/
86
89
  pid_t pid;
87
90
  int fd;
89
92
  size_t buffer_size;
90
93
  size_t buffer_length;
91
94
  bool eof;
92
 
  volatile bool completed;
93
 
  volatile int status;
 
95
  volatile sig_atomic_t completed;
 
96
  int status;
94
97
  struct plugin *next;
95
98
} plugin;
96
99
 
107
110
    }
108
111
  }
109
112
  /* Create a new plugin */
110
 
  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);
111
117
  if(new_plugin == NULL){
112
118
    return NULL;
113
119
  }
114
120
  char *copy_name = NULL;
115
121
  if(name != NULL){
116
 
    copy_name = strdup(name);
 
122
    do {
 
123
      copy_name = strdup(name);
 
124
    } while(copy_name == NULL and errno == EINTR);
117
125
    if(copy_name == NULL){
118
126
      free(new_plugin);
119
127
      return NULL;
120
128
    }
121
129
  }
122
130
  
123
 
  *new_plugin = (plugin) { .name = copy_name,
124
 
                           .argc = 1,
125
 
                           .disabled = false,
126
 
                           .next = plugin_list };
 
131
  *new_plugin = (plugin){ .name = copy_name,
 
132
                          .argc = 1,
 
133
                          .disabled = false,
 
134
                          .next = plugin_list };
127
135
  
128
 
  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);
129
139
  if(new_plugin->argv == NULL){
130
140
    free(copy_name);
131
141
    free(new_plugin);
134
144
  new_plugin->argv[0] = copy_name;
135
145
  new_plugin->argv[1] = NULL;
136
146
  
137
 
  new_plugin->environ = malloc(sizeof(char *));
 
147
  do {
 
148
    new_plugin->environ = malloc(sizeof(char *));
 
149
  } while(new_plugin->environ == NULL and errno == EINTR);
138
150
  if(new_plugin->environ == NULL){
139
151
    free(copy_name);
140
152
    free(new_plugin->argv);
152
164
static bool add_to_char_array(const char *new, char ***array,
153
165
                              int *len){
154
166
  /* Resize the pointed-to array to hold one more pointer */
155
 
  *array = realloc(*array, sizeof(char *)
156
 
                   * (size_t) ((*len) + 2));
 
167
  do {
 
168
    *array = realloc(*array, sizeof(char *)
 
169
                     * (size_t) ((*len) + 2));
 
170
  } while(*array == NULL and errno == EINTR);
157
171
  /* Malloc check */
158
172
  if(*array == NULL){
159
173
    return false;
160
174
  }
161
175
  /* Make a copy of the new string */
162
 
  char *copy = strdup(new);
 
176
  char *copy;
 
177
  do {
 
178
    copy = strdup(new);
 
179
  } while(copy == NULL and errno == EINTR);
163
180
  if(copy == NULL){
164
181
    return false;
165
182
  }
191
208
    if(strncmp(*e, def, namelen + 1) == 0){
192
209
      /* It already exists */
193
210
      if(replace){
194
 
        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);
195
215
        if(new == NULL){
196
216
          return false;
197
217
        }
207
227
/*
208
228
 * Based on the example in the GNU LibC manual chapter 13.13 "File
209
229
 * Descriptor Flags".
210
 
 * *Note File Descriptor Flags:(libc)Descriptor Flags.
 
230
 | [[info:libc:Descriptor%20Flags][File Descriptor Flags]] |
211
231
 */
212
232
static int set_cloexec_flag(int fd){
213
 
  int ret = fcntl(fd, F_GETFD, 0);
 
233
  int ret = (int)TEMP_FAILURE_RETRY(fcntl(fd, F_GETFD, 0));
214
234
  /* If reading the flags failed, return error indication now. */
215
235
  if(ret < 0){
216
236
    return ret;
217
237
  }
218
238
  /* Store modified flag word in the descriptor. */
219
 
  return fcntl(fd, F_SETFD, ret | FD_CLOEXEC);
 
239
  return (int)TEMP_FAILURE_RETRY(fcntl(fd, F_SETFD,
 
240
                                       ret | FD_CLOEXEC));
220
241
}
221
242
 
222
243
 
223
244
/* Mark processes as completed when they exit, and save their exit
224
245
   status. */
225
246
static void handle_sigchld(__attribute__((unused)) int sig){
 
247
  int old_errno = errno;
226
248
  while(true){
227
249
    plugin *proc = plugin_list;
228
250
    int status;
232
254
      break;
233
255
    }
234
256
    if(pid == -1){
235
 
      if(errno != ECHILD){
236
 
        perror("waitpid");
 
257
      if(errno == ECHILD){
 
258
        /* No child processes */
 
259
        break;
237
260
      }
238
 
      /* No child processes */
239
 
      break;
 
261
      perror("waitpid");
240
262
    }
241
263
    
242
264
    /* A child exited, find it in process_list */
248
270
      continue;
249
271
    }
250
272
    proc->status = status;
251
 
    proc->completed = true;
 
273
    proc->completed = 1;
252
274
  }
 
275
  errno = old_errno;
253
276
}
254
277
 
255
278
/* Prints out a password to stdout */
277
300
  }
278
301
  free(plugin_node->environ);
279
302
  free(plugin_node->buffer);
280
 
 
 
303
  
281
304
  /* Removes the plugin from the singly-linked list */
282
305
  if(plugin_node == plugin_list){
283
306
    /* First one - simple */
310
333
  struct dirent *dirst;
311
334
  struct stat st;
312
335
  fd_set rfds_all;
313
 
  int ret, numchars, maxfd = 0;
 
336
  int ret, maxfd = 0;
314
337
  ssize_t sret;
315
 
  intmax_t tmpmax;
316
338
  uid_t uid = 65534;
317
339
  gid_t gid = 65534;
318
340
  bool debug = false;
376
398
  };
377
399
  
378
400
  error_t parse_opt(int key, char *arg, __attribute__((unused))
379
 
                    struct argp_state *state) {
380
 
    switch(key) {
 
401
                    struct argp_state *state){
 
402
    switch(key){
 
403
      char *tmp;
 
404
      intmax_t tmpmax;
381
405
    case 'g':                   /* --global-options */
382
406
      if(arg != NULL){
383
 
        char *p;
384
 
        while((p = strsep(&arg, ",")) != NULL){
385
 
          if(p[0] == '\0'){
 
407
        char *plugin_option;
 
408
        while((plugin_option = strsep(&arg, ",")) != NULL){
 
409
          if(plugin_option[0] == '\0'){
386
410
            continue;
387
411
          }
388
 
          if(not add_argument(getplugin(NULL), p)){
 
412
          if(not add_argument(getplugin(NULL), plugin_option)){
389
413
            perror("add_argument");
390
414
            return ARGP_ERR_UNKNOWN;
391
415
          }
402
426
      break;
403
427
    case 'o':                   /* --options-for */
404
428
      if(arg != NULL){
405
 
        char *p_name = strsep(&arg, ":");
406
 
        if(p_name[0] == '\0' or arg == NULL){
407
 
          break;
408
 
        }
409
 
        char *opt = strsep(&arg, ":");
410
 
        if(opt[0] == '\0' or opt == NULL){
411
 
          break;
412
 
        }
413
 
        char *p;
414
 
        while((p = strsep(&opt, ",")) != NULL){
415
 
          if(p[0] == '\0'){
416
 
            continue;
417
 
          }
418
 
          if(not add_argument(getplugin(p_name), p)){
 
429
        char *plugin_name = strsep(&arg, ":");
 
430
        if(plugin_name[0] == '\0'){
 
431
          break;
 
432
        }
 
433
        char *plugin_option;
 
434
        while((plugin_option = strsep(&arg, ",")) != NULL){
 
435
          if(not add_argument(getplugin(plugin_name), plugin_option)){
419
436
            perror("add_argument");
420
437
            return ARGP_ERR_UNKNOWN;
421
438
          }
460
477
      plugindir = strdup(arg);
461
478
      if(plugindir == NULL){
462
479
        perror("strdup");
463
 
      }      
 
480
      }
464
481
      break;
465
482
    case 129:                   /* --config-file */
466
483
      /* This is already done by parse_opt_config_file() */
467
484
      break;
468
485
    case 130:                   /* --userid */
469
 
      ret = sscanf(arg, "%" SCNdMAX "%n", &tmpmax, &numchars);
470
 
      if(ret < 1 or tmpmax != (uid_t)tmpmax
471
 
         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){
472
490
        fprintf(stderr, "Bad user ID number: \"%s\", using %"
473
491
                PRIdMAX "\n", arg, (intmax_t)uid);
474
492
      } else {
476
494
      }
477
495
      break;
478
496
    case 131:                   /* --groupid */
479
 
      ret = sscanf(arg, "%" SCNdMAX "%n", &tmpmax, &numchars);
480
 
      if(ret < 1 or tmpmax != (gid_t)tmpmax
481
 
         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){
482
501
        fprintf(stderr, "Bad group ID number: \"%s\", using %"
483
502
                PRIdMAX "\n", arg, (intmax_t)gid);
484
503
      } else {
512
531
     ignores everything but the --config-file option. */
513
532
  error_t parse_opt_config_file(int key, char *arg,
514
533
                                __attribute__((unused))
515
 
                                struct argp_state *state) {
516
 
    switch(key) {
 
534
                                struct argp_state *state){
 
535
    switch(key){
517
536
    case 'g':                   /* --global-options */
518
537
    case 'G':                   /* --global-env */
519
538
    case 'o':                   /* --options-for */
528
547
      if(argfile == NULL){
529
548
        perror("strdup");
530
549
      }
531
 
      break;      
 
550
      break;
532
551
    case 130:                   /* --userid */
533
552
    case 131:                   /* --groupid */
534
553
    case 132:                   /* --debug */
563
582
    conffp = fopen(AFILE, "r");
564
583
  } else {
565
584
    conffp = fopen(argfile, "r");
566
 
  }  
 
585
  }
567
586
  if(conffp != NULL){
568
587
    char *org_line = NULL;
569
588
    char *p, *arg, *new_arg, *line;
570
589
    size_t size = 0;
571
590
    const char whitespace_delims[] = " \r\t\f\v\n";
572
591
    const char comment_delim[] = "#";
573
 
 
 
592
    
574
593
    custom_argc = 1;
575
594
    custom_argv = malloc(sizeof(char*) * 2);
576
595
    if(custom_argv == NULL){
580
599
    }
581
600
    custom_argv[0] = argv[0];
582
601
    custom_argv[1] = NULL;
583
 
 
 
602
    
584
603
    /* for each line in the config file, strip whitespace and ignore
585
604
       commented text */
586
605
    while(true){
588
607
      if(sret == -1){
589
608
        break;
590
609
      }
591
 
 
 
610
      
592
611
      line = org_line;
593
612
      arg = strsep(&line, comment_delim);
594
613
      while((p = strsep(&arg, whitespace_delims)) != NULL){
613
632
          goto fallback;
614
633
        }
615
634
        custom_argv[custom_argc-1] = new_arg;
616
 
        custom_argv[custom_argc] = NULL;        
 
635
        custom_argv[custom_argc] = NULL;
617
636
      }
618
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
    }
619
646
    free(org_line);
620
647
  } else {
621
648
    /* Check for harmful errors and go to fallback. Other errors might
662
689
  }
663
690
  
664
691
  /* Strip permissions down to nobody */
 
692
  setgid(gid);
 
693
  if(ret == -1){
 
694
    perror("setgid");
 
695
  }
665
696
  ret = setuid(uid);
666
697
  if(ret == -1){
667
698
    perror("setuid");
668
 
  }  
669
 
  setgid(gid);
670
 
  if(ret == -1){
671
 
    perror("setgid");
672
699
  }
673
700
  
674
701
  if(plugindir == NULL){
700
727
  
701
728
  /* Read and execute any executable in the plugin directory*/
702
729
  while(true){
703
 
    dirst = readdir(dir);
 
730
    do {
 
731
      dirst = readdir(dir);
 
732
    } while(dirst == NULL and errno == EINTR);
704
733
    
705
734
    /* All directory entries have been processed */
706
735
    if(dirst == NULL){
742
771
      for(const char **suf = bad_suffixes; *suf != NULL; suf++){
743
772
        size_t suf_len = strlen(*suf);
744
773
        if((d_name_len >= suf_len)
745
 
           and (strcmp((dirst->d_name)+d_name_len-suf_len, *suf)
 
774
           and (strcmp((dirst->d_name) + d_name_len-suf_len, *suf)
746
775
                == 0)){
747
776
          if(debug){
748
777
            fprintf(stderr, "Ignoring plugin dir entry \"%s\""
757
786
        continue;
758
787
      }
759
788
    }
760
 
 
 
789
    
761
790
    char *filename;
762
791
    if(plugindir == NULL){
763
 
      ret = asprintf(&filename, PDIR "/%s", dirst->d_name);
 
792
      ret = (int)TEMP_FAILURE_RETRY(asprintf(&filename, PDIR "/%s",
 
793
                                             dirst->d_name));
764
794
    } else {
765
 
      ret = asprintf(&filename, "%s/%s", plugindir, dirst->d_name);
 
795
      ret = (int)TEMP_FAILURE_RETRY(asprintf(&filename, "%s/%s",
 
796
                                             plugindir,
 
797
                                             dirst->d_name));
766
798
    }
767
799
    if(ret < 0){
768
800
      perror("asprintf");
769
801
      continue;
770
802
    }
771
803
    
772
 
    ret = stat(filename, &st);
 
804
    ret = (int)TEMP_FAILURE_RETRY(stat(filename, &st));
773
805
    if(ret == -1){
774
806
      perror("stat");
775
807
      free(filename);
776
808
      continue;
777
809
    }
778
 
 
 
810
    
779
811
    /* Ignore non-executable files */
780
 
    if(not S_ISREG(st.st_mode) or (access(filename, X_OK) != 0)){
 
812
    if(not S_ISREG(st.st_mode)
 
813
       or (TEMP_FAILURE_RETRY(access(filename, X_OK)) != 0)){
781
814
      if(debug){
782
815
        fprintf(stderr, "Ignoring plugin dir entry \"%s\""
783
816
                " with bad type or mode\n", filename);
829
862
    }
830
863
    
831
864
    int pipefd[2];
832
 
    ret = pipe(pipefd);
 
865
    ret = (int)TEMP_FAILURE_RETRY(pipe(pipefd));
833
866
    if(ret == -1){
834
867
      perror("pipe");
835
868
      exitstatus = EXIT_FAILURE;
849
882
      goto fallback;
850
883
    }
851
884
    /* Block SIGCHLD until process is safely in process list */
852
 
    ret = sigprocmask(SIG_BLOCK, &sigchld_action.sa_mask, NULL);
 
885
    ret = (int)TEMP_FAILURE_RETRY(sigprocmask(SIG_BLOCK,
 
886
                                              &sigchld_action.sa_mask,
 
887
                                              NULL));
853
888
    if(ret < 0){
854
889
      perror("sigprocmask");
855
890
      exitstatus = EXIT_FAILURE;
856
891
      goto fallback;
857
892
    }
858
893
    /* Starting a new process to be watched */
859
 
    pid_t pid = fork();
 
894
    pid_t pid;
 
895
    do {
 
896
      pid = fork();
 
897
    } while(pid == -1 and errno == EINTR);
860
898
    if(pid == -1){
861
899
      perror("fork");
862
900
      exitstatus = EXIT_FAILURE;
900
938
      /* no return */
901
939
    }
902
940
    /* Parent process */
903
 
    close(pipefd[1]);           /* Close unused write end of pipe */
 
941
    TEMP_FAILURE_RETRY(close(pipefd[1])); /* Close unused write end of
 
942
                                             pipe */
904
943
    free(filename);
905
944
    plugin *new_plugin = getplugin(dirst->d_name);
906
945
    if(new_plugin == NULL){
907
946
      perror("getplugin");
908
 
      ret = sigprocmask(SIG_UNBLOCK, &sigchld_action.sa_mask, NULL);
 
947
      ret = (int)(TEMP_FAILURE_RETRY
 
948
                  (sigprocmask(SIG_UNBLOCK, &sigchld_action.sa_mask,
 
949
                               NULL)));
909
950
      if(ret < 0){
910
951
        perror("sigprocmask");
911
952
      }
918
959
    
919
960
    /* Unblock SIGCHLD so signal handler can be run if this process
920
961
       has already completed */
921
 
    ret = sigprocmask(SIG_UNBLOCK, &sigchld_action.sa_mask, NULL);
 
962
    ret = (int)TEMP_FAILURE_RETRY(sigprocmask(SIG_UNBLOCK,
 
963
                                              &sigchld_action.sa_mask,
 
964
                                              NULL));
922
965
    if(ret < 0){
923
966
      perror("sigprocmask");
924
967
      exitstatus = EXIT_FAILURE;
925
968
      goto fallback;
926
969
    }
927
970
    
928
 
    FD_SET(new_plugin->fd, &rfds_all);
 
971
    FD_SET(new_plugin->fd, &rfds_all); /* Spurious warning from
 
972
                                          -Wconversion */
929
973
    
930
974
    if(maxfd < new_plugin->fd){
931
975
      maxfd = new_plugin->fd;
932
976
    }
933
977
  }
934
978
  
935
 
  closedir(dir);
 
979
  TEMP_FAILURE_RETRY(closedir(dir));
936
980
  dir = NULL;
 
981
  free_plugin(getplugin(NULL));
937
982
  
938
983
  for(plugin *p = plugin_list; p != NULL; p = p->next){
939
984
    if(p->pid != 0){
950
995
  while(plugin_list){
951
996
    fd_set rfds = rfds_all;
952
997
    int select_ret = select(maxfd+1, &rfds, NULL, NULL, NULL);
953
 
    if(select_ret == -1){
 
998
    if(select_ret == -1 and errno != EINTR){
954
999
      perror("select");
955
1000
      exitstatus = EXIT_FAILURE;
956
1001
      goto fallback;
959
1004
       from one of them */
960
1005
    for(plugin *proc = plugin_list; proc != NULL;){
961
1006
      /* Is this process completely done? */
962
 
      if(proc->eof and proc->completed){
 
1007
      if(proc->completed and proc->eof){
963
1008
        /* Only accept the plugin output if it exited cleanly */
964
1009
        if(not WIFEXITED(proc->status)
965
1010
           or WEXITSTATUS(proc->status) != 0){
966
1011
          /* Bad exit by plugin */
967
 
 
 
1012
          
968
1013
          if(debug){
969
1014
            if(WIFEXITED(proc->status)){
970
 
              fprintf(stderr, "Plugin %" PRIdMAX " exited with status"
971
 
                      " %d\n", (intmax_t) (proc->pid),
 
1015
              fprintf(stderr, "Plugin %s [%" PRIdMAX "] exited with"
 
1016
                      " status %d\n", proc->name,
 
1017
                      (intmax_t) (proc->pid),
972
1018
                      WEXITSTATUS(proc->status));
973
 
            } else if(WIFSIGNALED(proc->status)) {
974
 
              fprintf(stderr, "Plugin %" PRIdMAX " killed by signal"
975
 
                      " %d\n", (intmax_t) (proc->pid),
976
 
                      WTERMSIG(proc->status));
 
1019
            } else if(WIFSIGNALED(proc->status)){
 
1020
              fprintf(stderr, "Plugin %s [%" PRIdMAX "] killed by"
 
1021
                      " signal %d: %s\n", proc->name,
 
1022
                      (intmax_t) (proc->pid),
 
1023
                      WTERMSIG(proc->status),
 
1024
                      strsignal(WTERMSIG(proc->status)));
977
1025
            } else if(WCOREDUMP(proc->status)){
978
 
              fprintf(stderr, "Plugin %" PRIdMAX " dumped core\n",
979
 
                      (intmax_t) (proc->pid));
 
1026
              fprintf(stderr, "Plugin %s [%" PRIdMAX "] dumped"
 
1027
                      " core\n", proc->name, (intmax_t) (proc->pid));
980
1028
            }
981
1029
          }
982
1030
          
983
1031
          /* Remove the plugin */
984
 
          FD_CLR(proc->fd, &rfds_all);
985
 
 
 
1032
          FD_CLR(proc->fd, &rfds_all); /* Spurious warning from
 
1033
                                          -Wconversion */
 
1034
          
986
1035
          /* Block signal while modifying process_list */
987
 
          ret = sigprocmask(SIG_BLOCK, &sigchld_action.sa_mask, NULL);
 
1036
          ret = (int)TEMP_FAILURE_RETRY(sigprocmask
 
1037
                                        (SIG_BLOCK,
 
1038
                                         &sigchld_action.sa_mask,
 
1039
                                         NULL));
988
1040
          if(ret < 0){
989
1041
            perror("sigprocmask");
990
1042
            exitstatus = EXIT_FAILURE;
996
1048
          proc = next_plugin;
997
1049
          
998
1050
          /* We are done modifying process list, so unblock signal */
999
 
          ret = sigprocmask(SIG_UNBLOCK, &sigchld_action.sa_mask,
1000
 
                            NULL);
 
1051
          ret = (int)(TEMP_FAILURE_RETRY
 
1052
                      (sigprocmask(SIG_UNBLOCK,
 
1053
                                   &sigchld_action.sa_mask, NULL)));
1001
1054
          if(ret < 0){
1002
1055
            perror("sigprocmask");
1003
1056
            exitstatus = EXIT_FAILURE;
1023
1076
      }
1024
1077
      
1025
1078
      /* This process has not completed.  Does it have any output? */
1026
 
      if(proc->eof or not FD_ISSET(proc->fd, &rfds)){
 
1079
      if(proc->eof or not FD_ISSET(proc->fd, &rfds)){ /* Spurious
 
1080
                                                         warning from
 
1081
                                                         -Wconversion */
1027
1082
        /* This process had nothing to say at this time */
1028
1083
        proc = proc->next;
1029
1084
        continue;
1040
1095
        proc->buffer_size += BUFFER_SIZE;
1041
1096
      }
1042
1097
      /* Read from the process */
1043
 
      sret = read(proc->fd, proc->buffer + proc->buffer_length,
1044
 
                  BUFFER_SIZE);
 
1098
      sret = TEMP_FAILURE_RETRY(read(proc->fd,
 
1099
                                     proc->buffer
 
1100
                                     + proc->buffer_length,
 
1101
                                     BUFFER_SIZE));
1045
1102
      if(sret < 0){
1046
1103
        /* Read error from this process; ignore the error */
1047
1104
        proc = proc->next;
1055
1112
      }
1056
1113
    }
1057
1114
  }
1058
 
 
1059
 
 
 
1115
  
 
1116
  
1060
1117
 fallback:
1061
1118
  
1062
1119
  if(plugin_list == NULL or exitstatus != EXIT_SUCCESS){
1109
1166
  }
1110
1167
  
1111
1168
  /* Wait for any remaining child processes to terminate */
1112
 
  do{
 
1169
  do {
1113
1170
    ret = wait(NULL);
1114
1171
  } while(ret >= 0);
1115
1172
  if(errno != ECHILD){