Commit 2131954a authored by Thomas Haller's avatar Thomas Haller

config: add first_start paramter to NMConfig to detect restart

parent 1940be41
......@@ -149,6 +149,9 @@ nm_main_utils_ensure_rundir ()
exit (1);
}
/* NM_CONFIG_DEVICE_STATE_DIR is used to determine whether NM is restarted or not.
* It is important to set NMConfigCmdLineOptions.first_start before creating
* the directory. */
nm_assert (g_str_has_prefix (NM_CONFIG_DEVICE_STATE_DIR, NMRUNDIR"/"));
if (g_mkdir (NM_CONFIG_DEVICE_STATE_DIR, 0755) != 0) {
errsv = errno;
......
......@@ -239,7 +239,11 @@ main (int argc, char *argv[])
main_loop = g_main_loop_new (NULL, FALSE);
config_cli = nm_config_cmd_line_options_new ();
/* we determine a first-start (contrary to a restart during the same boot)
* based on the existence of NM_CONFIG_DEVICE_STATE_DIR directory. */
config_cli = nm_config_cmd_line_options_new (!g_file_test (NM_CONFIG_DEVICE_STATE_DIR,
G_FILE_TEST_IS_DIR));
do_early_setup (&argc, &argv, config_cli);
if (global_opt.g_fatal_warnings)
......@@ -356,7 +360,8 @@ main (int argc, char *argv[])
NM_CONFIG_GET_VALUE_STRIP | NM_CONFIG_GET_VALUE_NO_EMPTY),
nm_config_get_is_debug (config));
nm_log_info (LOGD_CORE, "NetworkManager (version " NM_DIST_VERSION ") is starting...");
nm_log_info (LOGD_CORE, "NetworkManager (version " NM_DIST_VERSION ") is starting... (%s)",
nm_config_get_first_start (config) ? "for the first time" : "after a restart");
nm_log_info (LOGD_CORE, "Read config: %s", nm_config_data_get_config_description (nm_config_get_data (config)));
nm_config_data_log (nm_config_get_data (config), "CONFIG: ", " ", NULL);
......
......@@ -60,6 +60,15 @@ struct NMConfigCmdLineOptions {
*/
int connectivity_interval;
char *connectivity_response;
/* @first_start is not provided by command line. It is a convenient hack
* to pass in an argument to NMConfig. This makes NMConfigCmdLineOptions a
* misnomer.
*
* It is true, if NM is started the first time -- contrary to a restart
* during the same boot up. That is determined by the content of the
* /var/run/NetworManager state directory. */
bool first_start;
};
typedef struct {
......@@ -291,6 +300,12 @@ nm_config_get_is_debug (NMConfig *config)
return NM_CONFIG_GET_PRIVATE (config)->cli.is_debug;
}
gboolean
nm_config_get_first_start (NMConfig *config)
{
return NM_CONFIG_GET_PRIVATE (config)->cli.first_start;
}
/*****************************************************************************/
static char **
......@@ -412,6 +427,7 @@ _nm_config_cmd_line_options_clear (NMConfigCmdLineOptions *cli)
g_clear_pointer (&cli->connectivity_uri, g_free);
g_clear_pointer (&cli->connectivity_response, g_free);
cli->connectivity_interval = -1;
cli->first_start = FALSE;
}
static void
......@@ -434,14 +450,18 @@ _nm_config_cmd_line_options_copy (const NMConfigCmdLineOptions *cli, NMConfigCmd
dst->connectivity_uri = g_strdup (cli->connectivity_uri);
dst->connectivity_response = g_strdup (cli->connectivity_response);
dst->connectivity_interval = cli->connectivity_interval;
dst->first_start = cli->first_start;
}
NMConfigCmdLineOptions *
nm_config_cmd_line_options_new ()
nm_config_cmd_line_options_new (gboolean first_start)
{
NMConfigCmdLineOptions *cli = g_new0 (NMConfigCmdLineOptions, 1);
_nm_config_cmd_line_options_clear (cli);
cli->first_start = first_start;
return cli;
}
......
......@@ -125,13 +125,15 @@ const char *nm_config_get_log_domains (NMConfig *config);
gboolean nm_config_get_configure_and_quit (NMConfig *config);
gboolean nm_config_get_is_debug (NMConfig *config);
gboolean nm_config_get_first_start (NMConfig *config);
void nm_config_set_values (NMConfig *self,
GKeyFile *keyfile_intern_new,
gboolean allow_write,
gboolean force_rewrite);
/* for main.c only */
NMConfigCmdLineOptions *nm_config_cmd_line_options_new (void);
NMConfigCmdLineOptions *nm_config_cmd_line_options_new (gboolean first_start);
void nm_config_cmd_line_options_free (NMConfigCmdLineOptions *cli);
void nm_config_cmd_line_options_add_to_entries (NMConfigCmdLineOptions *cli,
GOptionContext *opt_ctx);
......
......@@ -97,7 +97,7 @@ setup_config (GError **error, const char *config_file, const char *intern_config
argv = (char **)args->pdata;
argc = args->len;
cli = nm_config_cmd_line_options_new ();
cli = nm_config_cmd_line_options_new (FALSE);
context = g_option_context_new (NULL);
nm_config_cmd_line_options_add_to_entries (cli, context);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment