From c7adb019b5cc7eb9f72236c7c8c284526e836f1c Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 5 Dec 2025 20:45:44 +0100 Subject: [PATCH] Use file as default scheme from the start This removes one piece of state that init has to manage for the processes it spawns. This also allows getting rid of the concept of a default scheme from relibc if we want. --- bootstrap/src/exec.rs | 2 +- init.rc | 3 +-- init/src/main.rs | 39 +-------------------------------------- init_drivers.rc | 2 +- 4 files changed, 4 insertions(+), 42 deletions(-) diff --git a/bootstrap/src/exec.rs b/bootstrap/src/exec.rs index 9f5a32bdec..7d32305718 100644 --- a/bootstrap/src/exec.rs +++ b/bootstrap/src/exec.rs @@ -90,7 +90,7 @@ pub fn main() -> ! { // from this point, this_thr_fd is no longer valid const CWD: &[u8] = b"/scheme/initfs"; - const DEFAULT_SCHEME: &[u8] = b"initfs"; + const DEFAULT_SCHEME: &[u8] = b"file"; let extrainfo = ExtraInfo { cwd: Some(CWD), default_scheme: Some(DEFAULT_SCHEME), diff --git a/init.rc b/init.rc index 6fb3094f77..dc716b7582 100644 --- a/init.rc +++ b/init.rc @@ -1,6 +1,6 @@ # Various daemons that relibc needs to function as well as a bunch of env vars # that should be set for every program. -export PATH /bin +export PATH /scheme/initfs/bin export RUST_BACKTRACE 1 rtcd nulld @@ -34,7 +34,6 @@ redoxfs --uuid $REDOXFS_UUID file $REDOXFS_BLOCK unset REDOXFS_UUID REDOXFS_BLOCK REDOXFS_PASSWORD_ADDR REDOXFS_PASSWORD_SIZE # Exit initfs -set-default-scheme file cd / export PATH /usr/bin run.d /usr/lib/init.d /etc/init.d diff --git a/init/src/main.rs b/init/src/main.rs index a20e489f32..086b3e4fe7 100644 --- a/init/src/main.rs +++ b/init/src/main.rs @@ -1,33 +1,12 @@ use std::collections::BTreeMap; use std::env; -use std::ffi::CString; use std::fs::{read_dir, File}; use std::io::{BufRead, BufReader, Result}; use std::path::Path; use std::process::Command; -use libredox::error::Error as OsError; - use libredox::flag::{O_RDONLY, O_WRONLY}; -fn set_default_scheme(scheme: &str) -> std::result::Result<(), OsError> { - use std::ffi::{c_char, c_int}; - - extern "C" { - fn set_default_scheme(scheme: *const c_char) -> c_int; - } - - let cstr = - CString::new(scheme.as_bytes()).expect(&format!("init: invalid default scheme {}", scheme)); - - let res = unsafe { set_default_scheme(cstr.as_ptr()) }; - - match res { - 0 => Ok(()), - error_code => Err(OsError::new(error_code)), - } -} - fn switch_stdio(stdio: &str) -> Result<()> { let stdin = libredox::Fd::open(stdio, O_RDONLY, 0)?; let stdout = libredox::Fd::open(stdio, O_WRONLY, 0)?; @@ -66,18 +45,6 @@ pub fn run(file: &Path) -> Result<()> { println!("init: failed to cd: no argument"); } } - "set-default-scheme" => { - if let Some(scheme) = args.next() { - if let Err(err) = set_default_scheme(&scheme) { - println!( - "init: failed to set default scheme to '{}': {}", - scheme, err - ); - } - } else { - println!("init: failed to set default scheme: no argument"); - } - } "echo" => { if let Some(arg) = args.next() { print!("{}", arg); @@ -224,11 +191,7 @@ pub fn run(file: &Path) -> Result<()> { } pub fn main() { - if let Err(err) = set_default_scheme("initfs") { - println!("init: failed to set default scheme: {}", err); - } - - let config = "/etc/init.rc"; + let config = "/scheme/initfs/etc/init.rc"; if let Err(err) = run(&Path::new(config)) { println!("init: failed to run {}: {}", config, err); } diff --git a/init_drivers.rc b/init_drivers.rc index 586b45ac87..4ccdf61475 100644 --- a/init_drivers.rc +++ b/init_drivers.rc @@ -1,3 +1,3 @@ ps2d us hwd -pcid-spawner /etc/pcid/initfs.toml +pcid-spawner /scheme/initfs/etc/pcid/initfs.toml