Skip to content

Commit

Permalink
daemon: Add new Reload D-Bus method
Browse files Browse the repository at this point in the history
Add a new `Reload` method as a softer alternative to `ReloadConfig`.
We'll also make use of this on the client side to sync with the daemon.
  • Loading branch information
jlebon committed Mar 23, 2018
1 parent 82ee68d commit 8a0f8c8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 9 deletions.
6 changes: 6 additions & 0 deletions src/daemon/org.projectatomic.rpmostree1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
<arg type="a{sv}" name="options" direction="in"/>
</method>

<!-- Reload sysroot if changed. This can also be used as a way to sync with the daemon
to ensure e.g. D-Bus properties are updated before reading them. -->
<method name="Reload">
</method>

<!-- Like Reload, but also reload configuration files. -->
<method name="ReloadConfig">
</method>

Expand Down
44 changes: 35 additions & 9 deletions src/daemon/rpmostreed-sysroot.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,36 @@ reset_config_properties (RpmostreedSysroot *self,
return TRUE;
}

static gboolean
reload_sysroot_and_os (RpmostreedSysroot *self,
GError **error)
{
gboolean sysroot_changed;
if (!sysroot_reload (self, &sysroot_changed, error))
return FALSE;

/* always send an UPDATED signal to also force OS interfaces to reload */
if (!sysroot_changed) /* but only if not done already in sysroot_reload */
g_signal_emit (self, signals[UPDATED], 0);

return TRUE;
}

static gboolean
handle_reload (RPMOSTreeSysroot *object,
GDBusMethodInvocation *invocation)
{
RpmostreedSysroot *self = RPMOSTREED_SYSROOT (object);
g_autoptr(GError) local_error = NULL;

if (reload_sysroot_and_os (self, &local_error))
rpmostree_sysroot_complete_reload (object, invocation);
else if (local_error)
g_dbus_method_invocation_take_error (invocation, g_steal_pointer (&local_error));

return TRUE;
}

static gboolean
handle_reload_config (RPMOSTreeSysroot *object,
GDBusMethodInvocation *invocation)
Expand All @@ -447,15 +477,9 @@ handle_reload_config (RPMOSTreeSysroot *object,
if (changed && !reset_config_properties (self, error))
goto out;

gboolean sysroot_changed;
if (!sysroot_reload (self, &sysroot_changed, error))
if (!reload_sysroot_and_os (self, error))
goto out;

/* also send an UPDATED signal if configs changed to cause OS interfaces to reload; we do
* it here if not done already in `rpmostreed_sysroot_reload` */
if (changed && !sysroot_changed)
g_signal_emit (self, signals[UPDATED], 0);

rpmostree_sysroot_complete_reload_config (object, invocation);
out:
if (local_error)
Expand Down Expand Up @@ -600,9 +624,10 @@ sysroot_authorize_method (GDBusInterfaceSkeleton *interface,
/* The daemon is on the session bus, running self tests */
authorized = TRUE;
}
else if (g_strcmp0 (method_name, "GetOS") == 0)
else if (g_strcmp0 (method_name, "GetOS") == 0 ||
g_strcmp0 (method_name, "Reload") == 0)
{
/* GetOS() is always allowed */
/* GetOS() and Reload() are always allowed */
authorized = TRUE;
}
else if (g_strcmp0 (method_name, "ReloadConfig") == 0)
Expand Down Expand Up @@ -753,6 +778,7 @@ rpmostreed_sysroot_iface_init (RPMOSTreeSysrootIface *iface)
iface->handle_get_os = handle_get_os;
iface->handle_register_client = handle_register_client;
iface->handle_unregister_client = handle_unregister_client;
iface->handle_reload = handle_reload;
iface->handle_reload_config = handle_reload_config;
}

Expand Down

0 comments on commit 8a0f8c8

Please sign in to comment.