From bfd0d9e48acdbca5758b0d64c3d30f06f008a3b9 Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Sat, 21 Nov 2026 14:42:14 -0700 Subject: plist parsing Force-Push: yes Change-Id: I79789ad2bd761e27dd2437bec381e550e99029a7 --- src/facility/envsys.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/facility/envsys.rs') 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; @@ -16,10 +16,6 @@ pub struct EnvSys { sysmon: File, } -#[repr(C)] -struct PropertyList { -} - #[repr(C)] #[derive(Debug)] struct PropertyListReference { @@ -59,7 +55,7 @@ impl EnvSys { const ENVSYS_REMOVEPROPS: Opcode = read_write::(b'E', 2); - async fn get_dictionary(&self) -> Result<()> { + async fn get_dictionary(&self) -> Result { 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 } } -- cgit 1.4.1