2014-03-29 03:48:06 +04:00
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright ( C ) 2014 Colin Walters < walters @ verbum . org >
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation ; either version 2 of the licence or ( at
* your option ) any later version .
*
* This library is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
* Lesser General Public License for more details .
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library ; if not , write to the
* Free Software Foundation , Inc . , 59 Temple Place , Suite 330 ,
* Boston , MA 02111 - 1307 , USA .
*/
# include "config.h"
# include <string.h>
# include <glib-unix.h>
# include "rpmostree-builtins.h"
2015-04-19 16:36:53 +03:00
# include "rpmostree-libbuiltin.h"
2015-06-13 03:19:16 +03:00
# include "rpmostree-dbus-helpers.h"
2014-03-29 03:48:06 +04:00
2015-06-13 03:19:16 +03:00
# include <libglnx.h>
2014-03-29 03:48:06 +04:00
static gboolean opt_reboot ;
static GOptionEntry option_entries [ ] = {
{ " reboot " , ' r ' , 0 , G_OPTION_ARG_NONE , & opt_reboot , " Initiate a reboot after rollback is prepared " , NULL } ,
{ NULL }
} ;
2015-10-07 09:46:30 +03:00
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 ) ;
}
2017-12-28 23:11:32 +03:00
gboolean
2014-03-29 03:48:06 +04:00
rpmostree_builtin_rollback ( int argc ,
char * * argv ,
2017-03-15 21:52:43 +03:00
RpmOstreeCommandInvocation * invocation ,
2014-03-29 03:48:06 +04:00
GCancellable * cancellable ,
GError * * error )
{
2017-08-12 01:59:47 +03:00
GOptionContext * context = g_option_context_new ( " " ) ;
2015-06-13 03:19:16 +03:00
glnx_unref_object RPMOSTreeOS * os_proxy = NULL ;
glnx_unref_object RPMOSTreeSysroot * sysroot_proxy = NULL ;
2015-08-17 20:42:03 +03:00
g_autofree char * transaction_address = NULL ;
2017-03-23 21:50:18 +03:00
_cleanup_peer_ GPid peer_pid = 0 ;
2015-06-13 03:19:16 +03:00
2015-08-05 19:39:07 +03:00
if ( ! rpmostree_option_context_parse ( context ,
option_entries ,
& argc , & argv ,
2017-03-15 21:52:43 +03:00
invocation ,
2015-08-05 19:39:07 +03:00
cancellable ,
2017-03-31 16:07:29 +03:00
NULL , NULL ,
2015-08-05 19:39:07 +03:00
& sysroot_proxy ,
2017-03-23 21:50:18 +03:00
& peer_pid ,
2015-08-05 19:39:07 +03:00
error ) )
2017-12-28 23:11:32 +03:00
return FALSE ;
2014-03-29 03:48:06 +04:00
2015-08-05 04:09:54 +03:00
if ( ! rpmostree_load_os_proxy ( sysroot_proxy , NULL ,
2015-06-13 03:19:16 +03:00
cancellable , & os_proxy , error ) )
2017-12-28 23:11:32 +03:00
return FALSE ;
2014-03-29 03:48:06 +04:00
2017-10-03 21:33:10 +03:00
g_autoptr ( GVariant ) previous_deployment = rpmostree_os_dup_default_deployment ( os_proxy ) ;
2017-10-13 16:22:15 +03:00
/* really, rollback only supports the "reboot" option; all others are ignored */
2017-10-03 21:33:10 +03:00
g_autoptr ( GVariant ) options =
rpmostree_get_options_variant ( opt_reboot ,
2017-10-05 19:03:34 +03:00
FALSE , /* allow-downgrade */
FALSE , /* cache-only */
2017-10-13 16:22:15 +03:00
FALSE , /* download-only */
2017-10-05 19:03:34 +03:00
FALSE , /* skip-purge */
2017-10-03 21:33:10 +03:00
FALSE , /* no-pull-base */
FALSE , /* dry-run */
FALSE ) ; /* no-overrides */
2015-06-13 03:19:16 +03:00
if ( ! rpmostree_os_call_rollback_sync ( os_proxy ,
2015-10-07 09:46:30 +03:00
get_args_variant ( ) ,
2015-08-17 20:42:03 +03:00
& transaction_address ,
2015-06-13 03:19:16 +03:00
cancellable ,
error ) )
2017-12-28 23:11:32 +03:00
return FALSE ;
2014-03-29 03:48:06 +04:00
2017-12-28 23:11:32 +03:00
return rpmostree_transaction_client_run ( invocation , sysroot_proxy , os_proxy ,
2017-10-03 21:33:10 +03:00
options , FALSE ,
transaction_address ,
previous_deployment ,
cancellable , error ) ;
2014-03-29 03:48:06 +04:00
}