From 632c8302a4c1e6ab49066f3b8360ec97448e67d3 Mon Sep 17 00:00:00 2001 From: R Aadarsh Date: Thu, 4 Jun 2026 08:59:19 +0530 Subject: [PATCH] Change assertions and panics to display ERRNO --- src/header/spawn/mod.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/header/spawn/mod.rs b/src/header/spawn/mod.rs index 8497668227..ac046b5452 100644 --- a/src/header/spawn/mod.rs +++ b/src/header/spawn/mod.rs @@ -21,7 +21,7 @@ use crate::{ }, iter::NulTerminated, platform::{ - self, Pal, + self, ERRNO, Pal, types::{c_char, c_int, pid_t}, }, }; @@ -35,8 +35,12 @@ unsafe fn spawn( envp: Option>, use_path: bool, ) -> Result<()> { - let mut original_cwd = [0u8; PATH_MAX]; - assert!(unsafe { !getcwd(original_cwd.as_mut_ptr() as *mut c_char, PATH_MAX).is_null() }); + let mut original_cwd = [0 as c_char; PATH_MAX]; + assert!( + unsafe { !getcwd(original_cwd.as_mut_ptr() as *mut c_char, PATH_MAX).is_null() }, + "Error getting cwd: {}", + ERRNO.get() + ); if use_path { let path = unsafe { getenv(c"PATH".as_ptr()) }; @@ -87,7 +91,10 @@ unsafe fn spawn( } }) .map_err(|e| { - chdir(original_cwd.as_ptr() as *const c_char); + let status = chdir(original_cwd.as_ptr() as *const c_char); + if status != 0 { + panic!("Error switching back to original cwd: {}", ERRNO.get()); + } e })?; }