Skip to content

Commit

Permalink
mux initial
Browse files Browse the repository at this point in the history
  • Loading branch information
jlebon committed Jul 20, 2021
1 parent 1b7564b commit 42ea874
Show file tree
Hide file tree
Showing 34 changed files with 1,002 additions and 357 deletions.
41 changes: 27 additions & 14 deletions src/app/libmain.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ static RpmOstreeCommand commands[] = {
};

static gboolean opt_version;
static gboolean opt_force_peer;
static char *opt_sysroot;
static gchar **opt_install;
static gchar **opt_uninstall;
Expand All @@ -153,9 +152,8 @@ static GOptionEntry global_entries[] = {
{ NULL }
};

static GOptionEntry daemon_entries[] = {
static GOptionEntry mux_entries[] = {
{ "sysroot", 0, 0, G_OPTION_ARG_STRING, &opt_sysroot, "Use system root SYSROOT (default: /)", "SYSROOT" },
{ "peer", 0, 0, G_OPTION_ARG_NONE, &opt_force_peer, "Force a peer-to-peer connection instead of using the system message bus", NULL },
{ NULL }
};

Expand Down Expand Up @@ -219,13 +217,15 @@ rpmostree_option_context_parse (GOptionContext *context,
GCancellable *cancellable,
const char *const* *out_install_pkgs,
const char *const* *out_uninstall_pkgs,
/* eventually, we'll just have out_mux here */
RPMOSTreeSysroot **out_sysroot_proxy,
RpmOstreeMux **out_mux,
GError **error)
{
/* with --version there's no command, don't require a daemon for it */
const RpmOstreeBuiltinFlags flags =
invocation ? invocation->command->flags : RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD;
gboolean use_daemon = ((flags & RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD) == 0);
gboolean use_mux = ((flags & RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD) == 0);

if (invocation && invocation->command->description != NULL)
{
Expand All @@ -240,8 +240,8 @@ rpmostree_option_context_parse (GOptionContext *context,
if (main_entries != NULL)
g_option_context_add_main_entries (context, main_entries, NULL);

if (use_daemon)
g_option_context_add_main_entries (context, daemon_entries, NULL);
if (use_mux)
g_option_context_add_main_entries (context, mux_entries, NULL);

if ((flags & RPM_OSTREE_BUILTIN_FLAG_SUPPORTS_PKG_INSTALLS) > 0)
g_option_context_add_main_entries (context, pkg_entries, NULL);
Expand Down Expand Up @@ -276,13 +276,15 @@ rpmostree_option_context_parse (GOptionContext *context,
if ((flags & RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT) > 0)
rpmostreecxx::client_require_root();

if (use_daemon)
const char *sysroot_path = opt_sysroot ?: g_getenv ("RPMOSTREE_SYSROOT");

if (use_mux)
{
/* More gracefully handle the case where
* no --sysroot option was specified and we're not booted via ostree
* https://github.com/projectatomic/rpm-ostree/issues/1537
*/
if (!opt_sysroot)
if (!sysroot_path)
{
if (!glnx_fstatat_allow_noent (AT_FDCWD, "/run/ostree-booted", NULL, 0, error))
return FALSE;
Expand All @@ -301,10 +303,21 @@ rpmostree_option_context_parse (GOptionContext *context,
/* ignore errors; we print out a warning if we fail to spawn pkttyagent */
(void)rpmostree_polkit_agent_open ();

if (!rpmostree_load_sysroot (cancellable,
out_sysroot_proxy,
error))
return FALSE;
/* Eventually we'll always load the mux here. See also comment in that
* function. For now, we only use it if the caller is opted in. */
if (out_mux)
{
g_assert_null (out_sysroot_proxy);
*out_mux = rpmostree_mux_new (sysroot_path, cancellable, error);
if (!*out_mux)
return FALSE;
}
else
{
g_assert_nonnull (out_sysroot_proxy);
if (!rpmostree_load_sysroot (cancellable, out_sysroot_proxy, error))
return FALSE;
}
}

if (out_install_pkgs)
Expand Down Expand Up @@ -389,7 +402,7 @@ rpmostree_handle_subcommand (int argc, char **argv,
&argc, &argv,
invocation,
cancellable,
NULL, NULL, NULL, NULL);
NULL, NULL, NULL, NULL, NULL);
if (subcommand_name == NULL)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
Expand Down Expand Up @@ -504,7 +517,7 @@ rpmostree_main_inner (const rust::Slice<const rust::Str> args)
/* This will not return for some options (e.g. --version). */
(void) rpmostree_option_context_parse (context, NULL, &argc, &argv,
NULL, NULL, NULL, NULL, NULL,
NULL);
NULL, NULL);
g_autofree char *help = g_option_context_get_help (context, FALSE, NULL);
g_printerr ("%s", help);
if (command_name == NULL)
Expand Down
2 changes: 1 addition & 1 deletion src/app/rpmostree-builtin-cancel.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ rpmostree_builtin_cancel (int argc,
invocation,
cancellable,
NULL, NULL,
&sysroot_proxy,
&sysroot_proxy, NULL,
error))
return FALSE;

Expand Down
2 changes: 1 addition & 1 deletion src/app/rpmostree-builtin-cleanup.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ rpmostree_builtin_cleanup (int argc,
invocation,
cancellable,
NULL, NULL,
&sysroot_proxy,
&sysroot_proxy, NULL,
error))
return FALSE;

Expand Down
2 changes: 1 addition & 1 deletion src/app/rpmostree-builtin-db.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ rpmostree_db_option_context_parse (GOptionContext *context,
argc, argv,
invocation,
cancellable,
NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
error))
return FALSE;

Expand Down
5 changes: 3 additions & 2 deletions src/app/rpmostree-builtin-deploy.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ rpmostree_builtin_deploy (int argc,
cancellable,
&install_pkgs,
&uninstall_pkgs,
&sysroot_proxy,
&sysroot_proxy, NULL,
error))
return FALSE;

Expand Down Expand Up @@ -226,7 +226,8 @@ rpmostree_builtin_deploy (int argc,
}
else if (!opt_reboot)
{
if (!rpmostree_has_new_default_deployment (os_proxy, previous_deployment))
g_autoptr(GVariant) new_deployment = rpmostree_os_dup_default_deployment (os_proxy);
if (!rpmostree_has_new_default_deployment (previous_deployment, new_deployment))
{
if (opt_unchanged_exit_77)
invocation->exit_code = RPM_OSTREE_EXIT_UNCHANGED;
Expand Down
2 changes: 1 addition & 1 deletion src/app/rpmostree-builtin-finalize-deployment.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ rpmostree_builtin_finalize_deployment (int argc,
glnx_unref_object RPMOSTreeSysroot *sysroot_proxy = NULL;
if (!rpmostree_option_context_parse (context, option_entries, &argc, &argv,
invocation, cancellable, NULL, NULL,
&sysroot_proxy, error))
&sysroot_proxy, NULL, error))
return FALSE;

const char *checksum = NULL;
Expand Down
54 changes: 26 additions & 28 deletions src/app/rpmostree-builtin-initramfs-etc.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -58,33 +58,35 @@ rpmostree_ex_builtin_initramfs_etc (int argc,
GCancellable *cancellable,
GError **error)
{
g_autoptr(RpmOstreeMux) mux = NULL;
g_autoptr(GOptionContext) context = g_option_context_new ("");

glnx_unref_object RPMOSTreeSysroot *sysroot_proxy = NULL;
if (!rpmostree_option_context_parse (context,
option_entries,
&argc, &argv,
invocation,
cancellable,
NULL, NULL,
&sysroot_proxy,
NULL, &mux,
error))
return FALSE;

glnx_unref_object RPMOSTreeOS *os_proxy = NULL;
if (!rpmostree_load_os_proxy (sysroot_proxy, opt_osname,
cancellable, &os_proxy, error))
if (!rpmostree_mux_load_os (mux, opt_osname, cancellable, error))
return FALSE;

g_autoptr(GVariant) previous_deployment = rpmostree_os_dup_default_deployment (os_proxy);
g_autoptr(GVariant) previous_deployment = rpmostree_mux_get_default_deployment (mux, error);
if (!previous_deployment)
return FALSE;

if (!(opt_track || opt_untrack || opt_untrack_all || opt_force_sync))
{
if (opt_reboot)
return glnx_throw (error, "Cannot use ---reboot without --track, --untrack, --untrack-all, or --force-sync");

g_autofree char **files = NULL;
g_autoptr(GVariant) deployments = rpmostree_sysroot_dup_deployments (sysroot_proxy);
g_autoptr(GVariant) deployments = rpmostree_mux_get_deployments (mux, error);
if (!deployments)
return FALSE;

if (g_variant_n_children (deployments) > 0)
{
g_autoptr(GVariant) pending = g_variant_get_child_value (deployments, 0);
Expand Down Expand Up @@ -112,41 +114,37 @@ rpmostree_ex_builtin_initramfs_etc (int argc,
if (!opt_untrack)
opt_untrack = empty_strv;

GVariantDict dict;
g_auto(GVariantDict) dict;
g_variant_dict_init (&dict, NULL);
g_variant_dict_insert (&dict, "reboot", "b", opt_reboot);
g_variant_dict_insert (&dict, "initiating-command-line", "s", invocation->command_line);
g_variant_dict_insert (&dict, "lock-finalization", "b", opt_lock_finalization);
g_autoptr(GVariant) options = g_variant_ref_sink (g_variant_dict_end (&dict));

g_autofree char *transaction_address = NULL;
if (!rpmostree_os_call_initramfs_etc_sync (os_proxy,
(const char *const*)opt_track,
(const char *const*)opt_untrack,
opt_untrack_all,
opt_force_sync,
options,
&transaction_address,
cancellable,
error))
return FALSE;

if (!rpmostree_transaction_get_response_sync (sysroot_proxy,
transaction_address,
cancellable,
error))
if (!rpmostree_mux_call_initramfs_etc (mux,
(const char *const*)opt_track,
(const char *const*)opt_untrack,
opt_untrack_all,
opt_force_sync,
&dict,
cancellable,
error))
return FALSE;

if (!opt_reboot)
{
if (!rpmostree_has_new_default_deployment (os_proxy, previous_deployment))
g_autoptr(GVariant) new_deployment = rpmostree_mux_get_default_deployment (mux, error);
if (!new_deployment)
return FALSE;

if (!rpmostree_has_new_default_deployment (previous_deployment, new_deployment))
{
if (opt_unchanged_exit_77)
invocation->exit_code = RPM_OSTREE_EXIT_UNCHANGED;
return TRUE;
}

g_print ("Run \"systemctl reboot\" to start a reboot\n");
if (rpmostree_mux_is_dbus (mux))
g_print ("Run \"systemctl reboot\" to start a reboot\n");
}

return TRUE;
Expand Down
2 changes: 1 addition & 1 deletion src/app/rpmostree-builtin-initramfs.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ rpmostree_builtin_initramfs (int argc,
invocation,
cancellable,
NULL, NULL,
&sysroot_proxy,
&sysroot_proxy, NULL,
error))
return FALSE;

Expand Down
5 changes: 3 additions & 2 deletions src/app/rpmostree-builtin-kargs.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ rpmostree_builtin_kargs (int argc,
invocation,
cancellable,
NULL, NULL,
&sysroot_proxy,
&sysroot_proxy, NULL,
error))
return FALSE;

Expand Down Expand Up @@ -357,7 +357,8 @@ rpmostree_builtin_kargs (int argc,
error))
return FALSE;

if (rpmostree_has_new_default_deployment (os_proxy, previous_deployment))
g_autoptr(GVariant) new_deployment = rpmostree_os_dup_default_deployment (os_proxy);
if (!rpmostree_has_new_default_deployment (previous_deployment, new_deployment))
g_print("Kernel arguments updated.\nRun \"systemctl reboot\" to start a reboot\n");
else if (opt_unchanged_exit_77)
invocation->exit_code = RPM_OSTREE_EXIT_UNCHANGED;
Expand Down
2 changes: 1 addition & 1 deletion src/app/rpmostree-builtin-rebase.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ rpmostree_builtin_rebase (int argc,
cancellable,
&install_pkgs,
&uninstall_pkgs,
&sysroot_proxy,
&sysroot_proxy, NULL,
error))
return FALSE;

Expand Down
2 changes: 1 addition & 1 deletion src/app/rpmostree-builtin-refresh-md.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ rpmostree_builtin_refresh_md (int argc,
invocation,
cancellable,
NULL, NULL,
&sysroot_proxy,
&sysroot_proxy, NULL,
error))
return FALSE;

Expand Down
2 changes: 1 addition & 1 deletion src/app/rpmostree-builtin-reload.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ rpmostree_builtin_reload (int argc,
invocation,
cancellable,
NULL, NULL,
&sysroot_proxy,
&sysroot_proxy, NULL,
error))
return FALSE;

Expand Down
2 changes: 1 addition & 1 deletion src/app/rpmostree-builtin-reset.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ rpmostree_builtin_reset (int argc,
cancellable,
&install_pkgs,
&uninstall_pkgs,
&sysroot_proxy,
&sysroot_proxy, NULL,
error))
return FALSE;

Expand Down
2 changes: 1 addition & 1 deletion src/app/rpmostree-builtin-rollback.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ rpmostree_builtin_rollback (int argc,
invocation,
cancellable,
NULL, NULL,
&sysroot_proxy,
&sysroot_proxy, NULL,
error))
return FALSE;

Expand Down
Loading

0 comments on commit 42ea874

Please sign in to comment.