From d4f7ed69dbd3aad3be2c52d2da5f75af6d32e3c0 Mon Sep 17 00:00:00 2001
From: Alexey Tikhonov <atikhono@redhat.com>
Date: Mon, 13 Feb 2023 17:48:41 +0100
Subject: [PATCH] MONITOR: fix `socket_activated` flag initialization
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

When socket activated service connects for the first time, it is added to
`mt_ctx->svc_list` by `socket_activated_service_not_found()` with a proper
`socket_activated = true`.
But when it reconnects again, `get_service_in_the_list()` finds it in
`mt_ctx->svc_list` and overwrites `socket_activated = false` unconditionally.
This patch moves `socket_activated = false` to `start_service()`.

Resolves: https://github.com/SSSD/sssd/issues/6324

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
---
 src/monitor/monitor.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/monitor/monitor.c b/src/monitor/monitor.c
index 6d3d05cd3..0972465f9 100644
--- a/src/monitor/monitor.c
+++ b/src/monitor/monitor.c
@@ -242,7 +242,6 @@ get_service_in_the_list(struct mt_ctx *mt_ctx,
 
     for (svc = mt_ctx->svc_list; svc != NULL; svc = svc->next) {
         if (strcasecmp(svc->identity, svc_name) == 0) {
-            svc->socket_activated = false;
             *_svc = svc;
             return EOK;
         }
@@ -1802,6 +1801,8 @@ static int start_service(struct mt_svc *svc)
 
     DEBUG(SSSDBG_CONF_SETTINGS,"Queueing service %s for startup\n", svc->name);
 
+    svc->socket_activated = false;
+
     tv = tevent_timeval_current();
 
     /* Add a timed event to start up the service.
-- 
2.27.0

