/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: 2015-07-16 20:30:35 UTC
  • Revision ID: teddy@recompile.se-20150716203035-z7qjwm270o2vrjah
Assume the C11 language (ISO 9899:2011), when compiling C code.

* Makefile (LANGUAGE): Changed to "-std=gnu11".

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-2015 Teddy Hogeborn
6
 
 * Copyright © 2008-2015 Björn Påhlsson
 
5
 * Copyright © 2008-2014 Teddy Hogeborn
 
6
 * Copyright © 2008-2014 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
701
701
        custom_argc += 1;
702
702
        {
703
703
          char **new_argv = realloc(custom_argv, sizeof(char *)
704
 
                                    * ((size_t)custom_argc + 1));
 
704
                                    * ((unsigned int)
 
705
                                       custom_argc + 1));
705
706
          if(new_argv == NULL){
706
707
            error(0, errno, "realloc");
707
708
            exitstatus = EX_OSERR;
826
827
          }
827
828
        }
828
829
      }
829
 
      close(plugindir_fd);
 
830
      TEMP_FAILURE_RETRY(close(plugindir_fd));
830
831
    }
831
832
  }
832
833
  
924
925
    ret = (int)TEMP_FAILURE_RETRY(fstat(plugin_fd, &st));
925
926
    if(ret == -1){
926
927
      error(0, errno, "stat");
927
 
      close(plugin_fd);
 
928
      TEMP_FAILURE_RETRY(close(plugin_fd));
928
929
      free(direntries[i]);
929
930
      continue;
930
931
    }
939
940
                plugindir != NULL ? plugindir : PDIR,
940
941
                direntries[i]->d_name);
941
942
      }
942
 
      close(plugin_fd);
 
943
      TEMP_FAILURE_RETRY(close(plugin_fd));
943
944
      free(direntries[i]);
944
945
      continue;
945
946
    }
947
948
    plugin *p = getplugin(direntries[i]->d_name);
948
949
    if(p == NULL){
949
950
      error(0, errno, "getplugin");
950
 
      close(plugin_fd);
 
951
      TEMP_FAILURE_RETRY(close(plugin_fd));
951
952
      free(direntries[i]);
952
953
      continue;
953
954
    }
956
957
        fprintf(stderr, "Ignoring disabled plugin \"%s\"\n",
957
958
                direntries[i]->d_name);
958
959
      }
959
 
      close(plugin_fd);
 
960
      TEMP_FAILURE_RETRY(close(plugin_fd));
960
961
      free(direntries[i]);
961
962
      continue;
962
963
    }
1002
1003
    if(pipefd[0] >= FD_SETSIZE){
1003
1004
      fprintf(stderr, "pipe()[0] (%d) >= FD_SETSIZE (%d)", pipefd[0],
1004
1005
              FD_SETSIZE);
1005
 
      close(pipefd[0]);
1006
 
      close(pipefd[1]);
 
1006
      TEMP_FAILURE_RETRY(close(pipefd[0]));
 
1007
      TEMP_FAILURE_RETRY(close(pipefd[1]));
1007
1008
      exitstatus = EX_OSERR;
1008
1009
      free(direntries[i]);
1009
1010
      goto fallback;
1013
1014
    ret = set_cloexec_flag(pipefd[0]);
1014
1015
    if(ret < 0){
1015
1016
      error(0, errno, "set_cloexec_flag");
1016
 
      close(pipefd[0]);
1017
 
      close(pipefd[1]);
 
1017
      TEMP_FAILURE_RETRY(close(pipefd[0]));
 
1018
      TEMP_FAILURE_RETRY(close(pipefd[1]));
1018
1019
      exitstatus = EX_OSERR;
1019
1020
      free(direntries[i]);
1020
1021
      goto fallback;
1022
1023
    ret = set_cloexec_flag(pipefd[1]);
1023
1024
    if(ret < 0){
1024
1025
      error(0, errno, "set_cloexec_flag");
1025
 
      close(pipefd[0]);
1026
 
      close(pipefd[1]);
 
1026
      TEMP_FAILURE_RETRY(close(pipefd[0]));
 
1027
      TEMP_FAILURE_RETRY(close(pipefd[1]));
1027
1028
      exitstatus = EX_OSERR;
1028
1029
      free(direntries[i]);
1029
1030
      goto fallback;
1048
1049
      error(0, errno, "fork");
1049
1050
      TEMP_FAILURE_RETRY(sigprocmask(SIG_UNBLOCK,
1050
1051
                                     &sigchld_action.sa_mask, NULL));
1051
 
      close(pipefd[0]);
1052
 
      close(pipefd[1]);
 
1052
      TEMP_FAILURE_RETRY(close(pipefd[0]));
 
1053
      TEMP_FAILURE_RETRY(close(pipefd[1]));
1053
1054
      exitstatus = EX_OSERR;
1054
1055
      free(direntries[i]);
1055
1056
      goto fallback;
1083
1084
      /* no return */
1084
1085
    }
1085
1086
    /* Parent process */
1086
 
    close(pipefd[1]);           /* Close unused write end of pipe */
1087
 
    close(plugin_fd);
 
1087
    TEMP_FAILURE_RETRY(close(pipefd[1])); /* Close unused write end of
 
1088
                                             pipe */
 
1089
    TEMP_FAILURE_RETRY(close(plugin_fd));
1088
1090
    plugin *new_plugin = getplugin(direntries[i]->d_name);
1089
1091
    if(new_plugin == NULL){
1090
1092
      error(0, errno, "getplugin");
1136
1138
  
1137
1139
  free(direntries);
1138
1140
  direntries = NULL;
1139
 
  close(dir_fd);
 
1141
  TEMP_FAILURE_RETRY(close(dir_fd));
1140
1142
  dir_fd = -1;
1141
1143
  free_plugin(getplugin(NULL));
1142
1144
  
1340
1342
  free(direntries);
1341
1343
  
1342
1344
  if(dir_fd != -1){
1343
 
    close(dir_fd);
 
1345
    TEMP_FAILURE_RETRY(close(dir_fd));
1344
1346
  }
1345
1347
  
1346
1348
  /* Kill the processes */