1 /* Copyright (C) 1995,1996 Free Software Foundation, Inc.
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2, or (at your option)
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this software; see the file COPYING. If not, write to
15 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
17 * As a special exception, the Free Software Foundation gives permission
18 * for additional uses of the text contained in its release of GUILE.
20 * The exception is that, if you link the GUILE library with other files
21 * to produce an executable, this does not by itself cause the
22 * resulting executable to be covered by the GNU General Public License.
23 * Your use of that executable is in no way restricted on account of
24 * linking the GUILE library code into it.
26 * This exception does not however invalidate any other reasons why
27 * the executable file might be covered by the GNU General Public License.
29 * This exception applies only to the code released by the
30 * Free Software Foundation under the name GUILE. If you copy
31 * code from other Free Software Foundation releases into a copy of
32 * GUILE, as the General Public License permits, the exception does
33 * not apply to the code that you add in this way. To avoid misleading
34 * anyone as to the status of such modified files, you must delete
35 * this exception notice from them.
37 * If you write modifications of your own for GUILE, it is your choice
38 * whether to permit this exception to apply to your modifications.
39 * If you do not wish that, delete this exception notice.
57 #define signal ssignal /* Needed for TURBOC V1.0 */
60 #ifdef USE_MIT_PTHREADS
62 #define signal pthread_signal
67 /* SIGRETTYPE is the type that signal handlers return. See <signal.h>*/
70 #define SIGRETTYPE RETSIGTYPE
74 #define SIGRETTYPE int
76 #define SIGRETTYPE void
80 #define SIGRETTYPE void
82 #define SIGRETTYPE int
89 #define SIGRETTYPE int
95 #define SIGFN(NAME, SCM_NAME, SIGNAL) \
100 signal (SIGNAL, NAME); \
101 scm_take_signal (SCM_NAME); \
105 SIGFN(scm_hup_signal
, SCM_HUP_SIGNAL
, SIGHUP
)
109 SIGFN(scm_int_signal
, SCM_INT_SIGNAL
, SIGINT
)
113 SIGFN(scm_fpe_signal
, SCM_FPE_SIGNAL
, SIGFPE
)
117 SIGFN(scm_bus_signal
, SCM_BUS_SIGNAL
, SIGBUS
)
121 SIGFN(scm_segv_signal
, SCM_SEGV_SIGNAL
, SIGSEGV
)
125 SIGFN(scm_alrm_signal
, SCM_ALRM_SIGNAL
, SIGALRM
)
128 #define FAKESIGFN(NAME, SCM_NAME) \
133 scm_take_signal (SCM_NAME); \
138 FAKESIGFN(scm_gc_signal
, SCM_GC_SIGNAL
)
139 FAKESIGFN(scm_tick_signal
, SCM_TICK_SIGNAL
)
143 SCM_PROC(s_alarm
, "alarm", 1, 0, 0, scm_alarm
);
150 SCM_ASSERT (SCM_INUMP (i
) && (SCM_INUM (i
) >= 0), i
, SCM_ARG1
, s_alarm
);
151 SCM_SYSCALL (j
= alarm (SCM_INUM (i
)));
152 return SCM_MAKINUM (j
);
156 SCM_PROC(s_pause
, "pause", 0, 0, 0, scm_pause
);
162 return SCM_UNSPECIFIED
;
165 SCM_PROC(s_sleep
, "sleep", 1, 0, 0, scm_sleep
);
172 SCM_ASSERT (SCM_INUMP (i
) && (SCM_INUM (i
) >= 0), i
, SCM_ARG1
, s_sleep
);
174 SCM_SYSCALL(j
= 0; sleep(SCM_INUM(i
)););
176 SCM_SYSCALL(j
= sleep(SCM_INUM(i
)););
178 return SCM_MAKINUM (j
);
181 SCM_PROC(s_raise
, "raise", 1, 0, 0, scm_raise
);
187 SCM_ASSERT(SCM_INUMP(sig
), sig
, SCM_ARG1
, s_raise
);
189 return SCM_MAKINUM(gsignal((int)SCM_INUM(sig
)));
191 return kill (getpid(), (int)SCM_INUM(sig
)) ? SCM_BOOL_F
: SCM_BOOL_T
;
197 static SIGRETTYPE (*oldhup
) ();
201 static SIGRETTYPE (*oldint
) ();
205 static SIGRETTYPE (*oldfpe
) ();
209 static SIGRETTYPE (*oldbus
) ();
212 #ifdef SIGSEGV /* AMIGA lacks! */
213 static SIGRETTYPE (*oldsegv
) ();
217 static SIGRETTYPE (*oldalrm
) ();
221 static SIGRETTYPE (*oldpipe
) ();
230 oldint
= signal (SIGINT
, scm_int_signal
);
233 oldhup
= signal (SIGHUP
, scm_hup_signal
);
236 oldfpe
= signal (SIGFPE
, scm_fpe_signal
);
239 oldbus
= signal (SIGBUS
, scm_bus_signal
);
241 #ifdef SIGSEGV /* AMIGA lacks! */
242 oldsegv
= signal (SIGSEGV
, scm_segv_signal
);
245 alarm (0); /* kill any pending ALRM interrupts */
246 oldalrm
= signal (SIGALRM
, scm_alrm_signal
);
249 oldpipe
= signal (SIGPIPE
, SIG_IGN
);
252 siginterrupt (SIGINT
, 1);
253 siginterrupt (SIGALRM
, 1);
254 siginterrupt (SIGHUP
, 1);
255 siginterrupt (SIGPIPE
, 1);
259 /* This is used in preparation for a possible fork(). Ignore all
260 signals before the fork so that child will catch only if it
261 establishes a handler */
264 scm_ignore_signals ()
267 siginterrupt (SIGINT
, 0);
268 siginterrupt (SIGALRM
, 0);
269 siginterrupt (SIGHUP
, 0);
270 siginterrupt (SIGPIPE
, 0);
272 signal (SIGINT
, SIG_IGN
);
274 signal (SIGHUP
, SIG_DFL
);
277 signal (SIGFPE
, SIG_DFL
);
280 signal (SIGBUS
, SIG_DFL
);
282 #ifdef SIGSEGV /* AMIGA lacks! */
283 signal (SIGSEGV
, SIG_DFL
);
285 /* Some documentation claims that ALRMs are cleared accross forks.
286 If this is not always true then the value returned by alarm(0)
287 will have to be saved and scm_unignore_signals() will have to
289 /* This code should be neccessary only if the forked process calls
290 alarm() without establishing a handler:
292 oldalrm = signal(SIGALRM, SIG_DFL);
294 /* These flushes are per warning in man page on fork(). */
301 scm_unignore_signals ()
303 signal (SIGINT
, scm_int_signal
);
305 signal (SIGHUP
, scm_hup_signal
);
308 signal (SIGFPE
, scm_fpe_signal
);
311 signal (SIGBUS
, scm_bus_signal
);
313 #ifdef SIGSEGV /* AMIGA lacks! */
314 signal (SIGSEGV
, scm_segv_signal
);
317 signal (SIGALRM
, scm_alrm_signal
);
320 siginterrupt (SIGINT
, 1);
321 siginterrupt (SIGALRM
, 1);
322 siginterrupt (SIGHUP
, 1);
323 siginterrupt (SIGPIPE
, 1);
327 SCM_PROC (s_restore_signals
, "restore-signals", 0, 0, 0, scm_restore_signals
);
330 scm_restore_signals ()
333 siginterrupt (SIGINT
, 0);
334 siginterrupt (SIGALRM
, 0);
335 siginterrupt (SIGHUP
, 0);
336 siginterrupt (SIGPIPE
, 0);
338 signal (SIGINT
, oldint
);
340 signal (SIGHUP
, oldhup
);
343 signal (SIGFPE
, oldfpe
);
346 signal (SIGBUS
, oldbus
);
348 #ifdef SIGSEGV /* AMIGA lacks! */
349 signal (SIGSEGV
, oldsegv
);
352 signal (SIGPIPE
, oldpipe
);
355 alarm (0); /* kill any pending ALRM interrupts */
356 signal (SIGALRM
, oldalrm
);
358 return SCM_UNSPECIFIED
;