1
0
Fork 0
mirror of https://repo.or.cz/socat.git synced 2025-07-11 22:23:24 +00:00

Parent process might have been killed by signal to child

This commit is contained in:
Gerhard Rieger 2019-03-03 09:32:22 +01:00
parent 9f5abda361
commit e1a5931827
5 changed files with 33 additions and 8 deletions

29
error.c
View file

@ -110,15 +110,9 @@ static int diag_sock_recv = -1;
static int diag_msg_avail = 0; /* !=0: messages from within signal handler may be waiting */
static int diag_init(void) {
static int diag_sock_pair(void) {
int handlersocks[2];
if (diaginitialized) {
return 0;
}
diaginitialized = 1;
/* gcc with GNU libc refuses to set this in the initializer */
diagopts.logfile = stderr;
if (socketpair(AF_UNIX, SOCK_DGRAM, 0, handlersocks) < 0) {
diag_sock_send = -1;
diag_sock_recv = -1;
@ -128,6 +122,19 @@ static int diag_init(void) {
diag_sock_recv = handlersocks[0];
return 0;
}
static int diag_init(void) {
if (diaginitialized) {
return 0;
}
diaginitialized = 1;
/* gcc with GNU libc refuses to set this in the initializer */
diagopts.logfile = stderr;
if (diag_sock_pair() < 0) {
return -1;
}
return 0;
}
#define DIAG_INIT ((void)(diaginitialized || diag_init()))
@ -224,6 +231,14 @@ int diag_reserve_fd(int fd) {
return 0;
}
/* call this after a fork() from the child process to separate master/parent
sockets from child sockets */
int diag_fork() {
Close(diag_sock_send);
Close(diag_sock_recv);
return diag_sock_pair();
}
/* Linux and AIX syslog format:
Oct 4 17:10:37 hostname socat[52798]: D signal(13, 1)
*/