Compare commits

..

No commits in common. "b3a16d49bc864f27b54142a6131974c2c4472497" and "42d499e76a1be529457dfb8ee17ca9b1ba0e08ac" have entirely different histories.

2 changed files with 5 additions and 11 deletions

View File

@ -9,7 +9,7 @@ use system::dmesg;
fn main() { fn main() {
if let Err(e) = init() { if let Err(e) = init() {
dmesg(format!("Error: {e}")); dmesg(format!("Error: {e}"));
let mut opt = std::error::Error::source(&e); let mut opt = Some(&e as &dyn std::error::Error);
while let Some(current_source) = opt { while let Some(current_source) = opt {
dmesg(format!("Caused by: {current_source}")); dmesg(format!("Caused by: {current_source}"));
opt = current_source.source(); opt = current_source.source();
@ -28,7 +28,7 @@ fn init() -> Result<()> {
if let Err(errors) = system::mount_default_targets() { if let Err(errors) = system::mount_default_targets() {
for error in errors { for error in errors {
dmesg(format!("Error while mounting: {error}")); dmesg(format!("Error while mounting: {error}"));
let mut opt = std::error::Error::source(&error); let mut opt = Some(&error as &dyn std::error::Error);
while let Some(current_source) = opt { while let Some(current_source) = opt {
dmesg(format!("Caused by: {current_source}")); dmesg(format!("Caused by: {current_source}"));
opt = current_source.source(); opt = current_source.source();
@ -65,7 +65,7 @@ fn init() -> Result<()> {
*/ */
} }
config::Mode::Exec => { config::Mode::Exec => {
dmesg(format!("pivoting to {command}")); dmesg("pivoting to {command}");
system::syscall::execv(command, &[])?; system::syscall::execv(command, &[])?;
} }
} }

View File

@ -200,18 +200,12 @@ pub fn execv(command: impl AsRef<Path>, args: &[&str]) -> Result<()> {
.context(format_args!("bad command: {}", command.display()))?; .context(format_args!("bad command: {}", command.display()))?;
let mut args_cstr = vec![]; let mut args_cstr = vec![];
for arg in args { for arg in args {
let cur_arg_cstr = CString::new(arg.as_bytes()).context(format_args!("bad arg: {arg}"))?; let cur_arg_cstr = CString::new(arg.as_bytes()).context(format_args!("bad arg: {arg}"));
args_cstr.push(cur_arg_cstr); args_cstr.push(cur_arg_cstr);
} }
// NOTE: The last arg must be a null pointer. We construct a CString from the raw pointer.
args_cstr.push(unsafe { CString::from_raw(std::ptr::null_mut()) });
if unsafe { libc::execv(command_cstr.as_ptr().cast(), args_cstr.as_ptr().cast()) } == -1 { if unsafe { libc::execv(command_cstr.as_ptr().cast(), args_cstr.as_ptr().cast()) } == -1 {
return ctx_os_error(format_args!( return ctx_os_error(format_args!("error calling exec()"));
"error calling exec({command}, {args:?})",
command = command.display()
));
} }
Ok(()) Ok(())