/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: 2014-03-23 22:12:57 UTC
  • Revision ID: teddy@recompile.se-20140323221257-9lkufevfdn4kwoq6
Use openat() etc. in plugin-runner.  Also one less useless warning.

* plugin-runner.c (main): Only print warning about failure to work
                          around Debian bug #633582 if the plugin
                          directory actually exists.  Use openat(),
                          fstat(), faccessat(), and eliminate
                          asprintf().

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-2016 Teddy Hogeborn
6
 
 * Copyright © 2008-2016 Björn Påhlsson
 
5
 * Copyright © 2008-2013 Teddy Hogeborn
 
6
 * Copyright © 2008-2013 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
23
23
 */
24
24
 
25
25
#define _GNU_SOURCE             /* TEMP_FAILURE_RETRY(), getline(),
26
 
                                   O_CLOEXEC, pipe2() */
 
26
                                   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
32
                                   stderr, STDOUT_FILENO, fclose() */
33
 
#include <sys/types.h>          /* fstat(), struct stat, waitpid(),
34
 
                                   WIFEXITED(), WEXITSTATUS(), wait(),
35
 
                                   pid_t, uid_t, gid_t, getuid(),
36
 
                                   getgid() */
 
33
#include <sys/types.h>          /* DIR, fdopendir(), fstat(), struct
 
34
                                   stat, waitpid(), WIFEXITED(),
 
35
                                   WEXITSTATUS(), wait(), pid_t,
 
36
                                   uid_t, gid_t, getuid(), getgid(),
 
37
                                   dirfd() */
37
38
#include <sys/select.h>         /* fd_set, select(), FD_ZERO(),
38
39
                                   FD_SET(), FD_ISSET(), FD_CLR */
39
40
#include <sys/wait.h>           /* wait(), waitpid(), WIFEXITED(),
40
 
                                   WEXITSTATUS(), WTERMSIG() */
 
41
                                   WEXITSTATUS(), WTERMSIG(),
 
42
                                   WCOREDUMP() */
41
43
#include <sys/stat.h>           /* struct stat, fstat(), S_ISREG() */
42
44
#include <iso646.h>             /* and, or, not */
43
 
#include <dirent.h>             /* struct dirent, scandirat() */
 
45
#include <dirent.h>             /* DIR, struct dirent, fdopendir(),
 
46
                                   readdir(), closedir(), dirfd() */
44
47
#include <unistd.h>             /* fcntl(), F_GETFD, F_SETFD,
45
48
                                   FD_CLOEXEC, write(), STDOUT_FILENO,
46
49
                                   struct stat, fstat(), close(),
47
50
                                   setgid(), setuid(), S_ISREG(),
48
 
                                   faccessat() pipe2(), fork(),
 
51
                                   faccessat() pipe(), fork(),
49
52
                                   _exit(), dup2(), fexecve(), read()
50
53
                                */
51
54
#include <fcntl.h>              /* fcntl(), F_GETFD, F_SETFD,
52
 
                                   FD_CLOEXEC, openat(), scandirat(),
53
 
                                   pipe2() */
 
55
                                   FD_CLOEXEC, openat() */
54
56
#include <string.h>             /* strsep, strlen(), strsignal(),
55
57
                                   strcmp(), strncmp() */
56
58
#include <errno.h>              /* errno */
70
72
                                   EX_CONFIG, EX_UNAVAILABLE, EX_OK */
71
73
#include <errno.h>              /* errno */
72
74
#include <error.h>              /* error() */
73
 
#include <fnmatch.h>            /* fnmatch() */
74
75
 
75
76
#define BUFFER_SIZE 256
76
77
 
77
78
#define PDIR "/lib/mandos/plugins.d"
78
 
#define PHDIR "/lib/mandos/plugin-helpers"
79
79
#define AFILE "/conf/conf.d/mandos/plugin-runner.conf"
80
80
 
81
81
const char *argp_program_version = "plugin-runner " VERSION;
240
240
  return add_to_char_array(def, &(p->environ), &(p->envc));
241
241
}
242
242
 
243
 
#ifndef O_CLOEXEC
244
243
/*
245
244
 * Based on the example in the GNU LibC manual chapter 13.13 "File
246
245
 * Descriptor Flags".
257
256
  return (int)TEMP_FAILURE_RETRY(fcntl(fd, F_SETFD,
258
257
                                       ret | FD_CLOEXEC));
259
258
}
260
 
#endif  /* not O_CLOEXEC */
261
259
 
262
260
 
263
261
/* Mark processes as completed when they exit, and save their exit
347
345
 
348
346
int main(int argc, char *argv[]){
349
347
  char *plugindir = NULL;
350
 
  char *pluginhelperdir = NULL;
351
348
  char *argfile = NULL;
352
349
  FILE *conffp;
353
 
  struct dirent **direntries = NULL;
 
350
  size_t d_name_len;
 
351
  DIR *dir = NULL;
 
352
  struct dirent *dirst;
354
353
  struct stat st;
355
354
  fd_set rfds_all;
356
355
  int ret, maxfd = 0;
364
363
                                      .sa_flags = SA_NOCLDSTOP };
365
364
  char **custom_argv = NULL;
366
365
  int custom_argc = 0;
367
 
  int dir_fd = -1;
 
366
  int dir_fd;
368
367
  
369
368
  /* Establish a signal handler */
370
369
  sigemptyset(&sigchld_action.sa_mask);
415
414
      .doc = "Group ID the plugins will run as", .group = 3 },
416
415
    { .name = "debug", .key = 132,
417
416
      .doc = "Debug mode", .group = 4 },
418
 
    { .name = "plugin-helper-dir", .key = 133,
419
 
      .arg = "DIRECTORY",
420
 
      .doc = "Specify a different plugin helper directory",
421
 
      .group = 2 },
422
417
    /*
423
418
     * These reproduce what we would get without ARGP_NO_HELP
424
419
     */
550
545
    case 132:                   /* --debug */
551
546
      debug = true;
552
547
      break;
553
 
    case 133:                   /* --plugin-helper-dir */
554
 
      free(pluginhelperdir);
555
 
      pluginhelperdir = strdup(arg);
556
 
      if(pluginhelperdir != NULL){
557
 
        errno = 0;
558
 
      }
559
 
      break;
560
548
      /*
561
549
       * These reproduce what we would get without ARGP_NO_HELP
562
550
       */
613
601
    case 130:                   /* --userid */
614
602
    case 131:                   /* --groupid */
615
603
    case 132:                   /* --debug */
616
 
    case 133:                   /* --plugin-helper-dir */
617
604
    case '?':                   /* --help */
618
605
    case -3:                    /* --usage */
619
606
    case 'V':                   /* --version */
700
687
        custom_argc += 1;
701
688
        {
702
689
          char **new_argv = realloc(custom_argv, sizeof(char *)
703
 
                                    * ((size_t)custom_argc + 1));
 
690
                                    * ((unsigned int)
 
691
                                       custom_argc + 1));
704
692
          if(new_argv == NULL){
705
693
            error(0, errno, "realloc");
706
694
            exitstatus = EX_OSERR;
773
761
    goto fallback;
774
762
  }
775
763
  
776
 
  {
777
 
    char *pluginhelperenv;
778
 
    bool bret = true;
779
 
    ret = asprintf(&pluginhelperenv, "MANDOSPLUGINHELPERDIR=%s",
780
 
                   pluginhelperdir != NULL ? pluginhelperdir : PHDIR);
781
 
    if(ret != -1){
782
 
      bret = add_environment(getplugin(NULL), pluginhelperenv, true);
783
 
    }
784
 
    if(ret == -1 or not bret){
785
 
      error(0, errno, "Failed to set MANDOSPLUGINHELPERDIR"
786
 
            " environment variable to \"%s\" for all plugins\n",
787
 
            pluginhelperdir != NULL ? pluginhelperdir : PHDIR);
788
 
    }
789
 
    if(ret != -1){
790
 
      free(pluginhelperenv);
791
 
    }
792
 
  }
793
 
  
794
764
  if(debug){
795
765
    for(plugin *p = plugin_list; p != NULL; p=p->next){
796
766
      fprintf(stderr, "Plugin: %s has %d arguments\n",
825
795
          }
826
796
        }
827
797
      }
828
 
      close(plugindir_fd);
 
798
      TEMP_FAILURE_RETRY(close(plugindir_fd));
829
799
    }
830
800
  }
831
801
  
859
829
    ret = set_cloexec_flag(dir_fd);
860
830
    if(ret < 0){
861
831
      error(0, errno, "set_cloexec_flag");
 
832
      TEMP_FAILURE_RETRY(close(dir_fd));
862
833
      exitstatus = EX_OSERR;
863
834
      goto fallback;
864
835
    }
865
836
#endif  /* O_CLOEXEC */
866
 
  }
867
 
  
868
 
  int good_name(const struct dirent * const dirent){
869
 
    const char * const patterns[] = { ".*", "#*#", "*~", "*.dpkg-new",
870
 
                                      "*.dpkg-old", "*.dpkg-bak",
871
 
                                      "*.dpkg-divert", NULL };
872
 
#ifdef __GNUC__
873
 
#pragma GCC diagnostic push
874
 
#pragma GCC diagnostic ignored "-Wcast-qual"
875
 
#endif
876
 
    for(const char **pat = (const char **)patterns;
877
 
        *pat != NULL; pat++){
878
 
#ifdef __GNUC__
879
 
#pragma GCC diagnostic pop
880
 
#endif
881
 
      if(fnmatch(*pat, dirent->d_name, FNM_FILE_NAME | FNM_PERIOD)
882
 
         != FNM_NOMATCH){
883
 
        if(debug){
884
 
            fprintf(stderr, "Ignoring plugin dir entry \"%s\""
885
 
                    " matching pattern %s\n", dirent->d_name, *pat);
886
 
        }
887
 
        return 0;
888
 
      }
 
837
    
 
838
    dir = fdopendir(dir_fd);
 
839
    if(dir == NULL){
 
840
      error(0, errno, "Could not open plugin dir");
 
841
      TEMP_FAILURE_RETRY(close(dir_fd));
 
842
      exitstatus = EX_OSERR;
 
843
      goto fallback;
889
844
    }
890
 
    return 1;
891
 
  }
892
 
  
893
 
  int numplugins = scandirat(dir_fd, ".", &direntries, good_name,
894
 
                             alphasort);
895
 
  if(numplugins == -1){
896
 
    error(0, errno, "Could not scan plugin dir");
897
 
    direntries = NULL;
898
 
    exitstatus = EX_OSERR;
899
 
    goto fallback;
900
845
  }
901
846
  
902
847
  FD_ZERO(&rfds_all);
903
848
  
904
849
  /* Read and execute any executable in the plugin directory*/
905
 
  for(int i = 0; i < numplugins; i++){
906
 
    
907
 
    int plugin_fd = openat(dir_fd, direntries[i]->d_name, O_RDONLY);
 
850
  while(true){
 
851
    do {
 
852
      dirst = readdir(dir);
 
853
    } while(dirst == NULL and errno == EINTR);
 
854
    
 
855
    /* All directory entries have been processed */
 
856
    if(dirst == NULL){
 
857
      if(errno == EBADF){
 
858
        error(0, errno, "readdir");
 
859
        exitstatus = EX_IOERR;
 
860
        goto fallback;
 
861
      }
 
862
      break;
 
863
    }
 
864
    
 
865
    d_name_len = strlen(dirst->d_name);
 
866
    
 
867
    /* Ignore dotfiles, backup files and other junk */
 
868
    {
 
869
      bool bad_name = false;
 
870
      
 
871
      const char * const bad_prefixes[] = { ".", "#", NULL };
 
872
      
 
873
      const char * const bad_suffixes[] = { "~", "#", ".dpkg-new",
 
874
                                           ".dpkg-old",
 
875
                                           ".dpkg-bak",
 
876
                                           ".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
 
886
        size_t pre_len = strlen(*pre);
 
887
        if((d_name_len >= pre_len)
 
888
           and strncmp((dirst->d_name), *pre, pre_len) == 0){
 
889
          if(debug){
 
890
            fprintf(stderr, "Ignoring plugin dir entry \"%s\""
 
891
                    " with bad prefix %s\n", dirst->d_name, *pre);
 
892
          }
 
893
          bad_name = true;
 
894
          break;
 
895
        }
 
896
      }
 
897
      if(bad_name){
 
898
        continue;
 
899
      }
 
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
 
909
        size_t suf_len = strlen(*suf);
 
910
        if((d_name_len >= suf_len)
 
911
           and (strcmp((dirst->d_name) + d_name_len-suf_len, *suf)
 
912
                == 0)){
 
913
          if(debug){
 
914
            fprintf(stderr, "Ignoring plugin dir entry \"%s\""
 
915
                    " with bad suffix %s\n", dirst->d_name, *suf);
 
916
          }
 
917
          bad_name = true;
 
918
          break;
 
919
        }
 
920
      }
 
921
      
 
922
      if(bad_name){
 
923
        continue;
 
924
      }
 
925
    }
 
926
    
 
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
                            );
908
934
    if(plugin_fd == -1){
909
935
      error(0, errno, "Could not open plugin");
910
 
      free(direntries[i]);
911
 
      continue;
912
 
    }
 
936
      continue;
 
937
    }
 
938
#ifndef O_CLOEXEC
 
939
  /* Set the FD_CLOEXEC flag on the plugin FD */
 
940
    ret = set_cloexec_flag(plugin_fd);
 
941
    if(ret < 0){
 
942
      error(0, errno, "set_cloexec_flag");
 
943
      TEMP_FAILURE_RETRY(close(plugin_fd));
 
944
      continue;
 
945
    }
 
946
#endif  /* O_CLOEXEC */
913
947
    ret = (int)TEMP_FAILURE_RETRY(fstat(plugin_fd, &st));
914
948
    if(ret == -1){
915
949
      error(0, errno, "stat");
916
 
      close(plugin_fd);
917
 
      free(direntries[i]);
 
950
      TEMP_FAILURE_RETRY(close(plugin_fd));
918
951
      continue;
919
952
    }
920
953
    
921
954
    /* Ignore non-executable files */
922
955
    if(not S_ISREG(st.st_mode)
923
 
       or (TEMP_FAILURE_RETRY(faccessat(dir_fd, direntries[i]->d_name,
924
 
                                        X_OK, 0)) != 0)){
 
956
       or (TEMP_FAILURE_RETRY(faccessat(dir_fd, dirst->d_name, X_OK,
 
957
                                        0)) != 0)){
925
958
      if(debug){
926
959
        fprintf(stderr, "Ignoring plugin dir entry \"%s/%s\""
927
960
                " with bad type or mode\n",
928
 
                plugindir != NULL ? plugindir : PDIR,
929
 
                direntries[i]->d_name);
 
961
                plugindir != NULL ? plugindir : PDIR, dirst->d_name);
930
962
      }
931
 
      close(plugin_fd);
932
 
      free(direntries[i]);
 
963
      TEMP_FAILURE_RETRY(close(plugin_fd));
933
964
      continue;
934
965
    }
935
966
    
936
 
    plugin *p = getplugin(direntries[i]->d_name);
 
967
    plugin *p = getplugin(dirst->d_name);
937
968
    if(p == NULL){
938
969
      error(0, errno, "getplugin");
939
 
      close(plugin_fd);
940
 
      free(direntries[i]);
 
970
      TEMP_FAILURE_RETRY(close(plugin_fd));
941
971
      continue;
942
972
    }
943
973
    if(p->disabled){
944
974
      if(debug){
945
975
        fprintf(stderr, "Ignoring disabled plugin \"%s\"\n",
946
 
                direntries[i]->d_name);
 
976
                dirst->d_name);
947
977
      }
948
 
      close(plugin_fd);
949
 
      free(direntries[i]);
 
978
      TEMP_FAILURE_RETRY(close(plugin_fd));
950
979
      continue;
951
980
    }
952
981
    {
977
1006
    }
978
1007
    
979
1008
    int pipefd[2];
980
 
#ifndef O_CLOEXEC
981
1009
    ret = (int)TEMP_FAILURE_RETRY(pipe(pipefd));
982
 
#else  /* O_CLOEXEC */
983
 
    ret = (int)TEMP_FAILURE_RETRY(pipe2(pipefd, O_CLOEXEC));
984
 
#endif  /* O_CLOEXEC */
985
1010
    if(ret == -1){
986
1011
      error(0, errno, "pipe");
987
1012
      exitstatus = EX_OSERR;
988
 
      free(direntries[i]);
989
 
      goto fallback;
990
 
    }
991
 
    if(pipefd[0] >= FD_SETSIZE){
992
 
      fprintf(stderr, "pipe()[0] (%d) >= FD_SETSIZE (%d)", pipefd[0],
993
 
              FD_SETSIZE);
994
 
      close(pipefd[0]);
995
 
      close(pipefd[1]);
996
 
      exitstatus = EX_OSERR;
997
 
      free(direntries[i]);
998
 
      goto fallback;
999
 
    }
1000
 
#ifndef O_CLOEXEC
 
1013
      goto fallback;
 
1014
    }
1001
1015
    /* Ask OS to automatic close the pipe on exec */
1002
1016
    ret = set_cloexec_flag(pipefd[0]);
1003
1017
    if(ret < 0){
1004
1018
      error(0, errno, "set_cloexec_flag");
1005
 
      close(pipefd[0]);
1006
 
      close(pipefd[1]);
1007
1019
      exitstatus = EX_OSERR;
1008
 
      free(direntries[i]);
1009
1020
      goto fallback;
1010
1021
    }
1011
1022
    ret = set_cloexec_flag(pipefd[1]);
1012
1023
    if(ret < 0){
1013
1024
      error(0, errno, "set_cloexec_flag");
1014
 
      close(pipefd[0]);
1015
 
      close(pipefd[1]);
1016
1025
      exitstatus = EX_OSERR;
1017
 
      free(direntries[i]);
1018
1026
      goto fallback;
1019
1027
    }
1020
 
#endif  /* not O_CLOEXEC */
1021
1028
    /* Block SIGCHLD until process is safely in process list */
1022
1029
    ret = (int)TEMP_FAILURE_RETRY(sigprocmask(SIG_BLOCK,
1023
1030
                                              &sigchld_action.sa_mask,
1025
1032
    if(ret < 0){
1026
1033
      error(0, errno, "sigprocmask");
1027
1034
      exitstatus = EX_OSERR;
1028
 
      free(direntries[i]);
1029
1035
      goto fallback;
1030
1036
    }
1031
1037
    /* Starting a new process to be watched */
1035
1041
    } while(pid == -1 and errno == EINTR);
1036
1042
    if(pid == -1){
1037
1043
      error(0, errno, "fork");
1038
 
      TEMP_FAILURE_RETRY(sigprocmask(SIG_UNBLOCK,
1039
 
                                     &sigchld_action.sa_mask, NULL));
1040
 
      close(pipefd[0]);
1041
 
      close(pipefd[1]);
1042
1044
      exitstatus = EX_OSERR;
1043
 
      free(direntries[i]);
1044
1045
      goto fallback;
1045
1046
    }
1046
1047
    if(pid == 0){
1062
1063
        _exit(EX_OSERR);
1063
1064
      }
1064
1065
      
 
1066
      if(dirfd(dir) < 0){
 
1067
        /* If dir has no file descriptor, we could not set FD_CLOEXEC
 
1068
           above and must now close it manually here. */
 
1069
        closedir(dir);
 
1070
      }
1065
1071
      if(fexecve(plugin_fd, p->argv,
1066
1072
                (p->environ[0] != NULL) ? p->environ : environ) < 0){
1067
1073
        error(0, errno, "fexecve for %s/%s",
1068
 
              plugindir != NULL ? plugindir : PDIR,
1069
 
              direntries[i]->d_name);
 
1074
              plugindir != NULL ? plugindir : PDIR, dirst->d_name);
1070
1075
        _exit(EX_OSERR);
1071
1076
      }
1072
1077
      /* no return */
1073
1078
    }
1074
1079
    /* Parent process */
1075
 
    close(pipefd[1]);           /* Close unused write end of pipe */
1076
 
    close(plugin_fd);
1077
 
    plugin *new_plugin = getplugin(direntries[i]->d_name);
 
1080
    TEMP_FAILURE_RETRY(close(pipefd[1])); /* Close unused write end of
 
1081
                                             pipe */
 
1082
    TEMP_FAILURE_RETRY(close(plugin_fd));
 
1083
    plugin *new_plugin = getplugin(dirst->d_name);
1078
1084
    if(new_plugin == NULL){
1079
1085
      error(0, errno, "getplugin");
1080
1086
      ret = (int)(TEMP_FAILURE_RETRY
1084
1090
        error(0, errno, "sigprocmask");
1085
1091
      }
1086
1092
      exitstatus = EX_OSERR;
1087
 
      free(direntries[i]);
1088
1093
      goto fallback;
1089
1094
    }
1090
 
    free(direntries[i]);
1091
1095
    
1092
1096
    new_plugin->pid = pid;
1093
1097
    new_plugin->fd = pipefd[0];
1103
1107
      goto fallback;
1104
1108
    }
1105
1109
    
1106
 
    FD_SET(new_plugin->fd, &rfds_all);
 
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
    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
1107
1124
    
1108
1125
    if(maxfd < new_plugin->fd){
1109
1126
      maxfd = new_plugin->fd;
1110
1127
    }
1111
1128
  }
1112
1129
  
1113
 
  free(direntries);
1114
 
  direntries = NULL;
1115
 
  close(dir_fd);
1116
 
  dir_fd = -1;
 
1130
  TEMP_FAILURE_RETRY(closedir(dir));
 
1131
  dir = NULL;
1117
1132
  free_plugin(getplugin(NULL));
1118
1133
  
1119
1134
  for(plugin *p = plugin_list; p != NULL; p = p->next){
1158
1173
                      (intmax_t) (proc->pid),
1159
1174
                      WTERMSIG(proc->status),
1160
1175
                      strsignal(WTERMSIG(proc->status)));
 
1176
            } else if(WCOREDUMP(proc->status)){
 
1177
              fprintf(stderr, "Plugin %s [%" PRIdMAX "] dumped"
 
1178
                      " core\n", proc->name, (intmax_t) (proc->pid));
1161
1179
            }
1162
1180
          }
1163
1181
          
1164
1182
          /* Remove the plugin */
1165
 
          FD_CLR(proc->fd, &rfds_all);
 
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
          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
1166
1197
          
1167
1198
          /* Block signal while modifying process_list */
1168
1199
          ret = (int)TEMP_FAILURE_RETRY(sigprocmask
1208
1239
      }
1209
1240
      
1210
1241
      /* This process has not completed.  Does it have any output? */
1211
 
      if(proc->eof or not FD_ISSET(proc->fd, &rfds)){
 
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
      if(proc->eof or not FD_ISSET(proc->fd, &rfds)){ /* Spurious
 
1249
                                                         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
1212
1259
        /* This process had nothing to say at this time */
1213
1260
        proc = proc->next;
1214
1261
        continue;
1281
1328
    free(custom_argv);
1282
1329
  }
1283
1330
  
1284
 
  free(direntries);
1285
 
  
1286
 
  if(dir_fd != -1){
1287
 
    close(dir_fd);
 
1331
  if(dir != NULL){
 
1332
    closedir(dir);
1288
1333
  }
1289
1334
  
1290
1335
  /* Kill the processes */
1310
1355
  free_plugin_list();
1311
1356
  
1312
1357
  free(plugindir);
1313
 
  free(pluginhelperdir);
1314
1358
  free(argfile);
1315
1359
  
1316
1360
  return exitstatus;