我有一个监听端口8080的osx守护进程。
我的plist文件:com.mycompany.daemon.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.mycompany.daemon</string>
<key>Program</key>
<string>/Applications/MyApp/MyDaemon</string>
<key>KeepAlive</key>
<true/>
<key>inetdCompatibility</key>
<dict>
<key>Wait</key>
<false/>
</dict>
<key>Sockets</key>
<dict>
<key>MyListener</key>
<dict>
<key>SockServiceName</key>
<string>8080</string>
<key>SockType</key>
<string>stream</string>
</dict>
</dict>
</dict>
</plist>
当我通过curl或浏览器访问端口8080时,我的守护进程按预期启动但我需要从launchd获取打开的套接字以获取已发送的消息并发送响应。在the code sample from Apple之后,我正在使用launch.h来获取该套接字。
if ((checkin_request = launch_data_new_string(LAUNCH_KEY_CHECKIN)) == NULL) {
retval = EXIT_FAILURE;
goto done;
}
if ((checkin_response = launch_msg(checkin_request)) == NULL) {
asl_log(asl, log_msg, ASL_LEVEL_ERR, "launch_msg(\"" LAUNCH_KEY_CHECKIN "\") IPC failure: %m");
retval = EXIT_FAILURE;
goto done;
}
我的问题来到这里,当我通过launch_msg()尝试CheckIn时,我收到“不允许操作”错误。我试图以root身份启动我的守护进程但没有成功。这是好方法吗?有没有其他方法来获得打开的套接字?我正在使用osx 10.9.2。感谢。