[英]Execute launchctl in sandboxed mac app
I need to execute the launchctl load/unload
command from my sandboxed OSX app. 我需要从我的沙盒OSX应用程序执行
launchctl load/unload
命令。 The app has read-write
permissions to the folder where the launch agent's plist
file resides (using security scoped bookmarks which the user of the app is granting before). 该应用程序对启动代理程序的
plist
文件所在的文件夹具有read-write
权限(使用应用程序用户之前授予的安全范围书签)。
However the app gets the following error: 但是,该应用程序收到以下错误:
-
5/22/13 9:15:56.420 AM sandboxd[28463]: ([28473]) launchctl(28473) deny file-read-data /private/var/db/launchd.db/com.apple.launchd.peruser.501/overrides.plist
-
To make it clear, I do not want to add my own app to the launch items for autostart and I also found this http://www.mail-archive.com/cocoa-dev@lists.apple.com/msg80413.html conversation on a similar topic without any results yet. 为了说清楚,我不想将我自己的应用程序添加到自动启动的启动项目中,我也找到了这个http://www.mail-archive.com/cocoa-dev@lists.apple.com/msg80413.html关于类似主题的谈话还没有任何结果。
The file /private/var/db/launchd.db/com.apple.launchd.peruser.501/overrides.plist
cand only be read or write by the administrator user (root). 文件
/private/var/db/launchd.db/com.apple.launchd.peruser.501/overrides.plist
只能由管理员用户(root)读取或写入。 So for launchctl load\\unload
to work you must be root, or use sudo
, to elevate, before the command. 因此,对于
launchctl load\\unload
工作,您必须是root,或者在命令之前使用sudo
来提升。 But, in sandbox you are not allowed to do this. 但是,在沙箱中你不允许这样做。
Depending on your needs you can use an Helper app. 根据您的需要,您可以使用帮助应用程序。 Take a look at Adding Login Items Using the Service Management Framework .
请参阅使用服务管理框架添加登录项 。
In order for an application to do something that requires a privileged operation, Apple suggests that a helper app is created, which can only be called to run by the parent application, due to being signed. 为了让应用程序执行需要特权操作的操作,Apple建议创建一个帮助应用程序,由于被签名,该应用程序只能被父应用程序调用。 The helper app is launched with elevated permissions and performs the minimum required actions.
使用提升的权限启动帮助应用程序并执行所需的最少操作。 Take a look at SMJobBless here: -
在这里看一下SMJobBless: -
http://developer.apple.com/library/mac/#samplecode/SMJobBless/Introduction/Intro.html http://developer.apple.com/library/mac/#samplecode/SMJobBless/Introduction/Intro.html
As it states: - 如它所述: -
SMJobBless demonstrates how to securely install a helper tool that performs a privileged operation and how to associate the tool with an application that invokes it.
SMJobBless演示了如何安全地安装执行特权操作的帮助工具以及如何将该工具与调用它的应用程序相关联。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.