rc

[fork] interactive rc shell
git clone https://hhvn.uk/rc
git clone git://hhvn.uk/rc
Log | Files | Refs | README | LICENSE

mksignal.c (5802B)


      1 #include <signal.h>
      2 #include <stdio.h>
      3 #include <stdlib.h>
      4 
      5 #ifdef NSIG
      6 #define NUMSIG NSIG
      7 #else
      8 #define NUMSIG 1
      9 #endif
     10 
     11 struct signaming {
     12     int signo;
     13     const char *signame;
     14     const char *sigmsg;
     15 };
     16 
     17 static struct signaming signamings[] = {
     18 #ifdef SIGABRT
     19     { SIGABRT,	"sigabrt",	"abort"},
     20 #endif
     21 #ifdef SIGALRM
     22     { SIGALRM,	"sigalrm",	"alarm clock"},
     23 #endif
     24 #ifdef SIGBREAK
     25     { SIGBREAK,	"sigbreak",	"break"},
     26 #endif
     27 #ifdef SIGBUS
     28     { SIGBUS,	"sigbus",	"bus error"},
     29 #endif
     30 #ifdef SIGCANCEL
     31     { SIGCANCEL,	"sigcancel",	"thread cancellation"},
     32 #endif
     33 #ifdef SIGCHLD
     34     { SIGCHLD,	"sigchld",	"child stop or exit"},
     35 #endif
     36 #ifdef SIGCLD
     37     { SIGCLD,	"sigcld",	"child stop or exit"},
     38 #endif
     39 #ifdef SIGCONT
     40     { SIGCONT,	"sigcont",	"continue"},
     41 #endif
     42 #ifdef SIGDIL
     43     { SIGDIL,	"sigdil",	"dil signal"},
     44 #endif
     45 #ifdef SIGEMT
     46     { SIGEMT,	"sigemt",	"emt instruction"},
     47 #endif
     48 #ifdef SIGFPE
     49     { SIGFPE,	"sigfpe",	"floating point error"},
     50 #endif
     51 #ifdef SIGFREEZE
     52     { SIGFREEZE,	"sigfreeze",	"cpr freeze"},
     53 #endif
     54 #ifdef SIGHUP
     55     { SIGHUP,	"sighup",	"hangup"},
     56 #endif
     57 #ifdef SIGILL
     58     { SIGILL,	"sigill",	"illegal instruction"},
     59 #endif
     60 #ifdef SIGINT
     61     { SIGINT,	"sigint",	"interrupt"},
     62 #endif
     63 #ifdef SIGIO
     64     { SIGIO,	"sigio",	"socket i/o possible"},
     65 #endif
     66 #ifdef SIGIOT
     67     { SIGIOT,	"sigiot",	"iot instruction"},
     68 #endif
     69 #ifdef SIGKILL
     70     { SIGKILL,	"sigkill",	"killed"},
     71 #endif
     72 #ifdef SIGLOST
     73     { SIGLOST,	"siglost",	"resource lost"},
     74 #endif
     75 #ifdef SIGLWP
     76     { SIGLWP,	"siglwp",	"thread library signal"},
     77 #endif
     78 #ifdef SIGPIPE
     79     { SIGPIPE,	"sigpipe",	"broken pipe"},
     80 #endif
     81 #ifdef SIGPOLL
     82     { SIGPOLL,	"sigpoll",	"pollable event occurred"},
     83 #endif
     84 #ifdef SIGPROF
     85     { SIGPROF,	"sigprof",	"profiling timer alarm"},
     86 #endif
     87 #ifdef SIGPWR
     88     { SIGPWR,	"sigpwr",	"power-fail restart"},
     89 #endif
     90 #ifdef SIGQUIT
     91     { SIGQUIT,	"sigquit",	"quit"},
     92 #endif
     93 #ifdef SIGSEGV
     94     { SIGSEGV,	"sigsegv",	"segmentation violation"},
     95 #endif
     96 #ifdef SIGSTKFLT
     97     { SIGSTKFLT,	"sigstkflt",	"stack fault"},
     98 #endif
     99 #ifdef SIGSTOP
    100     { SIGSTOP,	"sigstop",	"stopped by program"},
    101 #endif
    102 #ifdef SIGSYS
    103     { SIGSYS,	"sigsys",	"invalid argument to system call"},
    104 #endif
    105 #ifdef SIGTERM
    106     { SIGTERM,	"sigterm",	"terminated"},
    107 #endif
    108 #ifdef SIGTHAW
    109     { SIGTHAW,	"sigthaw",	"cpr thaw"},
    110 #endif
    111 #ifdef SIGTRAP
    112     { SIGTRAP,	"sigtrap",	"trace trap"},
    113 #endif
    114 #ifdef SIGTSTP
    115     { SIGTSTP,	"sigtstp",	"stopped"},
    116 #endif
    117 #ifdef SIGTTIN
    118     { SIGTTIN,	"sigttin",	"background tty read"},
    119 #endif
    120 #ifdef SIGTTOU
    121     { SIGTTOU,	"sigttou",	"background tty write"},
    122 #endif
    123 #ifdef SIGURG
    124     { SIGURG,	"sigurg",	"urgent condition on i/o channel"},
    125 #endif
    126 #ifdef SIGUSR1
    127     { SIGUSR1,	"sigusr1",	"user defined signal 1"},
    128 #endif
    129 #ifdef SIGUSR2
    130     { SIGUSR2,	"sigusr2",	"user defined signal 2"},
    131 #endif
    132 #ifdef SIGVTALRM
    133     { SIGVTALRM,	"sigvtalrm",	"virtual timer alarm"},
    134 #endif
    135 #ifdef SIGWAITING
    136     { SIGWAITING,	"sigwaiting",	"lwps blocked"},
    137 #endif
    138 #ifdef SIGWINCH
    139     { SIGWINCH,	"sigwinch",	"window size change"},
    140 #endif
    141 #ifdef SIGWINDOW
    142     { SIGWINDOW,	"sigwindow",	"window size change"},
    143 #endif
    144 #ifdef SIGXCPU
    145     { SIGXCPU,	"sigxcpu",	"exceeded cpu time limit"},
    146 #endif
    147 #ifdef SIGXFSZ
    148     { SIGXFSZ,	"sigxfsz",	"exceeded file size limit"},
    149 #endif
    150 #ifdef SIGSAK
    151     { SIGSAK,	"sigsak",	"secure attention key"},
    152 #endif
    153 #ifdef SIGSOUND
    154     { SIGSOUND,	"sigsound",	"hft sound sequence completed"},
    155 #endif
    156 #ifdef SIGRETRACT
    157     { SIGRETRACT,	"sigretract",	"hft monitor mode retracted"},
    158 #endif
    159 #ifdef SIGKAP
    160     { SIGKAP,	"sigkap",	"keep alive poll"},
    161 #endif
    162 #ifdef SIGGRANT
    163     { SIGGRANT,	"siggrant",	"hft monitor mode granted"},
    164 #endif
    165 #ifdef SIGALRM1
    166     { SIGALRM1,	"sigalrm1",	"m:n condition alarm"},
    167 #endif
    168 #ifdef SIGVIRT
    169     { SIGVIRT,	"sigvirt",	"virtual time alarm"},
    170 #endif
    171 #ifdef SIGPRE
    172     { SIGPRE,	"sigpre",	"programming error"},
    173 #endif
    174 #ifdef SIGMIGRATE
    175     { SIGMIGRATE,	"sigmigrate",	"migrate process"},
    176 #endif
    177 #ifdef SIGDANGER
    178     { SIGDANGER,	"sigdanger",	"system crash imminent"},
    179 #endif
    180 #ifdef SIGMSG
    181     { SIGMSG,	"sigmsg",	"hft input data pending"},
    182 #endif
    183 #ifdef SIGINFO
    184     { SIGINFO,	"siginfo",	"information request"},
    185 #endif
    186     { 0, 0, 0}
    187 };
    188 
    189 static void barf(const char *msg) {
    190     fprintf(stderr, "mksignals: %s\n", msg);
    191     exit(1);
    192 }
    193 
    194 int main(void) {
    195     int maxsig = NUMSIG-1;
    196     int s;
    197     struct signaming *snp;
    198     FILE *outf;
    199 
    200     for (snp = signamings; snp->signo; ++snp)
    201 	if (snp->signo > maxsig)
    202 	    maxsig = snp->signo;
    203 
    204     outf = fopen("sigmsgs.h", "w");
    205     if (!outf) barf("could not open sigmsgs.h for writing");
    206     fprintf(outf, "typedef struct {\n");
    207     fprintf(outf, "\tchar *name, *msg;\n");
    208     fprintf(outf, "} Sigmsgs;\n");
    209     fprintf(outf, "extern Sigmsgs signals[];\n");
    210     fprintf(outf, "#define NUMOFSIGNALS %d\n", maxsig+1);
    211     if (fclose(outf) == EOF)  barf("could not fclose sigmsgs.h after writing");
    212 
    213     outf = fopen("sigmsgs.c", "w");
    214     if (!outf) barf("could not open sigmsgs.c for writing");
    215     fprintf(outf, "#include \"sigmsgs.h\"\n\n");
    216     fprintf(outf, "Sigmsgs signals[] = {\n");
    217     fprintf(outf, "\t{\"\",\t\"\"},\n");
    218 
    219     /* yes, we could avoid the quadratic searching with an aux array. fap. */
    220     for (s = 1; s <= maxsig; ++s) {
    221 	for (snp = signamings; snp->signo && snp->signo != s; ++snp)
    222 	    /* */;
    223 	if (snp->signo)
    224 	    fprintf(outf, "\t{\"%s\",\t\"%s\"},\n",
    225 		    snp->signame, snp->sigmsg);
    226 #if defined(SIGRTMIN) && defined(SIGRTMAX)
    227 	else if (s >= SIGRTMIN && s <= SIGRTMAX)
    228 	    fprintf(outf, "\t{\"sigrt%d\",\t\"real-time signal %d\"},\n",
    229 		    s - SIGRTMIN, s - SIGRTMIN);
    230 #endif
    231 	else
    232 	    fprintf(outf, "\t{\"sig%d\",\t\"unknown signal %d\"},\n",
    233 		    s, s);
    234     }
    235     fprintf(outf, "};\n");
    236     if (fclose(outf) == EOF) barf("could not fclose sigmsgs.c after writing");
    237     return 0;
    238 }