public inbox for openembedded-core@lists.openembedded.org
 help / color / mirror / Atom feed
From: Khem Raj <raj.khem@gmail.com>
To: openembedded-core@lists.openembedded.org
Cc: Khem Raj <raj.khem@gmail.com>
Subject: [PATCH] systemd: Make 254 work on musl
Date: Wed,  2 Aug 2023 21:55:08 -0700	[thread overview]
Message-ID: <20230803045508.80659-1-raj.khem@gmail.com> (raw)

Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 ...ake-malloc_trim-conditional-on-glibc.patch | 39 +++++++++++++++
 ...hared-Do-not-use-malloc_info-on-musl.patch | 50 +++++++++++++++++++
 meta/recipes-core/systemd/systemd_254.bb      |  2 +
 3 files changed, 91 insertions(+)
 create mode 100644 meta/recipes-core/systemd/systemd/0028-sd-event-Make-malloc_trim-conditional-on-glibc.patch
 create mode 100644 meta/recipes-core/systemd/systemd/0029-shared-Do-not-use-malloc_info-on-musl.patch

diff --git a/meta/recipes-core/systemd/systemd/0028-sd-event-Make-malloc_trim-conditional-on-glibc.patch b/meta/recipes-core/systemd/systemd/0028-sd-event-Make-malloc_trim-conditional-on-glibc.patch
new file mode 100644
index 00000000000..c9ec00012e8
--- /dev/null
+++ b/meta/recipes-core/systemd/systemd/0028-sd-event-Make-malloc_trim-conditional-on-glibc.patch
@@ -0,0 +1,39 @@
+From 148645ba8b62f04c7c5ff5907378663f97880f22 Mon Sep 17 00:00:00 2001
+From: Khem Raj <raj.khem@gmail.com>
+Date: Wed, 2 Aug 2023 12:06:27 -0700
+Subject: [PATCH 1/4] sd-event: Make malloc_trim() conditional on glibc
+
+musl does not have this API
+
+Upstream-Status: Inappropriate [musl-specific]
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+---
+ src/libsystemd/sd-event/sd-event.c | 4 +++-
+ 1 file changed, 3 insertions(+), 1 deletion(-)
+
+diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c
+index aba458185b..48c94a7672 100644
+--- a/src/libsystemd/sd-event/sd-event.c
++++ b/src/libsystemd/sd-event/sd-event.c
+@@ -1874,7 +1874,7 @@ _public_ int sd_event_add_exit(
+ }
+
+ _public_ int sd_event_trim_memory(void) {
+-        int r;
++        int r = 0;
+
+         /* A default implementation of a memory pressure callback. Simply releases our own allocation caches
+          * and glibc's. This is automatically used when people call sd_event_add_memory_pressure() with a
+@@ -1888,7 +1888,9 @@ _public_ int sd_event_trim_memory(void) {
+
+         usec_t before_timestamp = now(CLOCK_MONOTONIC);
+         hashmap_trim_pools();
++#ifdef __GLIBC__
+         r = malloc_trim(0);
++#endif
+         usec_t after_timestamp = now(CLOCK_MONOTONIC);
+
+         if (r > 0)
+--
+2.41.0
+
diff --git a/meta/recipes-core/systemd/systemd/0029-shared-Do-not-use-malloc_info-on-musl.patch b/meta/recipes-core/systemd/systemd/0029-shared-Do-not-use-malloc_info-on-musl.patch
new file mode 100644
index 00000000000..8e386551a19
--- /dev/null
+++ b/meta/recipes-core/systemd/systemd/0029-shared-Do-not-use-malloc_info-on-musl.patch
@@ -0,0 +1,50 @@
+From 9430646e72ea5d260ade300038a6d976fecf7da5 Mon Sep 17 00:00:00 2001
+From: Khem Raj <raj.khem@gmail.com>
+Date: Wed, 2 Aug 2023 12:20:40 -0700
+Subject: [PATCH 4/4] shared: Do not use malloc_info on musl
+
+Upstream-Status: Inappropriate [musl-specific]
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+---
+ src/shared/bus-util.c      | 5 +++--
+ src/shared/common-signal.c | 4 ++--
+ 2 files changed, 5 insertions(+), 4 deletions(-)
+
+--- a/src/shared/bus-util.c
++++ b/src/shared/bus-util.c
+@@ -617,15 +617,16 @@ static int method_dump_memory_state_by_f
+         _cleanup_close_ int fd = -EBADF;
+         size_t dump_size;
+         FILE *f;
+-        int r;
++        int r = 0;
+ 
+         assert(message);
+ 
+         f = memstream_init(&m);
+         if (!f)
+                 return -ENOMEM;
+-
++#ifdef __GLIBC__
+         r = RET_NERRNO(malloc_info(/* options= */ 0, f));
++#endif
+         if (r < 0)
+                 return r;
+ 
+--- a/src/shared/common-signal.c
++++ b/src/shared/common-signal.c
+@@ -65,12 +65,12 @@ int sigrtmin18_handler(sd_event_source *
+                         log_oom();
+                         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;
+         }
diff --git a/meta/recipes-core/systemd/systemd_254.bb b/meta/recipes-core/systemd/systemd_254.bb
index 7ba4233f6a2..ea1a4f02f05 100644
--- a/meta/recipes-core/systemd/systemd_254.bb
+++ b/meta/recipes-core/systemd/systemd_254.bb
@@ -53,6 +53,8 @@ SRC_URI_MUSL = "\
                file://0025-include-sys-file.h-for-LOCK_EX.patch \
                file://0026-test-test-sizeof-Include-sys-timex.h-for-struct-time.patch \
                file://0027-include-missing-sys-file.h-for-LOCK_EX.patch \
+               file://0028-sd-event-Make-malloc_trim-conditional-on-glibc.patch \
+               file://0029-shared-Do-not-use-malloc_info-on-musl.patch \
                "
 
 PAM_PLUGINS = " \
-- 
2.41.0



                 reply	other threads:[~2023-08-03  4:55 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230803045508.80659-1-raj.khem@gmail.com \
    --to=raj.khem@gmail.com \
    --cc=openembedded-core@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox