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;
if (!rpmostree_os_call_rollback_sync (os_proxy,
NULL,
&transaction_address,
cancellable,
error))

View File

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

View File

@ -579,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. */
@ -609,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);
@ -637,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. */
@ -665,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);

View File

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

View File

@ -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);