Commit c8282778 authored by Thomas Haller's avatar Thomas Haller

device: merge branch 'th/device-assume-guess-rh1443878'

https://bugzilla.redhat.com/show_bug.cgi?id=1443878
parents 4bdb6b02 27b2477c
......@@ -12997,7 +12997,7 @@ nm_device_update_permanent_hw_address (NMDevice *self, gboolean force_freeze)
{
gs_free NMConfigDeviceStateData *dev_state = NULL;
dev_state = nm_config_device_state_load (nm_config_get (), ifindex);
dev_state = nm_config_device_state_load (ifindex);
if ( dev_state
&& dev_state->perm_hw_addr_fake
&& nm_utils_hwaddr_aton (dev_state->perm_hw_addr_fake, buf, priv->hw_addr_len)
......
......@@ -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;
}
......@@ -1926,15 +1946,13 @@ _config_device_state_data_new (int ifindex, GKeyFile *kf)
/**
* nm_config_device_state_load:
* @self: the NMConfig instance
* @ifindex: the ifindex for which the state is to load
*
* Returns: (transfer full): a run state object.
* Must be freed with g_free().
*/
NMConfigDeviceStateData *
nm_config_device_state_load (NMConfig *self,
int ifindex)
nm_config_device_state_load (int ifindex)
{
NMConfigDeviceStateData *device_state;
char path[NM_STRLEN (NM_CONFIG_DEVICE_STATE_DIR) + 60];
......@@ -1972,8 +1990,7 @@ NM_UTILS_LOOKUP_STR_DEFINE_STATIC (_device_state_managed_type_to_str, NMConfigDe
);
gboolean
nm_config_device_state_write (NMConfig *self,
int ifindex,
nm_config_device_state_write (int ifindex,
NMConfigDeviceStateManagedType managed,
const char *perm_hw_addr_fake,
const char *connection_uuid)
......@@ -1982,7 +1999,6 @@ nm_config_device_state_write (NMConfig *self,
GError *local = NULL;
gs_unref_keyfile GKeyFile *kf = NULL;
g_return_val_if_fail (NM_IS_CONFIG (self), FALSE);
g_return_val_if_fail (ifindex > 0, FALSE);
g_return_val_if_fail (!connection_uuid || *connection_uuid, FALSE);
g_return_val_if_fail (managed == NM_CONFIG_DEVICE_STATE_MANAGED_TYPE_MANAGED || !connection_uuid, FALSE);
......@@ -2027,8 +2043,7 @@ nm_config_device_state_write (NMConfig *self,
}
void
nm_config_device_state_prune_unseen (NMConfig *self,
GHashTable *seen_ifindexes)
nm_config_device_state_prune_unseen (GHashTable *seen_ifindexes)
{
GDir *dir;
const char *fn;
......
......@@ -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);
......@@ -204,14 +206,12 @@ struct _NMConfigDeviceStateData {
const char *perm_hw_addr_fake;
};
NMConfigDeviceStateData *nm_config_device_state_load (NMConfig *self,
int ifindex);
gboolean nm_config_device_state_write (NMConfig *self,
int ifindex,
NMConfigDeviceStateData *nm_config_device_state_load (int ifindex);
gboolean nm_config_device_state_write (int ifindex,
NMConfigDeviceStateManagedType managed,
const char *perm_hw_addr_fake,
const char *connection_uuid);
void nm_config_device_state_prune_unseen (NMConfig *self, GHashTable *seen_ifindexes);
void nm_config_device_state_prune_unseen (GHashTable *seen_ifindexes);
/*****************************************************************************/
......
This diff is collapsed.
......@@ -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