-
Notifications
You must be signed in to change notification settings - Fork 339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add '--signal' option to replace SIGTERM #83
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,8 +33,20 @@ | |
pid_t child_pid = -1; | ||
char debug = 0; | ||
char use_setsid = 1; | ||
int sigterm_replacement = 15; | ||
|
||
|
||
int translate_signal(int signum) { | ||
switch (signum) { | ||
case SIGTERM: | ||
return sigterm_replacement; | ||
default: | ||
return signum; | ||
} | ||
} | ||
|
||
void forward_signal(int signum) { | ||
signum = translate_signal(signum); | ||
kill(use_setsid ? -child_pid : child_pid, signum); | ||
DEBUG("Forwarded signal %d to children.\n", signum); | ||
} | ||
|
@@ -125,6 +137,7 @@ void print_help(char *argv[]) { | |
" -c, --single-child Run in single-child mode.\n" | ||
" In this mode, signals are only proxied to the\n" | ||
" direct child and not any of its descendants.\n" | ||
" -s, --signal Signal to use in place of SIGTERM.\n" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
" -v, --verbose Print debugging information to stderr.\n" | ||
" -h, --help Print this help message and exit.\n" | ||
" -V, --version Print the current version and exit.\n" | ||
|
@@ -136,15 +149,21 @@ void print_help(char *argv[]) { | |
} | ||
|
||
|
||
void write_sigterm_replacement(char *arg) { | ||
sigterm_replacement = strtol(arg, NULL, 10); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this function is probably unnecessary and the line could just be put in the |
||
|
||
|
||
char **parse_command(int argc, char *argv[]) { | ||
int opt; | ||
struct option long_options[] = { | ||
{"help", no_argument, NULL, 'h'}, | ||
{"single-child", no_argument, NULL, 'c'}, | ||
{"verbose", no_argument, NULL, 'v'}, | ||
{"version", no_argument, NULL, 'V'}, | ||
{"help", no_argument, NULL, 'h'}, | ||
{"single-child", no_argument, NULL, 'c'}, | ||
{"signal", required_argument, NULL, 's'}, | ||
{"verbose", no_argument, NULL, 'v'}, | ||
{"version", no_argument, NULL, 'V'}, | ||
}; | ||
while ((opt = getopt_long(argc, argv, "+hvVc", long_options, NULL)) != -1) { | ||
while ((opt = getopt_long(argc, argv, "+hvVcs:", long_options, NULL)) != -1) { | ||
switch (opt) { | ||
case 'h': | ||
print_help(argv); | ||
|
@@ -158,6 +177,9 @@ char **parse_command(int argc, char *argv[]) { | |
case 'c': | ||
use_setsid = 0; | ||
break; | ||
case 's': | ||
write_sigterm_replacement(optarg); | ||
break; | ||
default: | ||
exit(1); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would be a little more clear written as: