summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPavel Březina <pbrezina@redhat.com>2013-10-24 11:30:09 +0200
committerJakub Hrozek <jhrozek@redhat.com>2013-10-25 22:12:19 +0200
commit4d6edda295ff05825d924f0450d2c2bf2034c357 (patch)
tree6eb4d0c57faf8d4bb95b7203a1c52a92370d9ecb /src
parentd19e343d3fcb0780300d69ba5813ca4762ca9b98 (diff)
downloadsssd-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')
-rw-r--r--src/providers/dp_ptask.c94
-rw-r--r--src/providers/dp_ptask.h23
2 files changed, 117 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;
+}
diff --git a/src/providers/dp_ptask.h b/src/providers/dp_ptask.h
index 6a241fb7a..11324db74 100644
--- a/src/providers/dp_ptask.h
+++ b/src/providers/dp_ptask.h
@@ -61,6 +61,17 @@ typedef errno_t
(*be_ptask_recv_t)(struct tevent_req *req);
/**
+ * If EOK, task will be scheduled again to 'last_execution_time + period'.
+ * If other error code, task will be rescheduled to 'now + period'.
+ */
+typedef errno_t
+(*be_ptask_sync_t)(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct be_ctx *be_ctx,
+ struct be_ptask *be_ptask,
+ void *pvt);
+
+/**
* The first execution is scheduled first_delay seconds after the task is
* created.
*
@@ -85,6 +96,18 @@ errno_t be_ptask_create(TALLOC_CTX *mem_ctx,
const char *name,
struct be_ptask **_task);
+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);
+
void be_ptask_enable(struct be_ptask *task);
void be_ptask_disable(struct be_ptask *task);
void be_ptask_destroy(struct be_ptask **task);