From bd97de8e9b8623b5486586c18b9f2233dc6828dd Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 6 Dec 2024 09:50:18 +0100 Subject: [PATCH] Revert "common/common.c: only close_sdbus_once() if we are the same PID that originally opened it [#1070]" This reverts commit a6496a6af1c1b90ca4b836bd0f0cf9c07d6ade3b: close from a child process does not seem to impact parent, but a non-close is a memory leak when such child exits. Signed-off-by: Jim Klimov --- common/common.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/common/common.c b/common/common.c index a51dfa5f27..b4f1b5456f 100644 --- a/common/common.c +++ b/common/common.c @@ -79,9 +79,6 @@ static int RET_NERRNO(int ret) { static /*_cleanup_(sd_bus_flush_close_unrefp)*/ sd_bus *systemd_bus = NULL; static int isSupported_Inhibit = -1, isSupported_Inhibit_errno = 0; static int isSupported_PreparingForSleep = -1, isSupported_PreparingForSleep_errno = 0; -/* We can end up forking after opening the SD BUS (e.g. for notifications - * from upsmon) - only the original process should close its own connection */ -static pid_t sdbusOpenedByPID = 0; static void close_sdbus_once(void) { /* Per https://manpages.debian.org/testing/libsystemd-dev/sd_bus_flush_close_unrefp.3.en.html @@ -94,13 +91,6 @@ static void close_sdbus_once(void) { return; } - if (sdbusOpenedByPID && sdbusOpenedByPID != getpid()) { - upsdebugx(3, "%s: skip actual closing (not our connection, likely parent's, just forget it)", __func__); - errno = 0; - systemd_bus = NULL; - return; - } - upsdebugx(1, "%s: trying", __func__); errno = 0; sd_bus_flush_close_unrefp(&systemd_bus); @@ -136,10 +126,6 @@ static int open_sdbus_once(const char *caller) { } else { upsdebugx(1, "%s: succeeded for %s", __func__, NUT_STRARG(caller)); faultReported = 0; - - /* track if we are still the process who owns the bus connection - * by the time we get to close it */ - sdbusOpenedByPID = getpid(); } if (systemd_bus && !openedOnce) {