settings: Follow symbolic link when installing file monitor

https://bugzilla.gnome.org/show_bug.cgi?id=765645
This commit is contained in:
Joel Holdsworth 2016-04-27 00:45:16 +01:00 committed by Thomas Haller
parent d3be90e3e7
commit 8606060121

View file

@ -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),