Skip to content

Commit

Permalink
Extend rpm-ostreed.service idle-timeout
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
lukewarmtemp committed Jul 31, 2024
1 parent 6987471 commit ad252b2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/daemon/rpmostreed-daemon.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,20 @@ on_idle_exit (void *data)
return FALSE;
}

void
reset_idle_exit_timer (GDBusConnection *connection, const gchar *sender_name,
const gchar *object_path, const gchar *interface_name,
const gchar *signal_name, GVariant *parameters, gpointer user_data)
{
auto self = static_cast<RpmostreedDaemon *> (user_data);
if (self->idle_exit_source)
{
guint64 curtime = g_source_get_time (self->idle_exit_source);
const guint idle_exit_secs = self->idle_exit_timeout + g_random_int_range (0, 5);
g_source_set_ready_time (self->idle_exit_source, curtime + idle_exit_secs * G_USEC_PER_SEC);
}
}

static void
update_status (RpmostreedDaemon *self)
{
Expand All @@ -571,6 +585,12 @@ update_status (RpmostreedDaemon *self)
const guint n_clients = g_hash_table_size (self->bus_clients);
gboolean currently_idle = FALSE;

guint subscription_id;

subscription_id = g_dbus_connection_signal_subscribe (
self->connection, NULL, NULL, NULL, "/org/freedesktop/DBus", NULL, G_DBUS_SIGNAL_FLAGS_NONE,
reset_idle_exit_timer, g_object_ref (self), g_object_unref);

g_object_get (rpmostreed_sysroot_get (), "active-transaction", &active_txn, NULL);

if (active_txn)
Expand Down Expand Up @@ -618,7 +638,10 @@ update_status (RpmostreedDaemon *self)
guint64 curtime = g_source_get_time (self->idle_exit_source);
guint64 timeout_micros = readytime - curtime;
if (readytime < curtime)
timeout_micros = 0;
{
timeout_micros = 0;
g_dbus_connection_signal_unsubscribe (self->connection, subscription_id);
}

g_assert (currently_idle && self->idle_exit_source);
sd_notifyf (0, "STATUS=clients=%u; idle exit in %" G_GUINT64_FORMAT " seconds", n_clients,
Expand Down
4 changes: 4 additions & 0 deletions src/daemon/rpmostreed-daemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,7 @@ namespace rpmostreecxx
{
rust::Box<TokioEnterGuard> rpmostreed_daemon_tokio_enter (RpmostreedDaemon *self);
}

void reset_idle_exit_timer (GDBusConnection *connection, const gchar *sender_name,
const gchar *object_path, const gchar *interface_name,
const gchar *signal_name, GVariant *parameters, gpointer user_data);

0 comments on commit ad252b2

Please sign in to comment.