/mandos/release

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

« back to all changes in this revision

Viewing changes to plugin-runner.c

* initramfs-tools-script: Abort if plugin-runner is missing.  Removed
                          workaround for Debian bug #633582; the
                          workaround required getopt, which can not be
                          guaranteed.
* plugin-runner.c (main): Work around Debian bug #633582.
* plugins.d/mandos-client.c (main): - '' -

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
/*
3
3
 * Mandos plugin runner - Run Mandos plugins
4
4
 *
5
 
 * Copyright © 2008-2013 Teddy Hogeborn
6
 
 * Copyright © 2008-2013 Björn Påhlsson
 
5
 * Copyright © 2008-2010 Teddy Hogeborn
 
6
 * Copyright © 2008-2010 Björn Påhlsson
7
7
 * 
8
8
 * This program is free software: you can redistribute it and/or
9
9
 * modify it under the terms of the GNU General Public License as
19
19
 * along with this program.  If not, see
20
20
 * <http://www.gnu.org/licenses/>.
21
21
 * 
22
 
 * Contact the authors at <mandos@recompile.se>.
 
22
 * Contact the authors at <mandos@fukt.bsnet.se>.
23
23
 */
24
24
 
25
25
#define _GNU_SOURCE             /* TEMP_FAILURE_RETRY(), getline(),
26
 
                                   O_CLOEXEC */
 
26
                                   asprintf(), O_CLOEXEC */
27
27
#include <stddef.h>             /* size_t, NULL */
28
28
#include <stdlib.h>             /* malloc(), exit(), EXIT_SUCCESS,
29
29
                                   realloc() */
30
30
#include <stdbool.h>            /* bool, true, false */
31
31
#include <stdio.h>              /* fileno(), fprintf(),
32
 
                                   stderr, STDOUT_FILENO, fclose() */
33
 
#include <sys/types.h>          /* DIR, fdopendir(), fstat(), struct
 
32
                                   stderr, STDOUT_FILENO */
 
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(),
40
40
#include <sys/wait.h>           /* wait(), waitpid(), WIFEXITED(),
41
41
                                   WEXITSTATUS(), WTERMSIG(),
42
42
                                   WCOREDUMP() */
43
 
#include <sys/stat.h>           /* struct stat, fstat(), S_ISREG() */
 
43
#include <sys/stat.h>           /* struct stat, stat(), S_ISREG() */
44
44
#include <iso646.h>             /* and, or, not */
45
45
#include <dirent.h>             /* DIR, struct dirent, fdopendir(),
46
46
                                   readdir(), closedir(), dirfd() */
47
 
#include <unistd.h>             /* fcntl(), F_GETFD, F_SETFD,
48
 
                                   FD_CLOEXEC, write(), STDOUT_FILENO,
49
 
                                   struct stat, fstat(), close(),
50
 
                                   setgid(), setuid(), S_ISREG(),
51
 
                                   faccessat() pipe(), fork(),
52
 
                                   _exit(), dup2(), fexecve(), read()
53
 
                                */
 
47
#include <unistd.h>             /* struct stat, stat(), S_ISREG(),
 
48
                                   fcntl(), setuid(), setgid(),
 
49
                                   F_GETFD, F_SETFD, FD_CLOEXEC,
 
50
                                   access(), pipe(), fork(), close()
 
51
                                   dup2(), STDOUT_FILENO, _exit(),
 
52
                                   execv(), write(), read(),
 
53
                                   close() */
54
54
#include <fcntl.h>              /* fcntl(), F_GETFD, F_SETFD,
55
 
                                   FD_CLOEXEC, openat() */
56
 
#include <string.h>             /* strsep, strlen(), strsignal(),
57
 
                                   strcmp(), strncmp() */
 
55
                                   FD_CLOEXEC */
 
56
#include <string.h>             /* strsep, strlen(), asprintf(),
 
57
                                   strsignal(), strcmp(), strncmp() */
58
58
#include <errno.h>              /* errno */
59
59
#include <argp.h>               /* struct argp_option, struct
60
60
                                   argp_state, struct argp,
79
79
#define AFILE "/conf/conf.d/mandos/plugin-runner.conf"
80
80
 
81
81
const char *argp_program_version = "plugin-runner " VERSION;
82
 
const char *argp_program_bug_address = "<mandos@recompile.se>";
 
82
const char *argp_program_bug_address = "<mandos@fukt.bsnet.se>";
83
83
 
84
84
typedef struct plugin{
85
85
  char *name;                   /* can be NULL or any plugin name */
105
105
 
106
106
/* Gets an existing plugin based on name,
107
107
   or if none is found, creates a new one */
108
 
__attribute__((warn_unused_result))
109
108
static plugin *getplugin(char *name){
110
109
  /* Check for existing plugin with that name */
111
110
  for(plugin *p = plugin_list; p != NULL; p = p->next){
172
171
}
173
172
 
174
173
/* Helper function for add_argument and add_environment */
175
 
__attribute__((nonnull, warn_unused_result))
176
174
static bool add_to_char_array(const char *new, char ***array,
177
175
                              int *len){
178
176
  /* Resize the pointed-to array to hold one more pointer */
179
 
  char **new_array = NULL;
180
177
  do {
181
 
    new_array = realloc(*array, sizeof(char *)
182
 
                        * (size_t) ((*len) + 2));
183
 
  } while(new_array == NULL and errno == EINTR);
 
178
    *array = realloc(*array, sizeof(char *)
 
179
                     * (size_t) ((*len) + 2));
 
180
  } while(*array == NULL and errno == EINTR);
184
181
  /* Malloc check */
185
 
  if(new_array == NULL){
 
182
  if(*array == NULL){
186
183
    return false;
187
184
  }
188
 
  *array = new_array;
189
185
  /* Make a copy of the new string */
190
186
  char *copy;
191
187
  do {
203
199
}
204
200
 
205
201
/* Add to a plugin's argument vector */
206
 
__attribute__((nonnull(2), warn_unused_result))
207
202
static bool add_argument(plugin *p, const char *arg){
208
203
  if(p == NULL){
209
204
    return false;
212
207
}
213
208
 
214
209
/* Add to a plugin's environment */
215
 
__attribute__((nonnull(2), warn_unused_result))
216
210
static bool add_environment(plugin *p, const char *def, bool replace){
217
211
  if(p == NULL){
218
212
    return false;
220
214
  /* namelen = length of name of environment variable */
221
215
  size_t namelen = (size_t)(strchrnul(def, '=') - def);
222
216
  /* Search for this environment variable */
223
 
  for(char **envdef = p->environ; *envdef != NULL; envdef++){
224
 
    if(strncmp(*envdef, def, namelen + 1) == 0){
 
217
  for(char **e = p->environ; *e != NULL; e++){
 
218
    if(strncmp(*e, def, namelen + 1) == 0){
225
219
      /* It already exists */
226
220
      if(replace){
227
 
        char *new_envdef;
 
221
        char *new;
228
222
        do {
229
 
          new_envdef = realloc(*envdef, strlen(def) + 1);
230
 
        } while(new_envdef == NULL and errno == EINTR);
231
 
        if(new_envdef == NULL){
 
223
          new = realloc(*e, strlen(def) + 1);
 
224
        } while(new == NULL and errno == EINTR);
 
225
        if(new == NULL){
232
226
          return false;
233
227
        }
234
 
        *envdef = new_envdef;
235
 
        strcpy(*envdef, def);
 
228
        *e = new;
 
229
        strcpy(*e, def);
236
230
      }
237
231
      return true;
238
232
    }
245
239
 * Descriptor Flags".
246
240
 | [[info:libc:Descriptor%20Flags][File Descriptor Flags]] |
247
241
 */
248
 
__attribute__((warn_unused_result))
249
242
static int set_cloexec_flag(int fd){
250
243
  int ret = (int)TEMP_FAILURE_RETRY(fcntl(fd, F_GETFD, 0));
251
244
  /* If reading the flags failed, return error indication now. */
293
286
}
294
287
 
295
288
/* Prints out a password to stdout */
296
 
__attribute__((nonnull, warn_unused_result))
297
289
static bool print_out_password(const char *buffer, size_t length){
298
290
  ssize_t ret;
299
291
  for(size_t written = 0; written < length; written += (size_t)ret){
307
299
}
308
300
 
309
301
/* Removes and free a plugin from the plugin list */
310
 
__attribute__((nonnull))
311
302
static void free_plugin(plugin *plugin_node){
312
303
  
313
304
  for(char **arg = plugin_node->argv; *arg != NULL; arg++){
363
354
                                      .sa_flags = SA_NOCLDSTOP };
364
355
  char **custom_argv = NULL;
365
356
  int custom_argc = 0;
366
 
  int dir_fd;
367
357
  
368
358
  /* Establish a signal handler */
369
359
  sigemptyset(&sigchld_action.sa_mask);
426
416
    { .name = NULL }
427
417
  };
428
418
  
429
 
  __attribute__((nonnull(3)))
430
419
  error_t parse_opt(int key, char *arg, struct argp_state *state){
431
420
    errno = 0;
432
421
    switch(key){
433
422
      char *tmp;
434
 
      intmax_t tmp_id;
 
423
      intmax_t tmpmax;
435
424
    case 'g':                   /* --global-options */
436
425
      {
437
426
        char *plugin_option;
440
429
            break;
441
430
          }
442
431
        }
443
 
        errno = 0;
444
432
      }
445
433
      break;
446
434
    case 'G':                   /* --global-env */
447
 
      if(add_environment(getplugin(NULL), arg, true)){
448
 
        errno = 0;
449
 
      }
 
435
      add_environment(getplugin(NULL), arg, true);
450
436
      break;
451
437
    case 'o':                   /* --options-for */
452
438
      {
469
455
            break;
470
456
          }
471
457
        }
472
 
        errno = 0;
473
458
      }
474
459
      break;
475
460
    case 'E':                   /* --env-for */
487
472
          errno = EINVAL;
488
473
          break;
489
474
        }
490
 
        if(add_environment(getplugin(arg), envdef, true)){
491
 
          errno = 0;
492
 
        }
 
475
        add_environment(getplugin(arg), envdef, true);
493
476
      }
494
477
      break;
495
478
    case 'd':                   /* --disable */
497
480
        plugin *p = getplugin(arg);
498
481
        if(p != NULL){
499
482
          p->disabled = true;
500
 
          errno = 0;
501
483
        }
502
484
      }
503
485
      break;
506
488
        plugin *p = getplugin(arg);
507
489
        if(p != NULL){
508
490
          p->disabled = false;
509
 
          errno = 0;
510
491
        }
511
492
      }
512
493
      break;
513
494
    case 128:                   /* --plugin-dir */
514
495
      free(plugindir);
515
496
      plugindir = strdup(arg);
516
 
      if(plugindir != NULL){
517
 
        errno = 0;
518
 
      }
519
497
      break;
520
498
    case 129:                   /* --config-file */
521
499
      /* This is already done by parse_opt_config_file() */
522
500
      break;
523
501
    case 130:                   /* --userid */
524
 
      tmp_id = strtoimax(arg, &tmp, 10);
 
502
      tmpmax = strtoimax(arg, &tmp, 10);
525
503
      if(errno != 0 or tmp == arg or *tmp != '\0'
526
 
         or tmp_id != (uid_t)tmp_id){
 
504
         or tmpmax != (uid_t)tmpmax){
527
505
        argp_error(state, "Bad user ID number: \"%s\", using %"
528
506
                   PRIdMAX, arg, (intmax_t)uid);
529
507
        break;
530
508
      }
531
 
      uid = (uid_t)tmp_id;
532
 
      errno = 0;
 
509
      uid = (uid_t)tmpmax;
533
510
      break;
534
511
    case 131:                   /* --groupid */
535
 
      tmp_id = strtoimax(arg, &tmp, 10);
 
512
      tmpmax = strtoimax(arg, &tmp, 10);
536
513
      if(errno != 0 or tmp == arg or *tmp != '\0'
537
 
         or tmp_id != (gid_t)tmp_id){
 
514
         or tmpmax != (gid_t)tmpmax){
538
515
        argp_error(state, "Bad group ID number: \"%s\", using %"
539
516
                   PRIdMAX, arg, (intmax_t)gid);
540
517
        break;
541
518
      }
542
 
      gid = (gid_t)tmp_id;
543
 
      errno = 0;
 
519
      gid = (gid_t)tmpmax;
544
520
      break;
545
521
    case 132:                   /* --debug */
546
522
      debug = true;
594
570
    case 129:                   /* --config-file */
595
571
      free(argfile);
596
572
      argfile = strdup(arg);
597
 
      if(argfile != NULL){
598
 
        errno = 0;
599
 
      }
600
573
      break;
601
574
    case 130:                   /* --userid */
602
575
    case 131:                   /* --groupid */
685
658
        }
686
659
        
687
660
        custom_argc += 1;
688
 
        {
689
 
          char **new_argv = realloc(custom_argv, sizeof(char *)
690
 
                                    * ((unsigned int)
691
 
                                       custom_argc + 1));
692
 
          if(new_argv == NULL){
693
 
            error(0, errno, "realloc");
694
 
            exitstatus = EX_OSERR;
695
 
            free(new_arg);
696
 
            free(org_line);
697
 
            goto fallback;
698
 
          } else {
699
 
            custom_argv = new_argv;
700
 
          }
 
661
        custom_argv = realloc(custom_argv, sizeof(char *)
 
662
                              * ((unsigned int) custom_argc + 1));
 
663
        if(custom_argv == NULL){
 
664
          error(0, errno, "realloc");
 
665
          exitstatus = EX_OSERR;
 
666
          free(org_line);
 
667
          goto fallback;
701
668
        }
702
669
        custom_argv[custom_argc-1] = new_arg;
703
670
        custom_argv[custom_argc] = NULL;
775
742
    }
776
743
  }
777
744
  
778
 
  if(getuid() == 0){
 
745
  {
779
746
    /* Work around Debian bug #633582:
780
747
       <http://bugs.debian.org/633582> */
781
748
    int plugindir_fd = open(/* plugindir or */ PDIR, O_RDONLY);
782
749
    if(plugindir_fd == -1){
783
 
      if(errno != ENOENT){
784
 
        error(0, errno, "open(\"" PDIR "\")");
785
 
      }
 
750
      error(0, errno, "open");
786
751
    } else {
787
752
      ret = (int)TEMP_FAILURE_RETRY(fstat(plugindir_fd, &st));
788
753
      if(ret == -1){
800
765
  }
801
766
  
802
767
  /* Lower permissions */
803
 
  ret = setgid(gid);
 
768
  setgid(gid);
804
769
  if(ret == -1){
805
770
    error(0, errno, "setgid");
806
771
  }
811
776
  
812
777
  /* Open plugin directory with close_on_exec flag */
813
778
  {
814
 
    dir_fd = open(plugindir != NULL ? plugindir : PDIR, O_RDONLY |
815
 
#ifdef O_CLOEXEC
816
 
                  O_CLOEXEC
817
 
#else  /* not O_CLOEXEC */
818
 
                  0
819
 
#endif  /* not O_CLOEXEC */
820
 
                  );
 
779
    int dir_fd = -1;
 
780
    if(plugindir == NULL){
 
781
      dir_fd = open(PDIR, O_RDONLY |
 
782
#ifdef O_CLOEXEC
 
783
                    O_CLOEXEC
 
784
#else  /* not O_CLOEXEC */
 
785
                    0
 
786
#endif  /* not O_CLOEXEC */
 
787
                    );
 
788
    } else {
 
789
      dir_fd = open(plugindir, O_RDONLY |
 
790
#ifdef O_CLOEXEC
 
791
                    O_CLOEXEC
 
792
#else  /* not O_CLOEXEC */
 
793
                    0
 
794
#endif  /* not O_CLOEXEC */
 
795
                    );
 
796
    }
821
797
    if(dir_fd == -1){
822
798
      error(0, errno, "Could not open plugin dir");
823
799
      exitstatus = EX_UNAVAILABLE;
868
844
    {
869
845
      bool bad_name = false;
870
846
      
871
 
      const char * const bad_prefixes[] = { ".", "#", NULL };
 
847
      const char const *bad_prefixes[] = { ".", "#", NULL };
872
848
      
873
 
      const char * const bad_suffixes[] = { "~", "#", ".dpkg-new",
 
849
      const char const *bad_suffixes[] = { "~", "#", ".dpkg-new",
874
850
                                           ".dpkg-old",
875
851
                                           ".dpkg-bak",
876
852
                                           ".dpkg-divert", NULL };
877
 
#ifdef __GNUC__
878
 
#pragma GCC diagnostic push
879
 
#pragma GCC diagnostic ignored "-Wcast-qual"
880
 
#endif
881
 
      for(const char **pre = (const char **)bad_prefixes;
882
 
          *pre != NULL; pre++){
883
 
#ifdef __GNUC__
884
 
#pragma GCC diagnostic pop
885
 
#endif
 
853
      for(const char **pre = bad_prefixes; *pre != NULL; pre++){
886
854
        size_t pre_len = strlen(*pre);
887
855
        if((d_name_len >= pre_len)
888
856
           and strncmp((dirst->d_name), *pre, pre_len) == 0){
897
865
      if(bad_name){
898
866
        continue;
899
867
      }
900
 
#ifdef __GNUC__
901
 
#pragma GCC diagnostic push
902
 
#pragma GCC diagnostic ignored "-Wcast-qual"
903
 
#endif
904
 
      for(const char **suf = (const char **)bad_suffixes;
905
 
          *suf != NULL; suf++){
906
 
#ifdef __GNUC__
907
 
#pragma GCC diagnostic pop
908
 
#endif
 
868
      for(const char **suf = bad_suffixes; *suf != NULL; suf++){
909
869
        size_t suf_len = strlen(*suf);
910
870
        if((d_name_len >= suf_len)
911
871
           and (strcmp((dirst->d_name) + d_name_len-suf_len, *suf)
924
884
      }
925
885
    }
926
886
    
927
 
    int plugin_fd = openat(dir_fd, dirst->d_name, O_RDONLY |
928
 
#ifdef O_CLOEXEC
929
 
                            O_CLOEXEC
930
 
#else  /* not O_CLOEXEC */
931
 
                            0
932
 
#endif  /* not O_CLOEXEC */
933
 
                            );
934
 
    if(plugin_fd == -1){
935
 
      error(0, errno, "Could not open plugin");
936
 
      continue;
 
887
    char *filename;
 
888
    if(plugindir == NULL){
 
889
      ret = (int)TEMP_FAILURE_RETRY(asprintf(&filename, PDIR "/%s",
 
890
                                             dirst->d_name));
 
891
    } else {
 
892
      ret = (int)TEMP_FAILURE_RETRY(asprintf(&filename, "%s/%s",
 
893
                                             plugindir,
 
894
                                             dirst->d_name));
937
895
    }
938
 
#ifndef O_CLOEXEC
939
 
  /* Set the FD_CLOEXEC flag on the plugin FD */
940
 
    ret = set_cloexec_flag(plugin_fd);
941
896
    if(ret < 0){
942
 
      error(0, errno, "set_cloexec_flag");
943
 
      TEMP_FAILURE_RETRY(close(plugin_fd));
 
897
      error(0, errno, "asprintf");
944
898
      continue;
945
899
    }
946
 
#endif  /* O_CLOEXEC */
947
 
    ret = (int)TEMP_FAILURE_RETRY(fstat(plugin_fd, &st));
 
900
    
 
901
    ret = (int)TEMP_FAILURE_RETRY(stat(filename, &st));
948
902
    if(ret == -1){
949
903
      error(0, errno, "stat");
950
 
      TEMP_FAILURE_RETRY(close(plugin_fd));
 
904
      free(filename);
951
905
      continue;
952
906
    }
953
907
    
954
908
    /* Ignore non-executable files */
955
909
    if(not S_ISREG(st.st_mode)
956
 
       or (TEMP_FAILURE_RETRY(faccessat(dir_fd, dirst->d_name, X_OK,
957
 
                                        0)) != 0)){
 
910
       or (TEMP_FAILURE_RETRY(access(filename, X_OK)) != 0)){
958
911
      if(debug){
959
 
        fprintf(stderr, "Ignoring plugin dir entry \"%s/%s\""
960
 
                " with bad type or mode\n",
961
 
                plugindir != NULL ? plugindir : PDIR, dirst->d_name);
 
912
        fprintf(stderr, "Ignoring plugin dir entry \"%s\""
 
913
                " with bad type or mode\n", filename);
962
914
      }
963
 
      TEMP_FAILURE_RETRY(close(plugin_fd));
 
915
      free(filename);
964
916
      continue;
965
917
    }
966
918
    
967
919
    plugin *p = getplugin(dirst->d_name);
968
920
    if(p == NULL){
969
921
      error(0, errno, "getplugin");
970
 
      TEMP_FAILURE_RETRY(close(plugin_fd));
 
922
      free(filename);
971
923
      continue;
972
924
    }
973
925
    if(p->disabled){
975
927
        fprintf(stderr, "Ignoring disabled plugin \"%s\"\n",
976
928
                dirst->d_name);
977
929
      }
978
 
      TEMP_FAILURE_RETRY(close(plugin_fd));
 
930
      free(filename);
979
931
      continue;
980
932
    }
981
933
    {
995
947
        }
996
948
      }
997
949
    }
998
 
    /* If this plugin has any environment variables, we need to
999
 
       duplicate the environment from this process, too. */
 
950
    /* If this plugin has any environment variables, we will call
 
951
       using execve and need to duplicate the environment from this
 
952
       process, too. */
1000
953
    if(p->environ[0] != NULL){
1001
954
      for(char **e = environ; *e != NULL; e++){
1002
955
        if(not add_environment(p, *e, false)){
1068
1021
           above and must now close it manually here. */
1069
1022
        closedir(dir);
1070
1023
      }
1071
 
      if(fexecve(plugin_fd, p->argv,
1072
 
                (p->environ[0] != NULL) ? p->environ : environ) < 0){
1073
 
        error(0, errno, "fexecve for %s/%s",
1074
 
              plugindir != NULL ? plugindir : PDIR, dirst->d_name);
1075
 
        _exit(EX_OSERR);
 
1024
      if(p->environ[0] == NULL){
 
1025
        if(execv(filename, p->argv) < 0){
 
1026
          error(0, errno, "execv for %s", filename);
 
1027
          _exit(EX_OSERR);
 
1028
        }
 
1029
      } else {
 
1030
        if(execve(filename, p->argv, p->environ) < 0){
 
1031
          error(0, errno, "execve for %s", filename);
 
1032
          _exit(EX_OSERR);
 
1033
        }
1076
1034
      }
1077
1035
      /* no return */
1078
1036
    }
1079
1037
    /* Parent process */
1080
1038
    TEMP_FAILURE_RETRY(close(pipefd[1])); /* Close unused write end of
1081
1039
                                             pipe */
1082
 
    TEMP_FAILURE_RETRY(close(plugin_fd));
 
1040
    free(filename);
1083
1041
    plugin *new_plugin = getplugin(dirst->d_name);
1084
1042
    if(new_plugin == NULL){
1085
1043
      error(0, errno, "getplugin");
1107
1065
      goto fallback;
1108
1066
    }
1109
1067
    
1110
 
#if defined (__GNUC__) and defined (__GLIBC__)
1111
 
#if not __GLIBC_PREREQ(2, 16)
1112
 
#pragma GCC diagnostic push
1113
 
#pragma GCC diagnostic ignored "-Wsign-conversion"
1114
 
#endif
1115
 
#endif
1116
1068
    FD_SET(new_plugin->fd, &rfds_all); /* Spurious warning from
1117
 
                                          -Wconversion in GNU libc
1118
 
                                          before 2.16 */
1119
 
#if defined (__GNUC__) and defined (__GLIBC__)
1120
 
#if not __GLIBC_PREREQ(2, 16)
1121
 
#pragma GCC diagnostic pop
1122
 
#endif
1123
 
#endif
 
1069
                                          -Wconversion */
1124
1070
    
1125
1071
    if(maxfd < new_plugin->fd){
1126
1072
      maxfd = new_plugin->fd;
1180
1126
          }
1181
1127
          
1182
1128
          /* Remove the plugin */
1183
 
#if defined (__GNUC__) and defined (__GLIBC__)
1184
 
#if not __GLIBC_PREREQ(2, 16)
1185
 
#pragma GCC diagnostic push
1186
 
#pragma GCC diagnostic ignored "-Wsign-conversion"
1187
 
#endif
1188
 
#endif
1189
1129
          FD_CLR(proc->fd, &rfds_all); /* Spurious warning from
1190
 
                                          -Wconversion in GNU libc
1191
 
                                          before 2.16 */
1192
 
#if defined (__GNUC__) and defined (__GLIBC__)
1193
 
#if not __GLIBC_PREREQ(2, 16)
1194
 
#pragma GCC diagnostic pop
1195
 
#endif
1196
 
#endif
 
1130
                                          -Wconversion */
1197
1131
          
1198
1132
          /* Block signal while modifying process_list */
1199
1133
          ret = (int)TEMP_FAILURE_RETRY(sigprocmask
1239
1173
      }
1240
1174
      
1241
1175
      /* This process has not completed.  Does it have any output? */
1242
 
#if defined (__GNUC__) and defined (__GLIBC__)
1243
 
#if not __GLIBC_PREREQ(2, 16)
1244
 
#pragma GCC diagnostic push
1245
 
#pragma GCC diagnostic ignored "-Wsign-conversion"
1246
 
#endif
1247
 
#endif
1248
1176
      if(proc->eof or not FD_ISSET(proc->fd, &rfds)){ /* Spurious
1249
1177
                                                         warning from
1250
 
                                                         -Wconversion
1251
 
                                                         in GNU libc
1252
 
                                                         before
1253
 
                                                         2.16 */
1254
 
#if defined (__GNUC__) and defined (__GLIBC__)
1255
 
#if not __GLIBC_PREREQ(2, 16)
1256
 
#pragma GCC diagnostic pop
1257
 
#endif
1258
 
#endif
 
1178
                                                         -Wconversion */
1259
1179
        /* This process had nothing to say at this time */
1260
1180
        proc = proc->next;
1261
1181
        continue;
1262
1182
      }
1263
1183
      /* Before reading, make the process' data buffer large enough */
1264
1184
      if(proc->buffer_length + BUFFER_SIZE > proc->buffer_size){
1265
 
        char *new_buffer = realloc(proc->buffer, proc->buffer_size
1266
 
                                   + (size_t) BUFFER_SIZE);
1267
 
        if(new_buffer == NULL){
 
1185
        proc->buffer = realloc(proc->buffer, proc->buffer_size
 
1186
                               + (size_t) BUFFER_SIZE);
 
1187
        if(proc->buffer == NULL){
1268
1188
          error(0, errno, "malloc");
1269
1189
          exitstatus = EX_OSERR;
1270
1190
          goto fallback;
1271
1191
        }
1272
 
        proc->buffer = new_buffer;
1273
1192
        proc->buffer_size += BUFFER_SIZE;
1274
1193
      }
1275
1194
      /* Read from the process */