process: fix inconsistent signal detection
Previously strtosig() detected the signal count at runtime, mutating the value of a static global variable. The signals were detected using \#ifdef directives and were taken from <signal.h> on my OpenBSD install. Extract the common signals that should be found in every POSIX implementation [1] and remove any vendor-specific signals with possibly differing names across implementations. Do not detect the signal count at runtime anymore. Keep it in a static const variable which holds the signal count known _at compile time_. Fix the logic error in the for loop in strtosig(). [1]: <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html>
This commit is contained in:
parent
82c47c778c
commit
1d2a6bcf8b
1 changed files with 33 additions and 95 deletions
128
lprocess.c
128
lprocess.c
|
@ -22,115 +22,58 @@
|
||||||
#define PID_MAX 8 /* rounded to the nearest even number */
|
#define PID_MAX 8 /* rounded to the nearest even number */
|
||||||
#define PROCESS_MAX 256
|
#define PROCESS_MAX 256
|
||||||
|
|
||||||
static int sigc = -1;
|
static const int sigc = 22;
|
||||||
|
|
||||||
/* clang-format off */
|
/* clang-format off */
|
||||||
|
|
||||||
static const int signals[] = {
|
static const int signals[] = {
|
||||||
SIGHUP,
|
|
||||||
SIGINT,
|
|
||||||
SIGQUIT,
|
|
||||||
SIGILL,
|
|
||||||
SIGTRAP,
|
|
||||||
SIGABRT,
|
SIGABRT,
|
||||||
SIGIOT,
|
|
||||||
SIGFPE,
|
|
||||||
SIGKILL,
|
|
||||||
SIGBUS,
|
|
||||||
SIGSEGV,
|
|
||||||
SIGSYS,
|
|
||||||
SIGPIPE,
|
|
||||||
SIGALRM,
|
SIGALRM,
|
||||||
SIGTERM,
|
SIGBUS,
|
||||||
SIGURG,
|
|
||||||
SIGSTOP,
|
|
||||||
SIGTSTP,
|
|
||||||
SIGCONT,
|
|
||||||
SIGCHLD,
|
SIGCHLD,
|
||||||
|
SIGCONT,
|
||||||
|
SIGFPE,
|
||||||
|
SIGHUP,
|
||||||
|
SIGILL,
|
||||||
|
SIGINT,
|
||||||
|
SIGKILL,
|
||||||
|
SIGPIPE,
|
||||||
|
SIGQUIT,
|
||||||
|
SIGSEGV,
|
||||||
|
SIGSTOP,
|
||||||
|
SIGTERM,
|
||||||
|
SIGTSTP,
|
||||||
SIGTTIN,
|
SIGTTIN,
|
||||||
SIGTTOU,
|
SIGTTOU,
|
||||||
#ifdef SIGSTKFL
|
|
||||||
SIGSTKFL,
|
|
||||||
#endif
|
|
||||||
SIGIO,
|
|
||||||
SIGXCPU,
|
|
||||||
SIGXFSZ,
|
|
||||||
#ifdef SIGVTALR
|
|
||||||
SIGVTALR,
|
|
||||||
#elif defined(SIGVTALRM)
|
|
||||||
SIGVTALRM,
|
|
||||||
#endif
|
|
||||||
SIGPROF,
|
|
||||||
#ifdef SIGWINC
|
|
||||||
SIGWINC,
|
|
||||||
#elif defined(SIGWINCH)
|
|
||||||
SIGWINCH,
|
|
||||||
#endif
|
|
||||||
#ifdef SIGINFO
|
|
||||||
SIGINFO,
|
|
||||||
#endif
|
|
||||||
#ifdef SIGPOLL
|
|
||||||
SIGPOLL,
|
|
||||||
#endif
|
|
||||||
#ifdef SIGPWR
|
|
||||||
SIGPWR,
|
|
||||||
#endif
|
|
||||||
SIGUSR1,
|
SIGUSR1,
|
||||||
SIGUSR2,
|
SIGUSR2,
|
||||||
-1 /* end */
|
SIGTRAP,
|
||||||
|
SIGURG
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char *sigstrs[] = {
|
static const char *sigstrs[] = {
|
||||||
[SIGHUP] = "SIGHUP",
|
|
||||||
[SIGINT] = "SIGINT",
|
|
||||||
[SIGQUIT] = "SIGQUIT",
|
|
||||||
[SIGILL] = "SIGILL",
|
|
||||||
[SIGTRAP] = "SIGTRAP",
|
|
||||||
[SIGABRT] = "SIGABRT",
|
[SIGABRT] = "SIGABRT",
|
||||||
[SIGIOT] = "SIGIOT",
|
|
||||||
[SIGFPE] = "SIGFPE",
|
|
||||||
[SIGKILL] = "SIGKILL",
|
|
||||||
[SIGBUS] = "SIGBUS",
|
|
||||||
[SIGSEGV] = "SIGSEGV",
|
|
||||||
[SIGSYS] = "SIGSYS",
|
|
||||||
[SIGPIPE] = "SIGPIPE",
|
|
||||||
[SIGALRM] = "SIGALRM",
|
[SIGALRM] = "SIGALRM",
|
||||||
[SIGTERM] = "SIGTERM",
|
[SIGBUS] = "SIGBUS",
|
||||||
[SIGURG] = "SIGURG",
|
|
||||||
[SIGSTOP] = "SIGSTOP",
|
|
||||||
[SIGTSTP] = "SIGTSTP",
|
|
||||||
[SIGCONT] = "SIGCONT",
|
|
||||||
[SIGCHLD] = "SIGCHLD",
|
[SIGCHLD] = "SIGCHLD",
|
||||||
|
[SIGCONT] = "SIGCONT",
|
||||||
|
[SIGFPE] = "SIGFPE",
|
||||||
|
[SIGHUP] = "SIGHUP",
|
||||||
|
[SIGILL] = "SIGILL",
|
||||||
|
[SIGINT] = "SIGINT",
|
||||||
|
[SIGKILL] = "SIGKILL",
|
||||||
|
[SIGPIPE] = "SIGPIPE",
|
||||||
|
[SIGQUIT] = "SIGQUIT",
|
||||||
|
[SIGSEGV] = "SIGSEGV",
|
||||||
|
[SIGSTOP] = "SIGSTOP",
|
||||||
|
[SIGTERM] = "SIGTERM",
|
||||||
|
[SIGTSTP] = "SIGTSTP",
|
||||||
[SIGTTIN] = "SIGTTIN",
|
[SIGTTIN] = "SIGTTIN",
|
||||||
[SIGTTOU] = "SIGTTOU",
|
[SIGTTOU] = "SIGTTOU",
|
||||||
#ifdef SIGSTKFL
|
|
||||||
[SIGSTKFL] = "SIGSTKFL",
|
|
||||||
#endif
|
|
||||||
[SIGIO] = "SIGIO",
|
|
||||||
[SIGXCPU] = "SIGXCPU",
|
|
||||||
[SIGXFSZ] = "SIGXFSZ",
|
|
||||||
#ifdef SIGVTALR
|
|
||||||
[SIGVTALR] = "SIGVTALR",
|
|
||||||
#elif defined(SIGVTALRM)
|
|
||||||
[SIGVTALRM] = "SIGVTALRM",
|
|
||||||
#endif
|
|
||||||
[SIGPROF] = "SIGPROF",
|
|
||||||
#ifdef SIGWINC
|
|
||||||
[SIGWINC] = "SIGWINC",
|
|
||||||
#elif defined(SIGWINCH)
|
|
||||||
[SIGWINCH] = "SIGWINCH",
|
|
||||||
#endif
|
|
||||||
#ifdef SIGINFO
|
|
||||||
[SIGINFO] = "SIGINFO",
|
|
||||||
#endif
|
|
||||||
#ifdef SIGPOLL
|
|
||||||
[SIGPOLL] = "SIGPOLL",
|
|
||||||
#endif
|
|
||||||
#ifdef SIGPWR
|
|
||||||
[SIGPWR] = "SIGPWR",
|
|
||||||
#endif
|
|
||||||
[SIGUSR1] = "SIGUSR1",
|
[SIGUSR1] = "SIGUSR1",
|
||||||
[SIGUSR2] = "SIGUSR2"
|
[SIGUSR2] = "SIGUSR2",
|
||||||
|
[SIGTRAP] = "SIGTRAP",
|
||||||
|
[SIGURG] = "SIGURG"
|
||||||
};
|
};
|
||||||
|
|
||||||
/* clang-format on */
|
/* clang-format on */
|
||||||
|
@ -187,13 +130,8 @@ strtosig(const char *sig)
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
sigc = 0;
|
|
||||||
while (signals[sigc] != -1)
|
|
||||||
sigc++;
|
|
||||||
sigc--;
|
|
||||||
|
|
||||||
j = 0;
|
j = 0;
|
||||||
for (i = signals[j]; i < sigc; j++) {
|
for (i = signals[j]; j < sigc; j++) {
|
||||||
i = signals[j];
|
i = signals[j];
|
||||||
if (strcasecmp(sigstrs[i], sig) == 0)
|
if (strcasecmp(sigstrs[i], sig) == 0)
|
||||||
return i; /* signal found */
|
return i; /* signal found */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue