/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 + small bugfix

Show diffs side-by-side

added added

removed removed

Lines of Context:
108
108
  char *copy_name = NULL;
109
109
  if(name != NULL){
110
110
    copy_name = strdup(name);
111
 
    if(copy_name == NULL){
112
 
      return NULL;
113
 
    }
 
111
  }
 
112
  if(copy_name == NULL){
 
113
    return NULL;
114
114
  }
115
115
  
116
116
  *new_plugin = (plugin) { .name = copy_name,
199
199
 
200
200
process *process_list = NULL;
201
201
 
202
 
/* Mark processes as completed when it exits, and save its exit
 
202
/* Mark a process as completed when it exits, and save its exit
203
203
   status. */
204
204
void handle_sigchld(__attribute__((unused)) int sig){
205
205
  process *proc = process_list;
206
 
  while(true){
207
 
    int status;
208
 
    pid_t pid = waitpid(-1, &status, WNOHANG);
209
 
    if(pid == 0){
210
 
      break;
211
 
    }
212
 
    if(pid == -1){
213
 
      if (errno != ECHILD){
214
 
        perror("waitpid");
215
 
      }
216
 
      return;
217
 
    }
218
 
 
219
 
    while(proc != NULL and proc->pid != pid){
220
 
      proc = proc->next;
221
 
    }
222
 
    if(proc == NULL){
223
 
      /* Process not found in process list */
224
 
      continue;
225
 
    }
226
 
    proc->status = status;
227
 
    proc->completed = true;
228
 
  }
 
206
  int status;
 
207
  pid_t pid = wait(&status);
 
208
  if(pid == -1){
 
209
    perror("wait");
 
210
    return;
 
211
  }
 
212
  while(proc != NULL and proc->pid != pid){
 
213
    proc = proc->next;
 
214
  }
 
215
  if(proc == NULL){
 
216
    /* Process not found in process list */
 
217
    return;
 
218
  }
 
219
  proc->status = status;
 
220
  proc->completed = true;
229
221
}
230
222
 
231
223
bool print_out_password(const char *buffer, size_t length){
260
252
    return NULL;
261
253
  }
262
254
  argv[*argc-1] = arg;
263
 
  argv[*argc] = NULL;
 
255
  argv[*argc] = NULL;   
264
256
  return argv;
265
257
}
266
258
 
267
259
static void free_plugin_list(plugin *plugin_list){
268
 
  for(plugin *next; plugin_list != NULL; plugin_list = next){
 
260
  for(plugin *next = plugin_list; plugin_list != NULL; plugin_list = next){
269
261
    next = plugin_list->next;
 
262
    free(plugin_list->name);
270
263
    for(char **arg = plugin_list->argv; *arg != NULL; arg++){
271
264
      free(*arg);
272
 
    }
 
265
    }    
273
266
    free(plugin_list->argv);
274
267
    for(char **env = plugin_list->environ; *env != NULL; env++){
275
268
      free(*env);
276
269
    }
277
270
    free(plugin_list->environ);
278
271
    free(plugin_list);
279
 
  }
 
272
  }  
280
273
}
281
274
 
282
275
int main(int argc, char *argv[]){
310
303
  ret = sigaction(SIGCHLD, &sigchld_action, &old_sigchld_action);
311
304
  if(ret == -1){
312
305
    perror("sigaction");
313
 
    exitstatus = EXIT_FAILURE;
 
306
    exitstatus = EXIT_FAILURE;    
314
307
    goto fallback;
315
308
  }
316
309
  
692
685
      }
693
686
    }
694
687
    
695
 
    int pipefd[2];
 
688
    int pipefd[2]; 
696
689
    ret = pipe(pipefd);
697
690
    if (ret == -1){
698
691
      perror("pipe");
799
792
  }
800
793
  
801
794
  free_plugin_list(plugin_list);
802
 
  plugin_list = NULL;
803
795
  
804
796
  closedir(dir);
805
797
  dir = NULL;