summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2015-03-13 20:09:46 +0100
committerThomas Haller <thaller@redhat.com>2015-03-20 11:43:29 +0100
commit5775df9a6dcfaa4a9d208c8e78d6a7419c0e6a07 (patch)
treef80ea27481e012791a860e9aad22ccf0d3fd36ba /src/main.c
parent1fc5aba42a175c0eca0b6d8804d6ee9088c1dfe5 (diff)
downloadNetworkManager-5775df9a6dcfaa4a9d208c8e78d6a7419c0e6a07.tar.gz
main: refactor early setup in main()
Move call to nm_main_utils_early_setup() to a separate function. Also move the @options array away from the main function, saving a few bytes on the stack. Now only do_early_setup() modifies the @global_opt structure.
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c58
1 files changed, 32 insertions, 26 deletions
diff --git a/src/main.c b/src/main.c
index a1747f2e59..c06c746ddf 100644
--- a/src/main.c
+++ b/src/main.c
@@ -211,23 +211,9 @@ manager_configure_quit (NMManager *manager, gpointer user_data)
configure_and_quit = TRUE;
}
-/*
- * main
- *
- */
-int
-main (int argc, char *argv[])
+static void
+do_early_setup (int *argc, char **argv[], NMConfigCmdLineOptions *config_cli)
{
- gboolean wifi_enabled = TRUE, net_enabled = TRUE, wwan_enabled = TRUE, wimax_enabled = TRUE;
- gboolean success;
- NMManager *manager = NULL;
- gs_unref_object NMSettings *settings = NULL;
- NMConfig *config;
- GError *error = NULL;
- gboolean wrote_pidfile = FALSE;
- char *bad_domains = NULL;
- NMConfigCmdLineOptions *config_cli;
-
GOptionEntry options[] = {
{ "version", 'V', 0, G_OPTION_ARG_NONE, &global_opt.show_version, N_("Print NetworkManager version and exit"), NULL },
{ "no-daemon", 'n', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &global_opt.become_daemon, N_("Don't become a daemon"), NULL },
@@ -243,20 +229,43 @@ main (int argc, char *argv[])
{NULL}
};
- _nm_utils_is_manager_process = TRUE;
-
- main_loop = g_main_loop_new (NULL, FALSE);
-
- config_cli = nm_config_cmd_line_options_new ();
if (!nm_main_utils_early_setup ("NetworkManager",
- &argc,
- &argv,
+ argc,
+ argv,
options,
(void (*)(gpointer, GOptionContext *)) nm_config_cmd_line_options_add_to_entries,
config_cli,
_("NetworkManager monitors all network connections and automatically\nchooses the best connection to use. It also allows the user to\nspecify wireless access points which wireless cards in the computer\nshould associate with.")))
exit (1);
+ global_opt.pidfile = global_opt.pidfile ? global_opt.pidfile : g_strdup (NM_DEFAULT_PID_FILE);
+ global_opt.state_file = global_opt.state_file ? global_opt.state_file : g_strdup (NM_DEFAULT_SYSTEM_STATE_FILE);
+}
+
+/*
+ * main
+ *
+ */
+int
+main (int argc, char *argv[])
+{
+ gboolean wifi_enabled = TRUE, net_enabled = TRUE, wwan_enabled = TRUE, wimax_enabled = TRUE;
+ gboolean success;
+ NMManager *manager = NULL;
+ gs_unref_object NMSettings *settings = NULL;
+ NMConfig *config;
+ GError *error = NULL;
+ gboolean wrote_pidfile = FALSE;
+ char *bad_domains = NULL;
+ NMConfigCmdLineOptions *config_cli;
+
+ _nm_utils_is_manager_process = TRUE;
+
+ main_loop = g_main_loop_new (NULL, FALSE);
+
+ config_cli = nm_config_cmd_line_options_new ();
+ do_early_setup (&argc, &argv, config_cli);
+
if (global_opt.show_version) {
fprintf (stdout, NM_DIST_VERSION "\n");
exit (0);
@@ -307,9 +316,6 @@ main (int argc, char *argv[])
exit (1);
}
- global_opt.pidfile = global_opt.pidfile ? global_opt.pidfile : g_strdup (NM_DEFAULT_PID_FILE);
- global_opt.state_file = global_opt.state_file ? global_opt.state_file : g_strdup (NM_DEFAULT_SYSTEM_STATE_FILE);
-
/* check pid file */
if (nm_main_utils_check_pidfile (global_opt.pidfile, "NetworkManager"))
exit (1);