aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2015-03-01 06:08:06 +0000
committerCI Train Bot <ci-train-bot@canonical.com>2015-03-01 06:08:06 +0000
commit30b31616438cbed31e7cf6066194ae2f715a07cc (patch)
tree9424d19e8506ea1f4d13563157e7fa97816cc360 /src
parentc2939aaca5e43a6080fdffbf3c9f7f410c3deef4 (diff)
parent510111c86d897d2095107387ebfb7a084e397efe (diff)
downloadayatana-indicator-datetime-30b31616438cbed31e7cf6066194ae2f715a07cc.tar.gz
ayatana-indicator-datetime-30b31616438cbed31e7cf6066194ae2f715a07cc.tar.bz2
ayatana-indicator-datetime-30b31616438cbed31e7cf6066194ae2f715a07cc.zip
create a new timerfd each time we need to call timerfd_settime(). Fixes: #1424966
Approved by: Ted Gould
Diffstat (limited to 'src')
-rw-r--r--src/clock-live.cpp59
1 files changed, 35 insertions, 24 deletions
diff --git a/src/clock-live.cpp b/src/clock-live.cpp
index 988d47f..7f8bd1b 100644
--- a/src/clock-live.cpp
+++ b/src/clock-live.cpp
@@ -52,31 +52,13 @@ public:
setter(m_timezone->timezone.get());
}
- m_timerfd = timerfd_create(CLOCK_REALTIME, 0);
- if (m_timerfd == -1)
- {
- g_warning("unable to create realtime timer: %s", g_strerror(errno));
- }
- else
- {
- reset_timer();
-
- m_timerfd_tag = g_unix_fd_add(m_timerfd,
- (GIOCondition)(G_IO_IN|G_IO_HUP|G_IO_ERR),
- on_timerfd_cond,
- this);
- }
-
+ reset_timer();
refresh();
}
~Impl()
{
- if (m_timerfd_tag != 0)
- g_source_remove(m_timerfd_tag);
-
- if (m_timerfd != -1)
- close(m_timerfd);
+ unset_timer();
g_clear_pointer(&m_gtimezone, g_time_zone_unref);
}
@@ -93,10 +75,33 @@ public:
private:
+ void unset_timer()
+ {
+ if (m_timerfd_tag != 0)
+ {
+ g_source_remove(m_timerfd_tag);
+ m_timerfd_tag = 0;
+ }
+
+ if (m_timerfd != -1)
+ {
+ close(m_timerfd);
+ m_timerfd = -1;
+ }
+ }
+
void reset_timer()
{
- struct itimerspec timerval;
+ // clear out any previous timer
+ unset_timer();
+
+ // create a new timer
+ m_timerfd = timerfd_create(CLOCK_REALTIME, 0);
+ if (m_timerfd == -1)
+ g_error("unable to create realtime timer: %s", g_strerror(errno));
+
// set args to fire at the beginning of the next minute...
+ struct itimerspec timerval;
int flags = TFD_TIMER_ABSTIME;
auto now = g_date_time_new_now(m_gtimezone);
auto next = g_date_time_add_minutes(now, 1);
@@ -115,6 +120,12 @@ private:
if (timerfd_settime(m_timerfd, flags, &timerval, NULL) == -1)
g_error("timerfd_settime failed: %s", g_strerror(errno));
+
+ // listen for the changes/timers
+ m_timerfd_tag = g_unix_fd_add(m_timerfd,
+ (GIOCondition)(G_IO_IN|G_IO_HUP|G_IO_ERR),
+ on_timerfd_cond,
+ this);
}
static gboolean on_timerfd_cond (gint fd, GIOCondition cond, gpointer gself)
@@ -130,9 +141,9 @@ private:
{
auto now = g_date_time_new_now(self->m_gtimezone);
auto now_str = g_date_time_format(now, "%F %T");
- g_message("%s triggered at %s.%06d by GIOCondition %d, read %zd bytes, found %zu interrupts",
- G_STRFUNC, now_str, g_date_time_get_microsecond(now),
- (int)cond, n_bytes, n_interrupts);
+ g_debug("%s triggered at %s.%06d by GIOCondition %d, read %zd bytes, found %zu interrupts",
+ G_STRFUNC, now_str, g_date_time_get_microsecond(now),
+ (int)cond, n_bytes, n_interrupts);
g_free(now_str);
g_date_time_unref(now);