blob: b3f93ff92bdaaa401786b5d7fe5c8a0f09f08224 [file] [log] [blame]
Brad Bishop34ae6002019-04-08 15:21:03 -04001From f43c9a5b07832a91383e59d655bc3c8a9f48c451 Mon Sep 17 00:00:00 2001
2From: =?UTF-8?q?Andreas=20M=C3=BCller?= <schnitzeltony@gmail.com>
3Date: Tue, 2 Apr 2019 01:34:35 +0200
4Subject: [PATCH] Fix build with musl
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8
9Upstream-Status: Pending
10
11Signed-off-by: Andreas Müller <schnitzeltony@gmail.com>
12---
13 clients/cli/connections.c | 1 -
14 libnm-core/nm-utils.c | 2 +-
15 shared/n-acd/src/n-acd.c | 1 -
16 shared/systemd/src/basic/in-addr-util.c | 1 +
17 shared/systemd/src/basic/process-util.c | 9 ++++++
18 shared/systemd/src/basic/socket-util.h | 6 ++++
19 shared/systemd/src/basic/stdio-util.h | 2 ++
20 shared/systemd/src/basic/string-util.h | 5 ++++
21 shared/systemd/src/basic/util.h | 29 ++++----------------
22 src/platform/wifi/nm-wifi-utils.h | 4 +++
23 src/platform/wpan/nm-wpan-utils.h | 2 --
24 src/settings/nm-settings-connection.h | 2 --
25 src/systemd/src/libsystemd-network/sd-lldp.c | 1 +
26 src/systemd/src/systemd/sd-dhcp-client.h | 2 ++
27 src/systemd/src/systemd/sd-dhcp-lease.h | 2 ++
28 src/systemd/src/systemd/sd-dhcp6-client.h | 2 ++
29 src/systemd/src/systemd/sd-ipv4ll.h | 2 ++
30 src/systemd/src/systemd/sd-lldp.h | 2 +-
31 19 files changed, 44 insertions(+), 32 deletions(-)
32
33diff --git a/clients/cli/connections.c b/clients/cli/connections.c
34index 6db44f8..36e51cc 100644
35--- a/clients/cli/connections.c
36+++ b/clients/cli/connections.c
37@@ -25,7 +25,6 @@
38 #include <stdlib.h>
39 #include <unistd.h>
40 #include <signal.h>
41-#include <netinet/ether.h>
42 #include <readline/readline.h>
43 #include <readline/history.h>
44 #include <fcntl.h>
45diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c
46index d276cfe..2aec785 100644
47--- a/libnm-core/nm-utils.c
48+++ b/libnm-core/nm-utils.c
49@@ -21,10 +21,10 @@
50
51 #include "nm-default.h"
52
53+#include <netinet/ether.h>
54 #include "nm-utils.h"
55
56 #include <stdlib.h>
57-#include <netinet/ether.h>
58 #include <arpa/inet.h>
59 #include <uuid/uuid.h>
60 #include <libintl.h>
61diff --git a/shared/n-acd/src/n-acd.c b/shared/n-acd/src/n-acd.c
62index def56a2..dd4eb78 100644
63--- a/shared/n-acd/src/n-acd.c
64+++ b/shared/n-acd/src/n-acd.c
65@@ -11,7 +11,6 @@
66 #include <inttypes.h>
67 #include <limits.h>
68 #include <linux/if_packet.h>
69-#include <netinet/if_ether.h>
70 #include <netinet/in.h>
71 #include <stdlib.h>
72 #include <string.h>
73diff --git a/shared/systemd/src/basic/in-addr-util.c b/shared/systemd/src/basic/in-addr-util.c
74index 5ced350..c6b52b8 100644
75--- a/shared/systemd/src/basic/in-addr-util.c
76+++ b/shared/systemd/src/basic/in-addr-util.c
77@@ -13,6 +13,7 @@
78 #include "in-addr-util.h"
79 #include "macro.h"
80 #include "parse-util.h"
81+#include "string-util.h"
82 #include "util.h"
83
84 bool in4_addr_is_null(const struct in_addr *a) {
85diff --git a/shared/systemd/src/basic/process-util.c b/shared/systemd/src/basic/process-util.c
86index b0afb5c..7adc8bd 100644
87--- a/shared/systemd/src/basic/process-util.c
88+++ b/shared/systemd/src/basic/process-util.c
89@@ -21,6 +21,9 @@
90 #include <sys/wait.h>
91 #include <syslog.h>
92 #include <unistd.h>
93+#ifndef __GLIBC__
94+#include <pthread.h>
95+#endif
96 #if 0 /* NM_IGNORED */
97 #if HAVE_VALGRIND_VALGRIND_H
98 #include <valgrind/valgrind.h>
99@@ -1168,11 +1171,13 @@ void reset_cached_pid(void) {
100 cached_pid = CACHED_PID_UNSET;
101 }
102
103+#ifdef __GLIBC__
104 /* We use glibc __register_atfork() + __dso_handle directly here, as they are not included in the glibc
105 * headers. __register_atfork() is mostly equivalent to pthread_atfork(), but doesn't require us to link against
106 * libpthread, as it is part of glibc anyway. */
107 extern int __register_atfork(void (*prepare) (void), void (*parent) (void), void (*child) (void), void *dso_handle);
108 extern void* __dso_handle _weak_;
109+#endif
110
111 pid_t getpid_cached(void) {
112 static bool installed = false;
113@@ -1201,7 +1206,11 @@ pid_t getpid_cached(void) {
114 * only half-documented (glibc doesn't document it but LSB does — though only superficially)
115 * we'll check for errors only in the most generic fashion possible. */
116
117+#ifdef __GLIBC__
118 if (__register_atfork(NULL, NULL, reset_cached_pid, __dso_handle) != 0) {
119+#else
120+ if (pthread_atfork(NULL, NULL, reset_cached_pid) != 0) {
121+#endif
122 /* OOM? Let's try again later */
123 cached_pid = CACHED_PID_UNSET;
124 return new_pid;
125diff --git a/shared/systemd/src/basic/socket-util.h b/shared/systemd/src/basic/socket-util.h
126index d2246a8..76f257f 100644
127--- a/shared/systemd/src/basic/socket-util.h
128+++ b/shared/systemd/src/basic/socket-util.h
129@@ -13,6 +13,12 @@
130 #include <sys/types.h>
131 #include <sys/un.h>
132
133+#if !defined(__GLIBC__)
134+/* SIOCGSTAMPNS from linux/asm-generic.h
135+ * for src/systemd/src/libsystemd-network/sd-lldp.c */
136+#include <linux/sockios.h>
137+#endif
138+
139 #include "macro.h"
140 #include "missing_socket.h"
141 #include "sparse-endian.h"
142diff --git a/shared/systemd/src/basic/stdio-util.h b/shared/systemd/src/basic/stdio-util.h
143index dc67b6e..6336243 100644
144--- a/shared/systemd/src/basic/stdio-util.h
145+++ b/shared/systemd/src/basic/stdio-util.h
146@@ -1,7 +1,9 @@
147 /* SPDX-License-Identifier: LGPL-2.1+ */
148 #pragma once
149
150+#if defined(__GLIBC__)
151 #include <printf.h>
152+#endif
153 #include <stdarg.h>
154 #include <stdio.h>
155 #include <sys/types.h>
156diff --git a/shared/systemd/src/basic/string-util.h b/shared/systemd/src/basic/string-util.h
157index 38070ab..6b918e0 100644
158--- a/shared/systemd/src/basic/string-util.h
159+++ b/shared/systemd/src/basic/string-util.h
160@@ -27,6 +27,11 @@
161 #define strcaseeq(a,b) (strcasecmp((a),(b)) == 0)
162 #define strncaseeq(a, b, n) (strncasecmp((a), (b), (n)) == 0)
163
164+/* musl does not know strndupa */
165+#if !defined(__GLIBC__)
166+#define strndupa(x,s) strncpy(alloca(strlen(x)+1),x,s)
167+#endif
168+
169 int strcmp_ptr(const char *a, const char *b) _pure_;
170
171 static inline bool streq_ptr(const char *a, const char *b) {
172diff --git a/shared/systemd/src/basic/util.h b/shared/systemd/src/basic/util.h
173index dc33d66..cc768e9 100644
174--- a/shared/systemd/src/basic/util.h
175+++ b/shared/systemd/src/basic/util.h
176@@ -27,6 +27,11 @@
177 #include "macro.h"
178 #include "time-util.h"
179
180+#if !defined(__GLIBC__)
181+typedef int (*__compar_fn_t) (const void*, const void*);
182+typedef __compar_fn_t comparison_fn_t;
183+#endif
184+
185 size_t page_size(void) _pure_;
186 #define PAGE_ALIGN(l) ALIGN_TO((l), page_size())
187
188@@ -66,16 +71,6 @@ int prot_from_flags(int flags) _const_;
189 bool in_initrd(void);
190 void in_initrd_force(bool value);
191
192-void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size,
193- __compar_d_fn_t compar, void *arg);
194-
195-#define typesafe_bsearch_r(k, b, n, func, userdata) \
196- ({ \
197- const typeof(b[0]) *_k = k; \
198- int (*_func_)(const typeof(b[0])*, const typeof(b[0])*, typeof(userdata)) = func; \
199- xbsearch_r((const void*) _k, (b), (n), sizeof((b)[0]), (__compar_d_fn_t) _func_, userdata); \
200- })
201-
202 /**
203 * Normal bsearch requires base to be nonnull. Here were require
204 * that only if nmemb > 0.
205@@ -116,20 +111,6 @@ static inline void qsort_safe(void *base, size_t nmemb, size_t size, __compar_fn
206 qsort_safe((p), (n), sizeof((p)[0]), (__compar_fn_t) _func_); \
207 })
208
209-static inline void qsort_r_safe(void *base, size_t nmemb, size_t size, __compar_d_fn_t compar, void *userdata) {
210- if (nmemb <= 1)
211- return;
212-
213- assert(base);
214- qsort_r(base, nmemb, size, compar, userdata);
215-}
216-
217-#define typesafe_qsort_r(p, n, func, userdata) \
218- ({ \
219- int (*_func_)(const typeof(p[0])*, const typeof(p[0])*, typeof(userdata)) = func; \
220- qsort_r_safe((p), (n), sizeof((p)[0]), (__compar_d_fn_t) _func_, userdata); \
221- })
222-
223 /* Normal memcpy requires src to be nonnull. We do nothing if n is 0. */
224 static inline void memcpy_safe(void *dst, const void *src, size_t n) {
225 if (n == 0)
226diff --git a/src/platform/wifi/nm-wifi-utils.h b/src/platform/wifi/nm-wifi-utils.h
227index 36148b5..d282eb2 100644
228--- a/src/platform/wifi/nm-wifi-utils.h
229+++ b/src/platform/wifi/nm-wifi-utils.h
230@@ -22,7 +22,11 @@
231 #ifndef __WIFI_UTILS_H__
232 #define __WIFI_UTILS_H__
233
234+#if defined(__GLIBC__)
235 #include <net/ethernet.h>
236+#else /* musl libc */
237+#define ETH_ALEN 6 /* Octets in one ethernet addr */
238+#endif
239
240 #include "nm-dbus-interface.h"
241 #include "nm-setting-wireless.h"
242diff --git a/src/platform/wpan/nm-wpan-utils.h b/src/platform/wpan/nm-wpan-utils.h
243index 1b54ec4..ed39938 100644
244--- a/src/platform/wpan/nm-wpan-utils.h
245+++ b/src/platform/wpan/nm-wpan-utils.h
246@@ -20,8 +20,6 @@
247 #ifndef __WPAN_UTILS_H__
248 #define __WPAN_UTILS_H__
249
250-#include <net/ethernet.h>
251-
252 #include "nm-dbus-interface.h"
253 #include "platform/nm-netlink.h"
254
255diff --git a/src/settings/nm-settings-connection.h b/src/settings/nm-settings-connection.h
256index e796b71..c01fef6 100644
257--- a/src/settings/nm-settings-connection.h
258+++ b/src/settings/nm-settings-connection.h
259@@ -22,8 +22,6 @@
260 #ifndef __NETWORKMANAGER_SETTINGS_CONNECTION_H__
261 #define __NETWORKMANAGER_SETTINGS_CONNECTION_H__
262
263-#include <net/ethernet.h>
264-
265 #include "nm-dbus-object.h"
266 #include "nm-connection.h"
267
268diff --git a/src/systemd/src/libsystemd-network/sd-lldp.c b/src/systemd/src/libsystemd-network/sd-lldp.c
269index 741128e..62914ae 100644
270--- a/src/systemd/src/libsystemd-network/sd-lldp.c
271+++ b/src/systemd/src/libsystemd-network/sd-lldp.c
272@@ -3,6 +3,7 @@
273 #include "nm-sd-adapt-core.h"
274
275 #include <arpa/inet.h>
276+#include <net/ethernet.h>
277 #include <linux/sockios.h>
278 #include <sys/ioctl.h>
279
280diff --git a/src/systemd/src/systemd/sd-dhcp-client.h b/src/systemd/src/systemd/sd-dhcp-client.h
281index bd0d429..c935fe1 100644
282--- a/src/systemd/src/systemd/sd-dhcp-client.h
283+++ b/src/systemd/src/systemd/sd-dhcp-client.h
284@@ -20,7 +20,9 @@
285 ***/
286
287 #include <inttypes.h>
288+#if defined(__GLIBC__)
289 #include <net/ethernet.h>
290+#endif
291 #include <netinet/in.h>
292 #include <sys/types.h>
293 #include <stdbool.h>
294diff --git a/src/systemd/src/systemd/sd-dhcp-lease.h b/src/systemd/src/systemd/sd-dhcp-lease.h
295index d299c79..991e67e 100644
296--- a/src/systemd/src/systemd/sd-dhcp-lease.h
297+++ b/src/systemd/src/systemd/sd-dhcp-lease.h
298@@ -19,7 +19,9 @@
299 ***/
300
301 #include <inttypes.h>
302+#if defined(__GLIBC__)
303 #include <net/ethernet.h>
304+#endif
305 #include <netinet/in.h>
306 #include <sys/types.h>
307
308diff --git a/src/systemd/src/systemd/sd-dhcp6-client.h b/src/systemd/src/systemd/sd-dhcp6-client.h
309index 43d38f5..57ab487 100644
310--- a/src/systemd/src/systemd/sd-dhcp6-client.h
311+++ b/src/systemd/src/systemd/sd-dhcp6-client.h
312@@ -20,7 +20,9 @@
313 ***/
314
315 #include <inttypes.h>
316+#if defined(__GLIBC__)
317 #include <net/ethernet.h>
318+#endif
319 #include <sys/types.h>
320
321 #include "sd-dhcp6-lease.h"
322diff --git a/src/systemd/src/systemd/sd-ipv4ll.h b/src/systemd/src/systemd/sd-ipv4ll.h
323index 71bd4cf..1c667ba 100644
324--- a/src/systemd/src/systemd/sd-ipv4ll.h
325+++ b/src/systemd/src/systemd/sd-ipv4ll.h
326@@ -19,7 +19,9 @@
327 along with systemd; If not, see <http://www.gnu.org/licenses/>.
328 ***/
329
330+#if defined(__GLIBC__)
331 #include <net/ethernet.h>
332+#endif
333 #include <netinet/in.h>
334
335 #include "sd-event.h"
336diff --git a/src/systemd/src/systemd/sd-lldp.h b/src/systemd/src/systemd/sd-lldp.h
337index bf3afad..4cace87 100644
338--- a/src/systemd/src/systemd/sd-lldp.h
339+++ b/src/systemd/src/systemd/sd-lldp.h
340@@ -18,7 +18,7 @@
341 ***/
342
343 #include <inttypes.h>
344-#include <net/ethernet.h>
345+//#include <net/ethernet.h>
346 #include <sys/types.h>
347
348 #include "sd-event.h"
349--
3502.20.1
351