Skip to content

Commit 5b35e56

Browse files
valpackettslp
authored andcommitted
Add a user init commands flag
Some custom init things (like spawning Wayland and D-Bus proxies) have to run after the user account has been set up and XDG_RUNTIME_DIR has been created and set. Let's simply add a big-X flag for executing things as the user. Signed-off-by: Val Packett <[email protected]>
1 parent 67fdf91 commit 5b35e56

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

crates/muvm/src/bin/muvm.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ fn main() -> Result<ExitCode> {
405405
emulator: options.emulator,
406406
cwd,
407407
init_commands,
408+
user_init_commands: options.user_init_commands,
408409
};
409410
let mut muvm_config_file = NamedTempFile::new()
410411
.context("Failed to create a temporary file to store the muvm guest config")?;

crates/muvm/src/cli_options.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub struct Options {
2222
pub publish_ports: Vec<String>,
2323
pub emulator: Option<Emulator>,
2424
pub init_commands: Vec<PathBuf>,
25+
pub user_init_commands: Vec<PathBuf>,
2526
pub command: PathBuf,
2627
pub command_args: Vec<String>,
2728
}
@@ -136,12 +137,20 @@ pub fn options() -> OptionParser<Options> {
136137
let init_commands = long("execute-pre")
137138
.short('x')
138139
.help(
139-
"Command to run inside the VM before guest server starts.
140+
"Command to run inside the VM before guest server starts, while still running as root.
140141
Can be used for e.g. setting up additional mounts.
141142
Can be specified multiple times.",
142143
)
143144
.argument("COMMAND")
144145
.many();
146+
let user_init_commands = long("user-execute-pre")
147+
.short('X')
148+
.help(
149+
"Command to run inside the VM before guest server starts, but after the user is set up.
150+
Can be specified multiple times.",
151+
)
152+
.argument("COMMAND")
153+
.many();
145154
let command = positional("COMMAND").help("the command you want to execute in the vm");
146155
let command_args = any::<String, _, _>("COMMAND_ARGS", |arg| {
147156
(!["--help", "-h"].contains(&&*arg)).then_some(arg)
@@ -163,6 +172,7 @@ pub fn options() -> OptionParser<Options> {
163172
publish_ports,
164173
emulator,
165174
init_commands,
175+
user_init_commands,
166176
// positionals
167177
command,
168178
command_args,

crates/muvm/src/guest/bin/muvm-guest.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,16 @@ fn main() -> Result<()> {
111111
Err(err) => return Err(err).context("Failed to set up user, bailing out"),
112112
};
113113

114+
for init_command in options.user_init_commands {
115+
let code = Command::new(&init_command)
116+
.current_dir(&options.cwd)
117+
.spawn()?
118+
.wait()?;
119+
if !code.success() {
120+
return Err(anyhow!("Executing `{}` failed", init_command.display()));
121+
}
122+
}
123+
114124
let pulse_path = run_path.join("pulse");
115125
std::fs::create_dir(&pulse_path)
116126
.context("Failed to create `pulse` directory in `XDG_RUNTIME_DIR`")?;

crates/muvm/src/utils/launch.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub struct GuestConfiguration {
4545
pub emulator: Option<Emulator>,
4646
pub cwd: PathBuf,
4747
pub init_commands: Vec<PathBuf>,
48+
pub user_init_commands: Vec<PathBuf>,
4849
}
4950

5051
pub const PULSE_SOCKET: u32 = 3333;

0 commit comments

Comments
 (0)