无网络连接时启动 NetworkState

发布于 2024-11-03 15:37:32 字数 779 浏览 5 评论 0原文

任何熟悉 Mac OS X 上 launchd 的人,特别是 KeepAlive 部分中的 NetworkState (bool) 键代码>.plist 文件?

man 页面来看,当 Mac 上没有网络连接时,当 plist 配置如下时,launchd 应该调用可执行文件:

...
<key>KeepAlive</key>
<dict>
    <key>NetworkState</key>
    <false/>
</dict>
...

这似乎工作正常,但是,一旦建立了有效的网络连接(定义为 Mac 具有至少一个非环回 IPv4/6 地址),launchd应该停止调用可执行文件(因为launchd应该停止调用可执行文件>NetworkState 标志应该可以阻止它)。

不过,我看到的行为是,无论 Mac 的网络连接如何,launchd 都会不断调用我的程序!就好像 launchd 完全忽略了 NetworkState 标志。

有谁知道如何做到这一点,以便 launchd 仅在没有网络连接时调用程序,并在建立网络连接后停止调用它?

Anyone familiar with launchd on Mac OS X, specifically the NetworkState (bool) key in KeepAlive section of a .plist file?

From the man pages, launchd should call an executable when there is no network connectivity on the Mac, when the plist is configured like this:

...
<key>KeepAlive</key>
<dict>
    <key>NetworkState</key>
    <false/>
</dict>
...

This seems to work okay, However, once a valid network connection is established (defined as the Mac having at least one non-loopback IPv4/6 address), launchd should stop calling the executable (because the NetworkState flag should prevent it).

The behavior I am seeing, though, is that launchd keeps calling my program regardless of the Mac's network connectivity! It’s as if launchd is completely ignoring the NetworkState flag.

Does anyone know how to make this work so that launchd will only call a program when there’s no network connection, and stop calling it once a network connection is established?

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

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

发布评论

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

评论(1

天生の放荡 2024-11-10 15:37:32

我已经尝试解决同样的问题一段时间了,今天我终于意识到了我的误解。

当 KeepAlive 的任何条件评估为 true 时,这意味着“确保此进程正在运行”。当它们都没有评估为 true 时,这意味着“不确保此进程正在运行”,而不是像我所希望的那样“确保此进程不运行”。

I've been trying to tackle this same problem for a while, and today I finally realized my misunderstanding.

When any of KeepAlive's conditions evaluate to true, that means "ensure this process is running." When none of them evaluate to true, that means "do not ensure this process is running," not, as I had hoped, "ensure this process is not running."

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