From aa166c09ba2b70fa093a6ca1d2995e461b16a4c0 Mon Sep 17 00:00:00 2001
From: "A. Wilcox" <AWilcox@Wilcox-Tech.com>
Date: Sun, 18 Aug 2024 03:08:13 -0500
Subject: [PATCH 21/34] Don't use malloc_trim or malloc_info
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit

The musl allocator does not define these functions.

This probably cannot be upstreamed.

Signed-off-by: Alexander Miroshnichenko <alex@millerson.name>
---
 src/libsystemd/sd-event/sd-event.c | 2 +-
 src/shared/bus-util.c              | 4 +++-
 src/shared/common-signal.c         | 2 ++
 3 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c
index 73a95e7fa135..c62dc07165ab 100644
--- a/src/libsystemd/sd-event/sd-event.c
+++ b/src/libsystemd/sd-event/sd-event.c
@@ -1891,7 +1891,7 @@ _public_ int sd_event_trim_memory(void) {
 
         usec_t before_timestamp = now(CLOCK_MONOTONIC);
         hashmap_trim_pools();
-        r = malloc_trim(0);
+        r = 0;
         usec_t after_timestamp = now(CLOCK_MONOTONIC);
 
         if (r > 0)
diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c
index 30f9602b1edb..b1a8da36612b 100644
--- a/src/shared/bus-util.c
+++ b/src/shared/bus-util.c
@@ -755,7 +755,7 @@ static int method_dump_memory_state_by_fd(sd_bus_message *message, void *userdat
         _cleanup_close_ int fd = -EBADF;
         size_t dump_size;
         FILE *f;
-        int r;
+        int r = 0;
 
         assert(message);
 
@@ -763,7 +763,9 @@ static int method_dump_memory_state_by_fd(sd_bus_message *message, void *userdat
         if (!f)
                 return -ENOMEM;
 
+#ifdef __GLIBC__
         r = RET_NERRNO(malloc_info(/* options= */ 0, f));
+#endif
         if (r < 0)
                 return r;
 
diff --git a/src/shared/common-signal.c b/src/shared/common-signal.c
index 8e70e365dd69..bb68fc56b664 100644
--- a/src/shared/common-signal.c
+++ b/src/shared/common-signal.c
@@ -66,10 +66,12 @@ int sigrtmin18_handler(sd_event_source *s, const struct signalfd_siginfo *si, vo
                         break;
                 }
 
+#ifdef __GLIBC__
                 if (malloc_info(0, f) < 0) {
                         log_error_errno(errno, "Failed to invoke malloc_info(): %m");
                         break;
                 }
+#endif
 
                 (void) memstream_dump(LOG_INFO, &m);
                 break;
-- 
2.41.0

