我是目标c的菜鸟,我有一个以root身份运行的守护程序代码(系统范围的应用程序)并与服务器通信。每隔一段时间,服务器就会命令该根应用程序启动在登录用户上下文中运行的其他应用程序(不会中断用户 - 静默)。 我也编写了用户上下文应用程序。我缺少的是了解我的根守护程序如何启动用户上下文应用程序。
我已阅读https://developer.apple.com/library/mac/#technotes/tn2005/tn2083.html以及http://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CreatingLaunchdJobs.html,但我觉得我错过了一些东西。
BTW - 解决方案应该适用于10.6,10.7,10.8 ......提前谢谢大家:o)
答案 0 :(得分:0)
如果你知道当前登录的用户,这将有效。
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的所有者,open将以current_loggedin_user模式运行myApp。
s set-user-ID-on-execution和set-group-ID-on-execution位。
u文件原始模式中的用户权限位。
但如果用户未登录,则会抛出以下错误。
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/.