diff --git a/src/app/rpmostree-builtin-rebase.c b/src/app/rpmostree-builtin-rebase.c index dc73c14b..d6d2d760 100644 --- a/src/app/rpmostree-builtin-rebase.c +++ b/src/app/rpmostree-builtin-rebase.c @@ -49,6 +49,7 @@ get_args_variant (void) g_variant_dict_init (&dict, NULL); g_variant_dict_insert (&dict, "skip-purge", "b", opt_skip_purge); + g_variant_dict_insert (&dict, "reboot", "b", opt_reboot); return g_variant_dict_end (&dict); } @@ -114,12 +115,6 @@ rpmostree_builtin_rebase (int argc, g_print ("Run \"systemctl reboot\" to start a reboot\n"); } - else - { - gs_subprocess_simple_run_sync (NULL, GS_SUBPROCESS_STREAM_DISPOSITION_INHERIT, - cancellable, error, - "systemctl", "reboot", NULL); - } ret = TRUE; diff --git a/src/app/rpmostree-builtin-rollback.c b/src/app/rpmostree-builtin-rollback.c index 60bacfe7..e21a7a6a 100644 --- a/src/app/rpmostree-builtin-rollback.c +++ b/src/app/rpmostree-builtin-rollback.c @@ -37,6 +37,17 @@ static GOptionEntry option_entries[] = { { NULL } }; +static GVariant * +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); +} + gboolean rpmostree_builtin_rollback (int argc, char **argv, @@ -64,6 +75,7 @@ rpmostree_builtin_rollback (int argc, goto out; if (!rpmostree_os_call_rollback_sync (os_proxy, + get_args_variant (), &transaction_address, cancellable, error)) @@ -89,12 +101,6 @@ rpmostree_builtin_rollback (int argc, g_print ("Run \"systemctl reboot\" to start a reboot\n"); } - else - { - gs_subprocess_simple_run_sync (NULL, GS_SUBPROCESS_STREAM_DISPOSITION_INHERIT, - cancellable, error, - "systemctl", "reboot", NULL); - } ret = TRUE; diff --git a/src/app/rpmostree-builtin-upgrade.c b/src/app/rpmostree-builtin-upgrade.c index 75d1ec21..c6795d90 100644 --- a/src/app/rpmostree-builtin-upgrade.c +++ b/src/app/rpmostree-builtin-upgrade.c @@ -52,6 +52,7 @@ get_args_variant (void) g_variant_dict_init (&dict, NULL); g_variant_dict_insert (&dict, "allow-downgrade", "b", opt_allow_downgrade); + g_variant_dict_insert (&dict, "reboot", "b", opt_reboot); return g_variant_dict_end (&dict); } @@ -88,6 +89,13 @@ rpmostree_builtin_upgrade (int argc, error)) goto out; + if (opt_check_diff && opt_reboot) + { + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, + "cannot specify both --reboot and --check-diff"); + goto out; + } + if (!rpmostree_load_os_proxy (sysroot_proxy, opt_osname, cancellable, &os_proxy, error)) goto out; @@ -185,13 +193,7 @@ rpmostree_builtin_upgrade (int argc, { goto out; } - if (opt_reboot) - { - gs_subprocess_simple_run_sync (NULL, GS_SUBPROCESS_STREAM_DISPOSITION_INHERIT, - cancellable, error, - "systemctl", "reboot", NULL); - } - else + if (!opt_reboot) { const char *sysroot_path; diff --git a/src/daemon/org.projectatomic.rpmostree1.xml b/src/daemon/org.projectatomic.rpmostree1.xml index a1bd0773..03f59ff6 100644 --- a/src/daemon/org.projectatomic.rpmostree1.xml +++ b/src/daemon/org.projectatomic.rpmostree1.xml @@ -84,22 +84,32 @@ + + + + diff --git a/src/daemon/rpmostreed-os.c b/src/daemon/rpmostreed-os.c index 206521af..2e0064fd 100644 --- a/src/daemon/rpmostreed-os.c +++ b/src/daemon/rpmostreed-os.c @@ -511,6 +511,7 @@ os_handle_upgrade (RPMOSTreeOS *interface, glnx_unref_object GCancellable *cancellable = NULL; GVariantDict options_dict; gboolean opt_allow_downgrade = FALSE; + gboolean opt_reboot = FALSE; const char *osname; GError *local_error = NULL; @@ -542,6 +543,9 @@ os_handle_upgrade (RPMOSTreeOS *interface, g_variant_dict_lookup (&options_dict, "allow-downgrade", "b", &opt_allow_downgrade); + g_variant_dict_lookup (&options_dict, + "reboot", "b", + &opt_reboot); g_variant_dict_clear (&options_dict); @@ -549,6 +553,7 @@ os_handle_upgrade (RPMOSTreeOS *interface, ot_sysroot, osname, opt_allow_downgrade, + opt_reboot, cancellable, &local_error); @@ -574,13 +579,16 @@ out: static gboolean os_handle_rollback (RPMOSTreeOS *interface, - GDBusMethodInvocation *invocation) + GDBusMethodInvocation *invocation, + GVariant *arg_options) { RpmostreedOS *self = RPMOSTREED_OS (interface); glnx_unref_object RpmostreedTransaction *transaction = NULL; glnx_unref_object OstreeSysroot *ot_sysroot = NULL; glnx_unref_object GCancellable *cancellable = NULL; const char *osname; + gboolean opt_reboot = FALSE; + GVariantDict options_dict; GError *local_error = NULL; /* If a compatible transaction is in progress, share its bus address. */ @@ -604,9 +612,18 @@ os_handle_rollback (RPMOSTreeOS *interface, osname = rpmostree_os_get_name (interface); + g_variant_dict_init (&options_dict, arg_options); + + g_variant_dict_lookup (&options_dict, + "reboot", "b", + &opt_reboot); + + g_variant_dict_clear (&options_dict); + transaction = rpmostreed_transaction_new_rollback (invocation, ot_sysroot, osname, + opt_reboot, cancellable, &local_error); @@ -632,13 +649,16 @@ out: static gboolean os_handle_clear_rollback_target (RPMOSTreeOS *interface, - GDBusMethodInvocation *invocation) + GDBusMethodInvocation *invocation, + GVariant *arg_options) { RpmostreedOS *self = RPMOSTREED_OS (interface); glnx_unref_object RpmostreedTransaction *transaction = NULL; glnx_unref_object OstreeSysroot *ot_sysroot = NULL; glnx_unref_object GCancellable *cancellable = NULL; const char *osname; + gboolean opt_reboot = FALSE; + GVariantDict options_dict; GError *local_error = NULL; /* If a compatible transaction is in progress, share its bus address. */ @@ -660,11 +680,20 @@ os_handle_clear_rollback_target (RPMOSTreeOS *interface, &local_error)) goto out; + g_variant_dict_init (&options_dict, arg_options); + + g_variant_dict_lookup (&options_dict, + "reboot", "b", + &opt_reboot); + + g_variant_dict_clear (&options_dict); + osname = rpmostree_os_get_name (interface); transaction = rpmostreed_transaction_new_clear_rollback (invocation, ot_sysroot, osname, + opt_reboot, cancellable, &local_error); @@ -703,6 +732,7 @@ os_handle_rebase (RPMOSTreeOS *interface, GVariantDict options_dict; gboolean opt_skip_purge = FALSE; const char *osname; + gboolean opt_reboot = FALSE; GError *local_error = NULL; /* If a compatible transaction is in progress, share its bus address. */ @@ -733,6 +763,9 @@ os_handle_rebase (RPMOSTreeOS *interface, g_variant_dict_lookup (&options_dict, "skip-purge", "b", &opt_skip_purge); + g_variant_dict_lookup (&options_dict, + "reboot", "b", + &opt_reboot); g_variant_dict_clear (&options_dict); @@ -741,6 +774,7 @@ os_handle_rebase (RPMOSTreeOS *interface, osname, arg_refspec, opt_skip_purge, + opt_reboot, cancellable, &local_error); diff --git a/src/daemon/rpmostreed-transaction-types.c b/src/daemon/rpmostreed-transaction-types.c index adce7a9a..6026e018 100644 --- a/src/daemon/rpmostreed-transaction-types.c +++ b/src/daemon/rpmostreed-transaction-types.c @@ -287,6 +287,7 @@ rpmostreed_transaction_new_package_diff (GDBusMethodInvocation *invocation, typedef struct { RpmostreedTransaction parent; char *osname; + gboolean reboot; } RollbackTransaction; typedef RpmostreedTransactionClass RollbackTransactionClass; @@ -363,6 +364,9 @@ rollback_transaction_execute (RpmostreedTransaction *transaction, goto out; } + if (self->reboot) + rpmostreed_reboot (cancellable, error); + ret = TRUE; out: @@ -389,6 +393,7 @@ RpmostreedTransaction * rpmostreed_transaction_new_rollback (GDBusMethodInvocation *invocation, OstreeSysroot *sysroot, const char *osname, + gboolean reboot, GCancellable *cancellable, GError **error) { @@ -407,6 +412,7 @@ rpmostreed_transaction_new_rollback (GDBusMethodInvocation *invocation, if (self != NULL) { self->osname = g_strdup (osname); + self->reboot = reboot; } return (RpmostreedTransaction *) self; @@ -417,6 +423,7 @@ rpmostreed_transaction_new_rollback (GDBusMethodInvocation *invocation, typedef struct { RpmostreedTransaction parent; char *osname; + gboolean reboot; } ClearRollbackTransaction; typedef RpmostreedTransactionClass ClearRollbackTransactionClass; @@ -476,6 +483,9 @@ clear_rollback_transaction_execute (RpmostreedTransaction *transaction, error)) goto out; + if (self->reboot) + rpmostreed_reboot (cancellable, error); + ret = TRUE; out: @@ -502,6 +512,7 @@ RpmostreedTransaction * rpmostreed_transaction_new_clear_rollback (GDBusMethodInvocation *invocation, OstreeSysroot *sysroot, const char *osname, + gboolean reboot, GCancellable *cancellable, GError **error) { @@ -520,6 +531,7 @@ rpmostreed_transaction_new_clear_rollback (GDBusMethodInvocation *invocation, if (self != NULL) { self->osname = g_strdup (osname); + self->reboot = reboot; } return (RpmostreedTransaction *) self; @@ -531,6 +543,7 @@ typedef struct { RpmostreedTransaction parent; char *osname; gboolean allow_downgrade; + gboolean reboot; } UpgradeTransaction; typedef RpmostreedTransactionClass UpgradeTransactionClass; @@ -612,6 +625,9 @@ upgrade_transaction_execute (RpmostreedTransaction *transaction, { if (!safe_sysroot_upgrader_deploy (upgrader, cancellable, error)) goto out; + + if (self->reboot) + rpmostreed_reboot (cancellable, error); } else { @@ -649,6 +665,7 @@ rpmostreed_transaction_new_upgrade (GDBusMethodInvocation *invocation, OstreeSysroot *sysroot, const char *osname, gboolean allow_downgrade, + gboolean reboot, GCancellable *cancellable, GError **error) { @@ -668,6 +685,7 @@ rpmostreed_transaction_new_upgrade (GDBusMethodInvocation *invocation, { self->osname = g_strdup (osname); self->allow_downgrade = allow_downgrade; + self->reboot = reboot; } return (RpmostreedTransaction *) self; @@ -680,6 +698,7 @@ typedef struct { char *osname; char *refspec; gboolean skip_purge; + gboolean reboot; } RebaseTransaction; typedef RpmostreedTransactionClass RebaseTransactionClass; @@ -781,6 +800,9 @@ rebase_transaction_execute (RpmostreedTransaction *transaction, goto out; } + if (self->reboot) + rpmostreed_reboot (cancellable, error); + ret = TRUE; out: @@ -813,6 +835,7 @@ rpmostreed_transaction_new_rebase (GDBusMethodInvocation *invocation, const char *osname, const char *refspec, gboolean skip_purge, + gboolean reboot, GCancellable *cancellable, GError **error) { @@ -834,6 +857,7 @@ rpmostreed_transaction_new_rebase (GDBusMethodInvocation *invocation, self->osname = g_strdup (osname); self->refspec = g_strdup (refspec); self->skip_purge = skip_purge; + self->reboot = reboot; } return (RpmostreedTransaction *) self; diff --git a/src/daemon/rpmostreed-transaction-types.h b/src/daemon/rpmostreed-transaction-types.h index 183b958c..75e90e0e 100644 --- a/src/daemon/rpmostreed-transaction-types.h +++ b/src/daemon/rpmostreed-transaction-types.h @@ -32,6 +32,7 @@ RpmostreedTransaction * rpmostreed_transaction_new_rollback (GDBusMethodInvocation *invocation, OstreeSysroot *sysroot, const char *osname, + gboolean reboot, GCancellable *cancellable, GError **error); @@ -39,6 +40,7 @@ RpmostreedTransaction * rpmostreed_transaction_new_clear_rollback (GDBusMethodInvocation *invocation, OstreeSysroot *sysroot, const char *osname, + gboolean reboot, GCancellable *cancellable, GError **error); @@ -47,6 +49,7 @@ RpmostreedTransaction * OstreeSysroot *sysroot, const char *osname, gboolean allow_downgrade, + gboolean reboot, GCancellable *cancellable, GError **error); @@ -56,5 +59,6 @@ RpmostreedTransaction * const char *osname, const char *refspec, gboolean skip_purge, + gboolean reboot, GCancellable *cancellable, GError **error); diff --git a/src/daemon/rpmostreed-utils.c b/src/daemon/rpmostreed-utils.c index 5067c1b4..7f264b3b 100644 --- a/src/daemon/rpmostreed-utils.c +++ b/src/daemon/rpmostreed-utils.c @@ -20,6 +20,7 @@ #include "rpmostreed-utils.h" #include "rpmostreed-errors.h" +#include "libgsystem.h" #include @@ -215,3 +216,11 @@ rpmostreed_refspec_parse_partial (const gchar *new_provided_refspec, out: return ret; } + +void +rpmostreed_reboot (GCancellable *cancellable, GError **error) +{ + gs_subprocess_simple_run_sync (NULL, GS_SUBPROCESS_STREAM_DISPOSITION_INHERIT, + cancellable, error, + "systemctl", "reboot", NULL); +} diff --git a/src/daemon/rpmostreed-utils.h b/src/daemon/rpmostreed-utils.h index afd18266..9f3bc09f 100644 --- a/src/daemon/rpmostreed-utils.h +++ b/src/daemon/rpmostreed-utils.h @@ -34,3 +34,5 @@ gboolean rpmostreed_refspec_parse_partial (const gchar *new_provided_refspec, gchar *base_refspec, gchar **out_refspec, GError **error); +void +rpmostreed_reboot (GCancellable *cancellable, GError **error);