diff options
author | Pavel Březina <pbrezina@redhat.com> | 2013-10-24 11:30:09 +0200 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2013-10-25 22:12:19 +0200 |
commit | 4d6edda295ff05825d924f0450d2c2bf2034c357 (patch) | |
tree | 6eb4d0c57faf8d4bb95b7203a1c52a92370d9ecb /src/providers/dp_ptask.c | |
parent | d19e343d3fcb0780300d69ba5813ca4762ca9b98 (diff) | |
download | sssd-4d6edda295ff05825d924f0450d2c2bf2034c357.tar.gz sssd-4d6edda295ff05825d924f0450d2c2bf2034c357.tar.xz sssd-4d6edda295ff05825d924f0450d2c2bf2034c357.zip |
be_ptask: add be_ptask_create_sync()
This is a wrapper around be_ptask_create() that allows to create
synchronous periodic tasks.
Resolves:
https://fedorahosted.org/sssd/ticket/1968
Diffstat (limited to 'src/providers/dp_ptask.c')
-rw-r--r-- | src/providers/dp_ptask.c | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/src/providers/dp_ptask.c b/src/providers/dp_ptask.c index d0f7c6d97..44a5e148a 100644 --- a/src/providers/dp_ptask.c +++ b/src/providers/dp_ptask.c @@ -352,3 +352,97 @@ time_t be_ptask_get_period(struct be_ptask *task) { return task->period; } + +struct be_ptask_sync_ctx { + be_ptask_sync_t fn; + void *pvt; +}; + +struct be_ptask_sync_state { + int dummy; +}; + +/* This is not an asynchronous request so there is not any _done function. */ +static struct tevent_req * +be_ptask_sync_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct be_ctx *be_ctx, + struct be_ptask *be_ptask, + void *pvt) +{ + struct be_ptask_sync_ctx *ctx = NULL; + struct be_ptask_sync_state *state = NULL; + struct tevent_req *req = NULL; + errno_t ret; + + req = tevent_req_create(mem_ctx, &state, struct be_ptask_sync_state); + if (req == NULL) { + DEBUG(SSSDBG_CRIT_FAILURE, ("tevent_req_create() failed\n")); + return NULL; + } + + ctx = talloc_get_type(pvt, struct be_ptask_sync_ctx); + ret = ctx->fn(mem_ctx, ev, be_ctx, be_ptask, ctx->pvt); + + if (ret == EOK) { + tevent_req_done(req); + } else { + tevent_req_error(req, ret); + } + tevent_req_post(req, ev); + + return req; +} + +static errno_t be_ptask_sync_recv(struct tevent_req *req) +{ + TEVENT_REQ_RETURN_ON_ERROR(req); + + return EOK; +} + +errno_t be_ptask_create_sync(TALLOC_CTX *mem_ctx, + struct be_ctx *be_ctx, + time_t period, + time_t first_delay, + time_t enabled_delay, + time_t timeout, + enum be_ptask_offline offline, + be_ptask_sync_t fn, + void *pvt, + const char *name, + struct be_ptask **_task) +{ + errno_t ret; + struct be_ptask_sync_ctx *ctx = NULL; + + ctx = talloc_zero(mem_ctx, struct be_ptask_sync_ctx); + if (ctx == NULL) { + ret = ENOMEM; + goto done; + } + + ctx->fn = fn; + ctx->pvt = pvt; + + ret = be_ptask_create(mem_ctx, be_ctx, period, first_delay, + enabled_delay, timeout, offline, + be_ptask_sync_send, be_ptask_sync_recv, + ctx, name, _task); + if (ret != EOK) { + goto done; + } + + if (_task != NULL) { + talloc_steal(*_task, ctx); + } + + ret = EOK; + +done: + if (ret != EOK) { + talloc_free(ctx); + } + + return ret; +} |