/*
|
/*
|
FUNCTION
|
FUNCTION
|
<<signal>>---specify handler subroutine for a signal
|
<<signal>>---specify handler subroutine for a signal
|
|
|
INDEX
|
INDEX
|
signal
|
signal
|
INDEX
|
INDEX
|
_signal_r
|
_signal_r
|
INDEX
|
INDEX
|
raise
|
raise
|
INDEX
|
INDEX
|
_raise_r
|
_raise_r
|
|
|
ANSI_SYNOPSIS
|
ANSI_SYNOPSIS
|
#include <signal.h>
|
#include <signal.h>
|
void ( * signal(int <[sig]>, void(*<[func]>)(int)) )(int);
|
void ( * signal(int <[sig]>, void(*<[func]>)(int)) )(int);
|
|
|
void ( * _signal_r(void *<[reent]>,
|
void ( * _signal_r(void *<[reent]>,
|
int <[sig]>, void(*<[func]>)(int)) )(int);
|
int <[sig]>, void(*<[func]>)(int)) )(int);
|
|
|
int raise (int <[sig]>);
|
int raise (int <[sig]>);
|
|
|
int _raise_r (void *<[reent]>, int <[sig]>);
|
int _raise_r (void *<[reent]>, int <[sig]>);
|
|
|
TRAD_SYNOPSIS
|
TRAD_SYNOPSIS
|
#include <signal.h>
|
#include <signal.h>
|
char ( * signal(<[sig]>, <[func]>) )()
|
char ( * signal(<[sig]>, <[func]>) )()
|
int <[sig]>;
|
int <[sig]>;
|
char ( * <[func]> )();
|
char ( * <[func]> )();
|
|
|
char ( * _signal_r(<[reent]>, <[sig]>, <[func]>) )()
|
char ( * _signal_r(<[reent]>, <[sig]>, <[func]>) )()
|
char *<[reent]>;
|
char *<[reent]>;
|
int <[sig]>;
|
int <[sig]>;
|
char ( * <[func]> )();
|
char ( * <[func]> )();
|
|
|
int raise (<[sig]>)()
|
int raise (<[sig]>)()
|
int <[sig]>;
|
int <[sig]>;
|
|
|
int _raise_r (<[reent]>, <[sig]>)()
|
int _raise_r (<[reent]>, <[sig]>)()
|
char *<[reent]>;
|
char *<[reent]>;
|
int <[sig]>;
|
int <[sig]>;
|
|
|
DESCRIPTION
|
DESCRIPTION
|
<<signal, raise>> provide a simple signal/raise implementation for embedded
|
<<signal, raise>> provide a simple signal/raise implementation for embedded
|
targets.
|
targets.
|
|
|
<<signal>> allows you to request changed treatment for a particular
|
<<signal>> allows you to request changed treatment for a particular
|
signal <[sig]>. You can use one of the predefined macros <<SIG_DFL>>
|
signal <[sig]>. You can use one of the predefined macros <<SIG_DFL>>
|
(select system default handling) or <<SIG_IGN>> (ignore this signal)
|
(select system default handling) or <<SIG_IGN>> (ignore this signal)
|
as the value of <[func]>; otherwise, <[func]> is a function pointer
|
as the value of <[func]>; otherwise, <[func]> is a function pointer
|
that identifies a subroutine in your program as the handler for this signal.
|
that identifies a subroutine in your program as the handler for this signal.
|
|
|
Some of the execution environment for signal handlers is
|
Some of the execution environment for signal handlers is
|
unpredictable; notably, the only library function required to work
|
unpredictable; notably, the only library function required to work
|
correctly from within a signal handler is @code{signal} itself, and
|
correctly from within a signal handler is @code{signal} itself, and
|
only when used to redefine the handler for the current signal value.
|
only when used to redefine the handler for the current signal value.
|
|
|
Static storage is likewise unreliable for signal handlers, with one
|
Static storage is likewise unreliable for signal handlers, with one
|
exception: if you declare a static storage location as `<<volatile
|
exception: if you declare a static storage location as `<<volatile
|
sig_atomic_t>>', then you may use that location in a signal handler to
|
sig_atomic_t>>', then you may use that location in a signal handler to
|
store signal values.
|
store signal values.
|
|
|
If your signal handler terminates using <<return>> (or implicit
|
If your signal handler terminates using <<return>> (or implicit
|
return), your program's execution continues at the point
|
return), your program's execution continues at the point
|
where it was when the signal was raised (whether by your program
|
where it was when the signal was raised (whether by your program
|
itself, or by an external event). Signal handlers can also
|
itself, or by an external event). Signal handlers can also
|
use functions such as <<exit>> and <<abort>> to avoid returning.
|
use functions such as <<exit>> and <<abort>> to avoid returning.
|
|
|
<<raise>> sends the signal sig to the executing program. It returns zero if
|
<<raise>> sends the signal sig to the executing program. It returns zero if
|
successful, non-zero if unsuccessful.
|
successful, non-zero if unsuccessful.
|
|
|
The alternate functions <<_signal_r, _raise_r>> are the reentrant versions.
|
The alternate functions <<_signal_r, _raise_r>> are the reentrant versions.
|
The extra argument <[reent]> is a pointer to a reentrancy structure.
|
The extra argument <[reent]> is a pointer to a reentrancy structure.
|
|
|
|
|
@c FIXME: do we have setjmp.h and assoc fns?
|
@c FIXME: do we have setjmp.h and assoc fns?
|
|
|
RETURNS
|
RETURNS
|
If your request for a signal handler cannot be honored, the result is
|
If your request for a signal handler cannot be honored, the result is
|
<<SIG_ERR>>; a specific error number is also recorded in <<errno>>.
|
<<SIG_ERR>>; a specific error number is also recorded in <<errno>>.
|
|
|
Otherwise, the result is the previous handler (a function pointer or
|
Otherwise, the result is the previous handler (a function pointer or
|
one of the predefined macros).
|
one of the predefined macros).
|
|
|
PORTABILITY
|
PORTABILITY
|
ANSI C requires <<raise>>, <<signal>>.
|
ANSI C requires <<raise>>, <<signal>>.
|
|
|
No supporting OS subroutines are required to link with <<signal>>, but
|
No supporting OS subroutines are required to link with <<signal>>, but
|
it will not have any useful effects, except for software generated signals,
|
it will not have any useful effects, except for software generated signals,
|
without an operating system that can actually raise exceptions.
|
without an operating system that can actually raise exceptions.
|
*/
|
*/
|
|
|
/*
|
/*
|
* signal.c
|
* signal.c
|
* Original Author: G. Haley
|
* Original Author: G. Haley
|
*
|
*
|
* signal associates the function pointed to by func with the signal sig. When
|
* signal associates the function pointed to by func with the signal sig. When
|
* a signal occurs, the value of func determines the action taken as follows:
|
* a signal occurs, the value of func determines the action taken as follows:
|
* if func is SIG_DFL, the default handling for that signal will occur; if func
|
* if func is SIG_DFL, the default handling for that signal will occur; if func
|
* is SIG_IGN, the signal will be ignored; otherwise, the default handling for
|
* is SIG_IGN, the signal will be ignored; otherwise, the default handling for
|
* the signal is restored (SIG_DFL), and the function func is called with sig
|
* the signal is restored (SIG_DFL), and the function func is called with sig
|
* as its argument. Returns the value of func for the previous call to signal
|
* as its argument. Returns the value of func for the previous call to signal
|
* for the signal sig, or SIG_ERR if the request fails.
|
* for the signal sig, or SIG_ERR if the request fails.
|
*/
|
*/
|
|
|
/* _init_signal initialises the signal handlers for each signal. This function
|
/* _init_signal initialises the signal handlers for each signal. This function
|
is called by crt0 at program startup. */
|
is called by crt0 at program startup. */
|
|
|
#ifdef SIGNAL_PROVIDED
|
#ifdef SIGNAL_PROVIDED
|
|
|
int _dummy_simulated_signal;
|
int _dummy_simulated_signal;
|
|
|
#else
|
#else
|
|
|
#include <errno.h>
|
#include <errno.h>
|
#include <signal.h>
|
#include <signal.h>
|
#include <stddef.h>
|
#include <stddef.h>
|
#include <stdlib.h>
|
#include <stdlib.h>
|
#include <reent.h>
|
#include <reent.h>
|
#include <_syslist.h>
|
#include <_syslist.h>
|
|
|
int
|
int
|
_DEFUN (_init_signal_r, (ptr),
|
_DEFUN (_init_signal_r, (ptr),
|
struct _reent *ptr)
|
struct _reent *ptr)
|
{
|
{
|
int i;
|
int i;
|
|
|
if (ptr->_sig_func == NULL)
|
if (ptr->_sig_func == NULL)
|
{
|
{
|
ptr->_sig_func = (_sig_func_ptr *)_malloc_r (ptr, sizeof (_sig_func_ptr) * NSIG);
|
ptr->_sig_func = (_sig_func_ptr *)_malloc_r (ptr, sizeof (_sig_func_ptr) * NSIG);
|
if (ptr->_sig_func == NULL)
|
if (ptr->_sig_func == NULL)
|
return -1;
|
return -1;
|
|
|
for (i = 0; i < NSIG; i++)
|
for (i = 0; i < NSIG; i++)
|
ptr->_sig_func[i] = SIG_DFL;
|
ptr->_sig_func[i] = SIG_DFL;
|
}
|
}
|
|
|
return 0;
|
return 0;
|
}
|
}
|
|
|
_sig_func_ptr
|
_sig_func_ptr
|
_DEFUN (_signal_r, (ptr, sig, func),
|
_DEFUN (_signal_r, (ptr, sig, func),
|
struct _reent *ptr _AND
|
struct _reent *ptr _AND
|
int sig _AND
|
int sig _AND
|
_sig_func_ptr func)
|
_sig_func_ptr func)
|
{
|
{
|
_sig_func_ptr old_func;
|
_sig_func_ptr old_func;
|
|
|
if (sig < 0 || sig >= NSIG)
|
if (sig < 0 || sig >= NSIG)
|
{
|
{
|
ptr->_errno = EINVAL;
|
ptr->_errno = EINVAL;
|
return SIG_ERR;
|
return SIG_ERR;
|
}
|
}
|
|
|
if (ptr->_sig_func == NULL && _init_signal_r (ptr) != 0)
|
if (ptr->_sig_func == NULL && _init_signal_r (ptr) != 0)
|
return SIG_ERR;
|
return SIG_ERR;
|
|
|
old_func = ptr->_sig_func[sig];
|
old_func = ptr->_sig_func[sig];
|
ptr->_sig_func[sig] = func;
|
ptr->_sig_func[sig] = func;
|
|
|
return old_func;
|
return old_func;
|
}
|
}
|
|
|
int
|
int
|
_raise_r (ptr, sig)
|
_raise_r (ptr, sig)
|
struct _reent *ptr;
|
struct _reent *ptr;
|
int sig;
|
int sig;
|
{
|
{
|
_sig_func_ptr func;
|
_sig_func_ptr func;
|
|
|
if (sig < 0 || sig >= NSIG)
|
if (sig < 0 || sig >= NSIG)
|
{
|
{
|
ptr->_errno = EINVAL;
|
ptr->_errno = EINVAL;
|
return -1;
|
return -1;
|
}
|
}
|
|
|
if (ptr->_sig_func == NULL && _init_signal_r (ptr) != 0)
|
if (ptr->_sig_func == NULL && _init_signal_r (ptr) != 0)
|
return -1;
|
return -1;
|
|
|
func = ptr->_sig_func[sig];
|
func = ptr->_sig_func[sig];
|
if (func == SIG_DFL)
|
if (func == SIG_DFL)
|
return _kill_r (ptr, _getpid_r (ptr), sig);
|
return _kill_r (ptr, _getpid_r (ptr), sig);
|
else if (func == SIG_IGN)
|
else if (func == SIG_IGN)
|
return 0;
|
return 0;
|
else if (func == SIG_ERR)
|
else if (func == SIG_ERR)
|
{
|
{
|
ptr->_errno = EINVAL;
|
ptr->_errno = EINVAL;
|
return 1;
|
return 1;
|
}
|
}
|
else
|
else
|
{
|
{
|
ptr->_sig_func[sig] = SIG_DFL;
|
ptr->_sig_func[sig] = SIG_DFL;
|
func (sig);
|
func (sig);
|
return 0;
|
return 0;
|
}
|
}
|
}
|
}
|
|
|
int
|
int
|
__sigtramp_r (ptr, sig)
|
__sigtramp_r (ptr, sig)
|
struct _reent *ptr;
|
struct _reent *ptr;
|
int sig;
|
int sig;
|
{
|
{
|
_sig_func_ptr func;
|
_sig_func_ptr func;
|
|
|
if (sig < 0 || sig >= NSIG)
|
if (sig < 0 || sig >= NSIG)
|
{
|
{
|
return -1;
|
return -1;
|
}
|
}
|
|
|
if (ptr->_sig_func == NULL && _init_signal_r (ptr) != 0)
|
if (ptr->_sig_func == NULL && _init_signal_r (ptr) != 0)
|
return -1;
|
return -1;
|
|
|
func = ptr->_sig_func[sig];
|
func = ptr->_sig_func[sig];
|
if (func == SIG_DFL)
|
if (func == SIG_DFL)
|
return 1;
|
return 1;
|
else if (func == SIG_ERR)
|
else if (func == SIG_ERR)
|
return 2;
|
return 2;
|
else if (func == SIG_IGN)
|
else if (func == SIG_IGN)
|
return 3;
|
return 3;
|
else
|
else
|
{
|
{
|
ptr->_sig_func[sig] = SIG_DFL;
|
ptr->_sig_func[sig] = SIG_DFL;
|
func (sig);
|
func (sig);
|
return 0;
|
return 0;
|
}
|
}
|
}
|
}
|
|
|
#ifndef _REENT_ONLY
|
#ifndef _REENT_ONLY
|
|
|
int
|
int
|
raise (sig)
|
raise (sig)
|
int sig;
|
int sig;
|
{
|
{
|
return _raise_r (_REENT, sig);
|
return _raise_r (_REENT, sig);
|
}
|
}
|
|
|
_sig_func_ptr
|
_sig_func_ptr
|
_DEFUN (signal, (sig, func),
|
_DEFUN (signal, (sig, func),
|
int sig _AND
|
int sig _AND
|
_sig_func_ptr func)
|
_sig_func_ptr func)
|
{
|
{
|
return _signal_r (_REENT, sig, func);
|
return _signal_r (_REENT, sig, func);
|
}
|
}
|
|
|
int
|
int
|
_init_signal ()
|
_init_signal ()
|
{
|
{
|
return _init_signal_r (_REENT);
|
return _init_signal_r (_REENT);
|
}
|
}
|
|
|
int
|
int
|
__sigtramp (int sig)
|
__sigtramp (int sig)
|
{
|
{
|
return __sigtramp_r (_REENT, sig);
|
return __sigtramp_r (_REENT, sig);
|
}
|
}
|
|
|
#endif
|
#endif
|
|
|
#endif /* !SIGNAL_PROVIDED */
|
#endif /* !SIGNAL_PROVIDED */
|
|
|