mirror of
https://repo.or.cz/socat.git
synced 2024-12-23 07:52:32 +00:00
fixed sporadic data loss on pid reuse
This commit is contained in:
parent
5b4d970c06
commit
f6b2e0b167
4 changed files with 29 additions and 27 deletions
5
CHANGES
5
CHANGES
|
@ -71,6 +71,11 @@ corrections:
|
||||||
only expected broken messages, not corrupted stack (glibc 2.11.1,
|
only expected broken messages, not corrupted stack (glibc 2.11.1,
|
||||||
Ubuntu 10.4)
|
Ubuntu 10.4)
|
||||||
|
|
||||||
|
an internal store for child pids was susceptible to pid reuse which
|
||||||
|
could lead to sporadic data loss when both fork option and exec address
|
||||||
|
were used. Thanks to Tetsuya Sodo for reporting this problem and
|
||||||
|
sending a patch
|
||||||
|
|
||||||
docu mentions option so-bindtodev but correct name is so-bindtodevice.
|
docu mentions option so-bindtodev but correct name is so-bindtodevice.
|
||||||
Thanks to Jim Zimmerman for reporting.
|
Thanks to Jim Zimmerman for reporting.
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* source: xioinitialize.c */
|
/* source: xioinitialize.c */
|
||||||
/* Copyright Gerhard Rieger 2001-2008 */
|
/* Copyright Gerhard Rieger 2001-2012 */
|
||||||
/* Published under the GNU General Public License V.2, see file COPYING */
|
/* Published under the GNU General Public License V.2, see file COPYING */
|
||||||
|
|
||||||
/* this file contains the source for the initialize function */
|
/* this file contains the source for the initialize function */
|
||||||
|
@ -206,7 +206,11 @@ static int xio_nokill(xiofile_t *sock) {
|
||||||
returns 0 on success or != 0 if an error occurred */
|
returns 0 on success or != 0 if an error occurred */
|
||||||
int xio_forked_inchild(void) {
|
int xio_forked_inchild(void) {
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i=0; i<NUMUNKNOWN; ++i) {
|
||||||
|
diedunknown[i] = 0;
|
||||||
|
}
|
||||||
xiodroplocks();
|
xiodroplocks();
|
||||||
#if WITH_FIPS
|
#if WITH_FIPS
|
||||||
if (xio_reset_fips_mode() != 0) {
|
if (xio_reset_fips_mode() != 0) {
|
||||||
|
|
31
xiosigchld.c
31
xiosigchld.c
|
@ -1,5 +1,5 @@
|
||||||
/* source: xiosigchld.c */
|
/* source: xiosigchld.c */
|
||||||
/* Copyright Gerhard Rieger 2001-2008 */
|
/* Copyright Gerhard Rieger 2001-2012 */
|
||||||
/* Published under the GNU General Public License V.2, see file COPYING */
|
/* Published under the GNU General Public License V.2, see file COPYING */
|
||||||
|
|
||||||
/* this is the source of the extended child signal handler */
|
/* this is the source of the extended child signal handler */
|
||||||
|
@ -27,11 +27,9 @@ static struct _xiosigchld_child * _xiosigchld_find(pid_t pid);
|
||||||
static struct _xiosigchld_child xio_childpids[XIO_MAXCHILDPIDS];
|
static struct _xiosigchld_child xio_childpids[XIO_MAXCHILDPIDS];
|
||||||
|
|
||||||
#if 1 /*!!!*/
|
#if 1 /*!!!*/
|
||||||
/*!! with socat, at most 4 managed children exist */
|
/*!! with socat 1, at most 4 managed children existed */
|
||||||
pid_t diedunknown1; /* child died before it is registered */
|
pid_t diedunknown[NUMUNKNOWN]; /* children that died before they were registered */
|
||||||
pid_t diedunknown2;
|
size_t nextunknown;
|
||||||
pid_t diedunknown3;
|
|
||||||
pid_t diedunknown4;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -135,21 +133,14 @@ void childdied(int signum
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
if (i == XIO_MAXSOCK) {
|
if (i == XIO_MAXSOCK) {
|
||||||
Info2("childdied(%d): cannot identify child %d", signum, pid);
|
Info2("childdied(%d): cannot identify child %d", signum, pid);
|
||||||
if (diedunknown1 == 0) {
|
if (nextunknown == NUMUNKNOWN) {
|
||||||
diedunknown1 = pid;
|
nextunknown = 0;
|
||||||
Debug("saving pid in diedunknown1");
|
|
||||||
} else if (diedunknown2 == 0) {
|
|
||||||
diedunknown2 = pid;
|
|
||||||
Debug("saving pid in diedunknown2");
|
|
||||||
} else if (diedunknown3 == 0) {
|
|
||||||
diedunknown3 = pid;
|
|
||||||
Debug("saving pid in diedunknown3");
|
|
||||||
} else {
|
|
||||||
diedunknown4 = pid;
|
|
||||||
Debug("saving pid in diedunknown4");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
diedunknown[nextunknown++] = pid;
|
||||||
|
Debug1("saving pid in diedunknown%u",
|
||||||
|
nextunknown/*sic, for compatibility*/);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
entry = _xiosigchld_find(pid);
|
entry = _xiosigchld_find(pid);
|
||||||
if (entry == NULL) {
|
if (entry == NULL) {
|
||||||
|
|
14
xiosigchld.h
14
xiosigchld.h
|
@ -1,14 +1,16 @@
|
||||||
/* $Id$ */
|
/* source: xiosigchld.h */
|
||||||
/* Copyright Gerhard Rieger 2006 */
|
/* Copyright Gerhard Rieger 2012 */
|
||||||
/* Published under the GNU General Public License V.2, see file COPYING */
|
/* Published under the GNU General Public License V.2, see file COPYING */
|
||||||
|
|
||||||
#ifndef __xiosigchld_h
|
#ifndef __xiosigchld_h
|
||||||
#define __xiosigchld_h 1
|
#define __xiosigchld_h 1
|
||||||
|
|
||||||
extern pid_t diedunknown1; /* child died before it is registered */
|
#define NUMUNKNOWN 4
|
||||||
extern pid_t diedunknown2;
|
extern pid_t diedunknown[NUMUNKNOWN]; /* child died before it is registered */
|
||||||
extern pid_t diedunknown3;
|
#define diedunknown1 (diedunknown[0])
|
||||||
extern pid_t diedunknown4;
|
#define diedunknown2 (diedunknown[1])
|
||||||
|
#define diedunknown3 (diedunknown[2])
|
||||||
|
#define diedunknown4 (diedunknown[3])
|
||||||
|
|
||||||
extern int xiosetsigchild(xiofile_t *xfd, int (*callback)(struct single *));
|
extern int xiosetsigchild(xiofile_t *xfd, int (*callback)(struct single *));
|
||||||
extern void childdied(int signum
|
extern void childdied(int signum
|
||||||
|
|
Loading…
Reference in a new issue