From 21d485184df986e1a123f70c689517386e51a5ce Mon Sep 17 00:00:00 2001 From: Michal Zidek Date: Thu, 16 Aug 2012 18:48:53 +0200 Subject: Unify usage of sysdb transactions Removing bad examples of usage of sysdb_transaction_start/commit/end functions and making it more consistent (all files except of src/db/sysdb_*.c). --- src/tools/sss_groupadd.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/tools/sss_groupadd.c') diff --git a/src/tools/sss_groupadd.c b/src/tools/sss_groupadd.c index f2e09a10..2a01f392 100644 --- a/src/tools/sss_groupadd.c +++ b/src/tools/sss_groupadd.c @@ -46,7 +46,9 @@ int main(int argc, const char **argv) poptContext pc = NULL; struct tools_ctx *tctx = NULL; int ret = EXIT_SUCCESS; + errno_t sret; const char *pc_groupname = NULL; + bool in_transaction = false; debug_prg_name = argv[0]; @@ -106,20 +108,32 @@ int main(int argc, const char **argv) tctx->error = sysdb_transaction_start(tctx->sysdb); if (tctx->error != EOK) { + DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to start transaction\n")); goto done; } + in_transaction = true; /* groupadd */ tctx->error = groupadd(tctx->sysdb, tctx->octx); if (tctx->error) { - /* cancel transaction */ - sysdb_transaction_cancel(tctx->sysdb); goto done; } tctx->error = sysdb_transaction_commit(tctx->sysdb); + if (tctx->error != EOK) { + DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to commit transaction\n")); + goto done; + } + in_transaction = false; done: + if (in_transaction) { + sret = sysdb_transaction_cancel(tctx->sysdb); + if (sret != EOK) { + DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to cancel transaction\n")); + } + } + if (tctx->error) { ret = tctx->error; switch (ret) { -- cgit