summary refs log tree commit diff
path: root/src/main.c
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2013-02-03 14:49:22 +0100
committerMichael Biebl <biebl@debian.org>2013-02-03 14:49:22 +0100
commit9c202e3e860b3be9e1f8882630b69affbb130102 (patch)
tree8202bf39f2129486971fa7d5ae0dee61a561aa53 /src/main.c
parent36cb2f364a821e1be50b23e03a18891ec55adb06 (diff)
Imported Upstream version 0.9.7.995 upstream/0.9.7.995
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c57
1 files changed, 33 insertions, 24 deletions
diff --git a/src/main.c b/src/main.c
index 8bc6d3f6..b074bd8a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -42,7 +42,6 @@
 #include "NetworkManagerUtils.h"
 #include "nm-manager.h"
 #include "nm-policy.h"
-#include "backends/nm-backend.h"
 #include "nm-dns-manager.h"
 #include "nm-dbus-manager.h"
 #include "nm-supplicant-manager.h"
@@ -55,13 +54,14 @@
 #include "nm-policy-hosts.h"
 #include "nm-config.h"
 #include "nm-posix-signals.h"
+#include "nm-system.h"
 
 #if !defined(NM_DIST_VERSION)
 # define NM_DIST_VERSION VERSION
 #endif
 
-#define NM_DEFAULT_PID_FILE          LOCALSTATEDIR"/run/NetworkManager.pid"
-#define NM_DEFAULT_SYSTEM_STATE_FILE LOCALSTATEDIR"/lib/NetworkManager/NetworkManager.state"
+#define NM_DEFAULT_PID_FILE          NMRUNDIR "/NetworkManager.pid"
+#define NM_DEFAULT_SYSTEM_STATE_FILE NMSTATEDIR "/NetworkManager.state"
 
 /*
  * Globals
@@ -278,24 +278,11 @@ parse_state_file (const char *filename,
 		 * users upgrading NM get this working too.
 		 */
 		if (g_error_matches (tmp_error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) {
-			char *data, *dirname;
+			char *data;
 			gsize len = 0;
 
 			g_clear_error (&tmp_error);
 
-			/* try to create the directory if it doesn't exist */
-			dirname = g_path_get_dirname (filename);
-			errno = 0;
-			if (g_mkdir_with_parents (dirname, 0755) != 0) {
-				if (errno != EEXIST) {
-					g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_ACCES,
-					             "Error creating state directory %s: %s", dirname, strerror(errno));
-					g_free (dirname);
-					return FALSE;
-				}
-			}
-			g_free (dirname);
-
 			/* Write out the initial state to the state file */
 			g_key_file_set_boolean (state_file, "main", "NetworkingEnabled", *net_enabled);
 			g_key_file_set_boolean (state_file, "main", "WirelessEnabled", *wifi_enabled);
@@ -401,10 +388,6 @@ main (int argc, char *argv[])
 		exit (1);
 	}
 
-	/* Set up unix signal handling */
-	if (!setup_signals ())
-		exit (1);
-
 	/* Set locale to be able to use environment variables */
 	setlocale (LC_ALL, "");
 
@@ -446,6 +429,18 @@ main (int argc, char *argv[])
 	 */
 	setenv ("GIO_USE_VFS", "local", 1);
 
+	/* Setup runtime directory */
+	if (g_mkdir_with_parents (NMRUNDIR, 0755) != 0) {
+		nm_log_err (LOGD_CORE, "Cannot create '%s': %s", NMRUNDIR, strerror (errno));
+		exit (1);
+	}
+
+	/* Ensure state directory exists */
+	if (g_mkdir_with_parents (NMSTATEDIR, 0755) != 0) {
+		nm_log_err (LOGD_CORE, "Cannot create '%s': %s", NMSTATEDIR, strerror (errno));
+		exit (1);
+	}
+
 	pidfile = pidfile ? pidfile : g_strdup (NM_DEFAULT_PID_FILE);
 	state_file = state_file ? state_file : g_strdup (NM_DEFAULT_SYSTEM_STATE_FILE);
 
@@ -501,6 +496,10 @@ main (int argc, char *argv[])
 			wrote_pidfile = TRUE;
 	}
 
+	/* Set up unix signal handling - before creating threads, but after daemonizing! */
+	if (!setup_signals ())
+		exit (1);
+
 	if (g_fatal_warnings) {
 		GLogLevelFlags fatal_mask;
 
@@ -600,7 +599,7 @@ main (int argc, char *argv[])
 		goto done;
 	}
 
-	policy = nm_policy_new (manager, vpn_manager, settings);
+	policy = nm_policy_new (manager, settings);
 	if (policy == NULL) {
 		nm_log_err (LOGD_CORE, "failed to initialize the policy.");
 		goto done;
@@ -640,8 +639,18 @@ main (int argc, char *argv[])
 
 	nm_manager_start (manager);
 
-	/* Bring up the loopback interface. */
-	nm_backend_enable_loopback ();
+	/* Make sure the loopback interface is up. If interface is down, we bring
+	 * it up and kernel will assign it link-local IPv4 and IPv6 addresses. If
+	 * it was already up, we assume is in clean state.
+	 *
+	 * TODO: it might be desirable to check the list of addresses and compare
+	 * it with a list of expected addresses (one of the protocol families
+	 * could be disabled). The 'lo' interface is sometimes used for assigning
+	 * global addresses so their availability doesn't depend on the state of
+	 * physical interfaces.
+	 */
+	nm_log_dbg (LOGD_CORE, "setting up local loopback");
+	nm_system_iface_set_up (nm_netlink_iface_to_index ("lo"), TRUE, NULL);
 
 	success = TRUE;