Skip to content
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

Merged
merged 4 commits into from Jun 14, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 27 additions & 5 deletions dumb-init.c
Expand Up @@ -33,8 +33,20 @@
pid_t child_pid = -1;
char debug = 0;
char use_setsid = 1;
int sigterm_replacement = 15;
Copy link
Contributor

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:

int sigterm_replacement = SIGTERM;



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);
}
Expand Down Expand Up @@ -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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--signal seems a little ambiguous, maybe --sigterm-replacement?

" -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"
Expand All @@ -136,15 +149,21 @@ void print_help(char *argv[]) {
}


void write_sigterm_replacement(char *arg) {
sigterm_replacement = strtol(arg, NULL, 10);
}
Copy link
Contributor

Choose a reason for hiding this comment

The 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 switch



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);
Expand All @@ -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);
}
Expand Down