是否可以与以 root 身份运行的启动守护程序和通过 XPC 的应用程序进行通信?当我的守护进程以我的用户身份运行时,我可以与它正常通信,当以 root 身份运行时,它会停止接收我的消息。这是 Mac OS X 内部的预期安全性吗?我需要使用低级 xpc(也可以在 Lion 上运行)。我知道我可以为我的应用程序创建一个以 root 身份运行的特权和签名帮助工具。我是否能够通过 XPC 或套接字与另一个进程进行通信?
谢谢!
从我的守护程序代码中提取的小片段:
int main()
{
Logger::Start(Poco::Path::expand("/Users/Shared/Me/Service.log"));
Logger::LogInfo("Starting xpc_main...");
void* observer = nullptr;
CFStringRef observedObject = CFSTR("com.me.service.close");
CFNotificationCenterRef center = CFNotificationCenterGetDistributedCenter();
CFNotificationCenterAddObserver(center, observer, notificationCallback, CFSTR("ClientClosing"), observedObject, CFNotificationSuspensionBehaviorDeliverImmediately);
xpc_connection_t listener = xpc_connection_create_mach_service("com.me.service", NULL, XPC_CONNECTION_MACH_SERVICE_LISTENER);
xpc_connection_set_event_handler(listener, ^(xpc_object_t event)
{
// New connections arrive here. You may safely cast to
// xpc_connection_t. You will never receive messages here.
// The semantics of this handler are similar to those of
// of the one given to xpc_main().
Logger::LogInfo("Event Handler on listener is called");
eventHandler((xpc_connection_t)event);
});
Logger::LogInfo("call xpc_connection_resume...");
xpc_connection_resume(listener);
CFRunLoopRun();
Logger::LogInfo("Main Program is Exiting...");
return 0;
}