Blame SOURCES/0008-data-provider-run-offline-callbacks-only-once.patch

cdf651
From 2d350235bc960a91233d29b97c3a205bd2e04c08 Mon Sep 17 00:00:00 2001
cdf651
From: Sumit Bose <sbose@redhat.com>
cdf651
Date: Fri, 8 Jun 2018 18:42:28 +0200
cdf651
Subject: [PATCH] data provider: run offline callbacks only once
cdf651
cdf651
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
cdf651
(cherry picked from commit f28d995719db632130e9e063cb1ab7cb4e0fc8d8)
cdf651
---
cdf651
 src/providers/backend.h                 |  1 +
cdf651
 src/providers/data_provider_be.c        |  1 +
cdf651
 src/providers/data_provider_callbacks.c | 36 +++++++++++++++++++------
cdf651
 3 files changed, 30 insertions(+), 8 deletions(-)
cdf651
cdf651
diff --git a/src/providers/backend.h b/src/providers/backend.h
cdf651
index 1914274037ce7f7ff4b6d8486b041789a865fd59..6a34b91a911fc12163fa9448ea82ff93f5bf3849 100644
cdf651
--- a/src/providers/backend.h
cdf651
+++ b/src/providers/backend.h
cdf651
@@ -95,6 +95,7 @@ struct be_ctx {
cdf651
     struct be_cb *online_cb_list;
cdf651
     bool run_online_cb;
cdf651
     struct be_cb *offline_cb_list;
cdf651
+    bool run_offline_cb;
cdf651
     struct be_cb *reconnect_cb_list;
cdf651
     /* In contrast to online_cb_list which are only run if the backend is
cdf651
      * offline the unconditional_online_cb_list should be run whenever the
cdf651
diff --git a/src/providers/data_provider_be.c b/src/providers/data_provider_be.c
cdf651
index e8cddd976bb164dc6d4655bf2ebe9a03c3d9d26a..fad6f280195b615d1de45afaf0c459bdf78c8c0a 100644
cdf651
--- a/src/providers/data_provider_be.c
cdf651
+++ b/src/providers/data_provider_be.c
cdf651
@@ -219,6 +219,7 @@ static void be_reset_offline(struct be_ctx *ctx)
cdf651
 {
cdf651
     ctx->offstat.went_offline = 0;
cdf651
     ctx->offstat.offline = false;
cdf651
+    ctx->run_offline_cb = true;
cdf651
 
cdf651
     reactivate_subdoms(ctx->domain);
cdf651
 
cdf651
diff --git a/src/providers/data_provider_callbacks.c b/src/providers/data_provider_callbacks.c
cdf651
index 436357e228c0e1a689aa18b8ef41a82f63774d3a..24e125ea5be70208d7cf2cb06a80c39207e29db4 100644
cdf651
--- a/src/providers/data_provider_callbacks.c
cdf651
+++ b/src/providers/data_provider_callbacks.c
cdf651
@@ -265,22 +265,42 @@ void be_run_unconditional_online_cb(struct be_ctx *be)
cdf651
 int be_add_offline_cb(TALLOC_CTX *mem_ctx, struct be_ctx *ctx, be_callback_t cb,
cdf651
                       void *pvt, struct be_cb **offline_cb)
cdf651
 {
cdf651
-    return be_add_cb(mem_ctx, ctx, cb, pvt, &ctx->offline_cb_list, offline_cb);
cdf651
+    int ret;
cdf651
+
cdf651
+    ret = be_add_cb(mem_ctx, ctx, cb, pvt, &ctx->offline_cb_list, offline_cb);
cdf651
+    if (ret != EOK) {
cdf651
+        DEBUG(SSSDBG_CRIT_FAILURE, "be_add_cb failed.\n");
cdf651
+        return ret;
cdf651
+    }
cdf651
+
cdf651
+    /* Make sure we run the callback when SSSD goes offline */
cdf651
+    ctx->run_offline_cb = true;
cdf651
+
cdf651
+    return EOK;
cdf651
 }
cdf651
 
cdf651
 void be_run_offline_cb(struct be_ctx *be) {
cdf651
     int ret;
cdf651
 
cdf651
-    if (be->offline_cb_list) {
cdf651
-        DEBUG(SSSDBG_MINOR_FAILURE, "Going offline. Running callbacks.\n");
cdf651
+    if (be->run_offline_cb) {
cdf651
+        /* Reset the flag, we only want to run these callbacks once when going
cdf651
+         * offline */
cdf651
+        be->run_offline_cb = false;
cdf651
 
cdf651
-        ret = be_run_cb(be, be->offline_cb_list);
cdf651
-        if (ret != EOK) {
cdf651
-            DEBUG(SSSDBG_CRIT_FAILURE, "be_run_cb failed.\n");
cdf651
+        if (be->offline_cb_list) {
cdf651
+            DEBUG(SSSDBG_MINOR_FAILURE, "Going offline. Running callbacks.\n");
cdf651
+
cdf651
+            ret = be_run_cb(be, be->offline_cb_list);
cdf651
+            if (ret != EOK) {
cdf651
+                DEBUG(SSSDBG_CRIT_FAILURE, "be_run_cb failed.\n");
cdf651
+            }
cdf651
+
cdf651
+        } else {
cdf651
+            DEBUG(SSSDBG_TRACE_ALL,
cdf651
+                  "Offline call back list is empty, nothing to do.\n");
cdf651
         }
cdf651
-
cdf651
     } else {
cdf651
         DEBUG(SSSDBG_TRACE_ALL,
cdf651
-              "Offline call back list is empty, nothing to do.\n");
cdf651
+              "Flag indicates that offline callback were already called.\n");
cdf651
     }
cdf651
 }
cdf651
-- 
cdf651
2.17.1
cdf651