diff options
author | Amitay Isaacs <amitay@gmail.com> | 2013-04-30 15:07:49 +1000 |
---|---|---|
committer | Amitay Isaacs <amitay@gmail.com> | 2013-05-24 09:06:40 +1000 |
commit | ae25420e565b46f7c745767b4b7b6ed58bad7d2a (patch) | |
tree | 12b606eb18297606819b8f3946fc605c5e82d5cf /ctdb/server/ctdb_lock.c | |
parent | e30978eae14a2c8fe982efa8c8fda4e2cf0c3496 (diff) | |
download | samba-ae25420e565b46f7c745767b4b7b6ed58bad7d2a.tar.gz samba-ae25420e565b46f7c745767b4b7b6ed58bad7d2a.tar.xz samba-ae25420e565b46f7c745767b4b7b6ed58bad7d2a.zip |
locking: Use separate locking helper binary for locking
Signed-off-by: Amitay Isaacs <amitay@gmail.com>
(This used to be ctdb commit 7cde53a6cbe74b1e46f7e1bca298df82c08de866)
Diffstat (limited to 'ctdb/server/ctdb_lock.c')
-rw-r--r-- | ctdb/server/ctdb_lock.c | 56 |
1 files changed, 39 insertions, 17 deletions
diff --git a/ctdb/server/ctdb_lock.c b/ctdb/server/ctdb_lock.c index 8e2f40dd4e..9469835397 100644 --- a/ctdb/server/ctdb_lock.c +++ b/ctdb/server/ctdb_lock.c @@ -808,7 +808,10 @@ static void ctdb_lock_schedule(struct ctdb_context *ctdb) { struct lock_context *lock_ctx, *next_ctx; int ret; - pid_t parent; + TALLOC_CTX *tmp_ctx; + const char *helper = BINDIR "/ctdb_lock_helper"; + const char *prog; + char **args; if (ctdb->lock_num_current >= MAX_LOCK_PROCESSES_PER_DB) { return; @@ -850,41 +853,60 @@ static void ctdb_lock_schedule(struct ctdb_context *ctdb) return; } - parent = getpid(); + set_close_on_exec(lock_ctx->fd[0]); + + /* Create data for child process */ + tmp_ctx = talloc_new(lock_ctx); + if (tmp_ctx == NULL) { + DEBUG(DEBUG_ERR, ("Failed to allocate memory for helper args\n")); + close(lock_ctx->fd[0]); + close(lock_ctx->fd[1]); + return; + } + + /* Create arguments for lock helper */ + args = lock_helper_args(tmp_ctx, lock_ctx, lock_ctx->fd[1]); + if (args == NULL) { + DEBUG(DEBUG_ERR, ("Failed to create lock helper args\n")); + close(lock_ctx->fd[0]); + close(lock_ctx->fd[1]); + talloc_free(tmp_ctx); + return; + } + + prog = getenv("CTDB_LOCK_HELPER"); + if (prog == NULL) { + prog = helper; + } + lock_ctx->child = ctdb_fork(ctdb); if (lock_ctx->child == (pid_t)-1) { DEBUG(DEBUG_ERR, ("Failed to create a child in ctdb_lock_schedule\n")); close(lock_ctx->fd[0]); close(lock_ctx->fd[1]); + talloc_free(tmp_ctx); return; } + /* Child process */ if (lock_ctx->child == 0) { - char c; - close(lock_ctx->fd[0]); - debug_extra = lock_child_log_prefix(lock_ctx); - if (ctdb_lock_item(lock_ctx)) { - c = 0; - } else { - c = 1; + ret = execv(prog, args); + if (ret < 0) { + DEBUG(DEBUG_ERR, ("Failed to execute helper %s (%d, %s)\n", + prog, errno, strerror(errno))); } - write(lock_ctx->fd[1], &c, 1); - - /* Hang around, but if parent dies, terminate */ - while (kill(parent, 0) == 0 || errno != ESRCH) { - sleep(5); - } - _exit(0); + _exit(1); } /* Parent process */ close(lock_ctx->fd[1]); - set_close_on_exec(lock_ctx->fd[0]); talloc_set_destructor(lock_ctx, ctdb_lock_context_destructor); + talloc_free(tmp_ctx); + /* Set up timeout handler */ lock_ctx->ttimer = tevent_add_timer(ctdb->ev, lock_ctx, |