1 /* 2 * Copyright 2002-2011, Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT license. 4 * 5 * Author: 6 * Daniel Reinhold, danielre@users.sf.net 7 * Ingo Weinhold, ingo_weinhold@gmx.de 8 */ 9 10 11 #include <signal.h> 12 13 #include <errno.h> 14 #include <stdio.h> 15 16 #include <symbol_versioning.h> 17 18 #include <errno_private.h> 19 #include <signal_private.h> 20 21 22 static __sighandler_t 23 signal_common(int signal, __sighandler_t signalHandler, int flags) 24 { 25 struct sigaction newAction, oldAction; 26 27 // setup the replacement sigaction 28 newAction.sa_handler = signalHandler; 29 newAction.sa_mask = 0; 30 newAction.sa_flags = flags; 31 32 if (__sigaction(signal, &newAction, &oldAction) != 0) 33 return SIG_ERR; 34 35 // success, return the original handler 36 return oldAction.sa_handler; 37 } 38 39 40 __sighandler_t 41 __signal_beos(int signal, __sighandler_t signalHandler) 42 { 43 // check signal range 44 if (signal < 0 || signal > MAX_SIGNAL_NUMBER_BEOS) { 45 __set_errno(EINVAL); 46 return SIG_ERR; 47 } 48 49 // set the signal handler 50 __sighandler_t result = signal_common(signal, signalHandler, 51 SA_BEOS_COMPATIBLE_HANDLER); 52 if (result == SIG_ERR) 53 return SIG_ERR; 54 55 // If the signal is SIGSEGV, set the same signal handler for SIGBUS. Those 56 // constants had the same value under BeOS. 57 if (signal == SIGSEGV) 58 signal_common(SIGBUS, signalHandler, SA_BEOS_COMPATIBLE_HANDLER); 59 60 return result; 61 } 62 63 64 __sighandler_t 65 __signal(int signal, __sighandler_t signalHandler) 66 { 67 return signal_common(signal, signalHandler, 0); 68 } 69 70 71 DEFINE_LIBROOT_KERNEL_SYMBOL_VERSION("__signal_beos", "signal@", "BASE"); 72 73 DEFINE_LIBROOT_KERNEL_SYMBOL_VERSION("__signal", "signal@@", "1_ALPHA4"); 74