Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame^] | 1 | From a89c2e6d40606f563467a83fb98933e990e71377 Mon Sep 17 00:00:00 2001 |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 2 | From: =?UTF-8?q?Andreas=20M=C3=BCller?= <schnitzeltony@gmail.com> |
| 3 | Date: Tue, 2 Apr 2019 01:34:35 +0200 |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame^] | 4 | Subject: [PATCH] Fix build with musl - systemd specific |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 5 | MIME-Version: 1.0 |
| 6 | Content-Type: text/plain; charset=UTF-8 |
| 7 | Content-Transfer-Encoding: 8bit |
| 8 | |
| 9 | Networkmanager imported some code from systemd. This requires some adjustments |
| 10 | for musl. |
| 11 | |
| 12 | Upstream-Status: Pending |
| 13 | |
| 14 | Signed-off-by: Andreas Müller <schnitzeltony@gmail.com> |
| 15 | --- |
| 16 | shared/systemd/src/basic/in-addr-util.c | 1 + |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame^] | 17 | shared/systemd/src/basic/process-util.c | 9 +++++++++ |
| 18 | shared/systemd/src/basic/socket-util.h | 6 ++++++ |
| 19 | shared/systemd/src/basic/sort-util.h | 27 ++++--------------------- |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 20 | shared/systemd/src/basic/stdio-util.h | 2 ++ |
| 21 | shared/systemd/src/basic/string-util.h | 5 +++++ |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame^] | 22 | 6 files changed, 27 insertions(+), 23 deletions(-) |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 23 | |
| 24 | diff --git a/shared/systemd/src/basic/in-addr-util.c b/shared/systemd/src/basic/in-addr-util.c |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame^] | 25 | index 5899f62..0adb248 100644 |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 26 | --- a/shared/systemd/src/basic/in-addr-util.c |
| 27 | +++ b/shared/systemd/src/basic/in-addr-util.c |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame^] | 28 | @@ -14,6 +14,7 @@ |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 29 | #include "in-addr-util.h" |
| 30 | #include "macro.h" |
| 31 | #include "parse-util.h" |
| 32 | +#include "string-util.h" |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame^] | 33 | #include "random-util.h" |
| 34 | #include "strxcpyx.h" |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 35 | #include "util.h" |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 36 | diff --git a/shared/systemd/src/basic/process-util.c b/shared/systemd/src/basic/process-util.c |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame^] | 37 | index 7431be3..189060a 100644 |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 38 | --- a/shared/systemd/src/basic/process-util.c |
| 39 | +++ b/shared/systemd/src/basic/process-util.c |
| 40 | @@ -21,6 +21,9 @@ |
| 41 | #include <sys/wait.h> |
| 42 | #include <syslog.h> |
| 43 | #include <unistd.h> |
| 44 | +#ifndef __GLIBC__ |
| 45 | +#include <pthread.h> |
| 46 | +#endif |
| 47 | #if 0 /* NM_IGNORED */ |
| 48 | #if HAVE_VALGRIND_VALGRIND_H |
| 49 | #include <valgrind/valgrind.h> |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame^] | 50 | @@ -1183,11 +1186,13 @@ void reset_cached_pid(void) { |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 51 | cached_pid = CACHED_PID_UNSET; |
| 52 | } |
| 53 | |
| 54 | +#ifdef __GLIBC__ |
| 55 | /* We use glibc __register_atfork() + __dso_handle directly here, as they are not included in the glibc |
| 56 | * headers. __register_atfork() is mostly equivalent to pthread_atfork(), but doesn't require us to link against |
| 57 | * libpthread, as it is part of glibc anyway. */ |
| 58 | extern int __register_atfork(void (*prepare) (void), void (*parent) (void), void (*child) (void), void *dso_handle); |
| 59 | extern void* __dso_handle _weak_; |
| 60 | +#endif |
| 61 | |
| 62 | pid_t getpid_cached(void) { |
| 63 | static bool installed = false; |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame^] | 64 | @@ -1216,7 +1221,11 @@ pid_t getpid_cached(void) { |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 65 | * only half-documented (glibc doesn't document it but LSB does — though only superficially) |
| 66 | * we'll check for errors only in the most generic fashion possible. */ |
| 67 | |
| 68 | +#ifdef __GLIBC__ |
| 69 | if (__register_atfork(NULL, NULL, reset_cached_pid, __dso_handle) != 0) { |
| 70 | +#else |
| 71 | + if (pthread_atfork(NULL, NULL, reset_cached_pid) != 0) { |
| 72 | +#endif |
| 73 | /* OOM? Let's try again later */ |
| 74 | cached_pid = CACHED_PID_UNSET; |
| 75 | return new_pid; |
| 76 | diff --git a/shared/systemd/src/basic/socket-util.h b/shared/systemd/src/basic/socket-util.h |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame^] | 77 | index 15443f1..4807198 100644 |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 78 | --- a/shared/systemd/src/basic/socket-util.h |
| 79 | +++ b/shared/systemd/src/basic/socket-util.h |
| 80 | @@ -13,6 +13,12 @@ |
| 81 | #include <sys/types.h> |
| 82 | #include <sys/un.h> |
| 83 | |
| 84 | +#if !defined(__GLIBC__) |
| 85 | +/* SIOCGSTAMPNS from linux/asm-generic.h |
| 86 | + * for src/systemd/src/libsystemd-network/sd-lldp.c */ |
| 87 | +#include <linux/sockios.h> |
| 88 | +#endif |
| 89 | + |
| 90 | #include "macro.h" |
| 91 | #include "missing_socket.h" |
| 92 | #include "sparse-endian.h" |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame^] | 93 | diff --git a/shared/systemd/src/basic/sort-util.h b/shared/systemd/src/basic/sort-util.h |
| 94 | index e029f86..1e8b6e1 100644 |
| 95 | --- a/shared/systemd/src/basic/sort-util.h |
| 96 | +++ b/shared/systemd/src/basic/sort-util.h |
| 97 | @@ -5,15 +5,10 @@ |
| 98 | |
| 99 | #include "macro.h" |
| 100 | |
| 101 | -void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size, |
| 102 | - __compar_d_fn_t compar, void *arg); |
| 103 | - |
| 104 | -#define typesafe_bsearch_r(k, b, n, func, userdata) \ |
| 105 | - ({ \ |
| 106 | - const typeof(b[0]) *_k = k; \ |
| 107 | - int (*_func_)(const typeof(b[0])*, const typeof(b[0])*, typeof(userdata)) = func; \ |
| 108 | - xbsearch_r((const void*) _k, (b), (n), sizeof((b)[0]), (__compar_d_fn_t) _func_, userdata); \ |
| 109 | - }) |
| 110 | +#if !defined(__GLIBC__) |
| 111 | +typedef int (*__compar_fn_t) (const void*, const void*); |
| 112 | +typedef __compar_fn_t comparison_fn_t; |
| 113 | +#endif |
| 114 | |
| 115 | /** |
| 116 | * Normal bsearch requires base to be nonnull. Here were require |
| 117 | @@ -54,17 +49,3 @@ static inline void qsort_safe(void *base, size_t nmemb, size_t size, __compar_fn |
| 118 | int (*_func_)(const typeof(p[0])*, const typeof(p[0])*) = func; \ |
| 119 | qsort_safe((p), (n), sizeof((p)[0]), (__compar_fn_t) _func_); \ |
| 120 | }) |
| 121 | - |
| 122 | -static inline void qsort_r_safe(void *base, size_t nmemb, size_t size, __compar_d_fn_t compar, void *userdata) { |
| 123 | - if (nmemb <= 1) |
| 124 | - return; |
| 125 | - |
| 126 | - assert(base); |
| 127 | - qsort_r(base, nmemb, size, compar, userdata); |
| 128 | -} |
| 129 | - |
| 130 | -#define typesafe_qsort_r(p, n, func, userdata) \ |
| 131 | - ({ \ |
| 132 | - int (*_func_)(const typeof(p[0])*, const typeof(p[0])*, typeof(userdata)) = func; \ |
| 133 | - qsort_r_safe((p), (n), sizeof((p)[0]), (__compar_d_fn_t) _func_, userdata); \ |
| 134 | - }) |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 135 | diff --git a/shared/systemd/src/basic/stdio-util.h b/shared/systemd/src/basic/stdio-util.h |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame^] | 136 | index c3b9448..e80a938 100644 |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 137 | --- a/shared/systemd/src/basic/stdio-util.h |
| 138 | +++ b/shared/systemd/src/basic/stdio-util.h |
| 139 | @@ -1,7 +1,9 @@ |
| 140 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
| 141 | #pragma once |
| 142 | |
| 143 | +#if defined(__GLIBC__) |
| 144 | #include <printf.h> |
| 145 | +#endif |
| 146 | #include <stdarg.h> |
| 147 | #include <stdio.h> |
| 148 | #include <sys/types.h> |
| 149 | diff --git a/shared/systemd/src/basic/string-util.h b/shared/systemd/src/basic/string-util.h |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame^] | 150 | index b23f4c8..8f2f6e0 100644 |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 151 | --- a/shared/systemd/src/basic/string-util.h |
| 152 | +++ b/shared/systemd/src/basic/string-util.h |
| 153 | @@ -27,6 +27,11 @@ |
| 154 | #define strcaseeq(a,b) (strcasecmp((a),(b)) == 0) |
| 155 | #define strncaseeq(a, b, n) (strncasecmp((a), (b), (n)) == 0) |
| 156 | |
| 157 | +/* musl does not know strndupa */ |
| 158 | +#if !defined(__GLIBC__) |
| 159 | +#define strndupa(x,s) strncpy(alloca(strlen(x)+1),x,s) |
| 160 | +#endif |
| 161 | + |
| 162 | int strcmp_ptr(const char *a, const char *b) _pure_; |
| 163 | |
| 164 | static inline bool streq_ptr(const char *a, const char *b) { |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 165 | -- |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame^] | 166 | 2.17.1 |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 167 | |