introduce daemonize 20/2920/1
authorAndy Green <andy.green@linaro.org>
Thu, 17 Jan 2013 02:05:39 +0000 (10:05 +0800)
committerKevron Rees <kevron_m_rees@linux.intel.com>
Thu, 7 Mar 2013 21:01:26 +0000 (13:01 -0800)
Signed-off-by: Andy Green <andy.green@linaro.org>
README-test-server
configure.ac
lib/Makefile.am
lib/libwebsockets.h

index 23af345..c59494a 100644 (file)
@@ -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
 -------------------
 
index 3bf09ae..7d7bc1a 100644 (file)
@@ -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,                                                          
index bf3586a..78ac33f 100644 (file)
@@ -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 \
index 83d7b3d..ac261b5 100644 (file)
@@ -819,6 +819,9 @@ 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);
 
 LWS_EXTERN unsigned char *