aboutsummaryrefslogtreecommitdiffstats
path: root/meta-networking/recipes-connectivity/networkmanager/networkmanager/musl/0001-Fix-build-with-musl-systemd-specific.patch
blob: 7807fc77c683bf972c211ee9d4bfa5fce6fd6a65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
From 9597122867c22e949ef3b69c779e0facebce6eb5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20M=C3=BCller?= <schnitzeltony@gmail.com>
Date: Tue, 2 Apr 2019 01:34:35 +0200
Subject: [PATCH] Fix build with musl - systemd specific
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

From: =?UTF-8?q?Andreas=20M=C3=BCller?= <schnitzeltony@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Networkmanager imported some code from systemd. This requires some adjustments
for musl.

Upstream-Status: Pending

Signed-off-by: Andreas Müller <schnitzeltony@gmail.com>

---
 shared/systemd/src/basic/in-addr-util.c |  1 +
 shared/systemd/src/basic/process-util.c |  9 +++++++++
 shared/systemd/src/basic/socket-util.h  |  6 ++++++
 shared/systemd/src/basic/sort-util.h    | 27 ++++---------------------
 shared/systemd/src/basic/stdio-util.h   |  2 ++
 shared/systemd/src/basic/string-util.h  |  5 +++++
 6 files changed, 27 insertions(+), 23 deletions(-)

diff --git a/shared/systemd/src/basic/in-addr-util.c b/shared/systemd/src/basic/in-addr-util.c
index 1ea3e7f..1204393 100644
--- a/shared/systemd/src/basic/in-addr-util.c
+++ b/shared/systemd/src/basic/in-addr-util.c
@@ -15,6 +15,7 @@
 #include "in-addr-util.h"
 #include "macro.h"
 #include "parse-util.h"
+#include "string-util.h"
 #include "random-util.h"
 #include "string-util.h"
 #include "strxcpyx.h"
diff --git a/shared/systemd/src/basic/process-util.c b/shared/systemd/src/basic/process-util.c
index 03ca04e..be8bca8 100644
--- a/shared/systemd/src/basic/process-util.c
+++ b/shared/systemd/src/basic/process-util.c
@@ -17,6 +17,9 @@
 #include <sys/wait.h>
 #include <syslog.h>
 #include <unistd.h>
+#ifndef __GLIBC__
+#include <pthread.h>
+#endif
 #if 0 /* NM_IGNORED */
 #if HAVE_VALGRIND_VALGRIND_H
 #include <valgrind/valgrind.h>
@@ -1152,11 +1155,13 @@ void reset_cached_pid(void) {
         cached_pid = CACHED_PID_UNSET;
 }
 
+#ifdef __GLIBC__
 /* We use glibc __register_atfork() + __dso_handle directly here, as they are not included in the glibc
  * headers. __register_atfork() is mostly equivalent to pthread_atfork(), but doesn't require us to link against
  * libpthread, as it is part of glibc anyway. */
 extern int __register_atfork(void (*prepare) (void), void (*parent) (void), void (*child) (void), void *dso_handle);
 extern void* __dso_handle _weak_;
+#endif
 
 pid_t getpid_cached(void) {
         static bool installed = false;
@@ -1185,7 +1190,11 @@ pid_t getpid_cached(void) {
                          * only half-documented (glibc doesn't document it but LSB does — though only superficially)
                          * we'll check for errors only in the most generic fashion possible. */
 
+#ifdef __GLIBC__
                         if (__register_atfork(NULL, NULL, reset_cached_pid, __dso_handle) != 0) {
+#else
+                        if (pthread_atfork(NULL, NULL, reset_cached_pid) != 0) {
+#endif
                                 /* OOM? Let's try again later */
                                 cached_pid = CACHED_PID_UNSET;
                                 return new_pid;
diff --git a/shared/systemd/src/basic/socket-util.h b/shared/systemd/src/basic/socket-util.h
index 1ece911..290e94c 100644
--- a/shared/systemd/src/basic/socket-util.h
+++ b/shared/systemd/src/basic/socket-util.h
@@ -14,6 +14,12 @@
 #include <sys/types.h>
 #include <sys/un.h>
 
+#if !defined(__GLIBC__)
+/* SIOCGSTAMPNS from linux/asm-generic.h
+ * for src/systemd/src/libsystemd-network/sd-lldp.c */
+#include <linux/sockios.h>
+#endif
+
 #include "macro.h"
 #include "missing_socket.h"
 #include "sparse-endian.h"
diff --git a/shared/systemd/src/basic/sort-util.h b/shared/systemd/src/basic/sort-util.h
index a8dc3bb..ff0aa88 100644
--- a/shared/systemd/src/basic/sort-util.h
+++ b/shared/systemd/src/basic/sort-util.h
@@ -5,15 +5,10 @@
 
 #include "macro.h"
 
-void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size,
-                 __compar_d_fn_t compar, void *arg);
-
-#define typesafe_bsearch_r(k, b, n, func, userdata)                     \
-        ({                                                              \
-                const typeof(b[0]) *_k = k;                             \
-                int (*_func_)(const typeof(b[0])*, const typeof(b[0])*, typeof(userdata)) = func; \
-                xbsearch_r((const void*) _k, (b), (n), sizeof((b)[0]), (__compar_d_fn_t) _func_, userdata); \
-        })
+#if !defined(__GLIBC__)
+typedef int (*__compar_fn_t) (const void*, const void*);
+typedef __compar_fn_t comparison_fn_t;
+#endif
 
 /**
  * Normal bsearch requires base to be nonnull. Here were require
@@ -54,17 +49,3 @@ static inline void _qsort_safe(void *base, size_t nmemb, size_t size, __compar_f
                 int (*_func_)(const typeof(p[0])*, const typeof(p[0])*) = func; \
                 _qsort_safe((p), (n), sizeof((p)[0]), (__compar_fn_t) _func_); \
         })
-
-static inline void qsort_r_safe(void *base, size_t nmemb, size_t size, __compar_d_fn_t compar, void *userdata) {
-        if (nmemb <= 1)
-                return;
-
-        assert(base);
-        qsort_r(base, nmemb, size, compar, userdata);
-}
-
-#define typesafe_qsort_r(p, n, func, userdata)                          \
-        ({                                                              \
-                int (*_func_)(const typeof(p[0])*, const typeof(p[0])*, typeof(userdata)) = func; \
-                qsort_r_safe((p), (n), sizeof((p)[0]), (__compar_d_fn_t) _func_, userdata); \
-        })
diff --git a/shared/systemd/src/basic/stdio-util.h b/shared/systemd/src/basic/stdio-util.h
index c3b9448..e80a938 100644
--- a/shared/systemd/src/basic/stdio-util.h
+++ b/shared/systemd/src/basic/stdio-util.h
@@ -1,7 +1,9 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
 #pragma once
 
+#if defined(__GLIBC__)
 #include <printf.h>
+#endif
 #include <stdarg.h>
 #include <stdio.h>
 #include <sys/types.h>
diff --git a/shared/systemd/src/basic/string-util.h b/shared/systemd/src/basic/string-util.h
index cefbda3..71e4dec 100644
--- a/shared/systemd/src/basic/string-util.h
+++ b/shared/systemd/src/basic/string-util.h
@@ -26,6 +26,11 @@
 #define strcaseeq(a,b) (strcasecmp((a),(b)) == 0)
 #define strncaseeq(a, b, n) (strncasecmp((a), (b), (n)) == 0)
 
+/* musl does not know strndupa */
+#if !defined(__GLIBC__)
+#define strndupa(x,s) strncpy(alloca(strlen(x)+1),x,s)
+#endif
+
 int strcmp_ptr(const char *a, const char *b) _pure_;
 int strcasecmp_ptr(const char *a, const char *b) _pure_;