From 468c08511c86dac621bc63169c0e3bb6e2517a68 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 26 Apr 2013 16:42:54 -0400 Subject: [PATCH] core: add libgsystem as a git submodule And change src/main.c to use the local allocation macros. This results in much cleaner code, as one can see from the diff. Because libgsystem is designed for nonrecursive make, it fits best in the current recursive setup if we build . first. This will be a lot nicer when we switch NM to a nonrecursive setup. --- .gitmodules | 3 +++ Makefile.am | 7 +++++++ autogen.sh | 8 ++++++++ libgsystem | 1 + src/Makefile.am | 3 ++- src/main.c | 50 ++++++++++++------------------------------------- 6 files changed, 33 insertions(+), 39 deletions(-) create mode 100644 .gitmodules create mode 160000 libgsystem diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000000..e93bbea6db --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "libgsystem"] + path = libgsystem + url = git://git.gnome.org/libgsystem diff --git a/Makefile.am b/Makefile.am index 32fc74d47a..9976a2aa0e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,6 +1,7 @@ include $(GLIB_MAKEFILE) SUBDIRS = \ + . \ include \ libnm-util \ libnm-glib \ @@ -53,3 +54,9 @@ CLEANFILES = cscope.in.out cscope.out cscope.po.out .PHONY: cscope cscope: cscope -b -q -R -Iinclude -ssrc -slibnm-glib -slibnm-util -scli/src; + +libgsystem_srcpath := libgsystem +libgsystem_cflags := $(GLIB_CFLAGS) -I$(srcdir)/libgsystem +libgsystem_libs = $(GLIB_LIBS) +include libgsystem/Makefile-libgsystem.am +noinst_LTLIBRARIES = libgsystem.la diff --git a/autogen.sh b/autogen.sh index ef6d20f5e8..8c6179a9ff 100755 --- a/autogen.sh +++ b/autogen.sh @@ -13,6 +13,14 @@ PKG_NAME=NetworkManager exit 1 } +# Fetch submodules if needed +if test ! -f src/libgsystem/README; +then + echo "+ Setting up submodules" + git submodule init + git submodule update +fi + (cd $srcdir; gtkdocize || exit 1 autopoint --force diff --git a/libgsystem b/libgsystem new file mode 160000 index 0000000000..be1b3b9d3d --- /dev/null +++ b/libgsystem @@ -0,0 +1 @@ +Subproject commit be1b3b9d3dbfacf15ede143de377452a92976468 diff --git a/src/Makefile.am b/src/Makefile.am index 12a7aa0632..d34e911fa2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -25,6 +25,7 @@ endif INCLUDES = \ -I$(top_srcdir)/include \ -I$(top_builddir)/include \ + -I${top_srcdir}/libgsystem \ -I$(top_srcdir)/libnm-util \ -I$(top_builddir)/libnm-util \ -I$(top_srcdir)/callouts @@ -42,7 +43,7 @@ sbin_PROGRAMS = NetworkManager NetworkManager_SOURCES = \ main.c -NetworkManager_LDADD = libNetworkManager.la +NetworkManager_LDADD = libNetworkManager.la $(top_builddir)/libgsystem.la noinst_LTLIBRARIES = libNetworkManager.la diff --git a/src/main.c b/src/main.c index ed71bb62e6..37e05c4e84 100644 --- a/src/main.c +++ b/src/main.c @@ -38,6 +38,7 @@ #include #include +#include "gsystem-local-alloc.h" #include "NetworkManager.h" #include "NetworkManagerUtils.h" #include "nm-manager.h" @@ -305,18 +306,19 @@ main (int argc, char *argv[]) GOptionContext *opt_ctx = NULL; gboolean become_daemon = FALSE; gboolean g_fatal_warnings = FALSE; - char *pidfile = NULL, *state_file = NULL; + gs_free char *pidfile = NULL; + gs_free char *state_file = NULL; gboolean wifi_enabled = TRUE, net_enabled = TRUE, wwan_enabled = TRUE, wimax_enabled = TRUE; gboolean success, show_version = FALSE; NMPolicy *policy = NULL; - NMVPNManager *vpn_manager = NULL; - NMDnsManager *dns_mgr = NULL; - NMDBusManager *dbus_mgr = NULL; - NMSupplicantManager *sup_mgr = NULL; - NMDHCPManager *dhcp_mgr = NULL; - NMFirewallManager *fw_mgr = NULL; - NMSettings *settings = NULL; - NMConfig *config; + gs_unref_object NMVPNManager *vpn_manager = NULL; + gs_unref_object NMDnsManager *dns_mgr = NULL; + gs_unref_object NMDBusManager *dbus_mgr = NULL; + gs_unref_object NMSupplicantManager *sup_mgr = NULL; + gs_unref_object NMDHCPManager *dhcp_mgr = NULL; + gs_unref_object NMFirewallManager *fw_mgr = NULL; + gs_unref_object NMSettings *settings = NULL; + gs_unref_object NMConfig *config = NULL; GError *error = NULL; gboolean wrote_pidfile = FALSE; @@ -579,41 +581,13 @@ done: if (policy) nm_policy_destroy (policy); - if (manager) - g_object_unref (manager); - - if (settings) - g_object_unref (settings); - - if (vpn_manager) - g_object_unref (vpn_manager); - - if (dns_mgr) - g_object_unref (dns_mgr); - - if (dhcp_mgr) - g_object_unref (dhcp_mgr); - - if (sup_mgr) - g_object_unref (sup_mgr); - - if (fw_mgr) - g_object_unref (fw_mgr); - - if (dbus_mgr) - g_object_unref (dbus_mgr); + g_clear_object (&manager); nm_logging_shutdown (); if (pidfile && wrote_pidfile) unlink (pidfile); - g_object_unref (config); - - /* Free options */ - g_free (pidfile); - g_free (state_file); - nm_log_info (LOGD_CORE, "exiting (%s)", success ? "success" : "error"); exit (success ? 0 : 1); }