launchctl 无法运行二进制文件并以代码 78 退出

2024-03-21

我一直在构建一个 golangapp https://gist.github.com/krlc/8b9a79b33b857d1a66221ffc802d3c0d带有系统托盘 GUI。我想了launchctl每当我登录时运行我的程序。程序编译并运行没有任何错误,但是,当launchctl运行它,我看到这个:Service exited with abnormal code: 78。也许这与权利有关。

  • 首先我尝试将当前用户的权限设置为两者plist文件和二进制文件。仍然错误78.

  • 然后我改变了权利plist文件和二进制文件root并运行sudo launchctl。我仍然看到错误78.

/var/log/system.log有这个错误:

14:46:00 Macchiato com.apple.xpc.launchd[1] (com.test.test[519]): Service could not initialize: 18A391: xpcproxy + 11291 [1534][8188841E-6D08-3F80-8488-9B5D7462BACB]: 0xd
14:46:00 Macchiato com.apple.xpc.launchd[1] (com.test.test[519]): Service exited with abnormal code: 78
14:46:00 Macchiato com.apple.xpc.launchd[1] (com.test.test): Service only ran for 0 seconds. Pushing respawn out by 10 seconds.

The 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.test.test</string>
        <key>ProgramArguments</key>
        <array>
                <string>/Users/test-user/test/test</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
        <key>ProcessType</key>
        <string>Standard</string>
        <key>KeepAlive</key>
        <true/>
        <key>StandardErrorPath</key>
        <string>/var/log/test-err.log</string>
        <key>StandardOutPath</key>
        <string>/var/log/test-out.log</string>
</dict>
</plist>

错误日志为空。

当我运行binary https://gist.github.com/krlc/8b9a79b33b857d1a66221ffc802d3c0d手动操作时,应用程序的图标会按预期出现在系统托盘上。

有一个有趣的时刻– 如果我手动输入launchctl load -w com.test.test.plist,应用程序运行良好 - 直到重新启动。我重启后,launchctl throws 78 error.

为什么会发生这种情况?


我想我解决了我自己的问题。看来是错误78当我使用时出现

<key>StandardErrorPath</key>
<string>/var/log/test-err.log</string>
<key>StandardOutPath</key>
<string>/var/log/test-out.log</string>

当我删除这行代码时,错误就消失了。这尤其奇怪,因为plist文件具有 root 权限并且launchd以 root 身份运行...

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

launchctl 无法运行二进制文件并以代码 78 退出 的相关文章

随机推荐