From afc7d974d9e92bfa6f5b197945fdf6ebea3fb6bc Mon Sep 17 00:00:00 2001
From: Gleb Popov <6yearold@gmail.com>
Date: Sat, 21 Feb 2026 20:34:18 +0300
Subject: [PATCH] sdap_select_principal_from_keytab_sync: waitpid()
 synchronously

Without this change the ldap_child process started by this function ends up
in the <defunct> state. kernel trace hints that the process isn't fully
finished by the time waitpid is called:

 13126 sssd_be  CALL  wait4(13127,0,0x1<WNOHANG>,0)
 13126 sssd_be  RET   wait4 0
waitpid(ldap_child) failed, process might be leaking

According to man waitpid(3), the function returns 0 when passed WNOHANG and
there is no child process that can be reported as exited. Omitting WNOHANG
fixes the issue.

Reviewed-by: Alexey Tikhonov <atikhono@redhat.com>
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
---
 src/providers/ldap/sdap_child_helpers.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/providers/ldap/sdap_child_helpers.c b/src/providers/ldap/sdap_child_helpers.c
index 1e66505c2..b87eda9bd 100644
--- a/src/providers/ldap/sdap_child_helpers.c
+++ b/src/providers/ldap/sdap_child_helpers.c
@@ -374,9 +374,9 @@ errno_t sdap_select_principal_from_keytab_sync(TALLOC_CTX *mem_ctx,
 
     sdap_close_fd(&child->io->read_from_child_fd);
 
-    if (waitpid(child->pid, NULL, WNOHANG) != child->pid) {
-        DEBUG(SSSDBG_MINOR_FAILURE, "waitpid(ldap_child) failed, "
-              "process might be leaking\n");
+    if (waitpid(child->pid, NULL, 0) != child->pid) {
+        DEBUG(SSSDBG_CRIT_FAILURE, "waitpid(ldap_child) failed: [%d][%s]\n",
+              errno, strerror(errno));
     }
 
     ret = parse_select_principal_response(mem_ctx, response, len,
-- 
2.53.0

