<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Taming Launchd</title>
	<atom:link href="http://www.red-sweater.com/blog/245/taming-launchd/feed" rel="self" type="application/rss+xml" />
	<link>http://www.red-sweater.com/blog/245/taming-launchd</link>
	<description>Mac &#38; Technology Writings by Daniel Jalkut</description>
	<pubDate>Thu, 28 Aug 2008 20:57:05 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
		<item>
		<title>By: Nathaniel</title>
		<link>http://www.red-sweater.com/blog/245/taming-launchd#comment-39833</link>
		<dc:creator>Nathaniel</dc:creator>
		<pubDate>Mon, 01 Jan 2007 16:54:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.red-sweater.com/blog/245/taming-launchd#comment-39833</guid>
		<description>I'm pretty sure Launchd Editor came first.  I remember using it for a while, and being really excited when Lingon came out.</description>
		<content:encoded><![CDATA[<p>I&#8217;m pretty sure Launchd Editor came first.  I remember using it for a while, and being really excited when Lingon came out.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adam Knight</title>
		<link>http://www.red-sweater.com/blog/245/taming-launchd#comment-39299</link>
		<dc:creator>Adam Knight</dc:creator>
		<pubDate>Sun, 31 Dec 2006 05:43:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.red-sweater.com/blog/245/taming-launchd#comment-39299</guid>
		<description>For the record, Launchd Editor was first, and the idea was only to create the file correctly rather than be a complete solution.  I've pondered doing the whole schebang at some point, however.  Perhaps in '07 I'll make a second, more full version that does those things.</description>
		<content:encoded><![CDATA[<p>For the record, Launchd Editor was first, and the idea was only to create the file correctly rather than be a complete solution.  I&#8217;ve pondered doing the whole schebang at some point, however.  Perhaps in &#8216;07 I&#8217;ll make a second, more full version that does those things.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul Kim</title>
		<link>http://www.red-sweater.com/blog/245/taming-launchd#comment-39273</link>
		<dc:creator>Paul Kim</dc:creator>
		<pubDate>Sun, 31 Dec 2006 04:12:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.red-sweater.com/blog/245/taming-launchd#comment-39273</guid>
		<description>Thanks for the mention though the irony of using me as the poster boy for launchd is that I am currently considering ditching it. The problem? Well, one thing that is mentioned in the tech note that Mark posted above is that after logout, the user context is disabled. It wasn't immediately obvious to me but after talking to Apple support, the user's launchd and everything it launches runs in this context and when the user re-logs in. The side effect is that none of these processes are able to get rights to any mach ports. While Hazel does not create any ports directly, it ends up using Launch Services and other subsystems that need mach ports so it throws all sorts of errors in this situation.

There's a good chance I will have to write my own daemon and stop using launchd which is too bad since it's works well for my needs. While there's a chance it will be fixed in Leopard, I imagine a good percentage of my users will be on Tiger for some time. It's unfortunate since the new daemon would be another moving part that I would have to write and maintain but them's the breaks.

Oh, and to Tom's point about polling: Hazel does poll as well. Certain conditions are time based and so having rules run only when a change in the folder occurs is not sufficient. This is also why, among other reasons, Folder Actions (which Hazel gets compared to now and then) are not a suitable replacement for Hazel since if there's no activity in the folder, time based rules will not get run.</description>
		<content:encoded><![CDATA[<p>Thanks for the mention though the irony of using me as the poster boy for launchd is that I am currently considering ditching it. The problem? Well, one thing that is mentioned in the tech note that Mark posted above is that after logout, the user context is disabled. It wasn&#8217;t immediately obvious to me but after talking to Apple support, the user&#8217;s launchd and everything it launches runs in this context and when the user re-logs in. The side effect is that none of these processes are able to get rights to any mach ports. While Hazel does not create any ports directly, it ends up using Launch Services and other subsystems that need mach ports so it throws all sorts of errors in this situation.</p>
<p>There&#8217;s a good chance I will have to write my own daemon and stop using launchd which is too bad since it&#8217;s works well for my needs. While there&#8217;s a chance it will be fixed in Leopard, I imagine a good percentage of my users will be on Tiger for some time. It&#8217;s unfortunate since the new daemon would be another moving part that I would have to write and maintain but them&#8217;s the breaks.</p>
<p>Oh, and to Tom&#8217;s point about polling: Hazel does poll as well. Certain conditions are time based and so having rules run only when a change in the folder occurs is not sufficient. This is also why, among other reasons, Folder Actions (which Hazel gets compared to now and then) are not a suitable replacement for Hazel since if there&#8217;s no activity in the folder, time based rules will not get run.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom Harrington</title>
		<link>http://www.red-sweater.com/blog/245/taming-launchd#comment-39224</link>
		<dc:creator>Tom Harrington</dc:creator>
		<pubDate>Sat, 30 Dec 2006 23:48:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.red-sweater.com/blog/245/taming-launchd#comment-39224</guid>
		<description>When considering launchd one should beware that per-user agents (those whose plists reside in one of the LaunchAgents folders) are in many cases much less useful than one might expect.

If you set up a LaunchAgents entry, launchd will start the process when the user logs in.  If it's a persistent process-- one which starts up and keeps running instead of one that starts up, does some work, and exits-- then launchd will stop it (via SIGTERM) when they log out.

That actually works OK, as far as described.  However launchd doesn't quite clean things up normally on log-out.  The upshot is that if you log in, log out, and then back in, your LaunchAgents entries will not start up on the second login (or any subsequent logins).

I had originally intended to use launchd with &lt;a href="http://www.atomicbird.com/mondomouse/" rel="nofollow"&gt;MondoMouse&lt;/a&gt;, but on discovering this limitation (confirmed by Apple engineers) I had to abandon the plan and go with a login item instead (and thanks to &lt;a href="http://www.zathras.de/" rel="nofollow"&gt;Uli&lt;/a&gt; for his sample code that made this easier).  Paul Kim was able to use launchd with &lt;a href="http://www.noodlesoft.com/hazel.html" rel="nofollow"&gt;Hazel&lt;/a&gt; because Hazel's launchd-started jobs are not persistent-- they start up, do something useful, and then start

Also for what it's worth-- unless I'm very much mistaken, Hazel's launchd usage doesn't involve any sort of polling-like behavior to check watched folders.  I'm pretty sure launchd makes use of Mac OS X (BSD's really) kqueue system to receive notifications of filesystem changes without the need for regular checking.</description>
		<content:encoded><![CDATA[<p>When considering launchd one should beware that per-user agents (those whose plists reside in one of the LaunchAgents folders) are in many cases much less useful than one might expect.</p>
<p>If you set up a LaunchAgents entry, launchd will start the process when the user logs in.  If it&#8217;s a persistent process&#8211; one which starts up and keeps running instead of one that starts up, does some work, and exits&#8211; then launchd will stop it (via SIGTERM) when they log out.</p>
<p>That actually works OK, as far as described.  However launchd doesn&#8217;t quite clean things up normally on log-out.  The upshot is that if you log in, log out, and then back in, your LaunchAgents entries will not start up on the second login (or any subsequent logins).</p>
<p>I had originally intended to use launchd with <a href="http://www.atomicbird.com/mondomouse/" rel="nofollow">MondoMouse</a>, but on discovering this limitation (confirmed by Apple engineers) I had to abandon the plan and go with a login item instead (and thanks to <a href="http://www.zathras.de/" rel="nofollow">Uli</a> for his sample code that made this easier).  Paul Kim was able to use launchd with <a href="http://www.noodlesoft.com/hazel.html" rel="nofollow">Hazel</a> because Hazel&#8217;s launchd-started jobs are not persistent&#8211; they start up, do something useful, and then start</p>
<p>Also for what it&#8217;s worth&#8211; unless I&#8217;m very much mistaken, Hazel&#8217;s launchd usage doesn&#8217;t involve any sort of polling-like behavior to check watched folders.  I&#8217;m pretty sure launchd makes use of Mac OS X (BSD&#8217;s really) kqueue system to receive notifications of filesystem changes without the need for regular checking.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark Dalrymple</title>
		<link>http://www.red-sweater.com/blog/245/taming-launchd#comment-39219</link>
		<dc:creator>Mark Dalrymple</dc:creator>
		<pubDate>Sat, 30 Dec 2006 23:19:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.red-sweater.com/blog/245/taming-launchd#comment-39219</guid>
		<description>Beware, launchd is pretty broken in Tiger, especially for per-user agents.  Sometimes they'll start in the wrong context (like if you ssh into a machine - see &lt;a href="http://developer.apple.com/technotes/tn2005/tn2083.html" rel="nofollow"&gt;tn2083&lt;/a&gt;), sometimes they won't shut down properly, and keep running (and re-launching) after you log out.  Plus there are race conditions if you're using watchPaths or queueDirectories.  If you stay running, you won't get any additional notifications, even if you use ServiceIPC, so you end up using kqueue() to watch the things that launchd is watching, Just In Case.   Also some of the launchd API is wishful thinking, and isn't actually implemented. (see &lt;a href="http://lists.apple.com/archives/Darwin-dev/2006/Apr/msg00109.html" rel="nofollow"&gt;Launchd and domain sockets&lt;/a&gt;)

Also watch out for launchd editor if you use unix domain sockets, it'll corrupt your plist file.  My &lt;a href="http://www.codepoetry.net/fourm/software/launchd_editor/unix_sockets_get_mangled" rel="nofollow"&gt;bug report&lt;/a&gt; is still sitting there.  I've since abandoned launchd and launchd editor for what I was originally intending to use it.</description>
		<content:encoded><![CDATA[<p>Beware, launchd is pretty broken in Tiger, especially for per-user agents.  Sometimes they&#8217;ll start in the wrong context (like if you ssh into a machine - see <a href="http://developer.apple.com/technotes/tn2005/tn2083.html" rel="nofollow">tn2083</a>), sometimes they won&#8217;t shut down properly, and keep running (and re-launching) after you log out.  Plus there are race conditions if you&#8217;re using watchPaths or queueDirectories.  If you stay running, you won&#8217;t get any additional notifications, even if you use ServiceIPC, so you end up using kqueue() to watch the things that launchd is watching, Just In Case.   Also some of the launchd API is wishful thinking, and isn&#8217;t actually implemented. (see <a href="http://lists.apple.com/archives/Darwin-dev/2006/Apr/msg00109.html" rel="nofollow">Launchd and domain sockets</a>)</p>
<p>Also watch out for launchd editor if you use unix domain sockets, it&#8217;ll corrupt your plist file.  My <a href="http://www.codepoetry.net/fourm/software/launchd_editor/unix_sockets_get_mangled" rel="nofollow">bug report</a> is still sitting there.  I&#8217;ve since abandoned launchd and launchd editor for what I was originally intending to use it.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.226 seconds -->
