Skip to contentSkip to conversation

systemd: Fix build on musl

PATCH New Khem Raj 1 participant 2 messages Oct 27, 2017

lore
Share & tools
lore

Khem Raj

author
#0 lore raw

PATCH v2 1/2 systemd: Fix build on musl

Add needed patches for portability across glibc/musl enable systemd on musl too

Disable utmp,ldconfig,nss,resolved,localed for musl which is not supported on musl

---
Changes since V1: Don't duplicate main SRC_URI

 ...PATH_WTMPX-and-_PATH_UTMPX-if-not-defined.patch |  43 ++
 ...llback-parse_printf_format-implementation.patch | 433 +++++++++++++++++++++
 ...asic-missing.h-check-for-missing-strndupa.patch | 104 +++++
 ...if-GLOB_BRACE-and-GLOB_ALTDIRFUNC-is-not-.patch | 157 ++++++++
 ...issing.h-check-for-missing-__compar_fn_t-.patch |  47 +++
 .../systemd/0006-Include-netinet-if_ether.h.patch  |  86 ++++
 ...-check-for-missing-canonicalize_file_name.patch |  63 +++
 .../systemd/0008-Do-not-enable-nss-tests.patch     |  35 ++
 ...xdecoct.c-Include-missing.h-form-strndupa.patch |  27 ++
 ....c-Disable-tests-for-missing-typedefs-in-.patch |  49 +++
 .../0011-don-t-use-glibc-specific-qsort_r.patch    | 105 +++++
 ...ass-AT_SYMLINK_NOFOLLOW-flag-to-faccessat.patch |  99 +++++
 ...fn_t-is-glibc-specific-use-raw-signature-.patch |  31 ++
 meta/recipes-core/systemd/systemd_234.bb           |  26 +-
 14 files changed, 1299 insertions(+), 6 deletions(-)
 create mode 100644 meta/recipes-core/systemd/systemd/0001-Define-_PATH_WTMPX-and-_PATH_UTMPX-if-not-defined.patch
 create mode 100644 meta/recipes-core/systemd/systemd/0001-add-fallback-parse_printf_format-implementation.patch
 create mode 100644 meta/recipes-core/systemd/systemd/0002-src-basic-missing.h-check-for-missing-strndupa.patch
 create mode 100644 meta/recipes-core/systemd/systemd/0003-don-t-fail-if-GLOB_BRACE-and-GLOB_ALTDIRFUNC-is-not-.patch
 create mode 100644 meta/recipes-core/systemd/systemd/0004-src-basic-missing.h-check-for-missing-__compar_fn_t-.patch
 create mode 100644 meta/recipes-core/systemd/systemd/0006-Include-netinet-if_ether.h.patch
 create mode 100644 meta/recipes-core/systemd/systemd/0007-check-for-missing-canonicalize_file_name.patch
 create mode 100644 meta/recipes-core/systemd/systemd/0008-Do-not-enable-nss-tests.patch
 create mode 100644 meta/recipes-core/systemd/systemd/0009-test-hexdecoct.c-Include-missing.h-form-strndupa.patch
 create mode 100644 meta/recipes-core/systemd/systemd/0010-test-sizeof.c-Disable-tests-for-missing-typedefs-in-.patch
 create mode 100644 meta/recipes-core/systemd/systemd/0011-don-t-use-glibc-specific-qsort_r.patch
 create mode 100644 meta/recipes-core/systemd/systemd/0012-don-t-pass-AT_SYMLINK_NOFOLLOW-flag-to-faccessat.patch
 create mode 100644 meta/recipes-core/systemd/systemd/0013-comparison_fn_t-is-glibc-specific-use-raw-signature-.patch
meta/recipes-core/systemd/systemd/0001-Define-_PATH_WTMPX-and-_PATH_UTMPX-if-not-defined.patch new file +43 -0
new file mode 100644
index 0000000000..35599d44c2
@@ -0,0 +1,43 @@
+From 3ca5326485cb19e775af6de615c17be66e44e472 Mon Sep 17 00:00:00 2001
+From: Khem Raj <[email protected]>
+Date: Tue, 24 Oct 2017 23:08:24 -0700
+Subject: [PATCH] Define _PATH_WTMPX and _PATH_UTMPX if not defined
+
+Musl needs these defines
+
+Signed-off-by: Khem Raj <[email protected]>
+---
+Upstream-Status: Pending
+
+ src/shared/utmp-wtmp.c | 8 ++++++++
+ 1 file changed, 8 insertions(+)
+
+diff --git a/src/shared/utmp-wtmp.c b/src/shared/utmp-wtmp.c
+index 9750dcd81..bd55d74a1 100644
+--- a/src/shared/utmp-wtmp.c
++++ b/src/shared/utmp-wtmp.c
+@@ -27,6 +27,7 @@
+ #include <sys/time.h>
+ #include <sys/utsname.h>
+ #include <unistd.h>
++#include <utmp.h>
+ #include <utmpx.h>
+ 
+ #include "alloc-util.h"
+@@ -41,6 +42,13 @@
+ #include "util.h"
+ #include "utmp-wtmp.h"
+ 
++#if defined _PATH_UTMP && !defined _PATH_UTMPX
++# define _PATH_UTMPX _PATH_UTMP
++#endif
++#if defined _PATH_WTMP && !defined _PATH_WTMPX
++# define _PATH_WTMPX _PATH_WTMP
++#endif
++
+ int utmp_get_runlevel(int *runlevel, int *previous) {
+         struct utmpx *found, lookup = { .ut_type = RUN_LVL };
+         int r;
+-- 
+2.14.3
+
meta/recipes-core/systemd/systemd/0001-add-fallback-parse_printf_format-implementation.patch new file +433 -0

433 lines not on this page · raw message

meta/recipes-core/systemd/systemd/0002-src-basic-missing.h-check-for-missing-strndupa.patch new file +104 -0

104 lines not on this page · raw message

meta/recipes-core/systemd/systemd/0003-don-t-fail-if-GLOB_BRACE-and-GLOB_ALTDIRFUNC-is-not-.patch new file +157 -0

157 lines not on this page · raw message

meta/recipes-core/systemd/systemd/0004-src-basic-missing.h-check-for-missing-__compar_fn_t-.patch new file +47 -0

47 lines not on this page · raw message

meta/recipes-core/systemd/systemd/0006-Include-netinet-if_ether.h.patch new file +86 -0

86 lines not on this page · raw message

meta/recipes-core/systemd/systemd/0007-check-for-missing-canonicalize_file_name.patch new file +63 -0

63 lines not on this page · raw message

meta/recipes-core/systemd/systemd/0008-Do-not-enable-nss-tests.patch new file +35 -0
new file mode 100644
index 0000000000..67a4f8e03e
@@ -0,0 +1,35 @@
+From 48e7c0f5b2f5d777a16ac5584dc4f50f1dfa832c Mon Sep 17 00:00:00 2001
+From: Khem Raj <[email protected]>
+Date: Mon, 23 Oct 2017 12:27:53 -0700
+Subject: [PATCH 08/12] Do not enable nss tests
+
+Signed-off-by: Khem Raj <[email protected]>
+---
+Upstream-Status: Pending
+
+ Makefile.am | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/Makefile.am b/Makefile.am
+index 3cc8f3451..df20a9a11 100644
+--- a/Makefile.am
++++ b/Makefile.am
+@@ -5290,6 +5290,7 @@ EXTRA_DIST += \
+ 	src/timesync/timesyncd.conf.in
+ 
+ # ------------------------------------------------------------------------------
++if ENABLE_NSS_SYSTEMD
+ test_nss_SOURCES = \
+ 	src/test/test-nss.c
+ 
+@@ -5302,7 +5303,6 @@ manual_tests += \
+ 	test-nss
+ 
+ # ------------------------------------------------------------------------------
+-if ENABLE_NSS_SYSTEMD
+ libnss_systemd_la_SOURCES = \
+ 	src/nss-systemd/nss-systemd.sym \
+ 	src/nss-systemd/nss-systemd.c
+-- 
+2.14.2
+
meta/recipes-core/systemd/systemd/0009-test-hexdecoct.c-Include-missing.h-form-strndupa.patch new file +27 -0
new file mode 100644
index 0000000000..d3694dcbd5
@@ -0,0 +1,27 @@
+From 75f4e7f167de533a160ee1af2a03fba4c5a5ffc6 Mon Sep 17 00:00:00 2001
+From: Khem Raj <[email protected]>
+Date: Mon, 23 Oct 2017 12:33:22 -0700
+Subject: [PATCH 09/12] test-hexdecoct.c: Include missing.h form strndupa
+
+Signed-off-by: Khem Raj <[email protected]>
+---
+Upstream-Status: Pending
+
+ src/test/test-hexdecoct.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/src/test/test-hexdecoct.c b/src/test/test-hexdecoct.c
+index fcae427e7..5eb5e2ed7 100644
+--- a/src/test/test-hexdecoct.c
++++ b/src/test/test-hexdecoct.c
+@@ -21,6 +21,7 @@
+ #include "hexdecoct.h"
+ #include "macro.h"
+ #include "string-util.h"
++#include "missing.h"
+ 
+ static void test_hexchar(void) {
+         assert_se(hexchar(0xa) == 'a');
+-- 
+2.14.2
+
meta/recipes-core/systemd/systemd/0010-test-sizeof.c-Disable-tests-for-missing-typedefs-in-.patch new file +49 -0

49 lines not on this page · raw message

meta/recipes-core/systemd/systemd/0011-don-t-use-glibc-specific-qsort_r.patch new file +105 -0

105 lines not on this page · raw message

meta/recipes-core/systemd/systemd/0012-don-t-pass-AT_SYMLINK_NOFOLLOW-flag-to-faccessat.patch new file +99 -0

99 lines not on this page · raw message

meta/recipes-core/systemd/systemd/0013-comparison_fn_t-is-glibc-specific-use-raw-signature-.patch new file +31 -0
new file mode 100644
index 0000000000..e219981ab0
@@ -0,0 +1,31 @@
+From 4b6733544beb662a0f77310302fae1fb7b76d167 Mon Sep 17 00:00:00 2001
+From: Khem Raj <[email protected]>
+Date: Sat, 12 Sep 2015 18:53:31 +0000
+Subject: [PATCH 13/13] comparison_fn_t is glibc specific, use raw signature in
+ function pointer
+
+make it work with musl where comparison_fn_t is not provided
+
+Signed-off-by: Khem Raj <[email protected]>
+---
+Upstream-Status: Pending
+
+ src/basic/util.h | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/src/basic/util.h b/src/basic/util.h
+index c7da6c39b..87f62b891 100644
+--- a/src/basic/util.h
++++ b/src/basic/util.h
+@@ -98,7 +98,7 @@ void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size,
+  * Normal qsort requires base to be nonnull. Here were require
+  * that only if nmemb > 0.
+  */
+-static inline void qsort_safe(void *base, size_t nmemb, size_t size, comparison_fn_t compar) {
++static inline void qsort_safe(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *)) {
+         if (nmemb <= 1)
+                 return;
+ 
+-- 
+2.14.2
+
meta/recipes-core/systemd/systemd_234.bb +20 -6
index 971226ff7c..3867986765 100644
@@ -27,6 +27,19 @@ SRC_URI += " \
            file://0017-remove-duplicate-include-uchar.h.patch \
            file://0018-check-for-uchar.h-in-configure.patch \
            file://0019-socket-util-don-t-fail-if-libc-doesn-t-support-IDN.patch \
+           file://0001-add-fallback-parse_printf_format-implementation.patch \
+           file://0002-src-basic-missing.h-check-for-missing-strndupa.patch \
+           file://0003-don-t-fail-if-GLOB_BRACE-and-GLOB_ALTDIRFUNC-is-not-.patch \
+           file://0004-src-basic-missing.h-check-for-missing-__compar_fn_t-.patch \
+           file://0006-Include-netinet-if_ether.h.patch \
+           file://0007-check-for-missing-canonicalize_file_name.patch \
+           file://0008-Do-not-enable-nss-tests.patch \
+           file://0009-test-hexdecoct.c-Include-missing.h-form-strndupa.patch \
+           file://0010-test-sizeof.c-Disable-tests-for-missing-typedefs-in-.patch \
+           file://0011-don-t-use-glibc-specific-qsort_r.patch \
+           file://0012-don-t-pass-AT_SYMLINK_NOFOLLOW-flag-to-faccessat.patch \
+           file://0013-comparison_fn_t-is-glibc-specific-use-raw-signature-.patch \
+           file://0001-Define-_PATH_WTMPX-and-_PATH_UTMPX-if-not-defined.patch \
            "
 SRC_URI_append_qemuall = " file://0001-core-device.c-Change-the-default-device-timeout-to-2.patch"
 
@@ -47,7 +60,8 @@ PACKAGECONFIG ??= "xz \
                    vconsole \
                    quotacheck \
                    hostnamed \
-                   ${@bb.utils.contains('TCLIBC', 'glibc', 'myhostname sysusers', '', d)} \
+                   ${@bb.utils.contains('TCLIBC', 'glibc', 'myhostname sysusers utmp', '', d)} \
+                   nss \
                    hibernate \
                    timedated \
                    timesyncd \
@@ -56,13 +70,16 @@ PACKAGECONFIG ??= "xz \
                    smack \
                    logind \
                    firstboot \
-                   utmp \
                    polkit \
                    resolved \
                    networkd \
 "
 PACKAGECONFIG_remove_libc-musl = "selinux"
 PACKAGECONFIG_remove_libc-musl = "smack"
+PACKAGECONFIG_remove_libc-musl = "resolved"
+PACKAGECONFIG_remove_libc-musl = "nss"
+PACKAGECONFIG_remove_libc-musl = "localed"
+PACKAGECONFIG_remove_libc-musl = "ldconfig"
 
 # Use the upstream systemd [email protected] and rely on
 # systemd-getty-generator instead of using the OE-core specific
@@ -83,6 +100,7 @@ PACKAGECONFIG[vconsole] = "--enable-vconsole,--disable-vconsole,,${PN}-vconsole-
 PACKAGECONFIG[quotacheck] = "--enable-quotacheck,--disable-quotacheck"
 PACKAGECONFIG[hostnamed] = "--enable-hostnamed,--disable-hostnamed"
 PACKAGECONFIG[myhostname] = "--enable-myhostname,--disable-myhostname"
+PACKAGECONFIG[nss] = "--enable-nss-systemd,--disable-nss-systemd"
 PACKAGECONFIG[rfkill] = "--enable-rfkill,--disable-rfkill"
 PACKAGECONFIG[hibernate] = "--enable-hibernate,--disable-hibernate"
 PACKAGECONFIG[timedated] = "--enable-timedated,--disable-timedated"
@@ -612,8 +630,4 @@ pkg_prerm_udev-hwdb () {
 python () {
     if not bb.utils.contains ('DISTRO_FEATURES', 'systemd', True, False, d):
         raise bb.parse.SkipPackage("'systemd' not in DISTRO_FEATURES")
-
-    import re
-    if re.match('.*musl*', d.getVar('TARGET_OS')) != None:
-        raise bb.parse.SkipPackage("Not _yet_ supported on musl based targets")
 }
Signature · 1 line
2.14.3
author
#1 lore raw

PATCH 2/2 systemd: Fix build with musl/mips64

---
 .../0001-Use-uintmax_t-for-handling-rlim_t.patch   | 89 ++++++++++++++++++++++
 meta/recipes-core/systemd/systemd_234.bb           |  1 +
 2 files changed, 90 insertions(+)
 create mode 100644 meta/recipes-core/systemd/systemd/0001-Use-uintmax_t-for-handling-rlim_t.patch
meta/recipes-core/systemd/systemd/0001-Use-uintmax_t-for-handling-rlim_t.patch new file +89 -0
new file mode 100644
index 0000000000..779dc78fd3
@@ -0,0 +1,89 @@
+From b2d4171c6e521cf1e70331fb769234d63a4a6d44 Mon Sep 17 00:00:00 2001
+From: Khem Raj <[email protected]>
+Date: Fri, 27 Oct 2017 13:00:41 -0700
+Subject: [PATCH] Use uintmax_t for handling rlim_t
+
+PRIu{32,64} is not right format to represent rlim_t type
+therefore use %ju and typecast the rlim_t variables to
+uintmax_t.
+
+Fixes portablility errors like
+
+execute.c:3446:36: error: format '%lu' expects argument of type 'long unsigned int', but argument 5 has type 'rlim_t {aka long long unsigned int}' [-Werror=format=]
+|                          fprintf(f, "%s%s: " RLIM_FMT "\n",
+|                                     ^~~~~~~~
+|                                  prefix, rlimit_to_string(i), c->rlimit[i]->rlim_max);
+|                                                               ~~~~~~~~~~~~~~~~~~~~~~
+
+Signed-off-by: Khem Raj <[email protected]>
+---
+Upstream-Status: Submitted [https://github.com/systemd/systemd/pull/7199]
+
+ src/basic/format-util.h | 8 --------
+ src/basic/rlimit-util.c | 8 ++++----
+ src/core/execute.c      | 8 ++++----
+ 3 files changed, 8 insertions(+), 16 deletions(-)
+
+diff --git a/src/basic/format-util.h b/src/basic/format-util.h
+index ae42a8f89..144249cd6 100644
+--- a/src/basic/format-util.h
++++ b/src/basic/format-util.h
+@@ -60,14 +60,6 @@
+ #  define PRI_TIMEX "li"
+ #endif
+ 
+-#if SIZEOF_RLIM_T == 8
+-#  define RLIM_FMT "%" PRIu64
+-#elif SIZEOF_RLIM_T == 4
+-#  define RLIM_FMT "%" PRIu32
+-#else
+-#  error Unknown rlim_t size
+-#endif
+-
+ #if SIZEOF_DEV_T == 8
+ #  define DEV_FMT "%" PRIu64
+ #elif SIZEOF_DEV_T == 4
+diff --git a/src/basic/rlimit-util.c b/src/basic/rlimit-util.c
+index ca834df62..41fcebb74 100644
+--- a/src/basic/rlimit-util.c
++++ b/src/basic/rlimit-util.c
+@@ -284,13 +284,13 @@ int rlimit_format(const struct rlimit *rl, char **ret) {
+         if (rl->rlim_cur >= RLIM_INFINITY && rl->rlim_max >= RLIM_INFINITY)
+                 s = strdup("infinity");
+         else if (rl->rlim_cur >= RLIM_INFINITY)
+-                (void) asprintf(&s, "infinity:" RLIM_FMT, rl->rlim_max);
++                (void) asprintf(&s, "infinity:%ju", (uintmax_t)rl->rlim_max);
+         else if (rl->rlim_max >= RLIM_INFINITY)
+-                (void) asprintf(&s, RLIM_FMT ":infinity", rl->rlim_cur);
++                (void) asprintf(&s, "%ju:infinity", (uintmax_t)rl->rlim_cur);
+         else if (rl->rlim_cur == rl->rlim_max)
+-                (void) asprintf(&s, RLIM_FMT, rl->rlim_cur);
++                (void) asprintf(&s, "%ju", (uintmax_t)rl->rlim_cur);
+         else
+-                (void) asprintf(&s, RLIM_FMT ":" RLIM_FMT, rl->rlim_cur, rl->rlim_max);
++                (void) asprintf(&s, "%ju:%ju", (uintmax_t)rl->rlim_cur, (uintmax_t)rl->rlim_max);
+ 
+         if (!s)
+                 return -ENOMEM;
+diff --git a/src/core/execute.c b/src/core/execute.c
+index d72e5bf08..d38946002 100644
+--- a/src/core/execute.c
++++ b/src/core/execute.c
+@@ -3443,10 +3443,10 @@ void exec_context_dump(ExecContext *c, FILE* f, const char *prefix) {
+ 
+         for (i = 0; i < RLIM_NLIMITS; i++)
+                 if (c->rlimit[i]) {
+-                        fprintf(f, "%s%s: " RLIM_FMT "\n",
+-                                prefix, rlimit_to_string(i), c->rlimit[i]->rlim_max);
+-                        fprintf(f, "%s%sSoft: " RLIM_FMT "\n",
+-                                prefix, rlimit_to_string(i), c->rlimit[i]->rlim_cur);
++                        fprintf(f, "%s%s: %ju\n",
++                                prefix, rlimit_to_string(i), (uintmax_t)c->rlimit[i]->rlim_max);
++                        fprintf(f, "%s%sSoft: %ju\n",
++                                prefix, rlimit_to_string(i), (uintmax_t)c->rlimit[i]->rlim_cur);
+                 }
+ 
+         if (c->ioprio_set) {
+-- 
+2.14.3
+
meta/recipes-core/systemd/systemd_234.bb +1 -0
index 3867986765..e2e42d61b6 100644
@@ -40,6 +40,7 @@ SRC_URI += " \
            file://0012-don-t-pass-AT_SYMLINK_NOFOLLOW-flag-to-faccessat.patch \
            file://0013-comparison_fn_t-is-glibc-specific-use-raw-signature-.patch \
            file://0001-Define-_PATH_WTMPX-and-_PATH_UTMPX-if-not-defined.patch \
+           file://0001-Use-uintmax_t-for-handling-rlim_t.patch \
            "
 SRC_URI_append_qemuall = " file://0001-core-device.c-Change-the-default-device-timeout-to-2.patch"
 
Signature · 1 line
2.14.3