summaryrefslogtreecommitdiff
path: root/ctdb/common
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2017-08-16 13:52:08 +1000
committerAmitay Isaacs <amitay@samba.org>2017-08-29 11:14:09 +0200
commit94cc5eaddc6cee3d7b24dc57b6194ef0a0a979ba (patch)
tree86559b227e6dc8c8f35780ce880f2fce5c0651cf /ctdb/common
parent4cb560386ad5fd10a482cf22698d224540a99ab0 (diff)
downloadsamba-94cc5eaddc6cee3d7b24dc57b6194ef0a0a979ba.tar.gz
ctdb-common: Allow sock_daemon to daemonise during startup
Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
Diffstat (limited to 'ctdb/common')
-rw-r--r--ctdb/common/sock_daemon.c8
-rw-r--r--ctdb/common/sock_daemon.h6
2 files changed, 13 insertions, 1 deletions
diff --git a/ctdb/common/sock_daemon.c b/ctdb/common/sock_daemon.c
index e8742a06aab..56205d019ec 100644
--- a/ctdb/common/sock_daemon.c
+++ b/ctdb/common/sock_daemon.c
@@ -30,6 +30,7 @@
#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"
@@ -529,6 +530,7 @@ 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)
{
struct tevent_req *req, *subreq;
@@ -542,6 +544,8 @@ struct tevent_req *sock_daemon_run_send(TALLOC_CTX *mem_ctx,
return NULL;
}
+ become_daemon(do_fork, !create_session, false);
+
if (pidfile != NULL) {
int ret = pidfile_context_create(sockd, pidfile,
&sockd->pid_ctx);
@@ -782,13 +786,15 @@ 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)
{
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;
}
diff --git a/ctdb/common/sock_daemon.h b/ctdb/common/sock_daemon.h
index 3fdd576e7a1..18210287771 100644
--- a/ctdb/common/sock_daemon.h
+++ b/ctdb/common/sock_daemon.h
@@ -181,6 +181,8 @@ int sock_daemon_add_unix(struct sock_daemon_context *sockd,
* @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
*/
@@ -188,6 +190,7 @@ 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);
/**
@@ -205,6 +208,8 @@ 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
*
@@ -213,6 +218,7 @@ 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__ */