Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/src/runtime/config/unix-signals.c
ViewVC logotype

Annotation of /sml/trunk/src/runtime/config/unix-signals.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1781 - (view) (download) (as text)

1 : monnier 249 /* unix-signals.c
2 :     *
3 :     * COPYRIGHT (c) 1995 by AT&T Bell Laboratories.
4 :     *
5 :     * Compute the signal table information for UNIX systems. This is used to
6 :     * generate the unix-signal-tbl.c file and the system-signals.h file. We
7 :     * assume that the signals SIGHUP, SIGINT, SIGQUIT, SIGALRM, and SIGTERM
8 :     * are (at least) provided.
9 :     */
10 :    
11 :     #include "ml-unixdep.h"
12 :     #include <signal.h>
13 :     #include <stdio.h>
14 : blume 569 #include <stdlib.h>
15 : monnier 249 #include "gen.h"
16 :     #include "gen-unix-signals.h"
17 :    
18 :    
19 :     /** The UNIX signals **/
20 :     sig_desc_t SigTable[] = {
21 :     { SIGHUP, "SIGHUP", "HUP"}, /* POSIX */
22 :     { SIGINT, "SIGINT", "INT"}, /* POSIX */
23 :     { SIGQUIT, "SIGQUIT", "QUIT"}, /* POSIX */
24 :     { SIGALRM, "SIGALRM", "ALRM"}, /* POSIX */
25 :     { SIGTERM, "SIGTERM", "TERM"}, /* POSIX */
26 :     #ifdef SIGPIPE
27 :     { SIGPIPE, "SIGPIPE", "PIPE"}, /* POSIX */
28 :     #endif
29 :     #ifdef SIGUSR1
30 :     { SIGUSR1, "SIGUSR1", "USR1"}, /* POSIX */
31 :     #endif
32 :     #ifdef SIGUSR2
33 :     { SIGUSR2, "SIGUSR2", "USR2"}, /* POSIX */
34 :     #endif
35 :     #if defined(SIGCHLD)
36 :     { SIGCHLD, "SIGCHLD", "CHLD"}, /* POSIX */
37 :     #elif defined(SIGCLD)
38 :     { SIGCLD, "SIGCLD", "CHLD"},
39 :     #endif
40 :     #if defined(SIGWINCH)
41 :     { SIGWINCH, "SIGWINCH", "WINCH"},
42 :     #elif defined(SIGWINDOW)
43 :     { SIGWINDOW, "SIGWINDOW", "WINCH"},
44 :     #endif
45 :     #ifdef SIGURG
46 :     { SIGURG, "SIGURG", "URG"},
47 :     #endif
48 :     #ifdef SIGIO
49 :     { SIGIO, "SIGIO", "IO"},
50 :     #endif
51 :     #ifdef SIGPOLL
52 :     { SIGPOLL, "SIGPOLL", "POLL"},
53 :     #endif
54 :     #ifdef SIGTSTP
55 :     { SIGTSTP, "SIGTSTP", "TSTP"}, /* POSIX */
56 :     #endif
57 :     #ifdef SIGCONT
58 :     { SIGCONT, "SIGCONT", "CONT"}, /* POSIX */
59 :     #endif
60 :     #ifdef SIGTTIN
61 :     { SIGTTIN, "SIGTTIN", "TTIN"}, /* POSIX */
62 :     #endif
63 :     #ifdef SIGTTOU
64 :     { SIGTTOU, "SIGTTOU", "TTOU"}, /* POSIX */
65 :     #endif
66 :     #ifdef SIGVTALRM
67 :     { SIGVTALRM, "SIGVTALRM", "VTALRM"},
68 :     #endif
69 :     };
70 :     #define TABLE_SIZE (sizeof(SigTable)/sizeof(sig_desc_t))
71 :    
72 :     /* the run-time system generated signals */
73 : jhr 1781 sig_desc_t RunTSignals[] = {
74 :     { -1, "RUNSIG_GC", "GC" },
75 : monnier 249 };
76 : jhr 1781 #define NUM_RUN_SIGS (sizeof(RunTSignals)/sizeof(sig_desc_t))
77 : monnier 249
78 :     /* SortSignalTbl:
79 :     */
80 :     sig_info_t *SortSignalTbl ()
81 :     {
82 :     int i, j, k, n;
83 :     sig_desc_t **signals;
84 :     sig_info_t *sigInfo;
85 :    
86 : jhr 1781 signals = NEW_VEC(sig_desc_t *, TABLE_SIZE + NUM_RUN_SIGS);
87 : monnier 249
88 :     /* sort the signal table by increaseing signal number; the sort removes
89 :     * duplicates by mapping to the first name. We need this because some
90 :     * systems alias signals.
91 :     */
92 :     for (i = 0, n = 0; i < TABLE_SIZE; i++) {
93 :     /* invariant: signals[0..n-1] is sorted */
94 :     sig_desc_t *p = &(SigTable[i]);
95 :     for (j = 0; j < n; j++) {
96 :     if (signals[j]->sig == p->sig)
97 :     /* a duplicate */
98 :     break;
99 :     if (signals[j]->sig > p->sig) {
100 :     /* insert the signal at position j */
101 :     for (k = n; k >= j; k--)
102 :     signals[k] = signals[k-1];
103 :     signals[j] = p; n++;
104 :     break;
105 :     }
106 :     }
107 :     if (j == n) {
108 :     signals[n++] = p;
109 :     }
110 :     }
111 :     /* Here, n is the number of system signals and signals[n-1]->sig is the
112 :     * largest system signal code.
113 :     */
114 :    
115 :     /* add the run-time system signals to the table */
116 :     for (i = 0, j = n; i < NUM_RUN_SIGS; i++, j++) {
117 : jhr 1781 signals[j] = &(RunTSignals[i]);
118 :     signals[j]->sig = signals[n-1]->sig+i+1;
119 : monnier 249 }
120 :    
121 : jhr 1781
122 : monnier 249 sigInfo = NEW_OBJ(sig_info_t);
123 :     sigInfo->sigs = signals;
124 :     sigInfo->numSysSigs = n;
125 :     sigInfo->numRunSigs = NUM_RUN_SIGS;
126 : jhr 1781 sigInfo->minSysSig = signals[0]->sig;
127 : monnier 249 sigInfo->maxSysSig = signals[n-1]->sig;
128 :    
129 :     return sigInfo;
130 :    
131 :     } /* end of SortSignalTbl */
132 :    

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0