Skip to content

Commit

Permalink
Move reboot handling to client
Browse files Browse the repository at this point in the history
Having the daemon start the reboot means that it can be killed
by `SIGTERM` before the client processes the completion, causing
the client to exit with a spurious error.

Instead, have the client start the reboot.  This is cleaner
in numerous ways.  An additional benefit for example is that
if there are systemd reboot inhibitors present, it will be
the client that blocks, not the daemon.
  • Loading branch information
cgwalters committed May 20, 2021
1 parent da84ab8 commit 8a102f6
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 23 deletions.
7 changes: 5 additions & 2 deletions src/app/rpmostree-builtin-deploy.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ rpmostree_builtin_deploy (int argc,

GVariantDict dict;
g_variant_dict_init (&dict, NULL);
g_variant_dict_insert (&dict, "reboot", "b", opt_reboot);
g_variant_dict_insert (&dict, "allow-downgrade", "b", !opt_disallow_downgrade);
/* If we're not specifying a revision, then don't touch the network */
if (revision == NULL)
Expand Down Expand Up @@ -225,8 +224,12 @@ rpmostree_builtin_deploy (int argc,
}

rpmostree_print_package_diffs (result);
return TRUE;
}
else if (!opt_reboot)

if (opt_reboot)
return rpmostree_client_reboot (error);
else
{
if (!rpmostree_has_new_default_deployment (os_proxy, previous_deployment))
{
Expand Down
5 changes: 3 additions & 2 deletions src/app/rpmostree-builtin-initramfs-etc.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ rpmostree_ex_builtin_initramfs_etc (int argc,

GVariantDict dict;
g_variant_dict_init (&dict, NULL);
g_variant_dict_insert (&dict, "reboot", "b", opt_reboot);
g_variant_dict_insert (&dict, "initiating-command-line", "s", invocation->command_line);
g_variant_dict_insert (&dict, "lock-finalization", "b", opt_lock_finalization);
g_autoptr(GVariant) options = g_variant_ref_sink (g_variant_dict_end (&dict));
Expand All @@ -138,7 +137,9 @@ rpmostree_ex_builtin_initramfs_etc (int argc,
error))
return FALSE;

if (!opt_reboot)
if (opt_reboot)
return rpmostree_client_reboot (error);
else
{
if (!rpmostree_has_new_default_deployment (os_proxy, previous_deployment))
{
Expand Down
4 changes: 3 additions & 1 deletion src/app/rpmostree-builtin-initramfs.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ rpmostree_builtin_initramfs (int argc,

GVariantDict dict;
g_variant_dict_init (&dict, NULL);
g_variant_dict_insert (&dict, "reboot", "b", opt_reboot);
g_variant_dict_insert (&dict, "initiating-command-line", "s", invocation->command_line);
g_variant_dict_insert (&dict, "lock-finalization", "b", opt_lock_finalization);
g_autoptr(GVariant) options = g_variant_ref_sink (g_variant_dict_end (&dict));
Expand All @@ -156,6 +155,9 @@ rpmostree_builtin_initramfs (int argc,
return FALSE;

g_print ("Initramfs regeneration is now: %s\n", opt_enable ? "enabled" : "disabled");

if (opt_reboot)
return rpmostree_client_reboot (error);
}

return TRUE;
Expand Down
4 changes: 3 additions & 1 deletion src/app/rpmostree-builtin-kargs.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ rpmostree_builtin_kargs (int argc,

GVariantDict dict;
g_variant_dict_init (&dict, NULL);
g_variant_dict_insert (&dict, "reboot", "b", opt_reboot);
g_variant_dict_insert (&dict, "initiating-command-line", "s", invocation->command_line);
g_variant_dict_insert (&dict, "lock-finalization", "b", opt_lock_finalization);
if (opt_kernel_append_if_missing_strings && *opt_kernel_append_if_missing_strings)
Expand Down Expand Up @@ -363,5 +362,8 @@ rpmostree_builtin_kargs (int argc,
else if (opt_unchanged_exit_77)
invocation->exit_code = RPM_OSTREE_EXIT_UNCHANGED;

if (opt_reboot)
return rpmostree_client_reboot (error);

return TRUE;
}
3 changes: 1 addition & 2 deletions src/app/rpmostree-builtin-rebase.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ rpmostree_builtin_rebase (int argc,

GVariantDict dict;
g_variant_dict_init (&dict, NULL);
g_variant_dict_insert (&dict, "reboot", "b", opt_reboot);
g_variant_dict_insert (&dict, "allow-downgrade", "b", !opt_disallow_downgrade);
g_variant_dict_insert (&dict, "cache-only", "b", opt_cache_only);
g_variant_dict_insert (&dict, "download-only", "b", opt_download_only);
Expand Down Expand Up @@ -231,7 +230,7 @@ rpmostree_builtin_rebase (int argc,
}

return rpmostree_transaction_client_run (invocation, sysroot_proxy, os_proxy,
options, FALSE,
options, FALSE, opt_reboot,
transaction_address,
previous_deployment,
cancellable, error);
Expand Down
3 changes: 1 addition & 2 deletions src/app/rpmostree-builtin-reset.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ rpmostree_builtin_reset (int argc,

GVariantDict dict;
g_variant_dict_init (&dict, NULL);
g_variant_dict_insert (&dict, "reboot", "b", opt_reboot);
g_variant_dict_insert (&dict, "no-pull-base", "b", TRUE);
g_variant_dict_insert (&dict, "no-layering", "b", opt_overlays);
g_variant_dict_insert (&dict, "no-overrides", "b", opt_overrides);
Expand All @@ -110,7 +109,7 @@ rpmostree_builtin_reset (int argc,
return FALSE;

return rpmostree_transaction_client_run (invocation, sysroot_proxy, os_proxy,
options, FALSE,
options, FALSE, opt_reboot,
transaction_address,
previous_deployment,
cancellable, error);
Expand Down
4 changes: 1 addition & 3 deletions src/app/rpmostree-builtin-rollback.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ get_args_variant (void)
GVariantDict dict;

g_variant_dict_init (&dict, NULL);
g_variant_dict_insert (&dict, "reboot", "b", opt_reboot);

return g_variant_dict_end (&dict);
}
Expand Down Expand Up @@ -78,7 +77,6 @@ rpmostree_builtin_rollback (int argc,
/* really, rollback only supports the "reboot" option; all others are ignored */
GVariantDict dict;
g_variant_dict_init (&dict, NULL);
g_variant_dict_insert (&dict, "reboot", "b", opt_reboot);
g_autoptr(GVariant) options = g_variant_ref_sink (g_variant_dict_end (&dict));

if (!rpmostree_os_call_rollback_sync (os_proxy,
Expand All @@ -89,7 +87,7 @@ rpmostree_builtin_rollback (int argc,
return FALSE;

return rpmostree_transaction_client_run (invocation, sysroot_proxy, os_proxy,
options, FALSE,
options, FALSE, opt_reboot,
transaction_address,
previous_deployment,
cancellable, error);
Expand Down
8 changes: 6 additions & 2 deletions src/app/rpmostree-builtin-upgrade.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ rpmostree_builtin_upgrade (int argc,
{
GVariantDict dict;
g_variant_dict_init (&dict, NULL);
g_variant_dict_insert (&dict, "reboot", "b", opt_reboot);
g_variant_dict_insert (&dict, "allow-downgrade", "b", opt_allow_downgrade);
g_variant_dict_insert (&dict, "cache-only", "b", opt_cache_only);
g_variant_dict_insert (&dict, "download-only", "b", opt_download_only);
Expand Down Expand Up @@ -233,8 +232,13 @@ rpmostree_builtin_upgrade (int argc,
cancellable, error))
return FALSE;
}

return TRUE;
}
else if (!opt_reboot)

if (opt_reboot)
return rpmostree_client_reboot (error);
else
{
if (!rpmostree_has_new_default_deployment (os_proxy, previous_deployment))
{
Expand Down
18 changes: 15 additions & 3 deletions src/app/rpmostree-clientlib.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,7 @@ rpmostree_transaction_client_run (RpmOstreeCommandInvocation *invocation,
RPMOSTreeOS *os_proxy,
GVariant *options,
gboolean exit_unchanged_77,
gboolean opt_reboot,
const char *transaction_address,
GVariant *previous_deployment,
GCancellable *cancellable,
Expand All @@ -918,16 +919,20 @@ rpmostree_transaction_client_run (RpmOstreeCommandInvocation *invocation,

g_auto(GVariantDict) optdict = G_VARIANT_DICT_INIT (options);
/* Parse back the options variant */
gboolean opt_reboot = FALSE;
g_variant_dict_lookup (&optdict, "reboot", "b", &opt_reboot);
gboolean opt_dry_run = FALSE;
g_variant_dict_lookup (&optdict, "dry-run", "b", &opt_dry_run);

if (opt_dry_run)
{
g_print ("Exiting because of '--dry-run' option\n");
return TRUE;
}
else if (!opt_reboot)

if (opt_reboot)
{
return rpmostree_client_reboot (error);
}
else
{
if (!rpmostree_has_new_default_deployment (os_proxy, previous_deployment))
{
Expand Down Expand Up @@ -1782,3 +1787,10 @@ error_if_driver_registered (GBusType bus_type,

return TRUE;
}

gboolean
rpmostree_client_reboot (GError ** error)
{
execlp ("reboot", "reboot", NULL);
return glnx_null_throw_errno_prefix (error, "execlp(reboot)");
}
4 changes: 4 additions & 0 deletions src/app/rpmostree-clientlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ rpmostree_transaction_client_run (RpmOstreeCommandInvocation *invoca
RPMOSTreeOS *os_proxy,
GVariant *options,
gboolean exit_unchanged_77,
gboolean reboot,
const char *transaction_address,
GVariant *previous_deployment,
GCancellable *cancellable,
Expand Down Expand Up @@ -176,4 +177,7 @@ error_if_driver_registered (GBusType bus_type,
GCancellable *cancellable,
GError **error);

gboolean
rpmostree_client_reboot (GError ** error);

G_END_DECLS
7 changes: 5 additions & 2 deletions src/app/rpmostree-override-builtins.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ handle_override (RPMOSTreeSysroot *sysroot_proxy,

GVariantDict dict;
g_variant_dict_init (&dict, NULL);
g_variant_dict_insert (&dict, "reboot", "b", opt_reboot);
g_variant_dict_insert (&dict, "cache-only", "b", cache_only);
g_variant_dict_insert (&dict, "no-pull-base", "b", TRUE);
g_variant_dict_insert (&dict, "dry-run", "b", opt_dry_run);
Expand Down Expand Up @@ -116,7 +115,11 @@ handle_override (RPMOSTreeSysroot *sysroot_proxy,
{
g_print ("Exiting because of '--dry-run' option\n");
}
else if (!opt_reboot)
else if (opt_reboot)
{
return rpmostree_client_reboot (error);
}
else
{
/* only print diff if a new deployment was laid down (e.g. reset --all may not) */
if (!rpmostree_has_new_default_deployment (os_proxy, previous_deployment))
Expand Down
3 changes: 1 addition & 2 deletions src/app/rpmostree-pkg-builtins.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ pkg_change (RpmOstreeCommandInvocation *invocation,

GVariantDict dict;
g_variant_dict_init (&dict, NULL);
g_variant_dict_insert (&dict, "reboot", "b", opt_reboot);
g_variant_dict_insert (&dict, "cache-only", "b", opt_cache_only);
g_variant_dict_insert (&dict, "download-only", "b", opt_download_only);
g_variant_dict_insert (&dict, "no-pull-base", "b", TRUE);
Expand Down Expand Up @@ -142,7 +141,7 @@ pkg_change (RpmOstreeCommandInvocation *invocation,
}

return rpmostree_transaction_client_run (invocation, sysroot_proxy, os_proxy,
options, opt_unchanged_exit_77,
options, opt_unchanged_exit_77, opt_reboot,
transaction_address,
previous_deployment,
cancellable, error);
Expand Down
5 changes: 4 additions & 1 deletion src/daemon/rpmostreed-transaction-types.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1526,7 +1526,10 @@ deploy_transaction_execute (RpmostreedTransaction *transaction,
}

if (deploy_has_bool_option (self, "reboot"))
rpmostreed_reboot (cancellable, error);
{
sd_journal_print (LOG_INFO, "daemon-initiated reboot is deprecated");
rpmostreed_reboot (cancellable, error);
}
}
else
{
Expand Down

0 comments on commit 8a102f6

Please sign in to comment.