Relicense Sortix to the ISC license.
I hereby relicense all my work on Sortix under the ISC license as below.
All Sortix contributions by other people are already under this license,
are not substantial enough to be copyrightable, or have been removed.
All imported code from other projects is compatible with this license.
All GPL licensed code from other projects had previously been removed.
Copyright 2011-2016 Jonas 'Sortie' Termansen and contributors.
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2016-03-02 17:38:16 -05:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2013, 2014 Jonas 'Sortie' Termansen.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
* signal/signal.c
|
|
|
|
* Configure and retrieve a signal handler.
|
|
|
|
*/
|
2011-09-15 16:38:40 -04:00
|
|
|
|
|
|
|
#include <signal.h>
|
2013-08-04 14:24:59 -04:00
|
|
|
#include <string.h>
|
2011-09-15 16:38:40 -04:00
|
|
|
|
2016-02-28 06:11:02 -05:00
|
|
|
void (*signal(int signum, void (*handler)(int)))(int)
|
2012-09-28 16:50:31 -04:00
|
|
|
{
|
2013-08-04 14:24:59 -04:00
|
|
|
// Create a structure describing the new handler.
|
|
|
|
struct sigaction newact;
|
|
|
|
memset(&newact, 0, sizeof(newact));
|
|
|
|
sigemptyset(&newact.sa_mask);
|
|
|
|
newact.sa_handler = handler;
|
|
|
|
newact.sa_flags = SA_RESTART;
|
|
|
|
|
|
|
|
// Register the new handler and atomically get the old.
|
|
|
|
struct sigaction oldact;
|
|
|
|
if ( sigaction(signum, &newact, &oldact) != 0 )
|
|
|
|
return SIG_ERR;
|
|
|
|
|
|
|
|
// We can't return the old handler properly if it's SA_SIGINFO or SA_COOKIE,
|
|
|
|
// unless it's the common SIG_IGN or SIG_DFL handlers. Let's just say to the
|
|
|
|
// caller that it's SIG_DFL and assume that they'll be using sigaction
|
|
|
|
// instead if they wish to restore an old handler.
|
|
|
|
if ( (oldact.sa_flags & (SA_SIGINFO | SA_COOKIE)) &&
|
|
|
|
oldact.sa_handler != SIG_IGN &&
|
|
|
|
oldact.sa_handler != SIG_DFL )
|
|
|
|
return SIG_DFL;
|
|
|
|
|
|
|
|
return oldact.sa_handler;
|
2011-09-15 16:38:40 -04:00
|
|
|
}
|