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/timezone-file.cpp') 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 From 835daa7778171256a02d8695776d0b8262b7b637 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 2 Feb 2014 15:28:52 -0600 Subject: copyediting: don't use camelCaseFunctionNames() in timezones-file --- include/datetime/timezone-file.h | 4 ++-- src/timezone-file.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/timezone-file.cpp') diff --git a/include/datetime/timezone-file.h b/include/datetime/timezone-file.h index d77aaae..a67c01a 100644 --- a/include/datetime/timezone-file.h +++ b/include/datetime/timezone-file.h @@ -42,8 +42,8 @@ public: ~FileTimezone(); private: - void setFilename(const std::string& filename); - static void onFileChanged(gpointer gself); + void set_filename(const std::string& filename); + static void on_file_changed(gpointer gself); void clear(); void reload(); diff --git a/src/timezone-file.cpp b/src/timezone-file.cpp index df4ee24..c99897a 100644 --- a/src/timezone-file.cpp +++ b/src/timezone-file.cpp @@ -32,7 +32,7 @@ FileTimezone::FileTimezone() FileTimezone::FileTimezone(const std::string& filename) { - setFilename(filename); + set_filename(filename); } FileTimezone::~FileTimezone() @@ -52,7 +52,7 @@ FileTimezone::clear() } void -FileTimezone::setFilename(const std::string& filename) +FileTimezone::set_filename(const std::string& filename) { clear(); @@ -79,7 +79,7 @@ FileTimezone::setFilename(const std::string& filename) } else { - m_monitor_handler_id = g_signal_connect_swapped(m_monitor, "changed", G_CALLBACK(onFileChanged), this); + m_monitor_handler_id = g_signal_connect_swapped(m_monitor, "changed", G_CALLBACK(on_file_changed), this); g_debug("%s Monitoring timezone file '%s'", G_STRLOC, m_filename.c_str()); } @@ -87,7 +87,7 @@ FileTimezone::setFilename(const std::string& filename) } void -FileTimezone::onFileChanged(gpointer gself) +FileTimezone::on_file_changed(gpointer gself) { static_cast(gself)->reload(); } -- cgit v1.2.3