From 5828562c08f8bd01826da4db12f7c4be3dc574d0 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 31 Jan 2014 12:04:47 -0600 Subject: use realpath() to dereference symbolic links when watching /etc/timezone. h/t pitti --- src/timezone-file.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/timezone-file.cpp b/src/timezone-file.cpp index 76737b4..df4ee24 100644 --- a/src/timezone-file.cpp +++ b/src/timezone-file.cpp @@ -19,6 +19,9 @@ #include +#include +#include + namespace unity { namespace indicator { namespace datetime { @@ -53,9 +56,19 @@ FileTimezone::setFilename(const std::string& filename) { clear(); - m_filename = filename; + auto tmp = realpath(filename.c_str(), nullptr); + if(tmp != nullptr) + { + m_filename = tmp; + free(tmp); + } + else + { + g_warning("Unable to resolve path '%s': %s", filename.c_str(), g_strerror(errno)); + m_filename = filename; // better than nothing? + } - auto file = g_file_new_for_path(filename.c_str()); + auto file = g_file_new_for_path(m_filename.c_str()); GError * err = nullptr; m_monitor = g_file_monitor_file(file, G_FILE_MONITOR_NONE, nullptr, &err); g_object_unref(file); @@ -67,7 +80,7 @@ FileTimezone::setFilename(const std::string& filename) else { m_monitor_handler_id = g_signal_connect_swapped(m_monitor, "changed", G_CALLBACK(onFileChanged), this); - g_debug("%s Monitoring timezone file '%s'", G_STRLOC, filename.c_str()); + g_debug("%s Monitoring timezone file '%s'", G_STRLOC, m_filename.c_str()); } reload(); -- cgit v1.2.3