src/3rdparty: Add 3rdparty files from Zeek's src/

This commit is contained in:
Benjamin Bannier 2021-11-05 09:45:20 +01:00 committed by Tim Wojtulewicz
parent f0cfaaaa78
commit 982d3b56a1
12 changed files with 3909 additions and 0 deletions

52
src/3rdparty/setsignal.c vendored Normal file
View file

@ -0,0 +1,52 @@
/*
* See the file "COPYING" in the main distribution directory for copyright.
*/
#include "zeek/zeek-config.h" /* must appear before first ifdef */
#include <sys/types.h>
#ifdef HAVE_MEMORY_H
#include <memory.h>
#endif
#include <signal.h>
#ifdef HAVE_SIGACTION
#include <string.h>
#endif
#include "setsignal.h"
/*
* An os independent signal() with BSD semantics, e.g. the signal
* catcher is restored following service of the signal.
*
* When sigset() is available, signal() has SYSV semantics and sigset()
* has BSD semantics and call interface. Unfortunately, Linux does not
* have sigset() so we use the more complicated sigaction() interface
* there.
*
* Did I mention that signals suck?
*/
RETSIGTYPE
(*setsignal (int sig, RETSIGTYPE (*func)(int)))(int)
{
#ifdef HAVE_SIGACTION
struct sigaction old, new;
memset(&new, 0, sizeof(new));
new.sa_handler = func;
#ifdef SA_RESTART
new.sa_flags |= SA_RESTART;
#endif
if (sigaction(sig, &new, &old) < 0)
return (SIG_ERR);
return (old.sa_handler);
#else
#ifdef HAVE_SIGSET
return (sigset(sig, func));
#else
return (signal(sig, func));
#endif
#endif
}