Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can you start a LaunchAgent for the first time without rebooting, when your code runs as a LaunchDaemon?
    text
    copied!<p>I have a LaunchDaemon. When it runs, it checks if SIMBL is installed. If SIMBL is not installed, it uses NSTask to run /usr/sbin/installer on the SIMBL.pkg.</p> <p>SIMBL's postflight script then tries to run a launchctl load command to start SIMBL's LaunchAgent immediately:</p> <pre><code>sudo -u "$USER" -- /bin/launchctl load -F -S Aqua -D user "${LAUNCHD_PLIST}" </code></pre> <p>This fails, because my LaunchDaemon's NSTask environment doesn't have $USER set. </p> <p>If I have my daemon detect the current user with the System Configuration framework and pass it to NSTask with setEnvironment, launchctl bugs out on me:</p> <pre><code>Bug: launchctl.c:2325 (23930):13: (dbfd = open(g_job_overrides_db_path, O_RDONLY | O_EXLOCK | O_CREAT, S_IRUSR | S_IWUSR)) != -1 </code></pre> <p>I realize a daemon, by definition, should not operate in a user session. By the same token, Apple seems to recommend LaunchAgents as helper objects for LaunchDaemons, to do that user session work. Is there any way to get such an agent up and running immediately?</p> <p>I have all the .plists in the right places (they start running after a reboot, the next time launchctl does its regular loading) so my first thought was to just tell launchctl to reload. But <a href="http://www.opensource.apple.com/source/launchd/launchd-392.35/launchd/src/launchctl.c?txt" rel="noreferrer">all the code to do that is commented out in launchctl.c</a>:</p> <pre><code>// { "reload", reload_cmd, "Reload configuration files and/or directories" }, </code></pre> <p>...</p> <pre><code> * 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. </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload