Skip to content

Commit

Permalink
Revert "common/common.c: only close_sdbus_once() if we are the same P…
Browse files Browse the repository at this point in the history
…ID that originally opened it [networkupstools#1070]"

This reverts commit a6496a6:
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 <[email protected]>
  • Loading branch information
jimklimov committed Dec 6, 2024
1 parent a36bc24 commit bd97de8
Showing 1 changed file with 0 additions and 14 deletions.
14 changes: 0 additions & 14 deletions common/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit bd97de8

Please sign in to comment.