ctdb-common: Add async version of shutdown in sock_daemon
[samba.git] / ctdb / common / sock_daemon.h
index 81853f66446aa42814a91ab065ca6ee9f2b067c5..a071833c2f382c43f5b9e2d9f41d1f6f9e39e259 100644 (file)
@@ -48,11 +48,27 @@ struct sock_client_context;
  * @brief The callback routines called during daemon life cycle
  *
  * startup() is called when the daemon starts running
- *            either via sock_daemon_run() or via sock_daemon_run_send()
- * reconfigure() is called when process receives SIGUSR1 or SIGHUP
+ *     either via sock_daemon_run() or via sock_daemon_run_send()
+ *     startup() should return 0 for success, non-zero value on failure
+ *     On failure, sock_daemon_run() will return error.
+ *
+ * startup_send()/startup_recv() is the async version of startup()
+ *
+ * reconfigure() is called when the daemon receives SIGUSR1 or SIGHUP
+ *     reconfigure() should return 0 for success, non-zero value on failure
+ *     On failure, sock_daemon_run() will continue to run.
+ *
+ * reconfigure_send()/reconfigure_recv() is the async version of reconfigure()
+ *
  * shutdown() is called when process receives SIGINT or SIGTERM or
  *             when wait computation has finished
  *
+ * shutdown_send()/shutdown_recv() is the async version of shutdown()
+ *
+ * Please note that only one (sync or async) version of these functions
+ * will be called.  If both versions are defined, then only async function
+ * will be called.
+ *
  * wait_send() starts the async computation to keep running the daemon
  * wait_recv() ends the async computation to keep running the daemon
  *
@@ -60,10 +76,27 @@ struct sock_client_context;
  * If wait_send() returns req, then when req is over, daemon will shutdown.
  */
 struct sock_daemon_funcs {
-       void (*startup)(void *private_data);
-       void (*reconfigure)(void *private_data);
+       int (*startup)(void *private_data);
+
+       struct tevent_req * (*startup_send)(TALLOC_CTX *mem_ctx,
+                                           struct tevent_context *ev,
+                                           void *private_data);
+       bool (*startup_recv)(struct tevent_req *req, int *perr);
+
+       int (*reconfigure)(void *private_data);
+
+       struct tevent_req * (*reconfigure_send)(TALLOC_CTX *mem_ctx,
+                                               struct tevent_context *ev,
+                                               void *private_data);
+       bool (*reconfigure_recv)(struct tevent_req *req, int *perr);
+
        void (*shutdown)(void *private_data);
 
+       struct tevent_req * (*shutdown_send)(TALLOC_CTX *mem_ctx,
+                                            struct tevent_context *ev,
+                                            void *private_data);
+       void (*shutdown_recv)(struct tevent_req *req);
+
        struct tevent_req * (*wait_send)(TALLOC_CTX *mem_ctx,
                                         struct tevent_context *ev,
                                         void *private_data);
@@ -149,7 +182,6 @@ bool sock_socket_write_recv(struct tevent_req *req, int *perr);
  * @param[in] daemon_name Name of the daemon, used for logging
  * @param[in] logging Logging setup string
  * @param[in] debug_level Debug level to log at
- * @param[in] pidfile PID file to create, NULL if no PID file required
  * @param[in] funcs Socket daemon callback routines
  * @param[in] private_data Private data associated with callback routines
  * @param[out] result New socket daemon context
@@ -157,7 +189,6 @@ bool sock_socket_write_recv(struct tevent_req *req, int *perr);
  */
 int sock_daemon_setup(TALLOC_CTX *mem_ctx, const char *daemon_name,
                      const char *logging, const char *debug_level,
-                     const char *pidfile,
                      struct sock_daemon_funcs *funcs,
                      void *private_data,
                      struct sock_daemon_context **result);
@@ -182,12 +213,17 @@ int sock_daemon_add_unix(struct sock_daemon_context *sockd,
  * @param[in] mem_ctx Talloc memory context
  * @param[in] ev Tevent context
  * @param[in] sockd The socket daemon context
+ * @param[in] pidfile PID file to create, NULL if no PID file required
+ * @param[in] do_fork Whether the daemon should fork on startup
+ * @param[in] create_session Whether the daemon should create a new session
  * @param[in] pid_watch PID to watch. If PID goes away, shutdown.
  * @return new tevent request, NULL on failure
  */
 struct tevent_req *sock_daemon_run_send(TALLOC_CTX *mem_ctx,
                                        struct tevent_context *ev,
                                        struct sock_daemon_context *sockd,
+                                       const char *pidfile,
+                                       bool do_fork, bool create_session,
                                        pid_t pid_watch);
 
 /**
@@ -204,6 +240,9 @@ bool sock_daemon_run_recv(struct tevent_req *req, int *perr);
  *
  * @param[in] ev Tevent context
  * @param[in] sockd The socket daemon context
+ * @param[in] pidfile PID file to create, NULL if no PID file required
+ * @param[in] do_fork Whether the daemon should fork on startup
+ * @param[in] create_session Whether the daemon should create a new session
  * @param[in] pid_watch PID to watch. If PID goes away, shutdown.
  * @return 0 on success, errno on failure
  *
@@ -211,6 +250,8 @@ bool sock_daemon_run_recv(struct tevent_req *req, int *perr);
  */
 int sock_daemon_run(struct tevent_context *ev,
                    struct sock_daemon_context *sockd,
+                   const char *pidfile,
+                   bool do_fork, bool create_session,
                    pid_t pid_watch);
 
 #endif /* __CTDB_SOCK_DAEMON_H__ */