rpm-ostree: support 'reboot' immediately after a rollback

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano 2015-10-02 17:14:30 +02:00
parent 391522ecdb
commit 1bc2029173
5 changed files with 51 additions and 2 deletions

View File

@ -64,6 +64,7 @@ rpmostree_builtin_rollback (int argc,
goto out; goto out;
if (!rpmostree_os_call_rollback_sync (os_proxy, if (!rpmostree_os_call_rollback_sync (os_proxy,
NULL,
&transaction_address, &transaction_address,
cancellable, cancellable,
error)) error))

View File

@ -91,10 +91,12 @@
</method> </method>
<method name="Rollback"> <method name="Rollback">
<arg type="a{sv}" name="options" direction="in"/>
<arg type="s" name="transaction_address" direction="out"/> <arg type="s" name="transaction_address" direction="out"/>
</method> </method>
<method name="ClearRollbackTarget"> <method name="ClearRollbackTarget">
<arg type="a{sv}" name="options" direction="in"/>
<arg type="s" name="transaction_address" direction="out"/> <arg type="s" name="transaction_address" direction="out"/>
</method> </method>

View File

@ -579,13 +579,16 @@ out:
static gboolean static gboolean
os_handle_rollback (RPMOSTreeOS *interface, os_handle_rollback (RPMOSTreeOS *interface,
GDBusMethodInvocation *invocation) GDBusMethodInvocation *invocation,
GVariant *arg_options)
{ {
RpmostreedOS *self = RPMOSTREED_OS (interface); RpmostreedOS *self = RPMOSTREED_OS (interface);
glnx_unref_object RpmostreedTransaction *transaction = NULL; glnx_unref_object RpmostreedTransaction *transaction = NULL;
glnx_unref_object OstreeSysroot *ot_sysroot = NULL; glnx_unref_object OstreeSysroot *ot_sysroot = NULL;
glnx_unref_object GCancellable *cancellable = NULL; glnx_unref_object GCancellable *cancellable = NULL;
const char *osname; const char *osname;
gboolean opt_reboot = FALSE;
GVariantDict options_dict;
GError *local_error = NULL; GError *local_error = NULL;
/* If a compatible transaction is in progress, share its bus address. */ /* If a compatible transaction is in progress, share its bus address. */
@ -609,9 +612,18 @@ os_handle_rollback (RPMOSTreeOS *interface,
osname = rpmostree_os_get_name (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, transaction = rpmostreed_transaction_new_rollback (invocation,
ot_sysroot, ot_sysroot,
osname, osname,
opt_reboot,
cancellable, cancellable,
&local_error); &local_error);
@ -637,13 +649,16 @@ out:
static gboolean static gboolean
os_handle_clear_rollback_target (RPMOSTreeOS *interface, os_handle_clear_rollback_target (RPMOSTreeOS *interface,
GDBusMethodInvocation *invocation) GDBusMethodInvocation *invocation,
GVariant *arg_options)
{ {
RpmostreedOS *self = RPMOSTREED_OS (interface); RpmostreedOS *self = RPMOSTREED_OS (interface);
glnx_unref_object RpmostreedTransaction *transaction = NULL; glnx_unref_object RpmostreedTransaction *transaction = NULL;
glnx_unref_object OstreeSysroot *ot_sysroot = NULL; glnx_unref_object OstreeSysroot *ot_sysroot = NULL;
glnx_unref_object GCancellable *cancellable = NULL; glnx_unref_object GCancellable *cancellable = NULL;
const char *osname; const char *osname;
gboolean opt_reboot = FALSE;
GVariantDict options_dict;
GError *local_error = NULL; GError *local_error = NULL;
/* If a compatible transaction is in progress, share its bus address. */ /* If a compatible transaction is in progress, share its bus address. */
@ -665,11 +680,20 @@ os_handle_clear_rollback_target (RPMOSTreeOS *interface,
&local_error)) &local_error))
goto out; 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); osname = rpmostree_os_get_name (interface);
transaction = rpmostreed_transaction_new_clear_rollback (invocation, transaction = rpmostreed_transaction_new_clear_rollback (invocation,
ot_sysroot, ot_sysroot,
osname, osname,
opt_reboot,
cancellable, cancellable,
&local_error); &local_error);

View File

@ -288,6 +288,7 @@ rpmostreed_transaction_new_package_diff (GDBusMethodInvocation *invocation,
typedef struct { typedef struct {
RpmostreedTransaction parent; RpmostreedTransaction parent;
char *osname; char *osname;
gboolean reboot;
} RollbackTransaction; } RollbackTransaction;
typedef RpmostreedTransactionClass RollbackTransactionClass; typedef RpmostreedTransactionClass RollbackTransactionClass;
@ -364,6 +365,13 @@ rollback_transaction_execute (RpmostreedTransaction *transaction,
goto out; goto out;
} }
if (self->reboot)
{
gs_subprocess_simple_run_sync (NULL, GS_SUBPROCESS_STREAM_DISPOSITION_INHERIT,
cancellable, error,
"systemctl", "reboot", NULL);
}
ret = TRUE; ret = TRUE;
out: out:
@ -390,6 +398,7 @@ RpmostreedTransaction *
rpmostreed_transaction_new_rollback (GDBusMethodInvocation *invocation, rpmostreed_transaction_new_rollback (GDBusMethodInvocation *invocation,
OstreeSysroot *sysroot, OstreeSysroot *sysroot,
const char *osname, const char *osname,
gboolean reboot,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
@ -408,6 +417,7 @@ rpmostreed_transaction_new_rollback (GDBusMethodInvocation *invocation,
if (self != NULL) if (self != NULL)
{ {
self->osname = g_strdup (osname); self->osname = g_strdup (osname);
self->reboot = reboot;
} }
return (RpmostreedTransaction *) self; return (RpmostreedTransaction *) self;
@ -418,6 +428,7 @@ rpmostreed_transaction_new_rollback (GDBusMethodInvocation *invocation,
typedef struct { typedef struct {
RpmostreedTransaction parent; RpmostreedTransaction parent;
char *osname; char *osname;
gboolean reboot;
} ClearRollbackTransaction; } ClearRollbackTransaction;
typedef RpmostreedTransactionClass ClearRollbackTransactionClass; typedef RpmostreedTransactionClass ClearRollbackTransactionClass;
@ -477,6 +488,13 @@ clear_rollback_transaction_execute (RpmostreedTransaction *transaction,
error)) error))
goto out; goto out;
if (self->reboot)
{
gs_subprocess_simple_run_sync (NULL, GS_SUBPROCESS_STREAM_DISPOSITION_INHERIT,
cancellable, error,
"systemctl", "reboot", NULL);
}
ret = TRUE; ret = TRUE;
out: out:
@ -503,6 +521,7 @@ RpmostreedTransaction *
rpmostreed_transaction_new_clear_rollback (GDBusMethodInvocation *invocation, rpmostreed_transaction_new_clear_rollback (GDBusMethodInvocation *invocation,
OstreeSysroot *sysroot, OstreeSysroot *sysroot,
const char *osname, const char *osname,
gboolean reboot,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
@ -521,6 +540,7 @@ rpmostreed_transaction_new_clear_rollback (GDBusMethodInvocation *invocation,
if (self != NULL) if (self != NULL)
{ {
self->osname = g_strdup (osname); self->osname = g_strdup (osname);
self->reboot = reboot;
} }
return (RpmostreedTransaction *) self; return (RpmostreedTransaction *) self;

View File

@ -32,6 +32,7 @@ RpmostreedTransaction *
rpmostreed_transaction_new_rollback (GDBusMethodInvocation *invocation, rpmostreed_transaction_new_rollback (GDBusMethodInvocation *invocation,
OstreeSysroot *sysroot, OstreeSysroot *sysroot,
const char *osname, const char *osname,
gboolean reboot,
GCancellable *cancellable, GCancellable *cancellable,
GError **error); GError **error);
@ -39,6 +40,7 @@ RpmostreedTransaction *
rpmostreed_transaction_new_clear_rollback (GDBusMethodInvocation *invocation, rpmostreed_transaction_new_clear_rollback (GDBusMethodInvocation *invocation,
OstreeSysroot *sysroot, OstreeSysroot *sysroot,
const char *osname, const char *osname,
gboolean reboot,
GCancellable *cancellable, GCancellable *cancellable,
GError **error); GError **error);