LaunchDaemon WatchPaths key spawning repeatedly

remodb
New Contributor II

We've been using the following trigger in a LaunchDaemon to spawn a script that disables Wifi:

<key>WatchPaths</key>
<array>
    <string>/Library/Preferences/SystemConfiguration</string>
</array>
<key>RunAtLoad</key>

This has been working fine, but I've recently noticed in '/var/log/system.log' that the LaunchDaemon is being spawned multiple times in bursts every ~30 seconds:

Oct 31 16:19:56 --- last message repeated 2 times ---
Oct 31 16:19:56 MALKiosk-22462 com.apple.xpc.launchd[1] (com.mycompany.disable_wifi): Service only ran for 0 seconds. Pushing respawn out by 10 seconds.
Oct 31 16:20:27 --- last message repeated 2 times ---
Oct 31 16:20:27 MALKiosk-22462 com.apple.xpc.launchd[1] (com.mycompany.disable_wifi): Service only ran for 0 seconds. Pushing respawn out by 10 seconds.
Oct 31 16:20:58 --- last message repeated 2 times ---
Oct 31 16:20:58 MALKiosk-22462 com.apple.xpc.launchd[1] (com.mycompany.disable_wifi): Service only ran for 0 seconds. Pushing respawn out by 10 seconds.

Has something changed in a recent OS that makes this folder change repeatedly like this? This seems excessive for this script and I wonder now if there's a better way to achieve this.

Thanks.

1 ACCEPTED SOLUTION

remodb
New Contributor II

So I figured out why the launchdaemon was running so often. My Wi-Fi disabling script wasn't doing a check whether it needed to turn power off. It just turned Wi-Fi power off every time it ran. This meant that every time the script was invoked it triggered the launchdaemon which ran the script again. Infinite loop. <facepalm>

I offer this as a cautionary tale for those who come after me.

View solution in original post

1 REPLY 1

remodb
New Contributor II

So I figured out why the launchdaemon was running so often. My Wi-Fi disabling script wasn't doing a check whether it needed to turn power off. It just turned Wi-Fi power off every time it ran. This meant that every time the script was invoked it triggered the launchdaemon which ran the script again. Infinite loop. <facepalm>

I offer this as a cautionary tale for those who come after me.