daemon: new scheme for graceful termination
[yaz-moved-to-github.git] / include / yaz / daemon.h
index 981327d..b5ed96b 100644 (file)
@@ -1,5 +1,5 @@
-/*
- * Copyright (c) 1995-2008, Index Data
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2012 Index Data.
  * All rights reserved.
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -24,7 +24,6 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
-/* $Id: daemon.h,v 1.1 2008-02-18 17:07:05 adam Exp $ */
 
 /**
  * \file daemon.h
@@ -43,17 +42,50 @@ YAZ_BEGIN_CDECL
 #define YAZ_DAEMON_DEBUG 2
 #define YAZ_DAEMON_KEEPALIVE 4
 
+/** \brief daemon utility.
+    \param progname program name for logging purposes.
+    \param flags flags which is a bit-wise combination of YAZ_DAEMON_..
+    \param work working handler (which may be running in different process)
+    \param data opaque data to be passed to work handler
+    \param pidfile filename with Process-ID (NULL for no file)
+    \param uid effective user ID for handler (NULL for no same as caller)
+    \returns 0 for success, non-zero for failure.
+
+    This function puts calls work handler which is supposed to carry
+    out a daemon service with a possible changed User ID and in a
+    child process.
+
+    Flag YAZ_DAEMON_FORK: Puts the service in the background on Unix.
+
+    Flag YAZ_DAEMON_DEBUG: Puts the service in debug mode (no fork at all).
+
+    Flag YAZ_DAEMON_KEEPALIVE: Repeatedly calls work handler if it makes a 
+    "fatal" error.
+*/
+YAZ_EXPORT
 int yaz_daemon(const char *progname,
                unsigned int flags,
                void (*work)(void *data), void *data,
                const char *pidfile, const char *uid);
 
+/** \brief stop daemon - stop parent process
+
+    This function sends a signal to the parent keepalive process that
+    makes it exit immediately - without waiting. If there's no parent
+    keepalive process, this function does nothing. SHould be called
+    when the child process has freed resources, such as listening socket.
+    But the child process may continue running.
+*/
+YAZ_EXPORT
+void yaz_daemon_stop(void);
+
 YAZ_END_CDECL
 
 #endif
 /*
  * Local variables:
  * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
  * indent-tabs-mode: nil
  * End:
  * vim: shiftwidth=4 tabstop=8 expandtab