dpward / rpms / sssd

Forked from rpms/sssd 3 years ago
Clone
Blob Blame History Raw
From 47c33b9c8b8613956ed4687d58e26cb9fe7dc9eb Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek@redhat.com>
Date: Mon, 20 May 2019 22:32:13 +0200
Subject: [PATCH 29/48] BE: Make be_refresh_ctx_init set up the periodical
 task, too

This is mostly a preparatory patch that rolls in setting up the ptask
into be_refresh_ctx_init. Since in later patches we will call
be_refresh_ctx_init from several different places, this will prevent
code duplication.

Related:
https://pagure.io/SSSD/sssd/issue/4012

Reviewed-by: Sumit Bose <sbose@redhat.com>
---
 src/providers/be_refresh.c       | 21 +++++++++++++++++++--
 src/providers/be_refresh.h       |  2 +-
 src/providers/data_provider_be.c | 14 --------------
 3 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/src/providers/be_refresh.c b/src/providers/be_refresh.c
index 02e478c95..c7b048a95 100644
--- a/src/providers/be_refresh.c
+++ b/src/providers/be_refresh.c
@@ -134,11 +134,13 @@ struct be_refresh_ctx {
     struct be_refresh_cb callbacks[BE_REFRESH_TYPE_SENTINEL];
 };
 
-struct be_refresh_ctx *be_refresh_ctx_init(TALLOC_CTX *mem_ctx)
+struct be_refresh_ctx *be_refresh_ctx_init(struct be_ctx *be_ctx)
 {
     struct be_refresh_ctx *ctx = NULL;
+    uint32_t refresh_interval;
+    errno_t ret;
 
-    ctx = talloc_zero(mem_ctx, struct be_refresh_ctx);
+    ctx = talloc_zero(be_ctx, struct be_refresh_ctx);
     if (ctx == NULL) {
         return NULL;
     }
@@ -147,6 +149,21 @@ struct be_refresh_ctx *be_refresh_ctx_init(TALLOC_CTX *mem_ctx)
     ctx->callbacks[BE_REFRESH_TYPE_GROUPS].name = "groups";
     ctx->callbacks[BE_REFRESH_TYPE_NETGROUPS].name = "netgroups";
 
+    refresh_interval = be_ctx->domain->refresh_expired_interval;
+    if (refresh_interval > 0) {
+        ret = be_ptask_create(be_ctx, be_ctx, refresh_interval, 30, 5, 0,
+                              refresh_interval, BE_PTASK_OFFLINE_SKIP, 0,
+                              be_refresh_send, be_refresh_recv,
+                              be_ctx->refresh_ctx, "Refresh Records", NULL);
+        if (ret != EOK) {
+            DEBUG(SSSDBG_FATAL_FAILURE,
+                  "Unable to initialize refresh periodic task [%d]: %s\n",
+                  ret, sss_strerror(ret));
+            talloc_free(ctx);
+            return NULL;
+        }
+    }
+
     return ctx;
 }
 
diff --git a/src/providers/be_refresh.h b/src/providers/be_refresh.h
index 927fa4a33..664f01816 100644
--- a/src/providers/be_refresh.h
+++ b/src/providers/be_refresh.h
@@ -52,7 +52,7 @@ enum be_refresh_type {
 
 struct be_refresh_ctx;
 
-struct be_refresh_ctx *be_refresh_ctx_init(TALLOC_CTX *mem_ctx);
+struct be_refresh_ctx *be_refresh_ctx_init(struct be_ctx *be_ctx);
 
 errno_t be_refresh_add_cb(struct be_refresh_ctx *ctx,
                           enum be_refresh_type type,
diff --git a/src/providers/data_provider_be.c b/src/providers/data_provider_be.c
index db62efdc6..a1e7999c7 100644
--- a/src/providers/data_provider_be.c
+++ b/src/providers/data_provider_be.c
@@ -454,7 +454,6 @@ errno_t be_process_init(TALLOC_CTX *mem_ctx,
                         struct tevent_context *ev,
                         struct confdb_ctx *cdb)
 {
-    uint32_t refresh_interval;
     struct tevent_req *req;
     struct be_ctx *be_ctx;
     char *str = NULL;
@@ -545,19 +544,6 @@ errno_t be_process_init(TALLOC_CTX *mem_ctx,
         goto done;
     }
 
-    refresh_interval = be_ctx->domain->refresh_expired_interval;
-    if (refresh_interval > 0) {
-        ret = be_ptask_create(be_ctx, be_ctx, refresh_interval, 30, 5, 0,
-                              refresh_interval, BE_PTASK_OFFLINE_SKIP, 0,
-                              be_refresh_send, be_refresh_recv,
-                              be_ctx->refresh_ctx, "Refresh Records", NULL);
-        if (ret != EOK) {
-            DEBUG(SSSDBG_FATAL_FAILURE,
-                  "Unable to initialize refresh periodic task\n");
-            goto done;
-        }
-    }
-
     req = dp_init_send(be_ctx, be_ctx->ev, be_ctx, be_ctx->uid, be_ctx->gid);
     if (req == NULL) {
         ret = ENOMEM;
-- 
2.20.1