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
# include "libgsystem.h"
2015-06-13 03:19:16 +03:00
# include <libglnx.h>
2014-03-29 03:48:06 +04:00
2014-06-22 20:39:49 +04:00
static char * opt_sysroot = " / " ;
2014-03-29 03:48:06 +04:00
static gboolean opt_reboot ;
2015-06-13 03:19:16 +03:00
static gboolean opt_force_peer ;
2014-03-29 03:48:06 +04:00
static GOptionEntry option_entries [ ] = {
2014-06-22 20:39:49 +04:00
{ " sysroot " , 0 , 0 , G_OPTION_ARG_STRING , & opt_sysroot , " Use system root SYSROOT (default: /) " , " SYSROOT " } ,
2014-03-29 03:48:06 +04:00
{ " reboot " , ' r ' , 0 , G_OPTION_ARG_NONE , & opt_reboot , " Initiate a reboot after rollback is prepared " , NULL } ,
2015-06-13 03:19:16 +03:00
{ " peer " , 0 , 0 , G_OPTION_ARG_NONE , & opt_force_peer , " Force a peer to peer connection instead of using the system message bus " , NULL } ,
2014-03-29 03:48:06 +04:00
{ NULL }
} ;
gboolean
rpmostree_builtin_rollback ( int argc ,
char * * argv ,
GCancellable * cancellable ,
GError * * error )
{
gboolean ret = FALSE ;
2015-06-13 03:19:16 +03:00
gboolean is_peer = FALSE ;
2014-03-29 03:48:06 +04:00
GOptionContext * context = g_option_context_new ( " - Revert to the previously booted tree " ) ;
2015-06-13 03:19:16 +03:00
glnx_unref_object GDBusConnection * connection = NULL ;
glnx_unref_object RPMOSTreeOS * os_proxy = NULL ;
glnx_unref_object RPMOSTreeSysroot * sysroot_proxy = NULL ;
g_autofree char * transaction_object_path = NULL ;
2014-11-24 20:34:45 +03:00
if ( ! rpmostree_option_context_parse ( context , option_entries , & argc , & argv , error ) )
2014-03-29 03:48:06 +04:00
goto out ;
2015-06-13 03:19:16 +03:00
if ( ! rpmostree_load_connection_and_sysroot ( opt_sysroot ,
opt_force_peer ,
cancellable ,
& connection ,
& sysroot_proxy ,
& is_peer ,
error ) )
2014-03-29 03:48:06 +04:00
goto out ;
2015-06-13 03:19:16 +03:00
if ( ! rpmostree_load_os_proxy ( sysroot_proxy , NULL , is_peer ,
cancellable , & os_proxy , error ) )
goto out ;
2014-03-29 03:48:06 +04:00
2015-06-13 03:19:16 +03:00
if ( ! rpmostree_os_call_rollback_sync ( os_proxy ,
& transaction_object_path ,
cancellable ,
error ) )
goto out ;
2014-03-29 03:48:06 +04:00
2015-06-13 03:19:16 +03:00
if ( ! rpmostree_transaction_get_response_sync ( connection ,
transaction_object_path ,
cancellable ,
error ) )
2014-03-29 03:48:06 +04:00
goto out ;
2015-06-13 03:19:16 +03:00
if ( ! opt_reboot )
2014-03-29 05:40:30 +04:00
{
2015-07-16 21:11:35 +03:00
/* By request, doing this without dbus */
2015-06-13 03:19:16 +03:00
if ( ! rpmostree_print_treepkg_diff_from_sysroot_path ( opt_sysroot ,
cancellable ,
error ) )
2014-03-29 05:40:30 +04:00
goto out ;
2015-06-13 03:19:16 +03:00
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 ) ;
2014-03-29 05:40:30 +04:00
}
2014-03-29 03:48:06 +04:00
ret = TRUE ;
2015-06-13 03:19:16 +03:00
out :
if ( is_peer )
rpmostree_cleanup_peer ( ) ;
2014-03-29 03:48:06 +04:00
return ret ;
}