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.
55 #define signal ssignal /* Needed for TURBOC V1.0 */
60 /* SIGRETTYPE is the type that signal handlers return. See <signal.h>*/
63 #define SIGRETTYPE RETSIGTYPE
67 #define SIGRETTYPE int
69 #define SIGRETTYPE void
73 #define SIGRETTYPE void
75 #define SIGRETTYPE int
82 #define SIGRETTYPE int
88 #define SIGFN(NAME, SCM_NAME, SIGNAL) \
93 signal (SIGNAL, NAME); \
94 scm_take_signal (SCM_NAME); \
98 SIGFN(scm_hup_signal
, SCM_HUP_SIGNAL
, SIGHUP
)
102 SIGFN(scm_int_signal
, SCM_INT_SIGNAL
, SIGINT
)
106 SIGFN(scm_fpe_signal
, SCM_FPE_SIGNAL
, SIGFPE
)
110 SIGFN(scm_bus_signal
, SCM_BUS_SIGNAL
, SIGBUS
)
114 SIGFN(scm_segv_signal
, SCM_SEGV_SIGNAL
, SIGSEGV
)
118 SIGFN(scm_alrm_signal
, SCM_ALRM_SIGNAL
, SIGALRM
)
121 #define FAKESIGFN(NAME, SCM_NAME) \
126 scm_take_signal (SCM_NAME); \
131 FAKESIGFN(scm_gc_signal
, SCM_GC_SIGNAL
)
132 FAKESIGFN(scm_tick_signal
, SCM_TICK_SIGNAL
)
136 SCM_PROC(s_alarm
, "alarm", 1, 0, 0, scm_alarm
);
147 SCM_ASSERT (SCM_INUMP (i
) && (SCM_INUM (i
) >= 0), i
, SCM_ARG1
, s_alarm
);
148 SCM_SYSCALL (j
= alarm (SCM_INUM (i
)));
149 return SCM_MAKINUM (j
);
153 SCM_PROC(s_pause
, "pause", 0, 0, 0, scm_pause
);
163 return SCM_UNSPECIFIED
;
166 SCM_PROC(s_sleep
, "sleep", 1, 0, 0, scm_sleep
);
177 SCM_ASSERT (SCM_INUMP (i
) && (SCM_INUM (i
) >= 0), i
, SCM_ARG1
, s_sleep
);
179 SCM_SYSCALL(j
= 0; sleep(SCM_INUM(i
)););
181 SCM_SYSCALL(j
= sleep(SCM_INUM(i
)););
183 return SCM_MAKINUM (j
);
186 SCM_PROC(s_raise
, "raise", 1, 0, 0, scm_raise
);
196 SCM_ASSERT(SCM_INUMP(sig
), sig
, SCM_ARG1
, s_raise
);
198 return SCM_MAKINUM(gsignal((int)SCM_INUM(sig
)));
200 return kill (getpid(), (int)SCM_INUM(sig
)) ? SCM_BOOL_F
: SCM_BOOL_T
;
206 static SIGRETTYPE (*oldhup
) ();
210 static SIGRETTYPE (*oldint
) ();
214 static SIGRETTYPE (*oldfpe
) ();
218 static SIGRETTYPE (*oldbus
) ();
221 #ifdef SIGSEGV /* AMIGA lacks! */
222 static SIGRETTYPE (*oldsegv
) ();
226 static SIGRETTYPE (*oldalrm
) ();
230 static SIGRETTYPE (*oldpipe
) ();
236 scm_init_signals (void)
243 oldint
= signal (SIGINT
, scm_int_signal
);
246 oldhup
= signal (SIGHUP
, scm_hup_signal
);
249 oldfpe
= signal (SIGFPE
, scm_fpe_signal
);
252 oldbus
= signal (SIGBUS
, scm_bus_signal
);
254 #ifdef SIGSEGV /* AMIGA lacks! */
255 oldsegv
= signal (SIGSEGV
, scm_segv_signal
);
258 alarm (0); /* kill any pending ALRM interrupts */
259 oldalrm
= signal (SIGALRM
, scm_alrm_signal
);
262 oldpipe
= signal (SIGPIPE
, SIG_IGN
);
265 siginterrupt (SIGINT
, 1);
266 siginterrupt (SIGALRM
, 1);
267 siginterrupt (SIGHUP
, 1);
268 siginterrupt (SIGPIPE
, 1);
272 /* This is used in preparation for a possible fork(). Ignore all
273 signals before the fork so that child will catch only if it
274 establishes a handler */
277 scm_ignore_signals (void)
280 scm_ignore_signals ()
284 siginterrupt (SIGINT
, 0);
285 siginterrupt (SIGALRM
, 0);
286 siginterrupt (SIGHUP
, 0);
287 siginterrupt (SIGPIPE
, 0);
289 signal (SIGINT
, SIG_IGN
);
291 signal (SIGHUP
, SIG_DFL
);
294 signal (SIGFPE
, SIG_DFL
);
297 signal (SIGBUS
, SIG_DFL
);
299 #ifdef SIGSEGV /* AMIGA lacks! */
300 signal (SIGSEGV
, SIG_DFL
);
302 /* Some documentation claims that ALRMs are cleared accross forks.
303 If this is not always true then the value returned by alarm(0)
304 will have to be saved and scm_unignore_signals() will have to
306 /* This code should be neccessary only if the forked process calls
307 alarm() without establishing a handler:
309 oldalrm = signal(SIGALRM, SIG_DFL);
311 /* These flushes are per warning in man page on fork(). */
318 scm_unignore_signals (void)
321 scm_unignore_signals ()
324 signal (SIGINT
, scm_int_signal
);
326 signal (SIGHUP
, scm_hup_signal
);
329 signal (SIGFPE
, scm_fpe_signal
);
332 signal (SIGBUS
, scm_bus_signal
);
334 #ifdef SIGSEGV /* AMIGA lacks! */
335 signal (SIGSEGV
, scm_segv_signal
);
338 signal (SIGALRM
, scm_alrm_signal
);
341 siginterrupt (SIGINT
, 1);
342 siginterrupt (SIGALRM
, 1);
343 siginterrupt (SIGHUP
, 1);
344 siginterrupt (SIGPIPE
, 1);
348 SCM_PROC (s_restore_signals
, "restore-signals", 0, 0, 0, scm_restore_signals
);
351 scm_restore_signals (void)
354 scm_restore_signals ()
358 siginterrupt (SIGINT
, 0);
359 siginterrupt (SIGALRM
, 0);
360 siginterrupt (SIGHUP
, 0);
361 siginterrupt (SIGPIPE
, 0);
363 signal (SIGINT
, oldint
);
365 signal (SIGHUP
, oldhup
);
368 signal (SIGFPE
, oldfpe
);
371 signal (SIGBUS
, oldbus
);
373 #ifdef SIGSEGV /* AMIGA lacks! */
374 signal (SIGSEGV
, oldsegv
);
377 signal (SIGPIPE
, oldpipe
);
380 alarm (0); /* kill any pending ALRM interrupts */
381 signal (SIGALRM
, oldalrm
);
383 return SCM_UNSPECIFIED
;
389 scm_init_scmsigs (void)