<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 22 Jul, 2015, at 22:49, James Bucanek <<a href="mailto:subscriber@gloaming.com" class="">subscriber@gloaming.com</a>> wrote:<div><blockquote type="cite" class=""><div class=""><blockquote cite="mid:915DC9C3-D635-40D5-9F85-E534E236416A@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="display: table; width: 901px; border-top-width: 1px; border-top-style: solid; border-top-color: rgb(237, 238, 240); padding-top: 5px;" class=""><div style="display: table-cell; white-space: nowrap; vertical-align: middle; width: 721px;" 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><div style="display: table-cell; white-space: nowrap; vertical-align: middle;" class=""><font color="#9FA2A5" class=""><span style="padding-left: 6px;" class="">July 22, 2015 at 6:19 PM</span></font></div></div></div><div __pbrmquotes="true" class="__pbConvBody" style="color: rgb(136, 136, 136); margin-left: 24px; margin-right: 24px;"><div class="">James,</div><div class=""><br class=""></div><div class="">Some replies inline...</div><div class=""><br class=""></div>On 22 Jul, 2015, at 17:46, James Bucanek <<a moz-do-not-send="true" class="" href="mailto:subscriber@gloaming.com">subscriber@gloaming.com</a>> wrote:<div class=""><blockquote class="" type="cite"><div class=""><div class="" text="#000000" bgcolor="#FFFFFF">Damien,<br class=""><br class="">Thanks for the suggestion, and apologies for the tardy reply; I just got buried under twenty other to-do items that were higher on the list.<br class=""><br class="">I tried removing the LimitLoadToSessionType entry from my agent's plist, but it doesn't make any difference. When trying to install it as a system-wide agent, the process still doesn't start.<br class=""></div></div></blockquote><div class=""><br class=""></div><div class="">In launchd's lexicon, "system-wide agent" is a conflict of terminology. System-wide things are, by definition, daemons. Agents are things which run on a per-user basis (cf. launchd(8)). So the real question is about the desired lifecycle of your job. Do you want it to run when a user logs in and to go away when the user logs out? Or do you want it to be available regardless of any user being logged in?</div></div></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="">That's the problem; I don't know what to call them. It's an agent, but it's an agent for all users (/Library/LaunchAgents) to distinguish it for exclusively for an individual user (~/Library/LaunchAgents). And it should run in the context of the user's bootstrap, not just within the GUI login.</span><br class="" 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);"><blockquote cite="mid:915DC9C3-D635-40D5-9F85-E534E236416A@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;"><div class=""><blockquote class="" type="cite"><div class=""><div class="" text="#000000" bgcolor="#FFFFFF">My reading of LimitLoadToSessionType would lead me to believe that it's applicable to my service, which *is* an agent. It runs as a regular user, and the docs would indicate that this property is just a hint to the load balancer on how to constrain its use of CPU/memory/IO. It doesn't make sense that it would keep the process from starting in the first place.<br class=""></div></div></blockquote><div class=""><br class=""></div><div class="">Wow, no that's not at all what that key is for. Please file a bug explaining how the documentation misled you into that impression so we can make it clearer!</div></div></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 think I got this confused with ProcessType. Both have a "Background" type.</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="">I'll file a bug report on the docs, but one problem that I run into is that terms are often never defined. For example, the LimitLoadToSessionType section in man 5 launchd.plist describes it thusly:</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=""> "LimitLoadToSessionType <string or array or strings></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); float: none; display: inline !important;" class=""> This configuration file only applies to sessions of the type(s) specified."</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="">But the descriptions of what "type(s)" can be is never defined or explained in the man pages for launchd.plist, launchctl, or launchd. I'm sure the description of what LimitLoadToSessionType does is accurate, but I still left wondering what values are valid or what they mean. :)</span></div></blockquote><div><br class=""></div><div>Yes, please file a documentation bug. This could be made clearer.</div><br class=""><blockquote type="cite" class=""><div class=""><blockquote cite="mid:915DC9C3-D635-40D5-9F85-E534E236416A@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;"><div class=""><div class="">Session types are basically collections of certain kinds of jobs. The "Aqua" session is all the jobs associated with a graphical login on the console. By default, if your job is an agent, it is loaded into the Aqua session. (That is, if no LimitLoadToSessionType key is present.)</div><div class=""><br class=""></div><div class="">The Background session is a collection of jobs that can run on behalf of a user even if that user is not logged in at the graphical console. They might be doing things like performing Spotlight indexing on that user's home directory even when that user isn't logged in for example.</div></div></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="">What I want, and I think that's what I've configured in the .plist, is a per-user Agent running in the Background session, for all users. The .plist is placed in /Library/LaunchAgents and the LimitLoadToSessionType is set to Background. (See my earlier message. It has all the details.)</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:915DC9C3-D635-40D5-9F85-E534E236416A@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;"><div class=""><div class=""><br class=""></div><div class="">So if you have a vanilla Terminal prompt and do a `launchctl load`, your plist will attempt to load in the Aqua session. If that service has LimitLoadToSessionType set to "Background", then that load will fail because it's attempting to load in the Aqua session and your service has expressed that it should only load in the Background session.</div></div></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="">In my case, the 'launchctl load ...' command is being executed via NSTask launched from a helper running as root, itself launched from a privileged helper service installed via SMJobBless. I don't know if this puts launchctl in the context of Background session of the user or in the root System session.</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="">That is your problem. In that context, `launchctl load` will attempt to load your job as a daemon because it is running as root in the root Mach bootstrap. One thing that's critical to understand is that there's nothing about the contents of your plist which identifies it as a daemon or agent; the same plist can be loaded into multiple contexts. Each context can have sessions within it. As it turns out, the only place this matters is the per-user context, which has Background and Aqua. The intended effect of `launchctl load` and friends is determined by your calling context.</div><div class=""><br class=""></div><div class="">This is why the new bootstrap subcommand introduced in Yosemite takes an explicit parameter identifying the context you want to bootstrap the job into. Try changing your NSTask invocation in your helper tool to this:</div><div class=""><br class=""></div><div class="">launchctl bootstrap user/$UID /path/to/plist</div><div class=""><br class=""></div><div class="">On earlier versions of OS X, this should also work:</div><div class=""><br class=""></div><div class="">launchctl asuser $UID launchctl load /path/to/plist</div><div class="">-damien</div><div class=""><br class=""></div></body></html>