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 249 - (view) (download) (as text)
Original Path: sml/branches/SMLNJ/src/runtime/config/unix-signals.c

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

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