* @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
*
* 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);
* @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
*/
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);
* @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);
/**
*
* @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
*
*/
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__ */