diff --git a/README-test-server b/README-test-server index 23af345b..c59494a9 100644 --- a/README-test-server +++ b/README-test-server @@ -80,6 +80,9 @@ There are several other possible configure options minimize library footprint for embedded server-only case +--without-daemonize Don't build daemonize.c / lws_daemonize + + Externally configurable important constants ------------------------------------------- @@ -206,6 +209,19 @@ configure option --nofork and simply call libwebsocket_service() from your own main loop as shown in the test app sources. +Daemonization +------------- + +There's a helper api lws_daemonize built by default that does everything you +need to daemonize well, including creating a lock file. If you're making +what's basically a daemon, just call this early in your init to fork to a +headless background process and exit the starting process. + +Notice stdout, stderr, stdin are all redirected to /dev/null to enforce your +daemon is headless, so you'll need to sort out alternative logging, by, eg, +syslog. + + Fragmented messages ------------------- diff --git a/configure.ac b/configure.ac index 3bf09ae3..7d7bc1ae 100644 --- a/configure.ac +++ b/configure.ac @@ -95,6 +95,16 @@ CFLAGS="$CFLAGS -DLWS_NO_CLIENT" fi AM_CONDITIONAL(NO_CLIENT, test x$no_client = xyes) +# +# +# +AC_ARG_WITH(daemonize, + [ --without-daemonize dont build the daemonization api ], + [ no_daemonize=yes + ]) + +AM_CONDITIONAL(NO_DAEMONIZE, test x$no_daemonize = xyes) + # # AC_ARG_ENABLE(mingw, diff --git a/lib/Makefile.am b/lib/Makefile.am index bf3586a6..78ac33f1 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -11,6 +11,11 @@ dist_libwebsockets_la_SOURCES=libwebsockets.c \ extension-deflate-frame.c extension-deflate-frame.h\ private-libwebsockets.h +if NO_DAEMONIZE +else +dist_libwebsockets_la_SOURCES+= daemonize.c +endif + if NO_CLIENT else dist_libwebsockets_la_SOURCES+= client.c \ diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h index 83d7b3d3..ac261b5b 100644 --- a/lib/libwebsockets.h +++ b/lib/libwebsockets.h @@ -818,6 +818,9 @@ LWS_EXTERN int libwebsockets_get_random(struct libwebsocket_context *context, void *buf, int len); +LWS_EXTERN int +lws_daemonize(const char *_lock_path); + LWS_EXTERN int lws_send_pipe_choked(struct libwebsocket *wsi);