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_sync_ops.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_sync_ops.c')
-rw-r--r-- | server/tools/sss_sync_ops.c | 80 |
1 files changed, 79 insertions, 1 deletions
diff --git a/server/tools/sss_sync_ops.c b/server/tools/sss_sync_ops.c index 50eb197e..68fe73e5 100644 --- a/server/tools/sss_sync_ops.c +++ b/server/tools/sss_sync_ops.c @@ -23,7 +23,6 @@ #include "util/util.h" #include "db/sysdb.h" - #include "tools/sss_sync_ops.h" /* Default settings for user attributes */ @@ -1468,3 +1467,82 @@ static void groupmod_done(struct tevent_req *req) res->error = ret; } +/* + * Synchronous transaction functions + */ +static void start_transaction_done(struct tevent_req *req); + +void start_transaction(struct tools_ctx *tctx) +{ + struct tevent_req *req; + + /* make sure handle is NULL, as it is the spy to check if the transaction + * has been started */ + tctx->handle = NULL; + tctx->error = 0; + + req = sysdb_transaction_send(tctx->octx, tctx->ev, tctx->sysdb); + if (!req) { + DEBUG(1, ("Could not start transaction\n")); + tctx->error = ENOMEM; + return; + } + tevent_req_set_callback(req, start_transaction_done, tctx); + + /* loop to obtain a transaction */ + while (!tctx->handle && !tctx->error) { + tevent_loop_once(tctx->ev); + } +} + +static void start_transaction_done(struct tevent_req *req) +{ + struct tools_ctx *tctx = tevent_req_callback_data(req, + struct tools_ctx); + int ret; + + ret = sysdb_transaction_recv(req, tctx, &tctx->handle); + if (ret) { + tctx->error = ret; + } + if (!tctx->handle) { + tctx->error = EIO; + } + talloc_zfree(req); +} + +static void end_transaction_done(struct tevent_req *req); + +void end_transaction(struct tools_ctx *tctx) +{ + struct tevent_req *req; + + tctx->error = 0; + + req = sysdb_transaction_commit_send(tctx, tctx->ev, tctx->handle); + if (!req) { + /* free transaction and signal error */ + tctx->error = ENOMEM; + return; + } + tevent_req_set_callback(req, end_transaction_done, tctx); + + /* loop to obtain a transaction */ + while (!tctx->transaction_done && !tctx->error) { + tevent_loop_once(tctx->ev); + } +} + +static void end_transaction_done(struct tevent_req *req) +{ + struct tools_ctx *tctx = tevent_req_callback_data(req, + struct tools_ctx); + int ret; + + ret = sysdb_transaction_commit_recv(req); + + tctx->transaction_done = true; + tctx->error = ret; + talloc_zfree(req); +} + |