=== modified file 'TODO' --- TODO 2009-08-30 03:10:29 +0000 +++ TODO 2009-09-04 16:32:22 +0000 @@ -2,6 +2,7 @@ * mandos-client ** TODO [#A] Clean up /tmp directory and take down interface on signal +** TODO [#A] Do not handle ignored signals ** TODO [#B] use scandir(3) instead of readdir(3) * splashy @@ -12,10 +13,8 @@ ** TODO [#A] Re-raise signal received when exiting due to handled signal. ** TODO [#B] use scandir(3) instead of readdir(3) -* password-prompt -** TODO [#A] Re-raise signal received when exiting due to handled signal. - * plugin-runner +** TODO [#A] Do not handle ignored signals ** TODO [#B] use scandir(3) instead of readdir(3) ** TODO [#C] use same file name rules as run-parts(8) === modified file 'plugin-runner.c' --- plugin-runner.c 2009-08-30 03:10:29 +0000 +++ plugin-runner.c 2009-09-04 16:32:22 +0000 @@ -38,7 +38,8 @@ #include /* fd_set, select(), FD_ZERO(), FD_SET(), FD_ISSET(), FD_CLR */ #include /* wait(), waitpid(), WIFEXITED(), - WEXITSTATUS() */ + WEXITSTATUS(), WTERMSIG(), + WCOREDUMP() */ #include /* struct stat, stat(), S_ISREG() */ #include /* and, or, not */ #include /* DIR, struct dirent, opendir(), @@ -52,7 +53,8 @@ close() */ #include /* fcntl(), F_GETFD, F_SETFD, FD_CLOEXEC */ -#include /* strsep, strlen(), asprintf() */ +#include /* strsep, strlen(), asprintf(), + strsignal() */ #include /* errno */ #include /* struct argp_option, struct argp_state, struct argp, @@ -973,9 +975,10 @@ WEXITSTATUS(proc->status)); } else if(WIFSIGNALED(proc->status)){ fprintf(stderr, "Plugin %s [%" PRIdMAX "] killed by" - " signal %d\n", proc->name, + " signal %d: %s\n", proc->name, (intmax_t) (proc->pid), - WTERMSIG(proc->status)); + WTERMSIG(proc->status), + strsignal(WTERMSIG(proc->status))); } else if(WCOREDUMP(proc->status)){ fprintf(stderr, "Plugin %s [%" PRIdMAX "] dumped" " core\n", proc->name, (intmax_t) (proc->pid)); === modified file 'plugins.d/password-prompt.c' --- plugins.d/password-prompt.c 2009-08-30 03:10:29 +0000 +++ plugins.d/password-prompt.c 2009-09-04 16:32:22 +0000 @@ -1,4 +1,4 @@ -/* -*- coding: utf-8 -*- */ +/* -*- coding: utf-8; mode: c; mode: orgtbl -*- */ /* * Password-prompt - Read a password from the terminal and print it * @@ -33,7 +33,8 @@ #include /* sig_atomic_t, raise(), struct sigaction, sigemptyset(), sigaction(), sigaddset(), SIGINT, - SIGQUIT, SIGHUP, SIGTERM */ + SIGQUIT, SIGHUP, SIGTERM, + raise() */ #include /* NULL, size_t, ssize_t */ #include /* ssize_t */ #include /* EXIT_SUCCESS, EXIT_FAILURE, @@ -52,12 +53,17 @@ ARGP_ERR_UNKNOWN */ volatile sig_atomic_t quit_now = 0; +int signal_received; bool debug = false; const char *argp_program_version = "password-prompt " VERSION; const char *argp_program_bug_address = ""; -static void termination_handler(__attribute__((unused))int signum){ +static void termination_handler(int signum){ + if(quit_now){ + return; + } quit_now = 1; + signal_received = signum; } int main(int argc, char **argv){ @@ -131,6 +137,10 @@ perror("sigaction"); return EXIT_FAILURE; } + /* Need to check if the handler is SIG_IGN before handling: + | [[info:libc:Initial Signal Actions]] | + | [[info:libc:Basic Signal Handling]] | + */ if(old_action.sa_handler != SIG_IGN){ ret = sigaction(SIGINT, &new_action, NULL); if(ret == -1){ @@ -242,7 +252,7 @@ /* if(ret == 0), then the only sensible thing to do is to retry to read from stdin */ fputc('\n', stderr); - if(debug and quit_now == 0){ + if(debug and not quit_now){ /* If quit_now is nonzero, we were interrupted by a signal, and will print that later, so no need to show this too. */ fprintf(stderr, "getline() returned 0, retrying.\n"); @@ -258,6 +268,16 @@ perror("tcsetattr+echo"); } + if(quit_now){ + sigemptyset(&old_action.sa_mask); + old_action.sa_handler = SIG_DFL; + ret = sigaction(signal_received, &old_action, NULL); + if(ret == -1){ + perror("sigaction"); + } + raise(signal_received); + } + if(debug){ fprintf(stderr, "%s is exiting with status %d\n", argv[0], status);