mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-06 23:20:34 +01:00
keyfile: crash less if conf_file is NULL
If for some reason we have no config file, don't segfault.
This commit is contained in:
parent
511bc09663
commit
644e245c0b
1 changed files with 19 additions and 6 deletions
|
|
@ -351,13 +351,15 @@ setup_monitoring (NMSystemConfigInterface *config)
|
|||
priv->monitor = monitor;
|
||||
}
|
||||
|
||||
file = g_file_new_for_path (priv->conf_file);
|
||||
monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, NULL);
|
||||
g_object_unref (file);
|
||||
if (priv->conf_file) {
|
||||
file = g_file_new_for_path (priv->conf_file);
|
||||
monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, NULL);
|
||||
g_object_unref (file);
|
||||
|
||||
if (monitor) {
|
||||
priv->conf_file_monitor_id = g_signal_connect (monitor, "changed", G_CALLBACK (conf_file_changed), config);
|
||||
priv->conf_file_monitor = monitor;
|
||||
if (monitor) {
|
||||
priv->conf_file_monitor_id = g_signal_connect (monitor, "changed", G_CALLBACK (conf_file_changed), config);
|
||||
priv->conf_file_monitor = monitor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -407,6 +409,9 @@ get_unmanaged_specs (NMSystemConfigInterface *config)
|
|||
GSList *specs = NULL;
|
||||
GError *error = NULL;
|
||||
|
||||
if (!priv->conf_file)
|
||||
return NULL;
|
||||
|
||||
key_file = g_key_file_new ();
|
||||
if (g_key_file_load_from_file (key_file, priv->conf_file, G_KEY_FILE_NONE, &error)) {
|
||||
char *str;
|
||||
|
|
@ -457,6 +462,9 @@ plugin_get_hostname (SCPluginKeyfile *plugin)
|
|||
char *hostname = NULL;
|
||||
GError *error = NULL;
|
||||
|
||||
if (!priv->conf_file)
|
||||
return NULL;
|
||||
|
||||
key_file = g_key_file_new ();
|
||||
if (g_key_file_load_from_file (key_file, priv->conf_file, G_KEY_FILE_NONE, &error))
|
||||
hostname = g_key_file_get_value (key_file, "keyfile", "hostname", NULL);
|
||||
|
|
@ -478,6 +486,11 @@ plugin_set_hostname (SCPluginKeyfile *plugin, const char *hostname)
|
|||
GError *error = NULL;
|
||||
gboolean result = FALSE;
|
||||
|
||||
if (!priv->conf_file) {
|
||||
g_warning ("Error saving hostname: no config file");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
key_file = g_key_file_new ();
|
||||
if (g_key_file_load_from_file (key_file, priv->conf_file, G_KEY_FILE_NONE, &error)) {
|
||||
char *data;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue