diff options
| author | Irene Knapp <ireneista@irenes.space> | 2026-11-21 14:42:14 -0700 |
|---|---|---|
| committer | Irene Knapp <ireneista@irenes.space> | 2026-11-21 14:52:48 -0700 |
| commit | bfd0d9e48acdbca5758b0d64c3d30f06f008a3b9 (patch) | |
| tree | 2642c8a186e429a2215a745878fa5d198dd21233 /src/facility | |
| parent | f6cb132d4e026db2b5fcb467bca50eab1c50f04c (diff) | |
plist parsing
Force-Push: yes Change-Id: I79789ad2bd761e27dd2437bec381e550e99029a7
Diffstat (limited to 'src/facility')
| -rw-r--r-- | src/facility/envsys.rs | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/src/facility/envsys.rs b/src/facility/envsys.rs index 31ad2de..dfecf94 100644 --- a/src/facility/envsys.rs +++ b/src/facility/envsys.rs @@ -1,9 +1,9 @@ -use crate::error::Result; +use crate::error::{ Error, Result }; use crate::facility::{ CreatableFacility, Facility, FacilityType }; +use crate::property_list::{ parse_dictionary, Array, Dictionary, Value }; use std::any::Any; -use std::ffi::{ c_void, OsStr }; -use std::os::unix::ffi::OsStrExt; +use std::ffi::c_void; use std::slice::from_raw_parts; use async_fs::File; @@ -17,10 +17,6 @@ pub struct EnvSys { } #[repr(C)] -struct PropertyList { -} - -#[repr(C)] #[derive(Debug)] struct PropertyListReference { data: *mut u8, @@ -59,7 +55,7 @@ impl EnvSys { const ENVSYS_REMOVEPROPS: Opcode = read_write::<PropertyListReference>(b'E', 2); - async fn get_dictionary(&self) -> Result<()> { + async fn get_dictionary(&self) -> Result<Dictionary> { let call = unsafe { Getter::<{ Self::ENVSYS_GETDICTIONARY }, PropertyListReference>::new() }; @@ -69,10 +65,14 @@ impl EnvSys { */ let result = unsafe { ioctl(&self.sysmon, call) }?; - println!("foo {:?}", result); - let slice: &[u8] = unsafe { from_raw_parts(result.data, result.size) }; - let xml = OsStr::from_bytes(slice); - println!("xml {:?}", xml); + /* We're expecting the final byte to be a null, acting as a C string + * terminator. We ignore it. + */ + let xml: &[u8] = unsafe { from_raw_parts(result.data, result.size - 1) }; + + /* This returns a Result, but we want to clean up before we peek inside. + */ + let dictionary = parse_dictionary(xml); /* So. Fun story. Inspecting NetBSD src/common/lib/libprop/prop_kern.c, * we find that the kernel creates a new memory mapping for the dictionary @@ -83,7 +83,7 @@ impl EnvSys { */ unsafe { munmap(result.data as *mut c_void, result.size) }?; - Ok(()) + dictionary } } |