summaryrefslogtreecommitdiff
path: root/ctdb/common
diff options
context:
space:
mode:
authorAmitay Isaacs <amitay@gmail.com>2017-08-28 18:39:40 +1000
committerAmitay Isaacs <amitay@samba.org>2017-08-29 11:14:09 +0200
commitb67cc00c9335d899402d28f229d2b4416dc8a674 (patch)
tree6ef1ed85c5db9f63bf4813b3e15891876829f71a /ctdb/common
parentfc6fdde60fadf88be3ef9a116feff70fe97a052e (diff)
downloadsamba-b67cc00c9335d899402d28f229d2b4416dc8a674.tar.gz
ctdb-common: Move PID file creation to sock_daemon_run_send()
Only create PID file when actually starting the daemon, rather than when setting up the context. This will facilitate future changes. Tweak test to confirm that PID file is no longer created during setup. 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.c22
-rw-r--r--ctdb/common/sock_daemon.h6
2 files changed, 16 insertions, 12 deletions
diff --git a/ctdb/common/sock_daemon.c b/ctdb/common/sock_daemon.c
index a6d430119a9..e8742a06aab 100644
--- a/ctdb/common/sock_daemon.c
+++ b/ctdb/common/sock_daemon.c
@@ -452,7 +452,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 **out)
@@ -476,14 +475,6 @@ int sock_daemon_setup(TALLOC_CTX *mem_ctx, const char *daemon_name,
return ret;
}
- if (pidfile != NULL) {
- ret = pidfile_context_create(sockd, pidfile, &sockd->pid_ctx);
- if (ret != 0) {
- talloc_free(sockd);
- return EEXIST;
- }
- }
-
*out = sockd;
return 0;
}
@@ -537,6 +528,7 @@ static void sock_daemon_run_wait_done(struct tevent_req *subreq);
struct tevent_req *sock_daemon_run_send(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
struct sock_daemon_context *sockd,
+ const char *pidfile,
pid_t pid_watch)
{
struct tevent_req *req, *subreq;
@@ -550,6 +542,15 @@ struct tevent_req *sock_daemon_run_send(TALLOC_CTX *mem_ctx,
return NULL;
}
+ if (pidfile != NULL) {
+ int ret = pidfile_context_create(sockd, pidfile,
+ &sockd->pid_ctx);
+ if (ret != 0) {
+ tevent_req_error(req, EEXIST);
+ return tevent_req_post(req, ev);
+ }
+ }
+
state->ev = ev;
state->sockd = sockd;
state->pid_watch = pid_watch;
@@ -780,13 +781,14 @@ 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,
pid_t pid_watch)
{
struct tevent_req *req;
int ret;
bool status;
- req = sock_daemon_run_send(ev, ev, sockd, pid_watch);
+ req = sock_daemon_run_send(ev, ev, sockd, pidfile, pid_watch);
if (req == NULL) {
return ENOMEM;
}
diff --git a/ctdb/common/sock_daemon.h b/ctdb/common/sock_daemon.h
index 81853f66446..3fdd576e7a1 100644
--- a/ctdb/common/sock_daemon.h
+++ b/ctdb/common/sock_daemon.h
@@ -149,7 +149,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 +156,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 +180,14 @@ 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] 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,
pid_t pid_watch);
/**
@@ -204,6 +204,7 @@ 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] pid_watch PID to watch. If PID goes away, shutdown.
* @return 0 on success, errno on failure
*
@@ -211,6 +212,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,
pid_t pid_watch);
#endif /* __CTDB_SOCK_DAEMON_H__ */