调用 system(“open<应用程序名称.app>”) 有时会导致应用程序以 root 身份启动

发布于 2024-07-26 01:44:39 字数 689 浏览 3 评论 0原文

我有一个以 root 身份运行的应用程序(准确地说是 /Library/StartupItems 内的守护进程),偶尔会使用 system("open /Applications/MyAppName.app") 启动另一个进程。 这工作正常,除了在某些计算机上 MyAppName 以 root 身份启动运行,而不是在当前用户下运行。

我试图找出原因,以及如何让应用程序始终以当前用户身份启动。

该问题似乎发生在运行某种开放/活动目录组合的企业站点上。 我对这些机器的访问权限有些有限,因此在请求更多时间使用它们之前,我至少尝试做出一些假设。

我得到的另一条线索是,在至少其中一台计算机上,如果您打开活动监视器并检查“Finder”进程,“用户:”部分显示用户名,但没有用户 ID(“(UID)”部分)完全缺失)。

此外,父进程显示为“launchd (1)”,而不是像大多数标准应用程序那样显示为“launchd (95)”。 我相信这个 launchd 实例是每次计算机启动并以 root 身份运行时首先启动的运行,与以登录用户身份运行的 launchd 的其他实例相比。

除了明显的安全问题之外,我需要应用程序不以 root 身份运行,以便它支持诸如对两个同时登录的用户开放/可见之类的功能。

有人对可能导致此问题的原因或我如何解决它有任何想法吗?

I've got an application (A daemon inside /Library/StartupItems to be precise) running as root that occasionally launches another process using system("open /Applications/MyAppName.app"). This works fine except that on certain computers MyAppName gets launched running as root, instead of under the current user.

I'm trying to figure out why this is, and how I can get the application to always launch as the current user.

The issue seems to occur at enterprise sites running some combination of Open/Active directory. I have somewhat limited access to these machines so I'm trying to at least form some hypotheses before I request more time on them.

The one other clue I have is that on at least one of these computers if you open up Activity Monitor and inspect the "Finder" process, the "User:" section shows user name but no user id (the "(UID)" section is entirely missing).

Also, the Parent Process shows as "launchd (1)" rather than "launchd (95)" like most standard applications do. This instance of launchd I believe is the run that's the first thing to start up any time the computer is booted up and runs as root, as compared to the other instance of launchd which runs as the logged in user.

Besides the obvious security concerns, I need the application to not run as root so that it will support things such as being open for/visible to two simultaneously logged in users.

Does anybody have any ideas about what might be causing this or how I might go about solving it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别靠近我心 2024-08-02 01:44:39

我有一些评论:

  1. 您应该使您的守护进程成为适当的 launchd 守护进程,即在 /Library/LaunchDaemons 中粘贴一个 plist。 /Library/StartupItems 已过时。 请参阅 http://developer.apple.com/documentation/MacOSX/Conceptual /BPSystemStartup/BPSystemStartup.html.

  2. 您可能不应该直接从守护程序启动第二个守护程序。 您可能应该将其设置为另一个守护进程。

  3. 确保您熟悉这项技术。 注意: http://developer.apple.com/technotes/tn2005/tn2083.html< /a>. 这是一本重要的读物,应该解释为什么有多个启动进程,并且应该为您提供有关您的案例中出现问题的线索。

  4. 顺便说一句,open 只是 Launch Services 的包装器,您可以直接访问它,而不是调用 system。 但是,正如我所说,您不应该使用 open 或 Launch Services 启动第二个守护程序。

如果您可以发布有关您的守护进程具体执行的操作的更多详细信息,我们也许可以为您提供有关最佳方法的建议。 例如,通常最好让您的启动守护程序按需启动,而不是让它们持续运行。

I’ve got a few comments:

  1. You should make your daemon a proper launchd daemon, i.e. stick a plist in /Library/LaunchDaemons. /Library/StartupItems is obsolete. See http://developer.apple.com/documentation/MacOSX/Conceptual/BPSystemStartup/BPSystemStartup.html.

  2. You probably shouldn’t be launching the second daemon directly from your daemon. You should probably make it another daemon.

  3. Make sure you’re familiar with this Tech. Note: http://developer.apple.com/technotes/tn2005/tn2083.html. It’s essential reading and should explain why there’s more than one launchd process and should give you decent clues as to what’s going wrong in your case.

  4. As an aside, open is just a wrapper around Launch Services which you can access directly, rather than calling system. However, as I said, you shouldn’t be launching your second daemon using open or Launch Services.

If you can post more detail about exactly what it is your daemons do, we might be able to give you advice as to the best way to do it. For example, it’s often best to have your launch daemon launched on demand rather than have them running continuously.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文