Misc header fixes for compatibility with musl libc.

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/sort-util.h b/shared/systemd/src/basic/sort-util.h
index e029f86..935f136 100644
--- a/shared/systemd/src/basic/sort-util.h
+++ b/shared/systemd/src/basic/sort-util.h
@@ -5,6 +5,13 @@

 #include "macro.h"

+#ifndef __COMPAR_FN_T
+# define __COMPAR_FN_T
+typedef int (*__compar_fn_t) (const void *, const void *);
+typedef __compar_fn_t comparison_fn_t;
+typedef int (*__compar_d_fn_t) (const void *, const void *, void *);
+#endif
+
 void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size,
                  __compar_d_fn_t compar, void *arg);
 
diff --git a/shared/systemd/src/basic/util.h b/shared/systemd/src/basic/util.h
index 25e6ab8..7967e8a 100644
--- a/shared/systemd/src/basic/util.h
+++ b/shared/systemd/src/basic/util.h
@@ -30,6 +30,12 @@ static inline unsigned u64log2(uint64_t n) {
 #endif
 }
 
+#if !defined(__GLIBC__)
+typedef int (*__compar_fn_t) (const void*, const void*);
+typedef __compar_fn_t comparison_fn_t;
+typedef int (*__compar_d_fn_t) (const void *, const void *, void *);
+#endif
+
 static inline unsigned u32ctz(uint32_t n) {
 #if __SIZEOF_INT__ == 4
         return n != 0 ? __builtin_ctz(n) : 32;
diff --git a/libnm-core/nm-utils.h b/libnm-core/nm-utils.h
index 2b5baba..976850c 100644
--- a/libnm-core/nm-utils.h
+++ b/libnm-core/nm-utils.h
@@ -15,7 +15,11 @@
 #include <netinet/in.h>
 
 /* For ETH_ALEN and INFINIBAND_ALEN */
+#if defined(__GLIBC__)
 #include <linux/if_ether.h>
+#else
+#define ETH_ALEN	6		/* Octets in one ethernet addr	 */
+#endif
 #include <linux/if_infiniband.h>
 
 #include "nm-core-enum-types.h"
diff --git a/shared/systemd/src/basic/socket-util.h b/shared/systemd/src/basic/socket-util.h
index d2246a8..4cb0807 100644
--- a/shared/systemd/src/basic/socket-util.h
+++ b/shared/systemd/src/basic/socket-util.h
@@ -13,6 +13,11 @@
 #include <sys/socket.h>
 #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"
diff --git a/src/platform/wifi/nm-wifi-utils.h b/src/platform/wifi/nm-wifi-utils.h
index 36148b5..d282eb2 100644
--- a/src/platform/wifi/nm-wifi-utils.h
+++ b/src/platform/wifi/nm-wifi-utils.h
@@ -7,7 +7,11 @@
 #ifndef __WIFI_UTILS_H__
 #define __WIFI_UTILS_H__
 
+#if defined(__GLIBC__)
 #include <net/ethernet.h>
+#else /* musl libc */
+#define ETH_ALEN	6		/* Octets in one ethernet addr	 */
+#endif
 
 #include "nm-dbus-interface.h"
 #include "nm-setting-wireless.h"
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index 7514fa7..f041382 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -17,7 +17,11 @@
 #include <arpa/inet.h>
 #include <fcntl.h>
 #include <linux/if_addr.h>
+#if defined(__GLIBC__)
 #include <linux/if_arp.h>
+#else
+#include <linux/if.h>
+#endif
 #include <linux/rtnetlink.h>
 #include <linux/pkt_sched.h>
 
diff --git a/src/nm-manager.c b/src/nm-manager.c
index 0bf6a75..e392507 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -15,6 +15,7 @@
 #include <sys/stat.h>
 #include <sys/sendfile.h>
 #include <limits.h>
+#include <asm/types.h>

 #include "nm-glib-aux/nm-c-list.h"

diff --git a/src/systemd/sd-adapt-core/nm-sd-adapt-core.h b/src/systemd/sd-adapt-core/nm-sd-adapt-core.h
index 8c07c53..d043afc 100644
--- a/src/systemd/sd-adapt-core/nm-sd-adapt-core.h
+++ b/src/systemd/sd-adapt-core/nm-sd-adapt-core.h
@@ -50,7 +50,7 @@
 #  ifdef HAVE___SECURE_GETENV
 #    define secure_getenv __secure_getenv
 #  else
-#    error neither secure_getenv nor __secure_getenv is available
+#    define secure_getenv getenv
 #  endif
 #endif
 
--- NetworkManager-1.18.1/src/platform/nm-linux-platform.c.old	2019-04-19 09:31:51.000000000 +0000
+++ NetworkManager-1.18.1/src/platform/nm-linux-platform.c	2019-05-10 07:21:32.665163629 +0000
@@ -6,6 +6,7 @@
 #include "nm-default.h"
 
 #include "nm-linux-platform.h"
+#include "wpan/nm-wpan-utils.h"
 
 #include <arpa/inet.h>
 #include <dlfcn.h>
@@ -14,7 +15,11 @@
 #include <libudev.h>
 #include <linux/fib_rules.h>
 #include <linux/ip.h>
+#ifdef __GLIBC__
 #include <linux/if_arp.h>
+#else
+#include <linux/if.h>
+#endif
 #include <linux/if_bridge.h>
 #include <linux/if_link.h>
 #include <linux/if_tun.h>
@@ -44,7 +49,6 @@
 #include "nm-platform-private.h"
 #include "wifi/nm-wifi-utils.h"
 #include "wifi/nm-wifi-utils-wext.h"
-#include "wpan/nm-wpan-utils.h"
 #include "nm-glib-aux/nm-io-utils.h"
 #include "nm-udev-aux/nm-udev-utils.h"

diff --git a/shared/systemd/src/basic/process-util.c b/shared/systemd/src/basic/process-util.c
index b0afb5c..f72e346 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>
@@ -1123,11 +1126,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;
@@ -1156,7 +1161,12 @@ 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. */
 
-                        if (__register_atfork(NULL, NULL, reset_cached_pid, __dso_handle) != 0) {
+                        #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;
 
--- NetworkManager-1.20.0/src/systemd/src/libsystemd-network/sd-dhcp6-client.c.old	2019-08-06 10:22:09.000000000 +0000
+++ NetworkManager-1.20.0/src/systemd/src/libsystemd-network/sd-dhcp6-client.c	2019-08-09 05:17:18.249955730 +0000
@@ -7,7 +7,7 @@
 #include <errno.h>
 #include <string.h>
 #include <sys/ioctl.h>
-#include <linux/if_arp.h>
+#include <net/if_arp.h>
 #include <linux/if_infiniband.h>
 
 #include "sd-dhcp6-client.h"