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

Allow specifying signal names for --rewrite #87

Open
chriskuehl opened this issue Jun 16, 2016 · 0 comments · May be fixed by #208
Open

Allow specifying signal names for --rewrite #87

chriskuehl opened this issue Jun 16, 2016 · 0 comments · May be fixed by #208
Labels

Comments

@chriskuehl
Copy link
Contributor

It would be nice to be able to specify --rewrite TERM:HUP rather than using signal numbers.

Unfortunately doesn't look like there is a list of signal names available in any common headers. There's sys_siglist (from string.h), but the names are like Hangup and Interrupt, rather than the short macro names that everyone uses.

From looking at the kill source, they define an array like this:

static const mapstruct sigtable[] = {
  {"ABRT",   SIGABRT},  /* IOT */
  {"ALRM",   SIGALRM},
  {"BUS",    SIGBUS},
  {"CHLD",   SIGCHLD},  /* CLD */
  {"CONT",   SIGCONT},
  {"FPE",    SIGFPE},
  {"HUP",    SIGHUP},
  {"ILL",    SIGILL},
  {"INT",    SIGINT},
  {"KILL",   SIGKILL},
  {"PIPE",   SIGPIPE},
  {"POLL",   SIGPOLL},  /* IO */
  {"PROF",   SIGPROF},
  {"PWR",    SIGPWR},
  {"QUIT",   SIGQUIT},
  {"SEGV",   SIGSEGV},
  {"STOP",   SIGSTOP},
  {"SYS",    SIGSYS},   /* UNUSED */
  {"TERM",   SIGTERM},
  {"TRAP",   SIGTRAP},
  {"TSTP",   SIGTSTP},
  {"TTIN",   SIGTTIN},
  {"TTOU",   SIGTTOU},
  {"URG",    SIGURG},
  {"USR1",   SIGUSR1},
  {"USR2",   SIGUSR2},
  {"VTALRM", SIGVTALRM},
  {"WINCH",  SIGWINCH},
  {"XCPU",   SIGXCPU},
  {"XFSZ",   SIGXFSZ}
};

It's not the absolute worst (they're still using the signal macros, so they don't need to worry about signal numbers not matching the ordering in the file (or it being recompiled on a different architecture with different numbers)).

Is it worth it to do something like this in dumb-init? (or is there a better way?)

jhriggs added a commit to jhriggs/dumb-init that referenced this issue May 13, 2020
- Adds a mapping of signal numbers to signal names based on the "most common" (subjective) signals.
- This allows the same config/script to be used on different platforms, for example: -r TERM:QUIT (15:3 on Linux vs. 25:20 on OS X).
- Each entry is wrapped in a #ifdef SIG<NAME>/#endif pair in an attempt to make this implementation as portable as possible.
- Names can be specified with or without the SIG prefix, and numbers and names can be used in any combination: -r 15:3, -r TERM:QUIT, -r SIGTERM:3, -r TERM:SIGQUIT, etc.
- Corresponding signum_to_signame() and signame_to_signum() functions were added.
- A new -l/--list option shows the mapping in use on the current system/platform/OS.
- Debug output has been updated to include the signal name along with the number.

Fixes Yelp#87.
@jhriggs jhriggs linked a pull request May 13, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant