Skip to content

Commit ad252b2

Browse files
committed
Extend rpm-ostreed.service idle-timeout
When making D-Bus calls to the rpm-ostreed.service, the service will always exit after the specified idle-timeout has passed from when the daemon was first created. Even if D-Bus calls are constantly being made, the idle-timeout will still be enforced. This commit subscribes to the bus, listening for new calls. If a call is detected, the idle-timeout is reset. The service will only stop after the idle-timeout has passed after the last call to the bus. Signed-off-by: Luke Yang <luyang@redhat.com>
1 parent 6987471 commit ad252b2

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/daemon/rpmostreed-daemon.cxx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,20 @@ on_idle_exit (void *data)
562562
return FALSE;
563563
}
564564

565+
void
566+
reset_idle_exit_timer (GDBusConnection *connection, const gchar *sender_name,
567+
const gchar *object_path, const gchar *interface_name,
568+
const gchar *signal_name, GVariant *parameters, gpointer user_data)
569+
{
570+
auto self = static_cast<RpmostreedDaemon *> (user_data);
571+
if (self->idle_exit_source)
572+
{
573+
guint64 curtime = g_source_get_time (self->idle_exit_source);
574+
const guint idle_exit_secs = self->idle_exit_timeout + g_random_int_range (0, 5);
575+
g_source_set_ready_time (self->idle_exit_source, curtime + idle_exit_secs * G_USEC_PER_SEC);
576+
}
577+
}
578+
565579
static void
566580
update_status (RpmostreedDaemon *self)
567581
{
@@ -571,6 +585,12 @@ update_status (RpmostreedDaemon *self)
571585
const guint n_clients = g_hash_table_size (self->bus_clients);
572586
gboolean currently_idle = FALSE;
573587

588+
guint subscription_id;
589+
590+
subscription_id = g_dbus_connection_signal_subscribe (
591+
self->connection, NULL, NULL, NULL, "/org/freedesktop/DBus", NULL, G_DBUS_SIGNAL_FLAGS_NONE,
592+
reset_idle_exit_timer, g_object_ref (self), g_object_unref);
593+
574594
g_object_get (rpmostreed_sysroot_get (), "active-transaction", &active_txn, NULL);
575595

576596
if (active_txn)
@@ -618,7 +638,10 @@ update_status (RpmostreedDaemon *self)
618638
guint64 curtime = g_source_get_time (self->idle_exit_source);
619639
guint64 timeout_micros = readytime - curtime;
620640
if (readytime < curtime)
621-
timeout_micros = 0;
641+
{
642+
timeout_micros = 0;
643+
g_dbus_connection_signal_unsubscribe (self->connection, subscription_id);
644+
}
622645

623646
g_assert (currently_idle && self->idle_exit_source);
624647
sd_notifyf (0, "STATUS=clients=%u; idle exit in %" G_GUINT64_FORMAT " seconds", n_clients,

src/daemon/rpmostreed-daemon.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,7 @@ namespace rpmostreecxx
6868
{
6969
rust::Box<TokioEnterGuard> rpmostreed_daemon_tokio_enter (RpmostreedDaemon *self);
7070
}
71+
72+
void reset_idle_exit_timer (GDBusConnection *connection, const gchar *sender_name,
73+
const gchar *object_path, const gchar *interface_name,
74+
const gchar *signal_name, GVariant *parameters, gpointer user_data);

0 commit comments

Comments
 (0)