mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-09 00:00:04 +01:00
check for prctl, poll parent PID if not present
this allows forking code to be used on non-linux systems
This commit is contained in:
parent
1e32663805
commit
915316644c
3 changed files with 18 additions and 2 deletions
|
@ -112,7 +112,7 @@ AM_CONDITIONAL(NOPING, test x$noping = xyes)
|
|||
|
||||
|
||||
# Checks for header files.
|
||||
AC_CHECK_HEADERS([zlib.h fcntl.h netinet/in.h stdlib.h string.h sys/socket.h unistd.h])
|
||||
AC_CHECK_HEADERS([zlib.h fcntl.h netinet/in.h stdlib.h string.h sys/socket.h unistd.h sys/prctl.h])
|
||||
|
||||
# Checks for typedefs, structures, and compiler characteristics.
|
||||
AC_TYPE_SIZE_T
|
||||
|
|
|
@ -3021,14 +3021,28 @@ libwebsockets_fork_service_loop(struct libwebsocket_context *context)
|
|||
return 0;
|
||||
}
|
||||
|
||||
#ifdef HAVE_SYS_PRCTL_H
|
||||
/* we want a SIGHUP when our parent goes down */
|
||||
prctl(PR_SET_PDEATHSIG, SIGHUP);
|
||||
#endif
|
||||
|
||||
/* in this forked process, sit and service websocket connections */
|
||||
|
||||
while (1)
|
||||
while (1) {
|
||||
if (libwebsocket_service(context, 1000))
|
||||
return -1;
|
||||
#ifndef HAVE_SYS_PRCTL_H
|
||||
/*
|
||||
* on systems without prctl() (i.e. anything but linux) we can notice that our
|
||||
* parent is dead if getppid() returns 1. FIXME apparently this is not true for
|
||||
* solaris, could remember ppid right after fork and wait for it to change.
|
||||
*/
|
||||
|
||||
if (getppid() == 1)
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -56,8 +56,10 @@
|
|||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#ifndef LWS_NO_FORK
|
||||
#ifdef HAVE_SYS_PRCTL_H
|
||||
#include <sys/prctl.h>
|
||||
#endif
|
||||
#endif
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <arpa/inet.h>
|
||||
|
|
Loading…
Add table
Reference in a new issue