1
0
Fork 0
mirror of https://repo.or.cz/socat.git synced 2025-07-08 13:36:32 +00:00

Made code async-signal-safe

This commit is contained in:
Gerhard Rieger 2015-01-12 21:46:16 +01:00
parent e4c6f3d934
commit 2af0495cc6
25 changed files with 1707 additions and 625 deletions

View file

@ -1,5 +1,5 @@
/* source: xiosignal.c */
/* Copyright Gerhard Rieger 2001-2003 */
/* Copyright Gerhard Rieger */
/* Published under the GNU General Public License V.2, see file COPYING */
/* this file contains code for handling signals (except SIGCHLD) */
@ -35,6 +35,7 @@ static struct socat_sig_desc socat_sigquit;
#endif
/* is async-signal-safe */
static struct socat_sig_desc *socat_get_sig_desc(int signum) {
struct socat_sig_desc *sigdesc;
switch (signum) {
@ -46,21 +47,26 @@ static struct socat_sig_desc *socat_get_sig_desc(int signum) {
return sigdesc;
}
/* a signal handler that eventually passes the signal to sub processes */
/* a signal handler that possibly passes the signal to sub processes */
void socatsignalpass(int sig) {
int i;
struct socat_sig_desc *sigdesc;
int _errno;
Debug1("socatsignalpass(%d)", sig);
if ((sigdesc = socat_get_sig_desc(sig)) == NULL) {
_errno = errno;
diag_in_handler = 1;
Notice1("socatsignalpass(%d)", sig);
if ((sigdesc = socat_get_sig_desc(sig)) == NULL) { /* is async-signal-safe */
diag_in_handler = 0;
errno = _errno;
return;
}
for (i=0; i<sigdesc->sig_use; ++i) {
if (sigdesc->sig_pids[i]) {
if (Kill(sigdesc->sig_pids[i], sig) < 0) {
Warn3("kill("F_pid", %d): %s",
sigdesc->sig_pids[i], sig, strerror(errno));
Warn2("kill("F_pid", %d): %m",
sigdesc->sig_pids[i], sig);
}
}
}
@ -68,6 +74,8 @@ void socatsignalpass(int sig) {
Signal(sig, socatsignalpass);
#endif /* !HAVE_SIGACTION */
Debug("socatsignalpass() ->");
diag_in_handler = 0;
errno = _errno;
}
@ -91,8 +99,9 @@ int xio_opt_signal(pid_t pid, int signum) {
#if HAVE_SIGACTION
struct sigaction act;
memset(&act, 0, sizeof(struct sigaction));
act.sa_flags = SA_RESTART;
act.sa_flags = 0/*|SA_RESTART*/;
act.sa_handler = socatsignalpass;
sigfillset(&act.sa_mask);
if (Sigaction(signum, &act, NULL) < 0) {
/*! man does not say that errno is defined */
Warn3("sigaction(%d, %p, NULL): %s", signum, &act, strerror(errno));