62
62
#include <signal.h> /* struct sigaction, sigemptyset(),
63
63
sigaddset(), sigaction(),
64
64
sigprocmask(), SIG_BLOCK, SIGCHLD,
65
SIG_UNBLOCK, kill() */
65
SIG_UNBLOCK, kill(), sig_atomic_t
66
67
#include <errno.h> /* errno, EBADF */
67
#include <inttypes.h> /* intmax_t, SCNdMAX, PRIdMAX, */
68
#include <inttypes.h> /* intmax_t, PRIdMAX, strtoimax() */
69
70
#define BUFFER_SIZE 256
380
381
error_t parse_opt(int key, char *arg, __attribute__((unused))
381
382
struct argp_state *state){
383
385
case 'g': /* --global-options */
386
while((p = strsep(&arg, ",")) != NULL){
388
while((plugin_option = strsep(&arg, ",")) != NULL){
389
if(plugin_option[0] == '\0'){
390
if(not add_argument(getplugin(NULL), p)){
392
if(not add_argument(getplugin(NULL), plugin_option)){
391
393
perror("add_argument");
392
394
return ARGP_ERR_UNKNOWN;
405
407
case 'o': /* --options-for */
407
char *p_name = strsep(&arg, ":");
408
if(p_name[0] == '\0' or arg == NULL){
411
char *opt = strsep(&arg, ":");
412
if(opt[0] == '\0' or opt == NULL){
416
while((p = strsep(&opt, ",")) != NULL){
420
if(not add_argument(getplugin(p_name), p)){
409
char *plugin_name = strsep(&arg, ":");
410
if(plugin_name[0] == '\0'){
414
while((plugin_option = strsep(&arg, ",")) != NULL){
415
if(not add_argument(getplugin(plugin_name), plugin_option)){
421
416
perror("add_argument");
422
417
return ARGP_ERR_UNKNOWN;
468
463
/* This is already done by parse_opt_config_file() */
470
465
case 130: /* --userid */
471
ret = sscanf(arg, "%" SCNdMAX "%n", &tmpmax, &numchars);
472
if(ret < 1 or tmpmax != (uid_t)tmpmax
473
or arg[numchars] != '\0'){
467
tmpmax = strtoimax(arg, &tmp, 10);
468
if(errno != 0 or tmp == arg or *tmp != '\0'
469
or tmpmax != (uid_t)tmpmax){
474
470
fprintf(stderr, "Bad user ID number: \"%s\", using %"
475
471
PRIdMAX "\n", arg, (intmax_t)uid);
480
476
case 131: /* --groupid */
481
ret = sscanf(arg, "%" SCNdMAX "%n", &tmpmax, &numchars);
482
if(ret < 1 or tmpmax != (gid_t)tmpmax
483
or arg[numchars] != '\0'){
478
tmpmax = strtoimax(arg, &tmp, 10);
479
if(errno != 0 or tmp == arg or *tmp != '\0'
480
or tmpmax != (gid_t)tmpmax){
484
481
fprintf(stderr, "Bad group ID number: \"%s\", using %"
485
482
PRIdMAX "\n", arg, (intmax_t)gid);
966
964
if(not WIFEXITED(proc->status)
967
965
or WEXITSTATUS(proc->status) != 0){
968
966
/* Bad exit by plugin */
971
969
if(WIFEXITED(proc->status)){
972
fprintf(stderr, "Plugin %" PRIdMAX " exited with status"
973
" %d\n", (intmax_t) (proc->pid),
970
fprintf(stderr, "Plugin %s [%" PRIdMAX "] exited with"
971
" status %d\n", proc->name,
972
(intmax_t) (proc->pid),
974
973
WEXITSTATUS(proc->status));
975
974
} else if(WIFSIGNALED(proc->status)){
976
fprintf(stderr, "Plugin %" PRIdMAX " killed by signal"
977
" %d\n", (intmax_t) (proc->pid),
975
fprintf(stderr, "Plugin %s [%" PRIdMAX "] killed by"
976
" signal %d\n", proc->name,
977
(intmax_t) (proc->pid),
978
978
WTERMSIG(proc->status));
979
979
} else if(WCOREDUMP(proc->status)){
980
fprintf(stderr, "Plugin %" PRIdMAX " dumped core\n",
981
(intmax_t) (proc->pid));
980
fprintf(stderr, "Plugin %s [%" PRIdMAX "] dumped"
981
" core\n", proc->name, (intmax_t) (proc->pid));
985
985
/* Remove the plugin */
986
986
FD_CLR(proc->fd, &rfds_all);
988
988
/* Block signal while modifying process_list */
989
989
ret = sigprocmask(SIG_BLOCK, &sigchld_action.sa_mask, NULL);