diff options
author | Artem Baguinski <artm@v2.nl> | 2011-12-14 22:14:03 +0100 |
---|---|---|
committer | Andy Green <andy.green@linaro.org> | 2012-07-20 10:04:45 +0800 |
commit | 915316644cb47ec5a2d2ad3b5a233e5cd2b73db5 (patch) | |
tree | b00b1195d8da5aa7c81c017e7ed0c78ea438a635 | |
parent | 1e326638056aa499ecdcc4b94adcd674043c9c5b (diff) |
check for prctl, poll parent PID if not present
this allows forking code to be used on non-linux systems
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | lib/libwebsockets.c | 16 | ||||
-rw-r--r-- | lib/private-libwebsockets.h | 2 |
3 files changed, 18 insertions, 2 deletions
diff --git a/configure.ac b/configure.ac index 93dc7f4..3980b2d 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index 06f5c06..7680817 100644 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -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; } diff --git a/lib/private-libwebsockets.h b/lib/private-libwebsockets.h index 2f682db..3c9776f 100644 --- a/lib/private-libwebsockets.h +++ b/lib/private-libwebsockets.h @@ -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> |