Private
Public Access
1
0

xpc: Some cleanup

This commit is contained in:
2025-08-24 16:19:56 -07:00
parent 00bbc3b330
commit 28738a1e92

View File

@@ -1,7 +1,5 @@
use crate::xpc::interface::SERVICE_NAME; use crate::xpc::interface::SERVICE_NAME;
use kordophoned::daemon::settings::Settings;
use kordophoned::daemon::{events::Event, signals::Signal, DaemonResult}; use kordophoned::daemon::{events::Event, signals::Signal, DaemonResult};
use std::collections::HashMap;
use std::ffi::CString; use std::ffi::CString;
use std::os::raw::c_char; use std::os::raw::c_char;
use std::ptr; use std::ptr;
@@ -15,7 +13,7 @@ pub(super) static LOG_TARGET: &str = "xpc";
/// Wrapper for raw XPC connection pointer to declare cross-thread usage. /// Wrapper for raw XPC connection pointer to declare cross-thread usage.
/// Safety: libxpc connections are reference-counted and may be used to send from other threads. /// Safety: libxpc connections are reference-counted and may be used to send from other threads.
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub(super) struct XpcConn(pub xpc_sys::xpc_connection_t); pub(crate) struct XpcConn(pub xpc_sys::xpc_connection_t);
unsafe impl Send for XpcConn {} unsafe impl Send for XpcConn {}
unsafe impl Sync for XpcConn {} unsafe impl Sync for XpcConn {}
@@ -110,19 +108,17 @@ impl XpcAgent {
let method = super::util::dict_get_str(&map, "method").or_else(|| super::util::dict_get_str(&map, "type")).unwrap_or_else(|| "<unknown>".to_string()); let method = super::util::dict_get_str(&map, "method").or_else(|| super::util::dict_get_str(&map, "type")).unwrap_or_else(|| "<unknown>".to_string());
log::trace!(target: LOG_TARGET, "XPC request received: {}", method); log::trace!(target: LOG_TARGET, "XPC request received: {}", method);
let response = rt_conn.block_on(super::rpc::dispatch(&agent_conn, &conns_for_handler, client, &map)); let response = rt_conn.block_on(super::rpc::dispatch(&agent_conn, &conns_for_handler, client, &map));
let reply = unsafe { xpc_sys::xpc_dictionary_create_reply(msg) }; let reply = xpc_sys::xpc_dictionary_create_reply(msg);
if !reply.is_null() { if !reply.is_null() {
let payload = message_to_xpc_object(response); let payload = message_to_xpc_object(response);
let apply_block = ConcreteBlock::new(move |key: *const c_char, value: xpc_sys::xpc_object_t| { let apply_block = ConcreteBlock::new(move |key: *const c_char, value: xpc_sys::xpc_object_t| {
unsafe { xpc_sys::xpc_dictionary_set_value(reply, key, value); } xpc_sys::xpc_dictionary_set_value(reply, key, value);
}) })
.copy(); .copy();
unsafe { xpc_sys::xpc_dictionary_apply(payload, apply_block.deref() as *const _ as *mut _);
xpc_sys::xpc_dictionary_apply(payload, apply_block.deref() as *const _ as *mut _); xpc_sys::xpc_connection_send_message(client, reply);
xpc_sys::xpc_connection_send_message(client, reply); xpc_sys::xpc_release(payload);
xpc_sys::xpc_release(payload); xpc_sys::xpc_release(reply);
xpc_sys::xpc_release(reply);
}
log::trace!(target: LOG_TARGET, "XPC reply sent for method: {}", method); log::trace!(target: LOG_TARGET, "XPC reply sent for method: {}", method);
} else { } else {
log::warn!(target: LOG_TARGET, "No reply port for method: {}", method); log::warn!(target: LOG_TARGET, "No reply port for method: {}", method);