/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

Merge.

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
#include <argp.h>               /* struct argp_option, struct
57
57
                                   argp_state, struct argp,
58
58
                                   argp_parse(), ARGP_ERR_UNKNOWN,
59
 
                                   ARGP_KEY_END, ARGP_KEY_ARG, error_t */
 
59
                                   ARGP_KEY_END, ARGP_KEY_ARG,
 
60
                                   error_t */
60
61
#include <signal.h>             /* struct sigaction, sigemptyset(),
61
62
                                   sigaddset(), sigaction(),
62
63
                                   sigprocmask(), SIG_BLOCK, SIGCHLD,
78
79
  size_t buffer_size;
79
80
  size_t buffer_length;
80
81
  bool eof;
81
 
  bool completed;
82
 
  int status;
 
82
  volatile bool completed;
 
83
  volatile int status;
83
84
  struct process *next;
84
85
} process;
85
86
 
199
200
 
200
201
process *process_list = NULL;
201
202
 
202
 
/* Mark processes as completed when it exits, and save its exit
 
203
/* Mark processes as completed when they exit, and save their exit
203
204
   status. */
204
205
void handle_sigchld(__attribute__((unused)) int sig){
205
 
  process *proc = process_list;
206
206
  while(true){
 
207
    process *proc = process_list;
207
208
    int status;
208
209
    pid_t pid = waitpid(-1, &status, WNOHANG);
209
210
    if(pid == 0){
 
211
      /* Only still running child processes */
210
212
      break;
211
213
    }
212
214
    if(pid == -1){
213
215
      if (errno != ECHILD){
214
216
        perror("waitpid");
215
217
      }
216
 
      return;
 
218
      /* No child processes */
 
219
      break;
217
220
    }
218
221
 
 
222
    /* A child exited, find it in process_list */
219
223
    while(proc != NULL and proc->pid != pid){
220
224
      proc = proc->next;
221
225
    }
843
847
          /* Remove the plugin */
844
848
          FD_CLR(proc->fd, &rfds_all);
845
849
          /* Block signal while modifying process_list */
846
 
          ret = sigprocmask (SIG_BLOCK, &sigchld_action.sa_mask, NULL);
 
850
          ret = sigprocmask(SIG_BLOCK, &sigchld_action.sa_mask, NULL);
847
851
          if(ret < 0){
848
852
            perror("sigprocmask");
849
853
            exitstatus = EXIT_FAILURE;
877
881
        }
878
882
        /* This process exited nicely, so print its buffer */
879
883
 
880
 
        bool bret = print_out_password(proc->buffer, proc->buffer_length);
 
884
        bool bret = print_out_password(proc->buffer,
 
885
                                       proc->buffer_length);
881
886
        if(not bret){
882
887
          perror("print_out_password");
883
888
          exitstatus = EXIT_FAILURE;
920
925
 fallback:
921
926
  
922
927
  if(process_list == NULL or exitstatus != EXIT_SUCCESS){
923
 
    /* Fallback if all plugins failed, none are found or an error occured */
 
928
    /* Fallback if all plugins failed, none are found or an error
 
929
       occured */
924
930
    bool bret;
925
931
    fprintf(stderr, "Going to fallback mode using getpass(3)\n");
926
932
    char *passwordbuffer = getpass("Password: ");