aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2014-01-31 12:04:47 -0600
committerCharles Kerr <charles.kerr@canonical.com>2014-01-31 12:04:47 -0600
commit5828562c08f8bd01826da4db12f7c4be3dc574d0 (patch)
tree2faada38d1c7dee5b99ff4648af4dc411053b738
parent271b0fbf8b14a4f7a8f47de0e3a8751bd50676c3 (diff)
downloadayatana-indicator-datetime-5828562c08f8bd01826da4db12f7c4be3dc574d0.tar.gz
ayatana-indicator-datetime-5828562c08f8bd01826da4db12f7c4be3dc574d0.tar.bz2
ayatana-indicator-datetime-5828562c08f8bd01826da4db12f7c4be3dc574d0.zip
use realpath() to dereference symbolic links when watching /etc/timezone. h/t pitti
-rw-r--r--src/timezone-file.cpp19
1 files changed, 16 insertions, 3 deletions
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 <datetime/timezone-file.h>
+#include <cerrno>
+#include <cstdlib>
+
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();