Skip to content

Commit

Permalink
main: Move usroverlay parsing back to C++ consistently
Browse files Browse the repository at this point in the history
Otherwise, we end up segfaulting because
`rpm-ostree -h usroverlay` confuses things.

Unfortunately, if we expose it publicly in our help text
it needs to have a C++ trampoline.
  • Loading branch information
cgwalters committed Aug 25, 2023
1 parent 12c0481 commit 9e9a403
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 4 deletions.
13 changes: 13 additions & 0 deletions rpmostree-cxxrs.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2027,6 +2027,9 @@ extern "C"
rpmostreecxx$cxxbridge1$Bubblewrap$run (::rpmostreecxx::Bubblewrap &self,
const ::rpmostreecxx::GCancellable &cancellable) noexcept;

::rust::repr::PtrLen
rpmostreecxx$cxxbridge1$usroverlay_entrypoint (const ::rust::Vec< ::rust::String> &args) noexcept;

::rust::repr::PtrLen
rpmostreecxx$cxxbridge1$applylive_entrypoint (const ::rust::Vec< ::rust::String> &args) noexcept;

Expand Down Expand Up @@ -3534,6 +3537,16 @@ Bubblewrap::run (const ::rpmostreecxx::GCancellable &cancellable)
}
}

void
usroverlay_entrypoint (const ::rust::Vec< ::rust::String> &args)
{
::rust::repr::PtrLen error$ = rpmostreecxx$cxxbridge1$usroverlay_entrypoint (args);
if (error$.ptr)
{
throw ::rust::impl< ::rust::Error>::error (error$);
}
}

void
applylive_entrypoint (const ::rust::Vec< ::rust::String> &args)
{
Expand Down
2 changes: 2 additions & 0 deletions rpmostree-cxxrs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1741,6 +1741,8 @@ ::rust::Box< ::rpmostreecxx::Bubblewrap>
bubblewrap_new_with_mutability (::std::int32_t rootfs_fd,
::rpmostreecxx::BubblewrapMutability mutability);

void usroverlay_entrypoint (const ::rust::Vec< ::rust::String> &args);

void applylive_entrypoint (const ::rust::Vec< ::rust::String> &args);

void applylive_finish (const ::rpmostreecxx::OstreeSysroot &sysroot);
Expand Down
2 changes: 1 addition & 1 deletion rust/src/builtins/usroverlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use clap::Command;
use std::os::unix::prelude::CommandExt;

/// Directly exec(ostree admin unlock) - does not return on success.
pub fn entrypoint(args: &[&str]) -> Result<()> {
pub fn usroverlay_entrypoint(args: &Vec<String>) -> Result<()> {
let cmd = cli_cmd();
cmd.get_matches_from(args.iter().skip(1));

Expand Down
2 changes: 2 additions & 0 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ pub mod ffi {

// builtins/apply_live.rs
extern "Rust" {
fn usroverlay_entrypoint(args: &Vec<String>) -> Result<()>;
fn applylive_entrypoint(args: &Vec<String>) -> Result<()>;
fn applylive_finish(sysroot: &OstreeSysroot) -> Result<()>;
}
Expand Down Expand Up @@ -898,6 +899,7 @@ pub mod ffi {
}

pub mod builtins;
pub(crate) use crate::builtins::usroverlay::usroverlay_entrypoint;
pub(crate) use crate::builtins::apply_live::*;
pub(crate) use crate::builtins::compose::commit::*;
pub(crate) use crate::builtins::compose::*;
Expand Down
2 changes: 0 additions & 2 deletions rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ async fn inner_async_main(args: Vec<String>) -> Result<i32> {
// Add custom Rust commands here, and also in `libmain.cxx` if user-visible.
"countme" => rpmostree_rust::countme::entrypoint(args).map(|_| 0),
"cliwrap" => rpmostree_rust::cliwrap::entrypoint(args).map(|_| 0),
// The `unlock` is a hidden alias for "ostree CLI compatibility"
"usroverlay" | "unlock" => builtins::usroverlay::entrypoint(args).map(|_| 0),
// A hidden wrapper to intercept some binaries in RPM scriptlets.
"scriptlet-intercept" => builtins::scriptlet_intercept::entrypoint(args).map(|_| 0),
// This is a deprecated entrypoint
Expand Down
18 changes: 17 additions & 1 deletion src/app/libmain.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@

#include "libglnx.h"

static gboolean
dispatch_usroverlay (int argc, char **argv, RpmOstreeCommandInvocation *invocation,
GCancellable *cancellable, GError **error)
{
rust::Vec<rust::String> rustargv;
for (int i = 0; i < argc; i++)
rustargv.push_back (std::string (argv[i]));
CXX_TRY (rpmostreecxx::usroverlay_entrypoint (rustargv), error);
return TRUE;
}

static RpmOstreeCommand commands[] = {
{ "compose",
static_cast<RpmOstreeBuiltinFlags> (RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD
Expand Down Expand Up @@ -91,7 +102,12 @@ static RpmOstreeCommand commands[] = {
{ "scriptlet-intercept", static_cast<RpmOstreeBuiltinFlags> (RPM_OSTREE_BUILTIN_FLAG_HIDDEN),
"Intercept some commands used by RPM scriptlets", NULL },
{ "usroverlay", static_cast<RpmOstreeBuiltinFlags> (RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT),
"Apply a transient overlayfs to /usr", NULL },
"Apply a transient overlayfs to /usr", dispatch_usroverlay },
// Alias for ostree compatibility
{ "unlock",
static_cast<RpmOstreeBuiltinFlags> (RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT
| RPM_OSTREE_BUILTIN_FLAG_HIDDEN),
"Apply a transient overlayfs to /usr", dispatch_usroverlay },
/* Legacy aliases */
{ "pkg-add", static_cast<RpmOstreeBuiltinFlags> (RPM_OSTREE_BUILTIN_FLAG_HIDDEN), NULL,
rpmostree_builtin_install },
Expand Down

0 comments on commit 9e9a403

Please sign in to comment.