#include "lib/util/blocking.h"
#include "lib/util/dlinklist.h"
#include "lib/util/tevent_unix.h"
+#include "lib/util/become_daemon.h"
#include "common/logging.h"
#include "common/reqid.h"
struct tevent_context *ev,
struct sock_daemon_context *sockd,
const char *pidfile,
+ bool do_fork, bool create_session,
pid_t pid_watch)
{
struct tevent_req *req, *subreq;
return NULL;
}
+ become_daemon(do_fork, !create_session, false);
+
if (pidfile != NULL) {
int ret = pidfile_context_create(sockd, pidfile,
&sockd->pid_ctx);
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)
{
struct tevent_req *req;
int ret;
bool status;
- req = sock_daemon_run_send(ev, ev, sockd, pidfile, pid_watch);
+ req = sock_daemon_run_send(ev, ev, sockd,
+ pidfile, do_fork, create_session, pid_watch);
if (req == NULL) {
return ENOMEM;
}
* @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_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__ */
goto fail;
}
- ret = sock_daemon_run(ev, sockd, options.pidfile, options.pid);
+ ret = sock_daemon_run(ev, sockd,
+ options.pidfile, false, false, options.pid);
if (ret == EINTR) {
ret = 0;
}
&dummy_socket_funcs, NULL);
assert(ret == 0);
- ret = sock_daemon_run(ev, sockd, pidfile, -1);
+ ret = sock_daemon_run(ev, sockd, pidfile, false, false, -1);
assert(ret == EINTR);
exit(0);
&dummy_socket_funcs, NULL);
assert(ret == 0);
- ret = sock_daemon_run(ev, sockd, NULL, pid_watch);
+ ret = sock_daemon_run(ev, sockd, NULL, false, false, pid_watch);
assert(ret == ESRCH);
exit(0);
&test4_funcs, NULL, &sockd);
assert(ret == 0);
- ret = sock_daemon_run(ev, sockd, pidfile, -1);
+ ret = sock_daemon_run(ev, sockd, pidfile, false, false, -1);
assert(ret == 0);
exit(0);
&test5_client_funcs, &state);
assert(ret == 0);
- ret = sock_daemon_run(ev, sockd, pidfile, pid);
+ ret = sock_daemon_run(ev, sockd, pidfile, false, false, pid);
assert(ret == EINTR);
exit(0);
&test6_client_funcs, &server_state);
assert(ret == 0);
- ret = sock_daemon_run(ev, sockd, pidfile, pid);
+ ret = sock_daemon_run(ev, sockd, pidfile, false, false, pid);
assert(ret == 0);
exit(0);
&test2_funcs, &fd[1], &sockd);
assert(ret == 0);
- ret = sock_daemon_run(ev, sockd, pidfile, -1);
+ ret = sock_daemon_run(ev, sockd, pidfile, false, false, -1);
assert(ret == EINTR);
exit(0);
&test2_funcs, &fd[1], &sockd);
assert(ret == 0);
- ret = sock_daemon_run(ev, sockd, pidfile, -1);
+ ret = sock_daemon_run(ev, sockd, pidfile, false, false, -1);
assert(ret == EEXIST);
ret = kill(pid, SIGTERM);