通过根守护程序按需启动用户上下文应用程序 [英] launching a user-context application by root-daemon on demand
问题描述
对于目标c我是菜鸟,而且我有一个守护程序代码,该代码作为root(系统范围的应用程序)运行并与服务器通信。服务器每隔一段时间就会命令该根应用程序启动在已登录用户上下文中运行的其他应用程序(不会无声地打断用户)。
我也编写了用户上下文应用程序。我所缺少的是对我的根守护程序如何启动用户上下文应用程序的理解。
I'm a noob to objective c and I have a daemon code that runs as root (system-wide application) and communicates with a server. Every once in a while, the server will command that root app to fire up an additional application that runs within the logged on user context (without interrupting the user - silently). I have the user context application written as well. What I'm lacking is the understanding on how my root daemon can launch the user context application.
- 我的守护程序如何启动它
- 我应该使用代理吗?
- 这是否意味着代理将在启动时运行?
我已阅读 https://developer.apple.com/library/mac/#technotes/tn2005/tn2083.html 以及 http://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual /BPSystemStartup/Chapters/CreatingLaunchdJobs.html ,但感觉我丢失了一些东西。
I've read https://developer.apple.com/library/mac/#technotes/tn2005/tn2083.html as well as http://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CreatingLaunchdJobs.html but feel I am missing something out.
BTW-解决方案应适用于10.6、10.7、10.8 ...
BTW - the solution should work on 10.6, 10.7, 10.8 ...
谢谢大家:o)
推荐答案
sudo chown -R current_loggedin_user myApp
sudo chmod u+s /Contents/MacOS/myApp
system([@"open myApp" UTF8String]); //inside root process
中,如果s组权限中设置了用户位(对应于u + s),则每当任何人执行该程序时,该过程就会获得拥有该程序的人的特权。因此,current_loggedin_user是myApp的所有者,打开后将在current_loggedin_user模式下运行myApp。
If the s group of permissions has the user bit set (corresponding to u+s), then whenever anyone executes that program, the process takes on the privileges of whoever owns it. So current_loggedin_user is owner of myApp, open will run myApp in current_loggedin_user mode.
s执行时设置用户ID和设置组ID -on-execution位。
s The set-user-ID-on-execution and set-group-ID-on-execution bits.
u文件原始模式下的用户权限位。
u The user permission bits in the original mode of the file.
但是如果用户未登录,它将引发以下错误。
But it will throw following error if user is not logged-in.
com.apple.launchd[1]: System: Bug: launchd_core_logic.c:8760 (24498):0
com.apple.launchd[1]: System: job_mig_spawn() can't find its session!
open[24459]: spawn_via_launchd() failed, errno=5 label=[0x0-0x274274].
rootProcess[23127]: LSOpenURLsWithRole() failed with error -10810 for the file /Applications/myApp.app/.
这篇关于通过根守护程序按需启动用户上下文应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!