several fixups:

a new typedef for signal handlers - sig_func_t
(the old one is kept around for backwards compatibility)

a new macro MAX_SIGNO to get rid of magic 32's all about

two more functions (sigemptyset and sigfillset) are now
defined inline as well


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1975 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Daniel Reinhold 2002-11-17 04:43:13 +00:00
parent cc4445505e
commit c69a62db20

View File

@ -12,25 +12,28 @@ extern "C" {
#endif #endif
typedef int sig_atomic_t; typedef int sig_atomic_t;
typedef void (*sig_func_t)(int);
typedef void (*__signal_func_ptr)(int); /* old BeOS typedef (kept for backwards compatibility) */
typedef void (*__signal_func_ptr)(int);
__signal_func_ptr signal(int signal, __signal_func_ptr signal_func); sig_func_t signal(int sig, sig_func_t signal_handler);
int raise(int signal); int raise(int sig);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#define SIG_DFL ((__signal_func_ptr) 0)
#define SIG_IGN ((__signal_func_ptr) 1) #define SIG_DFL ((sig_func_t) 0)
#define SIG_ERR ((__signal_func_ptr)-1) #define SIG_IGN ((sig_func_t) 1)
#define SIG_ERR ((sig_func_t)-1)
/* /*
The numbering of signals for BeOS attempts to maintain * The numbering of signals for BeOS attempts to maintain
some consistency with UN*X conventions so that things * some consistency with UN*X conventions so that things
like "kill -9" do what you expect. * like "kill -9" do what you expect.
*/ */
#define SIGHUP 1 /* hangup -- tty is gone! */ #define SIGHUP 1 /* hangup -- tty is gone! */
#define SIGINT 2 /* interrupt */ #define SIGINT 2 /* interrupt */
#define SIGQUIT 3 /* `quit' special character typed in tty */ #define SIGQUIT 3 /* `quit' special character typed in tty */
@ -56,11 +59,14 @@ int raise(int signal);
#define SIGBUS SIGSEGV /* for old style code */ #define SIGBUS SIGSEGV /* for old style code */
/* /*
Signal numbers 23-32 are currently free but may be used in future * Signal numbers 23-32 are currently free but may be used in future
releases. Use them at your own peril (if you do use them, at least * releases. Use them at your own peril (if you do use them, at least
be smart and use them backwards from signal 32). * be smart and use them backwards from signal 32).
*/ */
#define MAX_SIGNO 32
#define __signal_max 22 #define __signal_max 22
#define NSIG (__signal_max+1) #define NSIG (__signal_max+1)
@ -74,7 +80,7 @@ typedef long sigset_t;
(the signal number) is passed to the signal handler. It is useful (the signal number) is passed to the signal handler. It is useful
to have more information and the BeOS provides two extra arguments. to have more information and the BeOS provides two extra arguments.
However, to remain compatible with Posix and ANSI C, we declare the However, to remain compatible with Posix and ANSI C, we declare the
sa_handler field of the sigaction struct as type __signal_func_ptr. sa_handler field of the sigaction struct as type 'sig_func_t'.
That means you'll need to cast any function you assign to the That means you'll need to cast any function you assign to the
sa_handler field. NOTE: C++ member functions can not be signal sa_handler field. NOTE: C++ member functions can not be signal
handlers (because they expect a "this" pointer as the first handlers (because they expect a "this" pointer as the first
@ -99,10 +105,10 @@ typedef long sigset_t;
open some interesting programming possibilities. open some interesting programming possibilities.
*/ */
struct sigaction { struct sigaction {
__signal_func_ptr sa_handler; sig_func_t sa_handler;
sigset_t sa_mask; sigset_t sa_mask;
int sa_flags; int sa_flags;
void *sa_userdata; /* will be passed to the signal handler */ void *sa_userdata; /* will be passed to the signal handler */
}; };
@ -124,41 +130,64 @@ typedef struct stack_t {
extern "C" { extern "C" {
#endif #endif
int sigaction(int sig, const struct sigaction *act, struct sigaction *oact); int sigaction(int sig, const struct sigaction *act, struct sigaction *oact);
int sigemptyset(sigset_t *set); int sigemptyset(sigset_t *set);
int sigfillset(sigset_t *set); int sigfillset(sigset_t *set);
int sigaddset(sigset_t *set, int signo); int sigaddset(sigset_t *set, int signo);
int sigdelset(sigset_t *set, int signo); int sigdelset(sigset_t *set, int signo);
int sigismember(const sigset_t *set, int signo); int sigismember(const sigset_t *set, int signo);
int sigprocmask(int how, const sigset_t *set, sigset_t *oset); int sigprocmask(int how, const sigset_t *set, sigset_t *oset);
extern const char * const sys_siglist[NSIG]; extern const char * const sys_siglist[NSIG];
const char *strsignal(int sig); const char *strsignal(int sig);
const void set_signal_stack(void *ptr, size_t size); const void set_signal_stack(void *ptr, size_t size);
int sigaltstack(const stack_t *ss, stack_t *oss); /* XXXdbg */ int sigaltstack(const stack_t *ss, stack_t *oss); /* XXXdbg */
extern inline int
sigemptyset(sigset_t *set)
{
*set = (sigset_t) 0L;
return 0;
}
extern inline int
sigfillset(sigset_t *set)
{
*set = (sigset_t) ~(0UL);
return 0;
}
extern inline int extern inline int
sigismember(const sigset_t *set, int sig) sigismember(const sigset_t *set, int sig)
{ {
sigset_t mask = (((sigset_t) 1) << (( sig ) - 1)) ; sigset_t mask = (((sigset_t) 1) << (( sig ) - 1)) ;
return (*set & mask) ? 1 : 0 ; return (*set & mask) ? 1 : 0 ;
} }
extern inline int extern inline int
sigaddset(sigset_t *set, int sig) sigaddset(sigset_t *set, int sig)
{ {
sigset_t mask = (((sigset_t) 1) << (( sig ) - 1)) ; sigset_t mask = (((sigset_t) 1) << (( sig ) - 1)) ;
return ((*set |= mask), 0) ; return ((*set |= mask), 0) ;
} }
extern inline int extern inline int
sigdelset(sigset_t *set, int sig) sigdelset(sigset_t *set, int sig)
{ {
sigset_t mask = (((sigset_t) 1) << (( sig ) - 1)) ; sigset_t mask = (((sigset_t) 1) << (( sig ) - 1)) ;
return ((*set &= ~mask), 0) ; return ((*set &= ~mask), 0) ;
} }
#define SIG_BLOCK 1 /* defines for the how arg of sigprocmask() */ #define SIG_BLOCK 1 /* defines for the how arg of sigprocmask() */
#define SIG_UNBLOCK 2 #define SIG_UNBLOCK 2
#define SIG_SETMASK 3 #define SIG_SETMASK 3
int sigpending(sigset_t *set); int sigpending(sigset_t *set);
int sigsuspend(const sigset_t *mask); int sigsuspend(const sigset_t *mask);
@ -169,7 +198,9 @@ int send_signal(pid_t tid, uint sig);
} }
#endif #endif
/* signal handlers get this as the last argument */ /* signal handlers get this as the last argument */
typedef struct vregs vregs; typedef struct vregs vregs;
#if __POWERPC__ #if __POWERPC__