From 8d6017d799eb4389d1b3677f78c4879b47b7d5ad Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 11 Apr 2026 16:06:34 +0200 Subject: [PATCH 1/4] init: Make spawning for legacy scripts self-contained --- init/src/scheduler.rs | 20 +--------- init/src/script.rs | 89 +++++++++++++++++++++++++++++++------------ 2 files changed, 65 insertions(+), 44 deletions(-) diff --git a/init/src/scheduler.rs b/init/src/scheduler.rs index 670a552620..d42a4e5700 100644 --- a/init/src/scheduler.rs +++ b/init/src/scheduler.rs @@ -1,7 +1,6 @@ use std::collections::VecDeque; use crate::InitConfig; -use crate::script::Command; use crate::unit::{Unit, UnitId, UnitKind, UnitStore}; pub struct Scheduler { @@ -88,7 +87,7 @@ fn run(unit: &mut Unit, config: &mut InitConfig) { if config.log_debug { eprintln!("init: running: {cmd:?}"); } - run_command(cmd, config); + cmd.run(config); } } UnitKind::Service { service } => { @@ -115,20 +114,3 @@ fn run(unit: &mut Unit, config: &mut InitConfig) { } } } - -fn run_command(cmd: Command, config: &mut InitConfig) { - match cmd { - Command::Service(service) => { - if config.skip_cmd.contains(&service.cmd) { - eprintln!( - "init: skipping '{} {}'", - service.cmd, - service.args.join(" ") - ); - return; - } - - service.spawn(&config.envs); - } - } -} diff --git a/init/src/script.rs b/init/src/script.rs index 7db1f2ae38..d18e3a045b 100644 --- a/init/src/script.rs +++ b/init/src/script.rs @@ -1,7 +1,7 @@ -use std::collections::{BTreeMap, BTreeSet}; +use std::collections::BTreeMap; use std::{env, io, iter}; -use crate::service::{Service, ServiceType}; +use crate::InitConfig; use crate::unit::UnitId; pub fn subst_env<'a>(arg: &str) -> String { @@ -39,8 +39,15 @@ impl Script { } #[derive(Clone, Debug)] -pub enum Command { - Service(Service), +pub struct Command { + process: Process, + kind: CommandKind, +} + +#[derive(Clone, Debug)] +enum CommandKind { + Oneshot, + OneshotAsync, } impl Command { @@ -59,35 +66,67 @@ impl Command { } "nowait" => { let process = Process::parse(args)?; - - Ok(Some(Command::Service(Service { - cmd: process.cmd, - args: process.args, - envs: process.envs, - inherit_envs: BTreeSet::new(), - type_: ServiceType::OneshotAsync, - }))) + Ok(Some(Command { + process, + kind: CommandKind::OneshotAsync, + })) } _ => { let process = Process::parse(iter::once(cmd).chain(args))?; - - Ok(Some(Command::Service(Service { - cmd: process.cmd, - args: process.args, - envs: process.envs, - inherit_envs: BTreeSet::new(), - type_: ServiceType::Oneshot, - }))) + Ok(Some(Command { + process, + kind: CommandKind::Oneshot, + })) } } } + + pub fn run(&self, config: &mut InitConfig) { + let Command { process, kind } = self; + + if config.skip_cmd.contains(&process.cmd) { + eprintln!( + "init: skipping '{} {}'", + process.cmd, + process.args.join(" ") + ); + return; + } + + let mut command = std::process::Command::new(&process.cmd); + command.args(process.args.iter().map(|arg| subst_env(arg))); + command.env_clear(); + command.envs(&config.envs).envs(&process.envs); + + let mut child = match command.spawn() { + Ok(child) => child, + Err(err) => { + eprintln!("init: failed to execute {:?}: {}", command, err); + return; + } + }; + + match kind { + CommandKind::Oneshot => match child.wait() { + Ok(exit_status) => { + if !exit_status.success() { + eprintln!("init: {command:?} failed with {exit_status}"); + } + } + Err(err) => { + eprintln!("init: failed to wait for {:?}: {}", command, err) + } + }, + CommandKind::OneshotAsync => {} + } + } } -#[derive(Debug)] -pub struct Process { - pub cmd: String, - pub args: Vec, - pub envs: BTreeMap, +#[derive(Clone, Debug)] +struct Process { + cmd: String, + args: Vec, + envs: BTreeMap, } impl Process { From 06af174ce627f2601ec8face3bd26a5a9019836f Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 11 Apr 2026 17:59:54 +0200 Subject: [PATCH 2/4] drivers/virtio-core: Reduce log verbosity --- drivers/virtio-core/src/arch/x86.rs | 2 +- drivers/virtio-core/src/probe.rs | 2 +- drivers/virtio-core/src/transport.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/virtio-core/src/arch/x86.rs b/drivers/virtio-core/src/arch/x86.rs index 751f268e07..aea86c4ad5 100644 --- a/drivers/virtio-core/src/arch/x86.rs +++ b/drivers/virtio-core/src/arch/x86.rs @@ -32,6 +32,6 @@ pub fn enable_msix(pcid_handle: &mut PciFunctionHandle) -> Result { pcid_handle.enable_feature(PciFeature::MsiX); - log::info!("virtio: using MSI-X (interrupt_handle={interrupt_handle:?})"); + log::debug!("virtio: using MSI-X (interrupt_handle={interrupt_handle:?})"); Ok(interrupt_handle) } diff --git a/drivers/virtio-core/src/probe.rs b/drivers/virtio-core/src/probe.rs index 5762912f8e..5631ef676c 100644 --- a/drivers/virtio-core/src/probe.rs +++ b/drivers/virtio-core/src/probe.rs @@ -132,7 +132,7 @@ pub fn probe_device(pcid_handle: &mut PciFunctionHandle) -> Result { &mut *(self.notify.add(offset as usize) as *mut AtomicU16) }; - log::info!("virtio-core: enabled queue #{queue_index} (size={queue_size})"); + log::debug!("virtio-core: enabled queue #{queue_index} (size={queue_size})"); let queue = Queue::new( descriptor, From cdede58055853bb473150c9e420b6990aa96bea0 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 14 Apr 2026 22:08:54 +0200 Subject: [PATCH 3/4] Couple of minor scheme related cleanups --- logd/src/main.rs | 18 +++++++------- netstack/src/scheme/netcfg/mod.rs | 39 +++++++++++-------------------- 2 files changed, 22 insertions(+), 35 deletions(-) diff --git a/logd/src/main.rs b/logd/src/main.rs index b1db6d2beb..06aca1d8e0 100644 --- a/logd/src/main.rs +++ b/logd/src/main.rs @@ -22,11 +22,15 @@ fn daemon(daemon: daemon::SchemeDaemon) -> ! { .next_request(SignalBehavior::Restart) .expect("logd: failed to read events from log scheme") { - let request = match request.kind() { - RequestKind::Call(call) => call, + match request.kind() { + RequestKind::Call(call) => { + let response = call.handle_sync(&mut scheme, &mut state); + socket + .write_response(response, SignalBehavior::Restart) + .expect("logd: failed to write responses to log scheme"); + } RequestKind::OnClose { id } => { scheme.on_close(id); - continue; } RequestKind::SendFd(sendfd_request) => { let result = scheme.on_sendfd(&sendfd_request); @@ -34,15 +38,9 @@ fn daemon(daemon: daemon::SchemeDaemon) -> ! { socket .write_response(resp, SignalBehavior::Restart) .expect("logd: failed to write responses to log scheme"); - continue; } - _ => continue, + _ => {} }; - - let response = request.handle_sync(&mut scheme, &mut state); - socket - .write_response(response, SignalBehavior::Restart) - .expect("logd: failed to write responses to log scheme"); } process::exit(0); } diff --git a/netstack/src/scheme/netcfg/mod.rs b/netstack/src/scheme/netcfg/mod.rs index 978be20037..269c28c81f 100644 --- a/netstack/src/scheme/netcfg/mod.rs +++ b/netstack/src/scheme/netcfg/mod.rs @@ -4,7 +4,7 @@ mod notifier; use redox_scheme::{ scheme::{register_scheme_inner, SchemeState, SchemeSync}, - CallerCtx, OpenResult, RequestKind, Response, SignalBehavior, Socket, + CallerCtx, OpenResult, RequestKind, SignalBehavior, Socket, }; use scheme_utils::HandleMap; use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, Ipv4Address}; @@ -386,33 +386,22 @@ impl NetCfgScheme { } }; - let req = match request.kind() { - RequestKind::Call(c) => c, + match request.kind() { + RequestKind::Call(c) => { + let resp = c.handle_sync(&mut self.inner, &mut self.state); + let _ = self + .inner + .scheme_file + .write_response(resp, SignalBehavior::Restart) + .map_err(|e| { + Error::from_syscall_error(e.into(), "failed to write response") + })?; + } RequestKind::OnClose { id } => { self.inner.on_close(id); - continue; } - _ => { - continue; - } - }; - let caller = req.caller(); - let op = match req.op() { - Ok(op) => op, - Err(req) => { - self.inner.scheme_file.write_response( - Response::err(syscall::EOPNOTSUPP, req), - SignalBehavior::Restart, - ); - continue; - } - }; - let resp = op.handle_sync(caller, &mut self.inner, &mut self.state); - let _ = self - .inner - .scheme_file - .write_response(resp, SignalBehavior::Restart) - .map_err(|e| Error::from_syscall_error(e.into(), "failed to write response"))?; + _ => {} + } }; self.inner.notify_scheduled_fds(); Ok(result) From cb34b3da676e4ea63839fedd496c3eefaf93be7d Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 16 Apr 2026 19:10:34 +0200 Subject: [PATCH 4/4] Update ipcd to rand 0.10 --- Cargo.lock | 40 +++++++++++++++++++++++++++++++++++++++- ipcd/Cargo.toml | 2 +- ipcd/src/uds/dgram.rs | 4 ++-- ipcd/src/uds/stream.rs | 2 +- 4 files changed, 43 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bce49e16c3..91185a1f01 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -337,6 +337,17 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" +[[package]] +name = "chacha20" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f8d983286843e49675a4b7a2d174efe136dc93a18d69130dd18198a6c167601" +dependencies = [ + "cfg-if 1.0.4", + "cpufeatures", + "rand_core 0.10.1", +] + [[package]] name = "chashmap" version = "2.2.2" @@ -423,6 +434,15 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +[[package]] +name = "cpufeatures" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b2a41393f66f16b0823bb79094d54ac5fbd34ab292ddafb9a0456ac9f87d201" +dependencies = [ + "libc", +] + [[package]] name = "crc" version = "3.4.0" @@ -883,6 +903,7 @@ dependencies = [ "cfg-if 1.0.4", "libc", "r-efi", + "rand_core 0.10.1", "wasip2", "wasip3", ] @@ -1124,7 +1145,7 @@ dependencies = [ "daemon", "libc", "libredox", - "rand 0.8.5", + "rand 0.10.1", "redox-scheme", "redox_event", "redox_syscall 0.7.3", @@ -1643,6 +1664,17 @@ dependencies = [ "rand_core 0.6.4", ] +[[package]] +name = "rand" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2e8e8bcc7961af1fdac401278c6a831614941f6164ee3bf4ce61b7edb162207" +dependencies = [ + "chacha20", + "getrandom 0.4.2", + "rand_core 0.10.1", +] + [[package]] name = "rand_chacha" version = "0.2.2" @@ -1693,6 +1725,12 @@ dependencies = [ "getrandom 0.2.17", ] +[[package]] +name = "rand_core" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69" + [[package]] name = "randd" version = "0.1.0" diff --git a/ipcd/Cargo.toml b/ipcd/Cargo.toml index d7d8717b3d..e157df579f 100644 --- a/ipcd/Cargo.toml +++ b/ipcd/Cargo.toml @@ -13,7 +13,7 @@ scheme-utils = { path = "../scheme-utils" } redox_event.workspace = true anyhow.workspace = true libc.workspace = true -rand = { version = "0.8", features = ["small_rng"] } +rand = "0.10" [lints] workspace = true diff --git a/ipcd/src/uds/dgram.rs b/ipcd/src/uds/dgram.rs index f4d1f6dcbe..d68cbbc8ee 100644 --- a/ipcd/src/uds/dgram.rs +++ b/ipcd/src/uds/dgram.rs @@ -8,7 +8,7 @@ use super::{ use libc::{AF_UNIX, SO_DOMAIN, SO_PASSCRED}; use libredox::protocol::SocketCall; use rand::rngs::SmallRng; -use rand::{RngCore, SeedableRng}; +use rand::Rng; use redox_scheme::{ scheme::SchemeSync, CallerCtx, OpenResult, RecvFdRequest, Response, SendFdRequest, SignalBehavior, Socket as SchemeSocket, @@ -151,7 +151,7 @@ impl<'sock> UdsDgramScheme<'sock> { 0, )? }, - rng: SmallRng::from_entropy(), + rng: rand::make_rng(), }) } diff --git a/ipcd/src/uds/stream.rs b/ipcd/src/uds/stream.rs index 2b7700e293..c258a1c0e4 100644 --- a/ipcd/src/uds/stream.rs +++ b/ipcd/src/uds/stream.rs @@ -410,7 +410,7 @@ impl<'sock> UdsStreamScheme<'sock> { 0, )? }, - rng: SmallRng::from_entropy(), + rng: rand::make_rng(), }) }