From fd7cb6bd3d97e410c12e8cfcc35758b5533f1478 Mon Sep 17 00:00:00 2001 From: Giacomo Tesio Date: Mon, 18 Sep 2017 00:23:10 +0200 Subject: [PATCH] jehanne: introduce sigaction; signal as macro --- newlib/libc/sys/jehanne/Makefile.am | 2 +- newlib/libc/sys/jehanne/Makefile.in | 8 ++++++- newlib/libc/sys/jehanne/include/signal.h | 12 +++++++++- newlib/libc/sys/jehanne/sigaction.c | 28 ++++++++++++++++++++++++ newlib/libc/sys/jehanne/signal.c | 27 +++++++++++++++++++++-- newlib/libc/sys/jehanne/sys/signal.h | 16 +++++++++----- 6 files changed, 82 insertions(+), 11 deletions(-) create mode 100644 newlib/libc/sys/jehanne/sigaction.c diff --git a/newlib/libc/sys/jehanne/Makefile.am b/newlib/libc/sys/jehanne/Makefile.am index e4604edd6..af30c4ce4 100644 --- a/newlib/libc/sys/jehanne/Makefile.am +++ b/newlib/libc/sys/jehanne/Makefile.am @@ -16,7 +16,7 @@ lib_a_SOURCES = getenv_r.c getenv.c malloc.c mallocr.c free.c freer.c \ lib_a_LIBADD = $(extra_objs) EXTRA_lib_a_SOURCES = libposix_conf.c syscalls.c chown.c getrusage.c \ - ids.c chmod.c sigsets.c + ids.c chmod.c sigsets.c sigaction.c lib_a_DEPENDENCIES = $(extra_objs) lib_a_CCASFLAGS = $(AM_CCASFLAGS) lib_a_CFLAGS = $(AM_CFLAGS) diff --git a/newlib/libc/sys/jehanne/Makefile.in b/newlib/libc/sys/jehanne/Makefile.in index 08ee46c3f..3b61a0020 100644 --- a/newlib/libc/sys/jehanne/Makefile.in +++ b/newlib/libc/sys/jehanne/Makefile.in @@ -187,7 +187,7 @@ lib_a_SOURCES = getenv_r.c getenv.c malloc.c mallocr.c free.c freer.c \ lib_a_LIBADD = $(extra_objs) EXTRA_lib_a_SOURCES = libposix_conf.c syscalls.c chown.c getrusage.c \ - ids.c chmod.c sigsets.c + ids.c chmod.c sigsets.c sigaction.c lib_a_DEPENDENCIES = $(extra_objs) lib_a_CCASFLAGS = $(AM_CCASFLAGS) @@ -370,6 +370,12 @@ lib_a-sigsets.o: sigsets.c lib_a-sigsets.obj: sigsets.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sigsets.obj `if test -f 'sigsets.c'; then $(CYGPATH_W) 'sigsets.c'; else $(CYGPATH_W) '$(srcdir)/sigsets.c'; fi` +lib_a-sigaction.o: sigaction.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sigaction.o `test -f 'sigaction.c' || echo '$(srcdir)/'`sigaction.c + +lib_a-sigaction.obj: sigaction.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sigaction.obj `if test -f 'sigaction.c'; then $(CYGPATH_W) 'sigaction.c'; else $(CYGPATH_W) '$(srcdir)/sigaction.c'; fi` + ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ unique=`for i in $$list; do \ diff --git a/newlib/libc/sys/jehanne/include/signal.h b/newlib/libc/sys/jehanne/include/signal.h index 577dbbc0f..66a623f15 100644 --- a/newlib/libc/sys/jehanne/include/signal.h +++ b/newlib/libc/sys/jehanne/include/signal.h @@ -21,7 +21,17 @@ typedef PosixSigHandler sighandler_t; /* glibc naming */ struct _reent; -PosixSigHandler signal(int signo, PosixSigHandler handler); +PosixSigHandler sysv_signal(int signo, PosixSigHandler handler); +PosixSigHandler bsd_signal(int signo, PosixSigHandler handler); + +#define ssignal(signo, handler) bsd_signal(signo, handler) + +#ifdef _XOPEN_SOURCE +# define signal(signo, handler) sysv_signal(signo, handler) +#else +# define signal(signo, handler) bsd_signal(signo, handler) +#endif + int raise(int signo); void psignal(int signo, const char *s); diff --git a/newlib/libc/sys/jehanne/sigaction.c b/newlib/libc/sys/jehanne/sigaction.c new file mode 100644 index 000000000..3c870132e --- /dev/null +++ b/newlib/libc/sys/jehanne/sigaction.c @@ -0,0 +1,28 @@ +/* + * This file is part of Jehanne. + * + * Copyright (C) 2017 Giacomo Tesio + * + * Jehanne is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 of the License. + * + * Jehanne is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jehanne. If not, see . + */ +#include +#include +#include +#include + +int +sigaction(int signo, const struct sigaction *act, struct sigaction *old) +{ + int *errnop = &_REENT->_errno; + return POSIX_sigaction(errnop, signo, act, old); +} diff --git a/newlib/libc/sys/jehanne/signal.c b/newlib/libc/sys/jehanne/signal.c index d024ad9b1..959f843e9 100644 --- a/newlib/libc/sys/jehanne/signal.c +++ b/newlib/libc/sys/jehanne/signal.c @@ -21,8 +21,31 @@ #include PosixSigHandler -signal(int signo, PosixSigHandler handler) +sysv_signal(int signo, PosixSigHandler handler) { + struct sigaction sa, old; int *errnop = &_REENT->_errno; - return POSIX_signal(errnop, signo, handler); + + sa.sa_flags = 0; + sa.sa_handler = handler; + if(POSIX_sigemptyset(errnop, &sa.sa_mask) != 0 + || POSIX_sigaction(errnop, signo, &sa, &old) != 0) + return (PosixSigHandler)-1; + + return old.sa_handler; +} + +PosixSigHandler +bsd_signal(int signo, PosixSigHandler handler) +{ + struct sigaction sa, old; + int *errnop = &_REENT->_errno; + + sa.sa_flags = PosixSAFRestart; + sa.sa_handler = handler; + if(POSIX_sigemptyset(errnop, &sa.sa_mask) != 0 + || POSIX_sigaction(errnop, signo, &sa, &old) != 0) + return (PosixSigHandler)-1; + + return old.sa_handler; } diff --git a/newlib/libc/sys/jehanne/sys/signal.h b/newlib/libc/sys/jehanne/sys/signal.h index a85a38f12..76b7024ea 100644 --- a/newlib/libc/sys/jehanne/sys/signal.h +++ b/newlib/libc/sys/jehanne/sys/signal.h @@ -63,11 +63,15 @@ typedef PosixSignalMask sigset_t; /* 3.3.8 Synchronously Accept a Signal, P1003.1b-1993, p. 76 */ -#define SA_NOCLDSTOP 1 /* Do not generate SIGCHLD when children stop */ -#define SA_SIGINFO 2 /* Invoke the signal catching function with */ - /* three arguments instead of one. */ +#define SA_NOCLDSTOP PosixSAFNoChildrenStop +#define SA_RESETHAND PosixSAFResetHandler +#define SA_RESTART PosixSAFRestart +#define SA_SIGINFO PosixSAFSigInfo +#define SA_NOCLDWAIT PosixSAFNoChildrenWait +#define SA_NODEFER PosixSAFNoDefer + #if __BSD_VISIBLE || __XSI_VISIBLE >= 4 || __POSIX_VISIBLE >= 200809 -#define SA_ONSTACK 4 /* Signal delivery will be on a separate stack. */ +#define SA_ONSTACK PosixSAFOnStack /* Signal delivery will be on a separate stack. */ #endif @@ -86,8 +90,8 @@ typedef PosixSignalMask sigset_t; /* * Possible values for ss_flags in stack_t below. */ -#define SS_ONSTACK 0x1 -#define SS_DISABLE 0x2 +#define SS_ONSTACK PosixSAFOnStack +#define SS_DISABLE PosixSAFDisable #endif