summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2016-03-11 10:25:40 +0100
committerThomas Haller <thaller@redhat.com>2016-03-11 11:02:12 +0100
commitaed3c810b3681fa38000487f519660a338bc063e (patch)
tree080613a6399809f22c40f07dff09e0ae1dadc81c
parente1e428b21e56cad3c50419e3fe2806dbbb21c976 (diff)
downloadNetworkManager-aed3c810b3681fa38000487f519660a338bc063e.tar.gz
systemd: split "nm-sd.h" out of "nm-sd-adapt.h"
Now we have: "nm-sd.h" is a header file of NetworkManager with utilities related to systemd. It can be used anywhere freely. Also, systemd headers that are considered public API (like "sd-event.h") can be used without restrictions. When compiling the systemd sources, we always must include "nm-sd-adapt.h" as first. Similarly, systemd headers must not include "nm-sd-adapt.h", because they are either public (in which case the adapter is not needed) or they are internal (in which case they are themself included via a systemd source). Sometimes, we must internal API (like "dhcp-lease-internal.h"). In this case, we also must include "nm-sd-adapt.h".
-rw-r--r--src/Makefile.am2
-rw-r--r--src/devices/nm-lldp-listener.c10
-rw-r--r--src/devices/tests/test-lldp.c3
-rw-r--r--src/dhcp-manager/nm-dhcp-systemd.c1
-rw-r--r--src/main.c4
-rw-r--r--src/nm-iface-helper.c4
-rw-r--r--src/systemd/nm-sd-adapt.c113
-rw-r--r--src/systemd/nm-sd-adapt.h2
-rw-r--r--src/systemd/nm-sd.c136
-rw-r--r--src/systemd/nm-sd.h25
-rw-r--r--src/tests/test-systemd.c3
11 files changed, 179 insertions, 124 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index f7f2e73b6e..353a31dd45 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -64,6 +64,8 @@ SYSTEMD_NM_CFLAGS_PATHS = \
-I$(top_srcdir)/src/systemd
libsystemd_nm_la_SOURCES = \
+ systemd/nm-sd.c \
+ systemd/nm-sd.h \
systemd/nm-sd-adapt.c \
systemd/nm-sd-adapt.h \
systemd/src/basic/alloc-util.c \
diff --git a/src/devices/nm-lldp-listener.c b/src/devices/nm-lldp-listener.c
index 39e7a406b4..fe53a179c2 100644
--- a/src/devices/nm-lldp-listener.c
+++ b/src/devices/nm-lldp-listener.c
@@ -20,15 +20,19 @@
#include "nm-default.h"
+#include "nm-lldp-listener.h"
+
#include <net/ethernet.h>
#include <errno.h>
-#include "sd-lldp.h"
-#include "lldp.h"
-#include "nm-lldp-listener.h"
#include "nm-platform.h"
#include "nm-utils.h"
+#include "sd-lldp.h"
+
+#include "nm-sd-adapt.h"
+#include "lldp.h"
+
#define MAX_NEIGHBORS 4096
#define MIN_UPDATE_INTERVAL 2
diff --git a/src/devices/tests/test-lldp.c b/src/devices/tests/test-lldp.c
index 2af46ab976..97c6ad5d50 100644
--- a/src/devices/tests/test-lldp.c
+++ b/src/devices/tests/test-lldp.c
@@ -27,8 +27,9 @@
#include <sys/types.h>
#include "nm-lldp-listener.h"
-#include "nm-sd-adapt.h"
+#include "nm-sd.h"
+#include "nm-sd-adapt.h"
#include "lldp.h"
#include "test-common.h"
diff --git a/src/dhcp-manager/nm-dhcp-systemd.c b/src/dhcp-manager/nm-dhcp-systemd.c
index 7b3575ec14..91fa880305 100644
--- a/src/dhcp-manager/nm-dhcp-systemd.c
+++ b/src/dhcp-manager/nm-dhcp-systemd.c
@@ -38,7 +38,6 @@
#include "sd-dhcp-client.h"
#include "sd-dhcp6-client.h"
-/* we use a private systemd header, thus need to include nm-sd-adapt.h. */
#include "nm-sd-adapt.h"
#include "dhcp-lease-internal.h"
diff --git a/src/main.c b/src/main.c
index 9bbc299e58..bf007008b1 100644
--- a/src/main.c
+++ b/src/main.c
@@ -35,9 +35,9 @@
#include <string.h>
#include <sys/resource.h>
+#include "main-utils.h"
#include "nm-dbus-interface.h"
#include "NetworkManagerUtils.h"
-#include "main-utils.h"
#include "nm-manager.h"
#include "nm-linux-platform.h"
#include "nm-bus-manager.h"
@@ -50,7 +50,7 @@
#include "nm-auth-manager.h"
#include "nm-core-internal.h"
#include "nm-exported-object.h"
-#include "nm-sd-adapt.h"
+#include "nm-sd.h"
#if !defined(NM_DIST_VERSION)
# define NM_DIST_VERSION VERSION
diff --git a/src/nm-iface-helper.c b/src/nm-iface-helper.c
index 247b771d49..dab0ec5fec 100644
--- a/src/nm-iface-helper.c
+++ b/src/nm-iface-helper.c
@@ -36,15 +36,15 @@
* Forward declare if_nametoindex. */
extern unsigned int if_nametoindex (const char *__ifname);
+#include "main-utils.h"
#include "NetworkManagerUtils.h"
#include "nm-linux-platform.h"
#include "nm-dhcp-manager.h"
-#include "main-utils.h"
#include "nm-rdisc.h"
#include "nm-lndp-rdisc.h"
#include "nm-utils.h"
#include "nm-setting-ip6-config.h"
-#include "nm-sd-adapt.h"
+#include "nm-sd.h"
#if !defined(NM_DIST_VERSION)
# define NM_DIST_VERSION VERSION
diff --git a/src/systemd/nm-sd-adapt.c b/src/systemd/nm-sd-adapt.c
index ec276dcf9f..4e3082762d 100644
--- a/src/systemd/nm-sd-adapt.c
+++ b/src/systemd/nm-sd-adapt.c
@@ -13,14 +13,13 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
- * Copyright (C) 2014 Red Hat, Inc.
+ * Copyright (C) 2014 - 2016 Red Hat, Inc.
*/
#include "nm-default.h"
#include "nm-sd-adapt.h"
-#include "sd-event.h"
#include "fd-util.h"
/*****************************************************************************/
@@ -31,115 +30,5 @@ asynchronous_close (int fd) {
return -1;
}
-/*****************************************************************************
- * Integrating sd_event into glib. Taken and adjusted from
- * https://www.freedesktop.org/software/systemd/man/sd_event_get_fd.html
- *****************************************************************************/
-
-typedef struct SDEventSource {
- GSource source;
- GPollFD pollfd;
- sd_event *event;
- guint *default_source_id;
-} SDEventSource;
-
-static gboolean
-event_prepare (GSource *source, gint *timeout_)
-{
- return sd_event_prepare (((SDEventSource *) source)->event) > 0;
-}
-
-static gboolean
-event_check (GSource *source)
-{
- return sd_event_wait (((SDEventSource *) source)->event, 0) > 0;
-}
-
-static gboolean
-event_dispatch (GSource *source, GSourceFunc callback, gpointer user_data)
-{
- return sd_event_dispatch (((SDEventSource *)source)->event) > 0;
-}
-
-static void
-event_finalize (GSource *source)
-{
- SDEventSource *s;
-
- s = (SDEventSource *) source;
- sd_event_unref (s->event);
- if (s->default_source_id)
- *s->default_source_id = 0;
-}
-
-static SDEventSource *
-event_create_source (sd_event *event, guint *default_source_id)
-{
- static GSourceFuncs event_funcs = {
- .prepare = event_prepare,
- .check = event_check,
- .dispatch = event_dispatch,
- .finalize = event_finalize,
- };
- SDEventSource *source;
-
- g_return_val_if_fail (event, NULL);
-
- source = (SDEventSource *) g_source_new (&event_funcs, sizeof (SDEventSource));
-
- source->event = sd_event_ref (event);
- source->pollfd.fd = sd_event_get_fd (event);
- source->pollfd.events = G_IO_IN | G_IO_HUP | G_IO_ERR;
- source->default_source_id = default_source_id;
-
- g_source_add_poll ((GSource *) source, &source->pollfd);
-
- return source;
-}
-
-static guint
-event_attach (sd_event *event, GMainContext *context)
-{
- SDEventSource *source;
- guint id;
- int r;
- sd_event *e = event;
- guint *p_default_source_id = NULL;
-
- if (!e) {
- static guint default_source_id = 0;
-
- if (default_source_id) {
- /* The default event cannot be registered multiple times. */
- g_return_val_if_reached (0);
- }
-
- r = sd_event_default (&e);
- if (r < 0)
- g_return_val_if_reached (0);
-
- p_default_source_id = &default_source_id;
- }
-
- source = event_create_source (e, p_default_source_id);
- id = g_source_attach ((GSource *) source, context);
- g_source_unref ((GSource *) source);
-
-
- if (!event) {
- *p_default_source_id = id;
- sd_event_unref (e);
- }
-
- g_return_val_if_fail (id, 0);
- return id;
-}
-
-guint
-nm_sd_event_attach_default (void)
-{
- return event_attach (NULL, NULL);
-}
-
/*****************************************************************************/
diff --git a/src/systemd/nm-sd-adapt.h b/src/systemd/nm-sd-adapt.h
index 1439aac791..4fa0f5c18d 100644
--- a/src/systemd/nm-sd-adapt.h
+++ b/src/systemd/nm-sd-adapt.h
@@ -26,8 +26,6 @@
#include <sys/resource.h>
#include <time.h>
-guint nm_sd_event_attach_default (void);
-
#define noreturn G_GNUC_NORETURN
#ifndef CLOCK_BOOTTIME
diff --git a/src/systemd/nm-sd.c b/src/systemd/nm-sd.c
new file mode 100644
index 0000000000..4d596020c9
--- /dev/null
+++ b/src/systemd/nm-sd.c
@@ -0,0 +1,136 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright (C) 2014 - 2016 Red Hat, Inc.
+ */
+
+#include "nm-default.h"
+
+#include "nm-sd.h"
+
+#include "sd-event.h"
+
+/*****************************************************************************
+ * Integrating sd_event into glib. Taken and adjusted from
+ * https://www.freedesktop.org/software/systemd/man/sd_event_get_fd.html
+ *****************************************************************************/
+
+typedef struct SDEventSource {
+ GSource source;
+ GPollFD pollfd;
+ sd_event *event;
+ guint *default_source_id;
+} SDEventSource;
+
+static gboolean
+event_prepare (GSource *source, gint *timeout_)
+{
+ return sd_event_prepare (((SDEventSource *) source)->event) > 0;
+}
+
+static gboolean
+event_check (GSource *source)
+{
+ return sd_event_wait (((SDEventSource *) source)->event, 0) > 0;
+}
+
+static gboolean
+event_dispatch (GSource *source, GSourceFunc callback, gpointer user_data)
+{
+ return sd_event_dispatch (((SDEventSource *)source)->event) > 0;
+}
+
+static void
+event_finalize (GSource *source)
+{
+ SDEventSource *s;
+
+ s = (SDEventSource *) source;
+ sd_event_unref (s->event);
+ if (s->default_source_id)
+ *s->default_source_id = 0;
+}
+
+static SDEventSource *
+event_create_source (sd_event *event, guint *default_source_id)
+{
+ static GSourceFuncs event_funcs = {
+ .prepare = event_prepare,
+ .check = event_check,
+ .dispatch = event_dispatch,
+ .finalize = event_finalize,
+ };
+ SDEventSource *source;
+
+ g_return_val_if_fail (event, NULL);
+
+ source = (SDEventSource *) g_source_new (&event_funcs, sizeof (SDEventSource));
+
+ source->event = sd_event_ref (event);
+ source->pollfd.fd = sd_event_get_fd (event);
+ source->pollfd.events = G_IO_IN | G_IO_HUP | G_IO_ERR;
+ source->default_source_id = default_source_id;
+
+ g_source_add_poll ((GSource *) source, &source->pollfd);
+
+ return source;
+}
+
+static guint
+event_attach (sd_event *event, GMainContext *context)
+{
+ SDEventSource *source;
+ guint id;
+ int r;
+ sd_event *e = event;
+ guint *p_default_source_id = NULL;
+
+ if (!e) {
+ static guint default_source_id = 0;
+
+ if (default_source_id) {
+ /* The default event cannot be registered multiple times. */
+ g_return_val_if_reached (0);
+ }
+
+ r = sd_event_default (&e);
+ if (r < 0)
+ g_return_val_if_reached (0);
+
+ p_default_source_id = &default_source_id;
+ }
+
+ source = event_create_source (e, p_default_source_id);
+ id = g_source_attach ((GSource *) source, context);
+ g_source_unref ((GSource *) source);
+
+
+ if (!event) {
+ *p_default_source_id = id;
+ sd_event_unref (e);
+ }
+
+ g_return_val_if_fail (id, 0);
+ return id;
+}
+
+guint
+nm_sd_event_attach_default (void)
+{
+ return event_attach (NULL, NULL);
+}
+
+/*****************************************************************************/
+
diff --git a/src/systemd/nm-sd.h b/src/systemd/nm-sd.h
new file mode 100644
index 0000000000..888d44ab0c
--- /dev/null
+++ b/src/systemd/nm-sd.h
@@ -0,0 +1,25 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright (C) 2014 - 2016 Red Hat, Inc.
+ */
+
+#ifndef __NM_SD_H__
+#define __NM_SD_H__
+
+guint nm_sd_event_attach_default (void);
+
+#endif /* __NM_SD_H__ */
+
diff --git a/src/tests/test-systemd.c b/src/tests/test-systemd.c
index ceede91a64..936bff204f 100644
--- a/src/tests/test-systemd.c
+++ b/src/tests/test-systemd.c
@@ -19,10 +19,11 @@
#include "nm-default.h"
+#include "nm-sd.h"
+
#include "sd-dhcp-client.h"
#include "sd-lldp.h"
#include "sd-event.h"
-#include "nm-sd-adapt.h"
#include "nm-test-utils.h"