summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2019-10-10 13:38:17 +0200
committerJeremy Allison <jra@samba.org>2019-11-06 20:36:34 +0000
commit9dd65d1f991722bf6686ae21e4607192fc2bf327 (patch)
treea88dc774fd42547876f61c520aca3edd2065758d /source3
parentd9bd074cc8c0859f4f6333080d457a551e6367a4 (diff)
downloadsamba-9dd65d1f991722bf6686ae21e4607192fc2bf327.tar.gz
net: Avoid the use of g_lock_do()
g_lock_do() does too much in g_lock.c, and it's rarely used. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'source3')
-rw-r--r--source3/utils/net_g_lock.c51
1 files changed, 26 insertions, 25 deletions
diff --git a/source3/utils/net_g_lock.c b/source3/utils/net_g_lock.c
index 8b839d2e09f..8dd58b2c1ba 100644
--- a/source3/utils/net_g_lock.c
+++ b/source3/utils/net_g_lock.c
@@ -60,54 +60,55 @@ fail:
return false;
}
-struct net_g_lock_do_state {
- const char *cmd;
- int result;
-};
-
-static void net_g_lock_do_fn(void *private_data)
-{
- struct net_g_lock_do_state *state =
- (struct net_g_lock_do_state *)private_data;
- state->result = system(state->cmd);
-}
-
static int net_g_lock_do(struct net_context *c, int argc, const char **argv)
{
- struct net_g_lock_do_state state;
- const char *name, *cmd;
+ struct g_lock_ctx *ctx = NULL;
+ TDB_DATA key = {0};
+ const char *cmd = NULL;
int timeout;
NTSTATUS status;
+ int result = -1;
if (argc != 3) {
d_printf("Usage: net g_lock do <lockname> <timeout> "
"<command>\n");
return -1;
}
- name = argv[0];
+ key = string_term_tdb_data(argv[0]);
timeout = atoi(argv[1]);
cmd = argv[2];
- state.cmd = cmd;
- state.result = -1;
-
- status = g_lock_do(string_term_tdb_data(name), G_LOCK_WRITE,
- timeval_set(timeout / 1000, timeout % 1000),
- net_g_lock_do_fn, &state);
+ ctx = g_lock_ctx_init(c, c->msg_ctx);
+ if (ctx == NULL) {
+ d_fprintf(stderr, _("g_lock_ctx_init failed\n"));
+ return -1;
+ }
+ status = g_lock_lock(
+ ctx,
+ key,
+ G_LOCK_WRITE,
+ timeval_set(timeout / 1000, timeout % 1000));
if (!NT_STATUS_IS_OK(status)) {
- d_fprintf(stderr, "ERROR: g_lock_do failed: %s\n",
+ d_fprintf(stderr,
+ _("g_lock_lock failed: %s\n"),
nt_errstr(status));
goto done;
}
- if (state.result == -1) {
+
+ result = system(cmd);
+
+ g_lock_unlock(ctx, key);
+
+ if (result == -1) {
d_fprintf(stderr, "ERROR: system() returned %s\n",
strerror(errno));
goto done;
}
- d_fprintf(stderr, "command returned %d\n", state.result);
+ d_fprintf(stderr, "command returned %d\n", result);
done:
- return state.result;
+ TALLOC_FREE(ctx);
+ return result;
}
static void net_g_lock_dump_fn(const struct g_lock_rec *locks,