I have LaunchDaemon. When it starts, it checks to see if SIMBL is installed. If SIMBL is not installed, it uses NSTask to run / usr / sbin / installer on SIMBL.pkg.
The aftermarket SIMBL script will then attempt to run the loadctl load command to launch SIMBL LaunchAgent immediately:
sudo -u "$USER" -- /bin/launchctl load -F -S Aqua -D user "${LAUNCHD_PLIST}"
This fails because in my LaunchDaemon NSTask environment there is no USER set.
If my daemon detects the current user with the system configuration framework and transfers it to NSTask using setEnvironment, launchctl errors will appear on it:
Bug: launchctl.c:2325 (23930):13: (dbfd = open(g_job_overrides_db_path, O_RDONLY | O_EXLOCK | O_CREAT, S_IRUSR | S_IWUSR)) != -1
I understand that a daemon, by definition, should not work in a user session. Similarly, Apple seems to recommend LaunchAgents as helper objects for LaunchDaemons to do this work with the user. Is there a way to immediately start and run such an agent?
I have all the .plists in the right places (they start after reboot, the next time launchctctl performs its normal boot), so my first thought was to just launch launchctll. But all the code for this is commented out in the launchct.c file:
// { "reload", reload_cmd, "Reload configuration files and/or directories" },
...
* In later versions of launchd, I hope to load everything in the first pass,
* then do the Bonjour magic on the jobs that need it, and reload them, but for now,
* I haven't thought through the various complexities of reloading jobs, and therefore
* launchd doesn't have reload support right now.