<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">On 5 Nov, 2015, at 14:23, James Bucanek &lt;<a href="mailto:subscriber@gloaming.com" class="">subscriber@gloaming.com</a>&gt; wrote:<div><blockquote type="cite" class=""><div class=""><span style="font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); float: none; display: inline !important;" class="">Damien,</span><br style="font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);" class=""><br style="font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);" class=""><span style="font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); float: none; display: inline !important;" class="">Thanks for the feedback. Replies inline...</span><br style="font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);" class=""><span style="font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);" class=""></span><br style="font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);" class=""><blockquote cite="mid:BCED0EE5-125E-4D5E-BF0F-CA56898FF962@apple.com" type="cite" style="font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); border: 0px none;" class=""><div class="__pbConvHr" style="margin: 30px 25px 10px;"><div style="width: 837px; border-top-width: 1px; border-top-style: solid; border-top-color: rgb(237, 238, 240); padding-top: 5px;" class=""><div style="display: inline-block; white-space: nowrap; vertical-align: middle; width: 410.125px;" class=""><a moz-do-not-send="true" href="mailto:dsorresso@apple.com" style="padding-right: 6px; font-weight: bold; color: rgb(115, 127, 146) !important; text-decoration: none !important;" class="">Damien Sorresso</a></div><span class="Apple-converted-space">&nbsp;</span> <div style="display: inline-block; white-space: nowrap; vertical-align: middle; width: 401.75px; text-align: right;" class=""><font color="#9FA2A5" class=""><span style="padding-left: 6px;" class="">November 5, 2015 at 9:32 AM</span></font></div></div></div><div __pbrmquotes="true" class="__pbConvBody" style="color: rgb(136, 136, 136); margin-left: 24px; margin-right: 24px;"><pre wrap="" class="">James,

Answers inline...

On 4 Nov, 2015, at 21:44, James Bucanek <a class="moz-txt-link-rfc2396E" href="mailto:subscriber@gloaming.com">&lt;subscriber@gloaming.com&gt;</a> wrote:
</pre><blockquote type="cite" class=""><pre wrap="" class="">Greetings,

I have a user agent installed in the "Background" session that isn't starting up on one system.
</pre></blockquote><pre wrap="" class="">The Background session is typically only useful for agents which you want to run "as the user" independently of whether that user is logged in. In the strictest terms, you can't even rely on the home directory for that user being available. So you should be sure that this is the session you really want.</pre></div></blockquote><span style="font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); float: none; display: inline !important;" class="">I understand. This is exactly the session I want. My product has an option ("Start and run actions when logged out") that allows you install the scheduler agent the "Background" session so that backups and other maintenance can be performed even when logged out (or because you've logged out).</span><br style="font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);" class=""></div></blockquote><div><br class=""></div><div>Okay, just as long as you understand the implications.</div><blockquote type="cite" class=""><div class=""><blockquote cite="mid:BCED0EE5-125E-4D5E-BF0F-CA56898FF962@apple.com" type="cite" style="font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); border: 0px none;" class=""><div __pbrmquotes="true" class="__pbConvBody" style="color: rgb(136, 136, 136); margin-left: 24px; margin-right: 24px;"><blockquote type="cite" class=""><pre wrap="" class="">My customer is running OS X 10.11.1. I have this software running on hundreds of El Capitan systems, but for some reason this user agent won't start when the user logs in.

I've found two things that are suspicious. First, a message like this appears in the console log:

system.log: Oct 31 17:45:05 UsersMac otherbsd[488]: Failed to bootstrap agent: path = /Users/theuser/Library/LaunchAgents/com.qrecall.scheduler.plist, error = 134: Service cannot load in requested session

I was really hoping that someone could tell me what error 134 means.
</pre></blockquote><pre wrap="" class="">The string representation of the error is printed right after it. Also, you can decode launchd's error codes with the `launchctl error` subcommand; in this case it'll print "Service cannot load in requested session".

What this means is that one of launchd's helpers, otherbsd, tried loading the com.qrecall.scheduler service into the user's Aqua session. The plist almost certainly specifies a LimitLoadToSessionType entry which says it can only load in the Background session. So launchd refuses to load the service.</pre></div></blockquote><span style="font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); float: none; display: inline !important;" class="">So that begs two questions:(1) Why is the service being loaded in the Aqua session? (That might be an artifact of something that's loading it into a session it's excluded from. I get that, and I suppose that could be ignored.)</span><br style="font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);" class=""></div></blockquote><div><blockquote type="cite" class=""><br class=""></blockquote></div><blockquote type="cite" class=""><div class=""><span style="font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); float: none; display: inline !important;" class="">(2) More importantly, why isn't it being loaded into the Background session when that session is created?</span><br style="font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);" class=""></div></blockquote><div><blockquote type="cite" class=""><br class=""></blockquote></div><blockquote type="cite" class=""><div class=""><span style="font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); float: none; display: inline !important;" class="">I'm surprised that you say that the home folder might not be available when the Background session is created. How is that possible? The user agent configuration file (~/Library/LaunchAgents/com.qrecall.scheduler.plist) is _inside_ the home folder. How would launchd load an agent service *before* the configuration file that defines that service is readable?</span><br style="font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);" class=""></div></blockquote><div><br class=""></div><div>This gets complicated. First off, Background agents cannot rely on the presence of the user's home directory because there is code that executes only in the GUI login path which may be responsible for making that home directory available. Think NFS home directories or OG FileVault, which both require the user to enter her password at the login window to mount/decrypt the home directory. In either of those scenarios, without the user's secret, the home directory is inaccessible.</div><div><br class=""></div><div>For this reason, launchd cannot actually support loading Background agents from the user's home directory. This is what you're hitting.</div><div><br class=""></div><div>To give you a little more background on what's happening, launchd has to use a helper (otherbsd) to sniff out agents from the user's home directory because it itself cannot actually safely resolve a user's home directory location. The calls to do this (getpwnam(3) and friends) might wind up doing IPC to opendirectoryd, which launchd is responsible for launching, which would create a layering inversion.</div><div><br class=""></div><div>So what it does instead is spawn its little otherbsd helper to go off, find the user's home directory, and snarf the agents contained therein. But this agent is there specifically to load stuff into the Aqua session. So when it gives launchd a plist that has its loads limited to the Background session, launchd says "No you're in the wrong session", hence that error message.</div><br class=""><blockquote type="cite" class=""><div class=""><span style="font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); float: none; display: inline !important;" class="">Anyway, I really hope that's never true, because my service has always depended on resources in the home folder (preferences, cache, documents, and such). And in this case, the service executable is also stored in ~/Library/Application Support/, so the home folder has to be available if it's going to start (and it always starts on other systems).</span><br style="font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);" class=""></div></blockquote><div><br class=""></div><div>Unfortunately, while it may not be a very common case, it is nonetheless a case that we must deal with sanely and support.</div><br class=""><blockquote type="cite" class=""><div class=""><span style="font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); float: none; display: inline !important;" class="">But I'll also ask the user if they're doing anything "clever" with their home folder.</span><br style="font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);" class=""><br style="font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);" class=""><span style="font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); float: none; display: inline !important;" class="">Thanks for any insight,</span><br style="font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);" class=""></div></blockquote></div><br class=""><div class="">Something ugly you could do:</div><div class=""><br class=""></div><div class="">Have another plist inside ~/Library/LaunchAgents that does not have the LimitLoadToSession key set which runs a script which does</div><div class=""><br class=""></div><div class="">launchctl load -S Background ~/Library/LaunchAgents/com.qrecall.scheduler.plist</div><div class=""><br class=""></div><div class="">That will target the load to the background session upon the user's GUI login, and the agent will continue to be available after logout, but it will not be available until the user logs in at least once on the GUI.</div><div class="">-damien</div><div class=""><br class=""></div><div class=""><br class=""></div></body></html>