diff options
author | Simo Sorce <ssorce@redhat.com> | 2009-09-29 10:14:36 -0400 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2009-10-01 08:42:36 -0400 |
commit | f24c2dd7cc8414ea0a5c8c4ae7766ca71554480f (patch) | |
tree | cceff211fe8fc0c78c59b959af5367c0c4ce49f3 /server/tools/sss_groupadd.c | |
parent | bc58f5892d3a8f6b28e2148c5a0cca34b63ef354 (diff) | |
download | sssd-f24c2dd7cc8414ea0a5c8c4ae7766ca71554480f.tar.gz sssd-f24c2dd7cc8414ea0a5c8c4ae7766ca71554480f.tar.bz2 sssd-f24c2dd7cc8414ea0a5c8c4ae7766ca71554480f.zip |
Fix tools sync operations and mem hierarchy
Tools were using nested loops that are illegal.
(and enforced in latest tevent with a nice abort())
Fix them by creating appropriate synchronous transaction calls.
Also fix tools_ctx mem hierarchy setup.
Diffstat (limited to 'server/tools/sss_groupadd.c')
-rw-r--r-- | server/tools/sss_groupadd.c | 62 |
1 files changed, 15 insertions, 47 deletions
diff --git a/server/tools/sss_groupadd.c b/server/tools/sss_groupadd.c index 72bd0fdf..1f6a2f11 100644 --- a/server/tools/sss_groupadd.c +++ b/server/tools/sss_groupadd.c @@ -29,42 +29,7 @@ #include "util/util.h" #include "db/sysdb.h" #include "tools/tools_util.h" - -static void add_group_transaction(struct tevent_req *req) -{ - int ret; - struct tools_ctx *tctx = tevent_req_callback_data(req, - struct tools_ctx); - struct tevent_req *subreq; - - ret = sysdb_transaction_recv(req, tctx, &tctx->handle); - if (ret) { - tevent_req_error(req, ret); - return; - } - talloc_zfree(req); - - /* groupadd */ - ret = groupadd(tctx, tctx->ev, - tctx->sysdb, tctx->handle, tctx->octx); - if (ret != EOK) { - goto fail; - } - - subreq = sysdb_transaction_commit_send(tctx, tctx->ev, tctx->handle); - if (!subreq) { - ret = ENOMEM; - goto fail; - } - tevent_req_set_callback(subreq, tools_transaction_done, tctx); - return; - -fail: - /* free transaction and signal error */ - talloc_zfree(tctx->handle); - tctx->transaction_done = true; - tctx->error = ret; -} +#include "tools/sss_sync_ops.h" int main(int argc, const char **argv) { @@ -82,7 +47,6 @@ int main(int argc, const char **argv) struct tools_ctx *tctx = NULL; int ret = EXIT_SUCCESS; const char *pc_groupname = NULL; - struct tevent_req *req; debug_prg_name = argv[0]; @@ -140,20 +104,24 @@ int main(int argc, const char **argv) goto fini; } - /* add_group */ - req = sysdb_transaction_send(tctx->octx, tctx->ev, tctx->sysdb); - if (!req) { - DEBUG(1, ("Could not start transaction (%d)[%s]\n", ret, strerror(ret))); - ERROR("Transaction error. Could not add group.\n"); - ret = EXIT_FAILURE; - goto fini; + start_transaction(tctx); + if (tctx->error != EOK) { + goto done; } - tevent_req_set_callback(req, add_group_transaction, tctx); - while (!tctx->transaction_done) { - tevent_loop_once(tctx->ev); + /* groupadd */ + ret = groupadd(tctx, tctx->ev, tctx->sysdb, tctx->handle, tctx->octx); + if (ret != EOK) { + tctx->error = ret; + + /* cancel transaction */ + talloc_zfree(tctx->handle); + goto done; } + end_transaction(tctx); + +done: if (tctx->error) { ret = tctx->error; switch (ret) { |