Compare commits
4
Commits
eb1a3e05f1
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
27b18a778e | ||
|
|
3eb5cd434c | ||
|
|
fe6b03e268 | ||
|
|
5b2acfa526 |
No files matched your search
@@ -353,6 +353,9 @@ fn exec_command(argv: &[String], user: Option<UserSpec>) -> ! {
|
|||||||
let c_prog = cstrings[0].clone();
|
let c_prog = cstrings[0].clone();
|
||||||
let c_refs: Vec<&CString> = cstrings.iter().collect();
|
let c_refs: Vec<&CString> = cstrings.iter().collect();
|
||||||
|
|
||||||
|
// If UserSpec is 0:0, don't fork.
|
||||||
|
let user = user.filter(|u| !u.uid.is_root() || u.gid != Gid::from_raw(0));
|
||||||
|
|
||||||
match user {
|
match user {
|
||||||
None => {
|
None => {
|
||||||
// No privilege drop: exec directly, PID 1 becomes the command.
|
// No privilege drop: exec directly, PID 1 becomes the command.
|
||||||
@@ -362,6 +365,7 @@ fn exec_command(argv: &[String], user: Option<UserSpec>) -> ! {
|
|||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
Some(user) => {
|
Some(user) => {
|
||||||
|
warn(&format!("dropping privileges to {}:{}", user.uid, user.gid));
|
||||||
// Drop privileges in a child so PID 1 (root) can poweroff afterwards.
|
// Drop privileges in a child so PID 1 (root) can poweroff afterwards.
|
||||||
match unsafe { fork() } {
|
match unsafe { fork() } {
|
||||||
Ok(ForkResult::Child) => {
|
Ok(ForkResult::Child) => {
|
||||||
|
|||||||
Executable
+12
@@ -0,0 +1,12 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
cd "$(dirname "$0")/.."
|
||||||
|
|
||||||
|
mkdir -p "$HOME/.local/share/boco"
|
||||||
|
cargo build --release --target x86_64-unknown-linux-musl -p boco-init
|
||||||
|
|
||||||
|
target_dir="${CARGO_TARGET_DIR:-target}"
|
||||||
|
cp "$target_dir/x86_64-unknown-linux-musl/release/boco-init" "$HOME/.local/share/boco/"
|
||||||
|
|
||||||
+14
-1
@@ -24,6 +24,10 @@ pub struct BootCmd {
|
|||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
forward: Vec<PortForward>,
|
forward: Vec<PortForward>,
|
||||||
|
|
||||||
|
/// Pass a `guestfwd=...` argument to qemu `-nic` argument.
|
||||||
|
#[clap(long)]
|
||||||
|
guestfwd: Vec<String>,
|
||||||
|
|
||||||
/// Override the command to exec in the VM (base64-encoded on the kernel
|
/// Override the command to exec in the VM (base64-encoded on the kernel
|
||||||
/// cmdline as `boco.cmd=<b64>`). Overrides the CMD inferred at build time.
|
/// cmdline as `boco.cmd=<b64>`). Overrides the CMD inferred at build time.
|
||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
@@ -35,6 +39,9 @@ pub struct BootCmd {
|
|||||||
/// relative to the image's WORKINGDIR. Can be repeated.
|
/// relative to the image's WORKINGDIR. Can be repeated.
|
||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
mount: Vec<String>,
|
mount: Vec<String>,
|
||||||
|
|
||||||
|
/// Extra arguments to qemu
|
||||||
|
extra: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Invoke `qemu` to boot a boco image. See [`BootCmd`] for options
|
/// Invoke `qemu` to boot a boco image. See [`BootCmd`] for options
|
||||||
@@ -46,8 +53,10 @@ pub(crate) fn boot(
|
|||||||
name,
|
name,
|
||||||
memory,
|
memory,
|
||||||
forward,
|
forward,
|
||||||
|
guestfwd,
|
||||||
cmd,
|
cmd,
|
||||||
mount,
|
mount,
|
||||||
|
extra,
|
||||||
}: BootCmd,
|
}: BootCmd,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let reg_dir = registry_dir(&name)?;
|
let reg_dir = registry_dir(&name)?;
|
||||||
@@ -149,6 +158,9 @@ pub(crate) fn boot(
|
|||||||
for forward in &forward {
|
for forward in &forward {
|
||||||
_ = write!(&mut network, ",hostfwd={forward}");
|
_ = write!(&mut network, ",hostfwd={forward}");
|
||||||
}
|
}
|
||||||
|
for guestfwd in &guestfwd {
|
||||||
|
_ = write!(&mut network, ",guestfwd={guestfwd}");
|
||||||
|
}
|
||||||
|
|
||||||
let mut command = Command::new("qemu-system-x86_64");
|
let mut command = Command::new("qemu-system-x86_64");
|
||||||
|
|
||||||
@@ -165,7 +177,8 @@ pub(crate) fn boot(
|
|||||||
.args(["-no-reboot"])
|
.args(["-no-reboot"])
|
||||||
.args(["-append", &cmdline])
|
.args(["-append", &cmdline])
|
||||||
.args(["-nographic"])
|
.args(["-nographic"])
|
||||||
.args(["-nic", &network]);
|
.args(["-nic", &network])
|
||||||
|
.args(&extra);
|
||||||
|
|
||||||
println!("{command:?}");
|
println!("{command:?}");
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user