]> git.mdlowis.com Git - proto/rc.git/commitdiff
Hardcode signal messages in C99 style. Fixed null pointer access in several places...
authorMichael D. Lowis <mike.lowis@gentex.com>
Tue, 14 Mar 2017 15:02:10 +0000 (11:02 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Tue, 14 Mar 2017 15:02:10 +0000 (11:02 -0400)
.gitignore [new file with mode: 0644]
fn.c
sigmsgs.c

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..b9c4208
--- /dev/null
@@ -0,0 +1,5 @@
+*.o
+rc
+mkstatval
+statval.h
+tags
diff --git a/fn.c b/fn.c
index 97e0b4353c02044d87f0c24610a13099ebd55660..ac898955ea30672ae634db66b70b813b40f5576f 100644 (file)
--- a/fn.c
+++ b/fn.c
@@ -139,6 +139,7 @@ static void dud_handler(int ignore) {
 */
 
 extern void fnassign(char *name, Node *def) {
+       if (!name) return;
        Node *newdef = treecpy(def == NULL ? &null : def, ealloc); /* important to do the treecopy first */
        rc_Function *new = get_fn_place(name);
        int i;
@@ -212,7 +213,7 @@ extern char *fnlookup_string(char *name) {
 extern void fnrm(char *name) {
        int i;
        for (i = 1; i < NSIG; i++)
-               if (streq(signals[i].name, name)) {
+               if (signals[i].name && streq(signals[i].name, name)) {
                        handlers[i] = NULL;
                        switch (i) {
                        case SIGINT:
@@ -236,7 +237,7 @@ extern void fnrm(char *name) {
 extern void whatare_all_signals() {
        int i;
        for (i = 1; i < NSIG; i++)
-               if (*signals[i].name != '\0') {
+               if (signals[i].name && *signals[i].name) {
                        if (sighandlers[i] == SIG_IGN)
                                fprint(1, "fn %s {}\n", signals[i].name);
                        else if (sighandlers[i] == fn_handler)
index 54c94004319a4f98af3a5ad0a1eebb493c84a959..d7d32190b6bd84db18af1649f8b6dda8427bf969 100644 (file)
--- a/sigmsgs.c
+++ b/sigmsgs.c
@@ -1,36 +1,38 @@
 #include "rc.h"
 
-Sigmsgs signals[] = {
-       {"",    ""},
-       {"sighup",      "hangup"},
-       {"sigint",      ""},
-       {"sigquit",     "quit"},
-       {"sigill",      "illegal instruction"},
-       {"sigtrap",     "trace trap"},
-       {"sigabrt",     "abort"},
-       {"sigemt",      "emt instruction"},
-       {"sigfpe",      "floating point error"},
-       {"sigkill",     "killed"},
-       {"sigbus",      "bus error"},
-       {"sigsegv",     "segmentation violation"},
-       {"sigsys",      "invalid argument to system call"},
-       {"sigpipe",     ""},
-       {"sigalrm",     "alarm clock"},
-       {"sigterm",     "terminated"},
-       {"sigurg",      "urgent condition on i/o channel"},
-       {"sigstop",     "stopped by program"},
-       {"sigtstp",     "stopped"},
-       {"sigcont",     "continue"},
-       {"sigchld",     "child stop or exit"},
-       {"sigttin",     "background tty read"},
-       {"sigttou",     "background tty write"},
-       {"sigio",       "socket i/o possible"},
-       {"sigxcpu",     "exceeded cpu time limit"},
-       {"sigxfsz",     "exceeded file size limit"},
-       {"sigvtalrm",   "virtual timer alarm"},
-       {"sigprof",     "profiling timer alarm"},
-       {"sigwinch",    "window size change"},
-       {"siginfo",     "information request"},
-       {"sigusr1",     "user defined signal 1"},
-       {"sigusr2",     "user defined signal 2"},
+Sigmsgs signals[NSIG] = {
+    [SIGHUP]    = { "sighup",    "hangup" },
+    [SIGINT]    = { "sigint",    "" },
+    [SIGQUIT]   = { "sigquit",   "quit" },
+    [SIGILL]    = { "sigill",    "illegal instruction" },
+    [SIGTRAP]   = { "sigtrap",   "trace trap" },
+    [SIGABRT]   = { "sigabrt",   "abort" },
+    [SIGIOT]    = { "sigiot",    "iot trap " },
+    [SIGBUS]    = { "sigbus",    "bus error" },
+    [SIGFPE]    = { "sigfpe",    "floating-point exception" },
+    [SIGKILL]   = { "sigkill",   "kill, unblockable" },
+    [SIGUSR1]   = { "sigusr1",   "user-defined signal 1" },
+    [SIGSEGV]   = { "sigsegv",   "segmentation violation" },
+    [SIGUSR2]   = { "sigusr2",   "user-defined signal 2" },
+    [SIGPIPE]   = { "sigpipe",   "broken pipe" },
+    [SIGALRM]   = { "sigalrm",   "alarm clock" },
+    [SIGTERM]   = { "sigterm",   "termination" },
+    [SIGSTKFLT] = { "sigstkflt", "stack fault" },
+    [SIGCLD]    = { "sigcld",    "child stop or exit" },
+    [SIGCHLD]   = { "sigchld",   "child status has changed" },
+    [SIGCONT]   = { "sigcont",   "continue" },
+    [SIGSTOP]   = { "sigstop",   "stop, unblockable" },
+    [SIGTSTP]   = { "sigstp",    "keyboard stop" },
+    [SIGTTIN]   = { "sigttin",   "background read from tty" },
+    [SIGTTOU]   = { "sigttou",   "background write to tty" },
+    [SIGURG]    = { "sigurg",    "urgent condition on socket" },
+    [SIGXCPU]   = { "sigxcpu",   "cpu limit exceeded" },
+    [SIGXFSZ]   = { "sigxfsz",   "file size limit exceeded" },
+    [SIGVTALRM] = { "sigvtalrm", "virtual alarm clock" },
+    [SIGPROF]   = { "sigprof",   "profiling alarm clock" },
+    [SIGWINCH]  = { "sigwinch",  "window size change" },
+    [SIGPOLL]   = { "sigpoll",   "pollable event occurred" },
+    [SIGIO]     = { "sigio",     "i/o now possible" },
+    [SIGPWR]    = { "sigpwr",    "power failure restart" },
+    [SIGSYS]    = { "sigsys",    "bad system call" },
 };