/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-05-23 20:18:34 UTC
  • mto: This revision was merged to the branch mainline in revision 756.
  • Revision ID: teddy@recompile.se-20150523201834-e89ex4ito93yni8x
mandos: Use multiprocessing module to run checkers.

For a long time, the Mandos server has occasionally logged the message
"ERROR: Child process vanished".  This was never a fatal error, but it
has been annoying and slightly worrying, since a definite cause was
not found.  One potential cause could be the "multiprocessing" and
"subprocess" modules conflicting w.r.t. SIGCHLD.  To avoid this,
change the running of checkers from using subprocess.Popen
asynchronously to instead first create a multiprocessing.Process()
(which is asynchronous) calling a function, and have that function
then call subprocess.call() (which is synchronous).  In this way, the
only thing using any asynchronous subprocesses is the multiprocessing
module.

This makes it necessary to change one small thing in the D-Bus API,
since the subprocesses.call() function does not expose the raw wait(2)
status value.

DBUS-API (CheckerCompleted): Change the second value provided by this
                             D-Bus signal from the raw wait(2) status
                             to the actual terminating signal number.
mandos (subprocess_call_pipe): New function to be called by
                               multiprocessing.Process (starting a
                               separate process).
(Client.last_checker signal): New attribute for signal which
                              terminated last checker.  Like
                              last_checker_status, only not accessible
                              via D-Bus.
(Client.checker_callback): Take new "connection" argument and use it
                           to get returncode; set last_checker_signal.
                           Return False so gobject does not call this
                           callback again.
(Client.start_checker): Start checker using a multiprocessing.Process
                        instead of a subprocess.Popen.
(ClientDBus.checker_callback): Take new "connection" argument.        Call
                               Client.checker_callback early to have
                               it set last_checker_status and
                               last_checker_signal; use those.  Change
                               second value provided to D-Bus signal
                               CheckerCompleted to use
                               last_checker_signal if checker was
                               terminated by signal.
mandos-monitor: Update to reflect DBus API change.
(MandosClientWidget.checker_completed): Take "signal" instead of
                                        "condition" argument.  Use it
                                        accordingly.  Remove dead code
                                        (os.WCOREDUMP case).

Show diffs side-by-side

added added

removed removed

Lines of Context:
887
887
    int plugin_fd = openat(dir_fd, direntries[i]->d_name, O_RDONLY);
888
888
    if(plugin_fd == -1){
889
889
      error(0, errno, "Could not open plugin");
 
890
      free(direntries[i]);
890
891
      continue;
891
892
    }
892
893
    ret = (int)TEMP_FAILURE_RETRY(fstat(plugin_fd, &st));
893
894
    if(ret == -1){
894
895
      error(0, errno, "stat");
895
896
      TEMP_FAILURE_RETRY(close(plugin_fd));
 
897
      free(direntries[i]);
896
898
      continue;
897
899
    }
898
900
    
907
909
                direntries[i]->d_name);
908
910
      }
909
911
      TEMP_FAILURE_RETRY(close(plugin_fd));
 
912
      free(direntries[i]);
910
913
      continue;
911
914
    }
912
915
    
914
917
    if(p == NULL){
915
918
      error(0, errno, "getplugin");
916
919
      TEMP_FAILURE_RETRY(close(plugin_fd));
 
920
      free(direntries[i]);
917
921
      continue;
918
922
    }
919
923
    if(p->disabled){
922
926
                direntries[i]->d_name);
923
927
      }
924
928
      TEMP_FAILURE_RETRY(close(plugin_fd));
 
929
      free(direntries[i]);
925
930
      continue;
926
931
    }
927
932
    {
960
965
    if(ret == -1){
961
966
      error(0, errno, "pipe");
962
967
      exitstatus = EX_OSERR;
 
968
      free(direntries[i]);
963
969
      goto fallback;
964
970
    }
965
971
    if(pipefd[0] >= FD_SETSIZE){
968
974
      TEMP_FAILURE_RETRY(close(pipefd[0]));
969
975
      TEMP_FAILURE_RETRY(close(pipefd[1]));
970
976
      exitstatus = EX_OSERR;
 
977
      free(direntries[i]);
971
978
      goto fallback;
972
979
    }
973
980
#ifndef O_CLOEXEC
978
985
      TEMP_FAILURE_RETRY(close(pipefd[0]));
979
986
      TEMP_FAILURE_RETRY(close(pipefd[1]));
980
987
      exitstatus = EX_OSERR;
 
988
      free(direntries[i]);
981
989
      goto fallback;
982
990
    }
983
991
    ret = set_cloexec_flag(pipefd[1]);
986
994
      TEMP_FAILURE_RETRY(close(pipefd[0]));
987
995
      TEMP_FAILURE_RETRY(close(pipefd[1]));
988
996
      exitstatus = EX_OSERR;
 
997
      free(direntries[i]);
989
998
      goto fallback;
990
999
    }
991
1000
#endif  /* not O_CLOEXEC */
996
1005
    if(ret < 0){
997
1006
      error(0, errno, "sigprocmask");
998
1007
      exitstatus = EX_OSERR;
 
1008
      free(direntries[i]);
999
1009
      goto fallback;
1000
1010
    }
1001
1011
    /* Starting a new process to be watched */
1010
1020
      TEMP_FAILURE_RETRY(close(pipefd[0]));
1011
1021
      TEMP_FAILURE_RETRY(close(pipefd[1]));
1012
1022
      exitstatus = EX_OSERR;
 
1023
      free(direntries[i]);
1013
1024
      goto fallback;
1014
1025
    }
1015
1026
    if(pid == 0){
1054
1065
        error(0, errno, "sigprocmask");
1055
1066
      }
1056
1067
      exitstatus = EX_OSERR;
 
1068
      free(direntries[i]);
1057
1069
      goto fallback;
1058
1070
    }
 
1071
    free(direntries[i]);
1059
1072
    
1060
1073
    new_plugin->pid = pid;
1061
1074
    new_plugin->fd = pipefd[0];