<?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: Golf with an elf</title>
	<atom:link href="http://www.kuliniewicz.org/blog/archives/2008/03/17/golf-with-an-elf/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kuliniewicz.org/blog/archives/2008/03/17/golf-with-an-elf/</link>
	<description>After all, it could only cost you your life, and you got that for free.</description>
	<pubDate>Sun, 12 Oct 2008 18:34:08 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
		<item>
		<title>By: fluffy</title>
		<link>http://www.kuliniewicz.org/blog/archives/2008/03/17/golf-with-an-elf/#comment-1804</link>
		<dc:creator>fluffy</dc:creator>
		<pubDate>Fri, 21 Mar 2008 04:18:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.kuliniewicz.org/blog/archives/2008/03/17/golf-with-an-elf/#comment-1804</guid>
		<description>Which means it's relying on behavior of libc and the shell, not of the kernel.  So that gets into philosophical territory as to whether that could really be considered a valid program.</description>
		<content:encoded><![CDATA[<p>Which means it&#8217;s relying on behavior of libc and the shell, not of the kernel.  So that gets into philosophical territory as to whether that could really be considered a valid program.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul Kuliniewicz</title>
		<link>http://www.kuliniewicz.org/blog/archives/2008/03/17/golf-with-an-elf/#comment-1801</link>
		<dc:creator>Paul Kuliniewicz</dc:creator>
		<pubDate>Fri, 21 Mar 2008 02:29:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.kuliniewicz.org/blog/archives/2008/03/17/golf-with-an-elf/#comment-1801</guid>
		<description>Linux does the same thing: "Exec format error".  Changing the call from execl to execlp works, though.  Looking up the man page for exec reveals this paragraph about execlp and execvp:

&lt;blockquote&gt;
If  the  header  of  a  file  isn’t recognized (the attempted execve(2)
returned ENOEXEC), these functions will  execute  the  shell  (/bin/sh)
with  the  path  of  the  file as its first argument.  (If this attempt
fails, no further searching is done.)
&lt;/blockquote&gt;

And, lo and behold, strerror(ENOEXEC) returns "Exec format error".  So the empty-file-works-as-shell-script trick should work on any POSIX system.</description>
		<content:encoded><![CDATA[<p>Linux does the same thing: &#8220;Exec format error&#8221;.  Changing the call from execl to execlp works, though.  Looking up the man page for exec reveals this paragraph about execlp and execvp:</p>
<blockquote><p>
If  the  header  of  a  file  isn’t recognized (the attempted execve(2)<br />
returned ENOEXEC), these functions will  execute  the  shell  (/bin/sh)<br />
with  the  path  of  the  file as its first argument.  (If this attempt<br />
fails, no further searching is done.)
</p></blockquote>
<p>And, lo and behold, strerror(ENOEXEC) returns &#8220;Exec format error&#8221;.  So the empty-file-works-as-shell-script trick should work on any POSIX system.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fluffy</title>
		<link>http://www.kuliniewicz.org/blog/archives/2008/03/17/golf-with-an-elf/#comment-1799</link>
		<dc:creator>fluffy</dc:creator>
		<pubDate>Thu, 20 Mar 2008 06:25:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.kuliniewicz.org/blog/archives/2008/03/17/golf-with-an-elf/#comment-1799</guid>
		<description>The shell does not ignore the content of the shebang.  In fact there were some very well-known bugs with older version of tcsh where they would attempt to execute a bash script as tcsh instead under certain circumstances.

In order to isolate shell-specific behavior, try this code:

int main(int argc, char *argv[])
{
    execl(argv[1], argv[1], NULL);
    perror("execl");
    return 1;
}

and then run it with your zero-byte executable file, and see what happens. (I'm curious.  I don't have Linux handy right now, but on OSX it gives "exec format error."</description>
		<content:encoded><![CDATA[<p>The shell does not ignore the content of the shebang.  In fact there were some very well-known bugs with older version of tcsh where they would attempt to execute a bash script as tcsh instead under certain circumstances.</p>
<p>In order to isolate shell-specific behavior, try this code:</p>
<p>int main(int argc, char *argv[])<br />
{<br />
    execl(argv[1], argv[1], NULL);<br />
    perror(&#8221;execl&#8221;);<br />
    return 1;<br />
}</p>
<p>and then run it with your zero-byte executable file, and see what happens. (I&#8217;m curious.  I don&#8217;t have Linux handy right now, but on OSX it gives &#8220;exec format error.&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul Kuliniewicz</title>
		<link>http://www.kuliniewicz.org/blog/archives/2008/03/17/golf-with-an-elf/#comment-1798</link>
		<dc:creator>Paul Kuliniewicz</dc:creator>
		<pubDate>Wed, 19 Mar 2008 03:40:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.kuliniewicz.org/blog/archives/2008/03/17/golf-with-an-elf/#comment-1798</guid>
		<description>Ryan, that's a good question, and it's one I'll answer in a top-level post, since a good answer deserves a bit more room than I have in a comment.</description>
		<content:encoded><![CDATA[<p>Ryan, that&#8217;s a good question, and it&#8217;s one I&#8217;ll answer in a top-level post, since a good answer deserves a bit more room than I have in a comment.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan</title>
		<link>http://www.kuliniewicz.org/blog/archives/2008/03/17/golf-with-an-elf/#comment-1797</link>
		<dc:creator>Ryan</dc:creator>
		<pubDate>Wed, 19 Mar 2008 03:20:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.kuliniewicz.org/blog/archives/2008/03/17/golf-with-an-elf/#comment-1797</guid>
		<description>So if it does nothing, successfully, what is the point?  Is it part of a bigger program that does do something useful?  Or is it basically trying to reduce the code required to run a certain program [successfully], even if it does nothing useful?</description>
		<content:encoded><![CDATA[<p>So if it does nothing, successfully, what is the point?  Is it part of a bigger program that does do something useful?  Or is it basically trying to reduce the code required to run a certain program [successfully], even if it does nothing useful?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul Kuliniewicz</title>
		<link>http://www.kuliniewicz.org/blog/archives/2008/03/17/golf-with-an-elf/#comment-1796</link>
		<dc:creator>Paul Kuliniewicz</dc:creator>
		<pubDate>Tue, 18 Mar 2008 23:00:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.kuliniewicz.org/blog/archives/2008/03/17/golf-with-an-elf/#comment-1796</guid>
		<description>Ryan: The program, like /bin/true, does nothing, successfully.  Compare /bin/false, which does nothing, unsuccessfully.

fluffy: Portability goes out the window when playing golf.  Also, on Debian [ is in /usr/bin, not /bin.  Does POSIX specify where [ has to be?

Executing an empty file as a shell script would be a Linuxism if anything, since it's the kernel that decides what shell, if any, needs to be invoked.  I believe the shell itself ignores the content of the shebang line.

Running the empty script is noticably slower than /bin/true or a shell script with only "#!/bin/sh" in it, so the kernel must be doing a lot of extra work to handle the empty file case.  Maybe it's something to do with binfmt_misc.

Linux still supports a.out, at least as a module; my /boot/config has "CONFIG_BINFMT_AOUT=m".  Good luck finding an a.out to try it with, though.</description>
		<content:encoded><![CDATA[<p>Ryan: The program, like /bin/true, does nothing, successfully.  Compare /bin/false, which does nothing, unsuccessfully.</p>
<p>fluffy: Portability goes out the window when playing golf.  Also, on Debian [ is in /usr/bin, not /bin.  Does POSIX specify where [ has to be?</p>
<p>Executing an empty file as a shell script would be a Linuxism if anything, since it&#8217;s the kernel that decides what shell, if any, needs to be invoked.  I believe the shell itself ignores the content of the shebang line.</p>
<p>Running the empty script is noticably slower than /bin/true or a shell script with only &#8220;#!/bin/sh&#8221; in it, so the kernel must be doing a lot of extra work to handle the empty file case.  Maybe it&#8217;s something to do with binfmt_misc.</p>
<p>Linux still supports a.out, at least as a module; my /boot/config has &#8220;CONFIG_BINFMT_AOUT=m&#8221;.  Good luck finding an a.out to try it with, though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fluffy</title>
		<link>http://www.kuliniewicz.org/blog/archives/2008/03/17/golf-with-an-elf/#comment-1795</link>
		<dc:creator>fluffy</dc:creator>
		<pubDate>Tue, 18 Mar 2008 04:42:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.kuliniewicz.org/blog/archives/2008/03/17/golf-with-an-elf/#comment-1795</guid>
		<description>er, by non-executable I meant to say non-binary executable.</description>
		<content:encoded><![CDATA[<p>er, by non-executable I meant to say non-binary executable.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fluffy</title>
		<link>http://www.kuliniewicz.org/blog/archives/2008/03/17/golf-with-an-elf/#comment-1794</link>
		<dc:creator>fluffy</dc:creator>
		<pubDate>Tue, 18 Mar 2008 04:42:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.kuliniewicz.org/blog/archives/2008/03/17/golf-with-an-elf/#comment-1794</guid>
		<description>I thought POSIX mandated that non-executable files at least have a hashbang in them.  So if you want to be absolutely proper, the minimal file is:

#!/bin/[

which is 9 bytes. (counting the newline)

Basically, what you've made isn't a self-contained shell script but something that your shell is interpreting as a script anyway (which is probably a bashism, though I seem to recall that tcsh allows that too).

What's the minimal size for a.out format?  (does Linux even support a.out anymore?)</description>
		<content:encoded><![CDATA[<p>I thought POSIX mandated that non-executable files at least have a hashbang in them.  So if you want to be absolutely proper, the minimal file is:</p>
<p>#!/bin/[</p>
<p>which is 9 bytes. (counting the newline)</p>
<p>Basically, what you&#8217;ve made isn&#8217;t a self-contained shell script but something that your shell is interpreting as a script anyway (which is probably a bashism, though I seem to recall that tcsh allows that too).</p>
<p>What&#8217;s the minimal size for a.out format?  (does Linux even support a.out anymore?)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan</title>
		<link>http://www.kuliniewicz.org/blog/archives/2008/03/17/golf-with-an-elf/#comment-1793</link>
		<dc:creator>Ryan</dc:creator>
		<pubDate>Tue, 18 Mar 2008 04:34:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.kuliniewicz.org/blog/archives/2008/03/17/golf-with-an-elf/#comment-1793</guid>
		<description>For those of us following along at home...what is this?  What's being reduced to a fraction of its former self?

What does it do in a ton less lines of code?</description>
		<content:encoded><![CDATA[<p>For those of us following along at home&#8230;what is this?  What&#8217;s being reduced to a fraction of its former self?</p>
<p>What does it do in a ton less lines of code?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
