From 675617ecc823d4d3a1f6306d295874d76bf18fb1 Mon Sep 17 00:00:00 2001 From: Klaus Wenninger Date: Thu, 9 Dec 2021 11:25:22 +0100 Subject: [PATCH] Fix: ipc_client: use libqb async API for connect --- configure.ac | 3 +++ lib/common/ipc_client.c | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/configure.ac b/configure.ac index 31595c5d539..9603ca95ca7 100644 --- a/configure.ac +++ b/configure.ac @@ -1309,6 +1309,9 @@ PKG_CHECK_MODULES(libqb, libqb >= 0.17) CPPFLAGS="$libqb_CFLAGS $CPPFLAGS" LIBS="$libqb_LIBS $LIBS" +dnl libqb libqb-2.0.3 + ipc-connect-async-API (2022-01) +AC_CHECK_FUNCS([qb_ipcc_connect_async]) + dnl libqb 2.0.2+ (2020-10) AC_CHECK_FUNCS(qb_ipcc_auth_get, AC_DEFINE(HAVE_IPCC_AUTH_GET, 1, diff --git a/lib/common/ipc_client.c b/lib/common/ipc_client.c index 5106fb28444..f4524f3e4ee 100644 --- a/lib/common/ipc_client.c +++ b/lib/common/ipc_client.c @@ -1407,13 +1407,35 @@ pcmk__ipc_is_authentic_process_active(const char *name, uid_t refuid, int32_t qb_rc; pid_t found_pid = 0; uid_t found_uid = 0; gid_t found_gid = 0; qb_ipcc_connection_t *c; +#ifdef HAVE_QB_IPCC_CONNECT_ASYNC + struct pollfd pollfd = { 0, }; + int poll_rc; + c = qb_ipcc_connect_async(name, 0, + &(pollfd.fd)); +#else c = qb_ipcc_connect(name, 0); +#endif if (c == NULL) { crm_info("Could not connect to %s IPC: %s", name, strerror(errno)); rc = pcmk_rc_ipc_unresponsive; goto bail; } +#ifdef HAVE_QB_IPCC_CONNECT_ASYNC + pollfd.events = POLLIN; + do { + poll_rc = poll(&pollfd, 1, 2000); + } while ((poll_rc == -1) && (errno == EINTR)); + if ((poll_rc <= 0) || (qb_ipcc_connect_continue(c) != 0)) { + crm_info("Could not connect to %s IPC: %s", name, + (poll_rc == 0)?"timeout":strerror(errno)); + rc = pcmk_rc_ipc_unresponsive; + if (poll_rc > 0) { + c = NULL; // qb_ipcc_connect_continue cleaned up for us + } + goto bail; + } +#endif qb_rc = qb_ipcc_fd_get(c, &fd); if (qb_rc != 0) {