<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: CoreGraphics Log Jam</title>
	<atom:link href="http://www.red-sweater.com/blog/129/coregraphics-log-jam/feed" rel="self" type="application/rss+xml" />
	<link>http://www.red-sweater.com/blog/129/coregraphics-log-jam</link>
	<description>Mac &#38; Technology Writings by Daniel Jalkut</description>
	<lastBuildDate>Wed, 17 Mar 2010 22:33:24 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Daniel Jalkut</title>
		<link>http://www.red-sweater.com/blog/129/coregraphics-log-jam/comment-page-1#comment-4047</link>
		<dc:creator>Daniel Jalkut</dc:creator>
		<pubDate>Sat, 06 May 2006 21:08:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.red-sweater.com/blog/129/coregraphics-log-jam#comment-4047</guid>
		<description>Thanks, Don. I included a pointer to this blog entry in my bug report, so hopefully they&#039;ll check it out. It sounds like the best thing to do would be for Xcode to do whatever it can to convince the apps it runs that there is indeed a &quot;controlling terminal.&quot; But who knows, maybe this has other unwanted side-effects.</description>
		<content:encoded><![CDATA[<p>Thanks, Don. I included a pointer to this blog entry in my bug report, so hopefully they&#8217;ll check it out. It sounds like the best thing to do would be for Xcode to do whatever it can to convince the apps it runs that there is indeed a &#8220;controlling terminal.&#8221; But who knows, maybe this has other unwanted side-effects.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ++Don</title>
		<link>http://www.red-sweater.com/blog/129/coregraphics-log-jam/comment-page-1#comment-4046</link>
		<dc:creator>++Don</dc:creator>
		<pubDate>Sat, 06 May 2006 21:03:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.red-sweater.com/blog/129/coregraphics-log-jam#comment-4046</guid>
		<description>&gt; In fact it is just as simple as I described in the entry: hasTerminal checks only for “/dev/tty”.
&gt; It doesn’t check for file descriptors or anything. Just calls open(”/dev/tty”, 2).

Ah, I read over that bit. My bad. OK, /dev/tty won&#039;t work if the process has no controlling terminal, so the open() will fail. As I said, a process inherits its controlling terminal (or lack thereof), from its parent, and simply opening a terminal device (as Xcode does when it sends the debugged process&#039; output to a pseudo-terminal), won&#039;t automatically make it a controlling terminal. Xcode could execute the necessary ioctl() to make it a controlling terminal. I don&#039;t know if its failure to do this is simply an oversight on Apple&#039;s part or a deliberate decision to avoid some implications of having a controlling terminal that I don&#039;t know about. Controlling terminals generate job control signals (SIGTSTP, SIGTTIN, SIGTTOU), and maybe Apple has some reason for wanting to avoid those.

If Xcode is directing stdout to a pty, then you should be able to insert an ioctl(1. TIOCSCTTY, 0) call in your code in order to make it a controlling terminal. If the process already has a controlling terminal, or if stdout is not a tty device, then this call will fail harmlessly.</description>
		<content:encoded><![CDATA[<p>&gt; In fact it is just as simple as I described in the entry: hasTerminal checks only for “/dev/tty”.<br />
&gt; It doesn’t check for file descriptors or anything. Just calls open(”/dev/tty”, 2).</p>
<p>Ah, I read over that bit. My bad. OK, /dev/tty won&#8217;t work if the process has no controlling terminal, so the open() will fail. As I said, a process inherits its controlling terminal (or lack thereof), from its parent, and simply opening a terminal device (as Xcode does when it sends the debugged process&#8217; output to a pseudo-terminal), won&#8217;t automatically make it a controlling terminal. Xcode could execute the necessary ioctl() to make it a controlling terminal. I don&#8217;t know if its failure to do this is simply an oversight on Apple&#8217;s part or a deliberate decision to avoid some implications of having a controlling terminal that I don&#8217;t know about. Controlling terminals generate job control signals (SIGTSTP, SIGTTIN, SIGTTOU), and maybe Apple has some reason for wanting to avoid those.</p>
<p>If Xcode is directing stdout to a pty, then you should be able to insert an ioctl(1. TIOCSCTTY, 0) call in your code in order to make it a controlling terminal. If the process already has a controlling terminal, or if stdout is not a tty device, then this call will fail harmlessly.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sanjay Samani</title>
		<link>http://www.red-sweater.com/blog/129/coregraphics-log-jam/comment-page-1#comment-3998</link>
		<dc:creator>Sanjay Samani</dc:creator>
		<pubDate>Sat, 06 May 2006 06:58:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.red-sweater.com/blog/129/coregraphics-log-jam#comment-3998</guid>
		<description>The thing is that Java style Exceptions, NSException and @try/ @catch / @finally are relatively new in Objective-C / Cocoa (10.3) - even Wil Shipley didn&#039;t know about them (see comments in http://wilshipley.com/blog/2005/08/pimp-my-code-part-4-returning-late-to.html).  And unfortunately a lot of people leave adding Exception handling in their software until last because they try to code to handle all conditions.  Its hard to get into the habit when you&#039;re new to Cocoa programming cos the learning curve is so great anyway and once you&#039;re up the learning curve you&#039;re into bad habits. What&#039;s fascinating is that the CG guys actually have good error and exception handling - the only problem is that cos Exception handling isn&#039;t really ingrained in Cocoa programmers is it going to end up throwing a whole wobbly of exceptions that will never be handled?</description>
		<content:encoded><![CDATA[<p>The thing is that Java style Exceptions, NSException and @try/ @catch / @finally are relatively new in Objective-C / Cocoa (10.3) &#8211; even Wil Shipley didn&#8217;t know about them (see comments in <a href="http://wilshipley.com/blog/2005/08/pimp-my-code-part-4-returning-late-to.html)" rel="nofollow">http://wilshipley.com/blog/2005/08/pimp-my-code-part-4-returning-late-to.html)</a>.  And unfortunately a lot of people leave adding Exception handling in their software until last because they try to code to handle all conditions.  Its hard to get into the habit when you&#8217;re new to Cocoa programming cos the learning curve is so great anyway and once you&#8217;re up the learning curve you&#8217;re into bad habits. What&#8217;s fascinating is that the CG guys actually have good error and exception handling &#8211; the only problem is that cos Exception handling isn&#8217;t really ingrained in Cocoa programmers is it going to end up throwing a whole wobbly of exceptions that will never be handled?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Oldfield</title>
		<link>http://www.red-sweater.com/blog/129/coregraphics-log-jam/comment-page-1#comment-3984</link>
		<dc:creator>John Oldfield</dc:creator>
		<pubDate>Sat, 06 May 2006 02:25:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.red-sweater.com/blog/129/coregraphics-log-jam#comment-3984</guid>
		<description>&gt; All Jon had to do was test his app from the command-line...
   ...
&gt; But the “hasTerminal” function returns false when debugging from within Xcode.
  (and from ++Don)
&gt; A process inherits its controlling terminal from its parent...

So what happens if you launch Xcode from the terminal?</description>
		<content:encoded><![CDATA[<p>&gt; All Jon had to do was test his app from the command-line&#8230;<br />
   &#8230;<br />
&gt; But the “hasTerminal” function returns false when debugging from within Xcode.<br />
  (and from ++Don)<br />
&gt; A process inherits its controlling terminal from its parent&#8230;</p>
<p>So what happens if you launch Xcode from the terminal?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sam&#8217;s random musings &#187; CoreGraphics Log Jam</title>
		<link>http://www.red-sweater.com/blog/129/coregraphics-log-jam/comment-page-1#comment-3975</link>
		<dc:creator>Sam&#8217;s random musings &#187; CoreGraphics Log Jam</dc:creator>
		<pubDate>Fri, 05 May 2006 22:26:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.red-sweater.com/blog/129/coregraphics-log-jam#comment-3975</guid>
		<description>[...] CoreGraphics Log Jam: [...]</description>
		<content:encoded><![CDATA[<p>[...] CoreGraphics Log Jam: [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Jalkut</title>
		<link>http://www.red-sweater.com/blog/129/coregraphics-log-jam/comment-page-1#comment-3973</link>
		<dc:creator>Daniel Jalkut</dc:creator>
		<pubDate>Fri, 05 May 2006 21:12:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.red-sweater.com/blog/129/coregraphics-log-jam#comment-3973</guid>
		<description>Thanks Don for the analysis. From your comments:
&lt;blockquote&gt;Given that Xcode has the ability to send stdout to a pty but hasTerminal() doesn&#039;t seem to be picking up on that fact, I can think of two possibilities: 1) Xcode connects stdout to the pty but not stdin, and hasTerminal() only checks stdin; or 2) hasTerminal() checks for a controlling terminal. Feel free to continue your assembly traipsing to figure out which it is. :-)
&lt;/blockquote&gt;
In fact it is just as simple as I described in the entry: hasTerminal checks only for &quot;/dev/tty&quot;. It doesn&#039;t check for file descriptors or anything. Just calls open(&quot;/dev/tty&quot;, 2).</description>
		<content:encoded><![CDATA[<p>Thanks Don for the analysis. From your comments:</p>
<blockquote><p>Given that Xcode has the ability to send stdout to a pty but hasTerminal() doesn&#8217;t seem to be picking up on that fact, I can think of two possibilities: 1) Xcode connects stdout to the pty but not stdin, and hasTerminal() only checks stdin; or 2) hasTerminal() checks for a controlling terminal. Feel free to continue your assembly traipsing to figure out which it is. :-)
</p></blockquote>
<p>In fact it is just as simple as I described in the entry: hasTerminal checks only for &#8220;/dev/tty&#8221;. It doesn&#8217;t check for file descriptors or anything. Just calls open(&#8220;/dev/tty&#8221;, 2).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ++Don</title>
		<link>http://www.red-sweater.com/blog/129/coregraphics-log-jam/comment-page-1#comment-3972</link>
		<dc:creator>++Don</dc:creator>
		<pubDate>Fri, 05 May 2006 21:08:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.red-sweater.com/blog/129/coregraphics-log-jam#comment-3972</guid>
		<description>&gt; I don’t know enough about how “/dev/tty” gets hooked up to
&gt; the process’s pseudo ttys to know who is really at fault here.

It&#039;s been a while since I looked under the hood, but here goes...

/dev/tty is a pseudo-device that the kernel guarantees always refers to a process&#039;s controlling terminal, if it has one. A process inherits its controlling terminal from its parent, but can disassociate itself from its controlling terminal (in which case its children will also have no controlling terminal). As far as I can tell, GUI programs have no controlling terminal if they aren&#039;t run from the command line.  XCode can allocate and open a pty device (pseudo-terminal, see pty4. man page),  for a process it is debugging. However, just opening a tty device, pseudo or otherwise, does not automatically make that device a controlling terminal. It takes a specific ioctl() call to make it a controlling terminal, and thereby enabling /dev/tty for that process.

On the other hand, there is no requirement that a terminal be a *controlling* terminal. A controlling terminal is important for Unix-style job control (foreground and background processes, terminal signals, etc.), but not for plain old terminal I/O.  I don&#039;t know what hasTerminal() does under the hood, but the very similar C standard library function isatty() takes a file descriptor as an argument and tells you whether or not it refers to a terminal device, irrespective of whether or not it is the process&#039; controlling terminal. It does this by executing an ioctl() that only works for terminal devices (see the tty.4 man page for a list; isatty() uses a nondestructive call like TIOCGETA or TIOCGETD).

In either case, starting a process from the command line both will give it a controlling terminal and will have the stdin/out/err file descriptors open on that terminal (the latter assuming no I/O redirection is done). Given that Xcode has the ability to send stdout to a pty but hasTerminal() doesn&#039;t seem to be picking up on that fact, I can think of two possibilities: 1) Xcode connects stdout to the pty but not stdin, and hasTerminal() only checks stdin; or 2) hasTerminal() checks for a controlling terminal. Feel free to continue your assembly traipsing to figure out which it is. :-)</description>
		<content:encoded><![CDATA[<p>&gt; I don’t know enough about how “/dev/tty” gets hooked up to<br />
&gt; the process’s pseudo ttys to know who is really at fault here.</p>
<p>It&#8217;s been a while since I looked under the hood, but here goes&#8230;</p>
<p>/dev/tty is a pseudo-device that the kernel guarantees always refers to a process&#8217;s controlling terminal, if it has one. A process inherits its controlling terminal from its parent, but can disassociate itself from its controlling terminal (in which case its children will also have no controlling terminal). As far as I can tell, GUI programs have no controlling terminal if they aren&#8217;t run from the command line.  XCode can allocate and open a pty device (pseudo-terminal, see pty4. man page),  for a process it is debugging. However, just opening a tty device, pseudo or otherwise, does not automatically make that device a controlling terminal. It takes a specific ioctl() call to make it a controlling terminal, and thereby enabling /dev/tty for that process.</p>
<p>On the other hand, there is no requirement that a terminal be a *controlling* terminal. A controlling terminal is important for Unix-style job control (foreground and background processes, terminal signals, etc.), but not for plain old terminal I/O.  I don&#8217;t know what hasTerminal() does under the hood, but the very similar C standard library function isatty() takes a file descriptor as an argument and tells you whether or not it refers to a terminal device, irrespective of whether or not it is the process&#8217; controlling terminal. It does this by executing an ioctl() that only works for terminal devices (see the tty.4 man page for a list; isatty() uses a nondestructive call like TIOCGETA or TIOCGETD).</p>
<p>In either case, starting a process from the command line both will give it a controlling terminal and will have the stdin/out/err file descriptors open on that terminal (the latter assuming no I/O redirection is done). Given that Xcode has the ability to send stdout to a pty but hasTerminal() doesn&#8217;t seem to be picking up on that fact, I can think of two possibilities: 1) Xcode connects stdout to the pty but not stdin, and hasTerminal() only checks stdin; or 2) hasTerminal() checks for a controlling terminal. Feel free to continue your assembly traipsing to figure out which it is. :-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Jalkut</title>
		<link>http://www.red-sweater.com/blog/129/coregraphics-log-jam/comment-page-1#comment-3970</link>
		<dc:creator>Daniel Jalkut</dc:creator>
		<pubDate>Fri, 05 May 2006 19:13:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.red-sweater.com/blog/129/coregraphics-log-jam#comment-3970</guid>
		<description>Brian: Yeah, Kevin Ballard also wondered whether those might make any difference.  I tried them out and didn&#039;t see any change. I think the problem is that the &quot;Pseudo TTY&quot; choice is the closest to what we want, but even when that is selected, it&#039;s not sufficient to convince CoreGraphics that there is a tty.

I don&#039;t know enough about how &quot;/dev/tty&quot; gets hooked up to the process&#039;s pseudo ttys to know who is really at fault here.</description>
		<content:encoded><![CDATA[<p>Brian: Yeah, Kevin Ballard also wondered whether those might make any difference.  I tried them out and didn&#8217;t see any change. I think the problem is that the &#8220;Pseudo TTY&#8221; choice is the closest to what we want, but even when that is selected, it&#8217;s not sufficient to convince CoreGraphics that there is a tty.</p>
<p>I don&#8217;t know enough about how &#8220;/dev/tty&#8221; gets hooked up to the process&#8217;s pseudo ttys to know who is really at fault here.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian Webster</title>
		<link>http://www.red-sweater.com/blog/129/coregraphics-log-jam/comment-page-1#comment-3969</link>
		<dc:creator>Brian Webster</dc:creator>
		<pubDate>Fri, 05 May 2006 19:08:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.red-sweater.com/blog/129/coregraphics-log-jam#comment-3969</guid>
		<description>I haven&#039;t tried this, so I don&#039;t know if it would make a difference, but in Xcode, if you inspect the executable you&#039;re running, it gives you an option for where standard I/O should go.  The default is &quot;Pseudo terminal&quot;, but there&#039;s also an option for &quot;System console&quot;, which I assume would spit the output to console.log.  I&#039;m not sure if that would cause the CoreGraphics logging to get output, but it may be worth a try.  There&#039;s also a third option in the pop-up, &quot;Pipe&quot;.  Heck if I know what that does though. :-\</description>
		<content:encoded><![CDATA[<p>I haven&#8217;t tried this, so I don&#8217;t know if it would make a difference, but in Xcode, if you inspect the executable you&#8217;re running, it gives you an option for where standard I/O should go.  The default is &#8220;Pseudo terminal&#8221;, but there&#8217;s also an option for &#8220;System console&#8221;, which I assume would spit the output to console.log.  I&#8217;m not sure if that would cause the CoreGraphics logging to get output, but it may be worth a try.  There&#8217;s also a third option in the pop-up, &#8220;Pipe&#8221;.  Heck if I know what that does though. :-\</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Wight</title>
		<link>http://www.red-sweater.com/blog/129/coregraphics-log-jam/comment-page-1#comment-3956</link>
		<dc:creator>Jonathan Wight</dc:creator>
		<pubDate>Fri, 05 May 2006 15:25:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.red-sweater.com/blog/129/coregraphics-log-jam#comment-3956</guid>
		<description>Wow. Thanks for taking the time to write this up and even posting a radar bug.

As much as people love to bitch about old school Carbon programming, at least Carbon had the ever so useful OSErr (and later OSStatus) types to inform the programmer what went wrong with a OS function call. While the errors returned from old Carbon APIs were often cryptic, at least they would point you in the right direction. With the CGBitmapContextCreate problem I was making all sorts of wild guesses before I found the Q&amp;A article. Returning &#039;paramErr&#039; from the function (and returning the CGContextRef as a indirect parameter) would have saved me a little bit of time.</description>
		<content:encoded><![CDATA[<p>Wow. Thanks for taking the time to write this up and even posting a radar bug.</p>
<p>As much as people love to bitch about old school Carbon programming, at least Carbon had the ever so useful OSErr (and later OSStatus) types to inform the programmer what went wrong with a OS function call. While the errors returned from old Carbon APIs were often cryptic, at least they would point you in the right direction. With the CGBitmapContextCreate problem I was making all sorts of wild guesses before I found the Q&amp;A article. Returning &#8216;paramErr&#8217; from the function (and returning the CGContextRef as a indirect parameter) would have saved me a little bit of time.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
