无网络连接时启动 NetworkState
任何熟悉 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经尝试解决同样的问题一段时间了,今天我终于意识到了我的误解。
当 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."