diff options
author | Joel Holdsworth <joel.holdsworth@vcatechnology.com> | 2016-04-27 00:45:16 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2016-05-12 15:24:11 +0200 |
commit | 860606012145b42590e389655e4e4e3fec86e1d1 (patch) | |
tree | e03573f414f5ebc4a7dc8e6c43f81094c2b14342 | |
parent | d3be90e3e7059e6bb70b9c8f0f23ad84c5910df4 (diff) |
settings: Follow symbolic link when installing file monitor
https://bugzilla.gnome.org/show_bug.cgi?id=765645
-rw-r--r-- | src/settings/nm-settings.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c index da0a59493e..953662bb5b 100644 --- a/src/settings/nm-settings.c +++ b/src/settings/nm-settings.c @@ -2199,14 +2199,30 @@ setup_hostname_file_monitors (NMSettings *self) { NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self); GFileMonitor *monitor; + const char *path = HOSTNAME_FILE; + char *link_path = NULL; + struct stat file_stat; GFile *file; priv->hostname.value = nm_settings_get_hostname (self); + /* resolve the path to the hostname file if it is a symbolic link */ + if ( lstat(path, &file_stat) == 0 + && S_ISLNK (file_stat.st_mode) + && (link_path = nm_utils_read_link_absolute (path, NULL))) { + path = link_path; + if ( lstat(link_path, &file_stat) == 0 + && S_ISLNK (file_stat.st_mode)) { + _LOGW ("only one level of symbolic link indirection is allowed when monitoring " + HOSTNAME_FILE); + } + } + /* monitor changes to hostname file */ - file = g_file_new_for_path (HOSTNAME_FILE); + file = g_file_new_for_path (path); monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, NULL); g_object_unref (file); + g_free(link_path); if (monitor) { priv->hostname.monitor_id = g_signal_connect (monitor, "changed", G_CALLBACK (hostname_file_changed_cb), |