Blob Blame History Raw
From 739910de98cfc6c1c8764855703a6a8315bb09c6 Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek@redhat.com>
Date: Mon, 20 May 2019 22:32:13 +0200
Subject: [PATCH 48/64] 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>
(cherry picked from commit bb0bd61ac54dca429b6562e808755152d4c90ce7)

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 17513111c..8dbddbb5f 100644
--- a/src/providers/data_provider_be.c
+++ b/src/providers/data_provider_be.c
@@ -431,7 +431,6 @@ errno_t be_process_init(TALLOC_CTX *mem_ctx,
                         struct tevent_context *ev,
                         struct confdb_ctx *cdb)
 {
-    uint32_t refresh_interval;
     struct tevent_signal *tes;
     struct be_ctx *be_ctx;
     char *str = NULL;
@@ -531,19 +530,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;
-        }
-    }
-
     ret = dp_init(be_ctx->ev, be_ctx, be_ctx->uid, be_ctx->gid);
     if (ret != EOK) {
         DEBUG(SSSDBG_FATAL_FAILURE, "Unable to setup data provider "
-- 
2.20.1