64
64
sigprocmask(), SIG_BLOCK, SIGCHLD,
65
65
SIG_UNBLOCK, kill() */
66
66
#include <errno.h> /* errno, EBADF */
67
#include <inttypes.h> /* intmax_t, SCNdMAX, PRIdMAX, */
69
68
#define BUFFER_SIZE 256
115
114
if(name != NULL){
116
115
copy_name = strdup(name);
117
116
if(copy_name == NULL){
123
*new_plugin = (plugin){ .name = copy_name,
126
.next = plugin_list };
121
*new_plugin = (plugin) { .name = copy_name,
124
.next = plugin_list };
128
126
new_plugin->argv = malloc(sizeof(char *) * 2);
129
127
if(new_plugin->argv == NULL){
380
375
error_t parse_opt(int key, char *arg, __attribute__((unused))
381
struct argp_state *state){
376
struct argp_state *state) {
383
378
case 'g': /* --global-options */
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'){
474
fprintf(stderr, "Bad user ID number: \"%s\", using %"
475
PRIdMAX "\n", arg, (intmax_t)uid);
466
/* In the GNU C library, uid_t is always unsigned int */
467
ret = sscanf(arg, "%u", &uid);
469
fprintf(stderr, "Bad user ID number: \"%s\", using %u\n", arg,
480
473
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'){
484
fprintf(stderr, "Bad group ID number: \"%s\", using %"
485
PRIdMAX "\n", arg, (intmax_t)gid);
474
/* In the GNU C library, gid_t is always unsigned int */
475
ret = sscanf(arg, "%u", &gid);
477
fprintf(stderr, "Bad group ID number: \"%s\", using %u\n",
490
481
case 132: /* --debug */
514
505
ignores everything but the --config-file option. */
515
506
error_t parse_opt_config_file(int key, char *arg,
516
507
__attribute__((unused))
517
struct argp_state *state){
508
struct argp_state *state) {
519
510
case 'g': /* --global-options */
520
511
case 'G': /* --global-env */
521
512
case 'o': /* --options-for */
656
647
for(char **a = p->argv; *a != NULL; a++){
657
648
fprintf(stderr, "\tArg: %s\n", *a);
659
fprintf(stderr, "...and %d environment variables\n", p->envc);
650
fprintf(stderr, "...and %u environment variables\n", p->envc);
660
651
for(char **a = p->environ; *a != NULL; a++){
661
652
fprintf(stderr, "\t%s\n", *a);
961
952
from one of them */
962
953
for(plugin *proc = plugin_list; proc != NULL;){
963
954
/* Is this process completely done? */
964
if(proc->completed and proc->eof){
955
if(proc->eof and proc->completed){
965
956
/* Only accept the plugin output if it exited cleanly */
966
957
if(not WIFEXITED(proc->status)
967
958
or WEXITSTATUS(proc->status) != 0){
971
962
if(WIFEXITED(proc->status)){
972
fprintf(stderr, "Plugin %s [%" PRIdMAX "] exited with"
973
" status %d\n", proc->name,
974
(intmax_t) (proc->pid),
963
fprintf(stderr, "Plugin %u exited with status %d\n",
964
(unsigned int) (proc->pid),
975
965
WEXITSTATUS(proc->status));
976
} else if(WIFSIGNALED(proc->status)){
977
fprintf(stderr, "Plugin %s [%" PRIdMAX "] killed by"
978
" signal %d\n", proc->name,
979
(intmax_t) (proc->pid),
966
} else if(WIFSIGNALED(proc->status)) {
967
fprintf(stderr, "Plugin %u killed by signal %d\n",
968
(unsigned int) (proc->pid),
980
969
WTERMSIG(proc->status));
981
970
} else if(WCOREDUMP(proc->status)){
982
fprintf(stderr, "Plugin %s [%" PRIdMAX "] dumped"
983
" core\n", proc->name, (intmax_t) (proc->pid));
971
fprintf(stderr, "Plugin %u dumped core\n",
972
(unsigned int) (proc->pid));