<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Carpé Cocoa &#187; Linux</title>
	<atom:link href="http://carpe-cocoa.com/category/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://carpe-cocoa.com</link>
	<description>My journey into iPhone development</description>
	<lastBuildDate>Tue, 24 Nov 2009 21:03:31 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>WWDC Parties/Events &#8211; WWDC 2009</title>
		<link>http://carpe-cocoa.com/2009-05-21/wwdc-partiesevents-wwdc-2009/</link>
		<comments>http://carpe-cocoa.com/2009-05-21/wwdc-partiesevents-wwdc-2009/#comments</comments>
		<pubDate>Thu, 21 May 2009 21:04:22 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[Events]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[iPhone Development]]></category>

		<guid isPermaLink="false">http://carpe-cocoa.com/?p=169</guid>
		<description><![CDATA[June 4 Update: Added Loopt Mixer and Developer/Artist Meetup. Thanks LooptChris and Steve Weller!
There are a number of events going on around WWDC this year. Brandon Kwaselow has the most comprehensive list I&#8217;ve seen so far, it even includes Three Wolf Tuesday!
WWDC Parties/events &#8211; WWDC 2009 &#8211; Brandon &#8220;Quazie&#8221; Kwaselow&#8217;s Blog.
Google Calendar with the events: [...]]]></description>
			<content:encoded><![CDATA[<p><strong>June 4 Update:</strong> Added <a href="http://www.looptblog.com/2009/06/time-to-party-loopt-mixer-on-june-8.html" target="_blank">Loopt Mixer</a> and <a href="http://steveweller.com/articles/developer-artist-meetup-wwdc/" target="_blank">Developer/Artist Meetup</a>. Thanks <a href="http://www.looptblog.com/2009/06/time-to-party-loopt-mixer-on-june-8.html" target="_blank">LooptChris</a> and <a href="http://steveweller.com/" target="_blank">Steve Weller</a>!</p>
<p>There are a number of events going on around WWDC this year. Brandon Kwaselow has the most comprehensive list I&#8217;ve seen so far, it even includes Three Wolf Tuesday!</p>
<p><a href="http://blog.quazie.net/2009/05/wwdc-partiesevents/">WWDC Parties/events &#8211; WWDC 2009 &#8211; Brandon &#8220;Quazie&#8221; Kwaselow&#8217;s Blog</a>.</p>
<p><a href="http://www.google.com/calendar/embed?src=62mjk3b5jan9k5046cgdutgk30%40group.calendar.google.com">Google Calendar</a> with the events: <iframe src="https://www.google.com/calendar/embed?title=WWDC%20Parties%2FEvents%20-%20WWDC%202009&amp;showCalendars=0&amp;mode=AGENDA&amp;height=600&amp;wkst=1&amp;bgcolor=%23FFFFFF&amp;src=62mjk3b5jan9k5046cgdutgk30%40group.calendar.google.com&amp;color=%23A32929&amp;ctz=America%2FLos_Angeles" style=" border-width:0 " width="800" height="600" frameborder="0" scrolling="no"></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://carpe-cocoa.com/2009-05-21/wwdc-partiesevents-wwdc-2009/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Virtual Serial Ports Under VMware</title>
		<link>http://carpe-cocoa.com/2008-10-14/virtual-serial-ports-under-vmware/</link>
		<comments>http://carpe-cocoa.com/2008-10-14/virtual-serial-ports-under-vmware/#comments</comments>
		<pubDate>Tue, 14 Oct 2008 16:10:40 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.szczerba.net/2008-10-14/virtual-serial-ports-under-vmware/</guid>
		<description><![CDATA[VMware has an option to create virtual serial ports. The &#8220;Named Pipe&#8221; used under Linux is actually a UNIX domain socket, which is not easily accessed by most tools. My goal was to be able to connect to the virtual serial port using minicom the same way I would connect to a physical device with [...]]]></description>
			<content:encoded><![CDATA[<p>VMware has an option to <a href="http://www.vmware.com/support/ws45/doc/devices_serial_ws.html#1023803">create virtual serial ports</a>. The &#8220;Named Pipe&#8221; used under Linux is actually a UNIX domain socket, which is not easily accessed by most tools. My goal was to be able to connect to the virtual serial port using minicom the same way I would connect to a physical device with a real serial port.</p>
<p>The solution is to use <a href="http://www.dest-unreach.org/socat/">socat</a> along with <a href="http://www.kernel.org/doc/man-pages/online/pages/man4/pts.4.html">Unix98 pseudo-terminals</a> (/dev/pts/*).</p>
<p>I set up the Virtual Machine to &#8220;Use named pipe&#8221;, &#8220;This end is the client&#8221;, &#8220;The other end is an application&#8221;, and &#8220;Yield CPU on poll&#8221;. I put the pipe in /export/vmware/<em>DUT</em>.serial0.</p>
<p>At host startup I run the following socat command using start-stop-daemon:</p>
<p><code># start-stop-daemon --start --pidfile /var/run/socat.<em>DUT</em>.pid \<br />
&nbsp;&nbsp;&nbsp;&nbsp;--background --make-pidfile \<br />
&nbsp;&nbsp;&nbsp;&nbsp;--exec /usr/bin/socat -- \<br />
&nbsp;&nbsp;&nbsp;&nbsp;-ly -d -lpsocat:<em>DUT</em> \<br />
&nbsp;&nbsp;&nbsp;&nbsp;PTY,b115200,raw,link=/dev/tty<em>DUT</em>Serial0,group=uucp,mode=660 \<br />
&nbsp;&nbsp;&nbsp;&nbsp;UNIX-LISTEN:/export/vmware/<em>DUT</em>.serial0,fork,owner=frank,group=frank,mode=755</code></p>
<p><em>DUT</em> is a placeholder for the virtual machine&#8217;s name.</p>
<p>I can then make a minicom config using /dev/tty<em>DUT</em>Serial0 for the serial port and work as usual.</p>
<p>The above is actually wrapped up in some <a href="http://www.gentoo.org/">Gentoo</a> init scripts.<br />
<span id="more-47"></span></p>
<p>In <code>/etc/conf.d/socat</code> I have:</p>
<pre><code># socat configuration

# add dependencies to socat_use, socat_need, socat_before, and socat_after
socat_use="net"

# Common args used for all invocations. This is an Array.
#
# -ly : log to syslog
socat_args=( -ly -d )

# Configurations to auto-start. This is an Array.
socat_autostart=( WCBSerial0 )

# Lists of arguments for each configuration. These are arrays to better support
# embedded spaces in arguments.
socat_WCBSerial0=(
	"PTY,b115200,raw,link=/dev/ttyWCBSerial0,group=uucp,mode=660"
	"UNIX-LISTEN:/export/vmware/WCB.serial0,fork,owner=frank,group=frank,mode=755"
)

socat_WCBSerial1=(
	"PTY,b115200,raw,link=/dev/ttyWCBSerial1,group=uucp,mode=660"
	"UNIX-LISTEN:/var/run/vmware/WCB.serial1,fork,group=uucp,mode=755"
)
</code></pre>
<p>and in /etc/init.d/socat I have:</p>
<pre><code>
#!/sbin/runscript
# Copyright 2008 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/sys-libs/gpm/files/gpm.rc6,v 1.12 2004/07/15 01:02:02 agriffis Exp $

#NB: Config is in /etc/conf.d/socat
autostart_count=${#socat_autostart[@]}
socat=${socat:-/usr/bin/socat}

depend() {
	local t a
	for t in $deptypes $ordtypes ; do
		a="socat_${t}"
		a="${!a}"

		[ -n "$a" ] &#038;&#038; $t $a
	done
}

checkconfig() {
	local i a n name

	for (( i=0; i< $autostart_count; i++ )) ; do
		name=${socat_autostart[$i]}
		a="socat_${name}[@]"
		a=( "${!a}" )
		n=${#a[@]}

		if [ $n -lt 2 ] ; then
			eerror "Too few args ($n) for socat.$name (${a[*]})"
			return 1
		fi
	done
}

start() {
	checkconfig || return 1

	local i a n name extra

	for (( i=0; i<$autostart_count; i++ )); do
		let n=i+1
		name=${socat_autostart[$i]}
		a="socat_${name}[@]"
		a=( "${!a}" )

		ebegin "Starting socat config $name ($n of $autostart_count)"
		#echo $socat "${socat_args[@]}" -lpsocat:$name "${a[@]}"
		start-stop-daemon --start --pidfile /var/run/socat.$name.pid \
			--background --make-pidfile \
			--exec $socat -- \
			"${socat_args[@]}" -lpsocat:$name "${a[@]}" \
			< /dev/null
		eend ${?}
	done
}

stop() {
	local i n name

	for (( i=0; i<$autostart_count; i++ )); do
		let n=i+1
		name=${socat_autostart[$i]}

		ebegin "Stopping socat config $name ($n of $autostart_count)"
		start-stop-daemon --stop --pidfile /var/run/socat.$name.pid \
			--exec $socat
		eend ${?}
	done
}
</code></code></pre>
]]></content:encoded>
			<wfw:commentRss>http://carpe-cocoa.com/2008-10-14/virtual-serial-ports-under-vmware/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Finding Average File Size with Perl</title>
		<link>http://carpe-cocoa.com/2008-10-09/finding-average-file-size-with-perl/</link>
		<comments>http://carpe-cocoa.com/2008-10-09/finding-average-file-size-with-perl/#comments</comments>
		<pubDate>Thu, 09 Oct 2008 20:22:47 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.szczerba.net/2008-10-09/finding-average-file-size-with-perl/</guid>
		<description><![CDATA[I was creating a new filesystem on a NetBSD box today, and wondered about the appropriate value for the &#8220;average file size&#8221; parameter. The first question I had was &#8220;what is the average filesize in my data set&#8221;, which I figured I could answer, since I had some representative data handy. I put together a [...]]]></description>
			<content:encoded><![CDATA[<p>I was creating a new filesystem on a NetBSD box today, and wondered about the appropriate value for the &#8220;average file size&#8221; parameter. The first question I had was &#8220;what is the average filesize in my data set&#8221;, which I figured I could answer, since I had some representative data handy. I put together a quick one-liner to answer this question:</p>
<p><code>find /export -type f -print | perl -ne 'chomp; $count++; $total += (stat())[7]; END { print "$count files $total bytes total ", $total/$count, " byte average\n"; }</code></p>
<p>After running this, I was surprised at just how large the &#8220;average&#8221; size was, which led me to wonder just <em>which</em> average they were looking for here: <a href="http://en.wikipedia.org/wiki/Arithmetic_mean">mean</a> or <a href="http://en.wikipedia.org/wiki/Median">median</a>? While I was at it, I decided to calculate the <a href="http://en.wikipedia.org/wiki/Mode_(statistics)">mode</a> as well.</p>
<p><span id="more-46"></span></p>
<p>The one-liner evolved to:</p>
<p><code>find /export -type f -print | perl -ne 'chomp; $count++; $size = (stat())[7]; push @sizes, $size; $total += $size; $sizes{int(($size+511)/512)}++; print "$count\r" if ($count % 2048 == 0); END { $median = (sort @sizes)[$#sizes / 2]; $mode = 512 * (sort { $sizes{$b} &lt;=&gt; $sizes{$a} } keys %sizes)[0]; print "$count files $total bytes total ", $total/$count, " byte mean $median byte median $mode byte mode\n"; } BEGIN { $| = 1; }'<br />
</code></p>
<p>We can make this a bit more legible:</p>
<pre><code>find /export -type f -print | perl -ne '\
      chomp; \
      $count++; \
      $size = (stat())[7]; \
      push @sizes, $size; \
      $total += $size; \
      $sizes{int(($size+511)/512)}++; \
      print &#34;$count\r&#34; if ($count % 2048 == 0); \
BEGIN { $| = 1; } \
END { $median = (sort @sizes)[$#sizes / 2]; \
      $mode = 512 * (sort { $sizes{$b} &lt;=&gt; $sizes{$a} } keys %sizes)[0]; \
      print &#34;$count files $total bytes total &#34;, $total/$count, \
            &#34; byte mean $median byte median $mode byte mode\n&#34;; }'</code></pre>
<p>Let&#8217;s take it line by line. First, the shell pipeline <code>find /export -type f -print | perl -ne &#39;<i>stuff</i>&#39;</code>  recursively descends into the /export directory and prints the names of all regular files found, one per line. This output is piped into Perl, which processes the commands in the <code>-e &#39;<i>stuff</i>&#39;</code> block once per line due to the <code>-n</code> flag.</p>
<p>The heavy lifting is done in the Perl program:</p>
<p><strong>Gathering the Information</strong></p>
<p><code>chomp;</code> strips the trailing newline from the input line.</p>
<p><code>$count++;</code> counts the number of lines.</p>
<p><code>$size = (stat())[7];</code> gets the size in bytes of the input file.</p>
<p><code>push @sizes, $size;</code> saves the size in a list of all file sizes seen.</p>
<p><code>$total += $size;</code> adds up the total number of bytes seen.</p>
<p><code>$sizes{int(($size+511)/512)}++;</code> converts the size in bytes into a size in 512-byte blocks, and counts the number of files with a given block count. This creates a histogram of file sizes using 512-byte bins.</p>
<p><strong>Showing Progress</strong></p>
<p><code>print &#34;$count\r&#34; if ($count % 2048 == 0);</code> prints a progress indication for every 512 files processed.</p>
<p><code>BEGIN { $| = 1; }</code> is a BEGIN block, which means it is executed once at the beginning of the program. It sets the perl built-in variable $| to a true value, so that output is displayed immediately. With out this, the progress indication would not print until it had been output hundreds of times.</p>
<p><strong>Calculating Results</strong></p>
<p>Results a reported in the <code>END {}</code> block, which, as you may guess, is executed once at the end of the program. It starts with a few calculations:</p>
<p><code>$median = (sort @sizes)[$#sizes / 2];</code> sorts the list of sizes seen (<code>sort @sizes</code>), the selects the middle item from the sorted list (<code>$#sizes</code> is the index of the last element in the list, we use half of that as the index to get the middle element).</p>
<p><code>$mode = 512 * (sort { $sizes{$b} &lt;=&gt; $sizes{$a} } keys %sizes)[0];</code> calculates the mode (the most frequently-occurring item). Working from the inside out, <code>keys %sizes</code> gets a list of the keys from the %sizes hash. Then <code>sort { $sizes{$b} &lt;=&gt; $sizes{$a} } keys %sizes</code> sorts those keys by hash value in descending order, so that the most-frequently occurring element comes first. The first element is accessed at index 0, then multiplied by 512 to convert back to bytes.</p>
<blockquote>
<p><strong>Sorting The Data:</strong> The sort is done by passing a custom comparison routine <code>{&nbsp;$sizes{$b}&nbsp;&lt;=&gt;&nbsp;$sizes{$a}&nbsp;}</code> to the built-in <code>sort</code> function.</p>
<p>Perl&#8217;s <code>sort</code> will call this routine repeatedly with pairs of list elements in <code>$a</code> and <code>$b</code>. The routine should return 0 if the elements are equal, less than 0 if <code>$a</code> should come first, or greater than 0 if <code>$b</code> should come first.</p>
<p>The default comparison is <code>$a&nbsp;&lt;=&gt;&nbsp;$b</code>, which is a lexical sort. Since out data is numeric, we could use the equivalent <code>$a&nbsp;&lt;=&gt;&nbsp;$b</code>, which in this case would sort the list in ascending order by size. Reversing the comparison to <code>$b&nbsp;&lt;=&gt;&nbsp;$a</code> sorts in descending order by size. Finally, using the hash values rather than the keys sorts by frequency of occurrence.</p>
</blockquote>
<p></p>
<p><strong>Output Results</strong></p>
<p>Now it&#8217;s a simple matter of displaying the results:</p>
<p><code>print &#34;$count files $total bytes total &#34;, $total/$count, &#34; byte mean $median byte median $mode byte mode\n&#34;; }'</code></p>
]]></content:encoded>
			<wfw:commentRss>http://carpe-cocoa.com/2008-10-09/finding-average-file-size-with-perl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VMWare network devices and udev</title>
		<link>http://carpe-cocoa.com/2007-09-16/vmware-network-devices-and-udev/</link>
		<comments>http://carpe-cocoa.com/2007-09-16/vmware-network-devices-and-udev/#comments</comments>
		<pubDate>Sun, 16 Sep 2007 22:41:52 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.szczerba.net/2007-09-16/vmware-network-devices-and-udev/</guid>
		<description><![CDATA[I&#8217;ve been struggling for a while trying to get udev to maintain device names for vmxnet devices when running in a virtual machine. Well, I finally figured it out. The 75-persistent-net-generator.rules script in Gentoo was making rules that looked like:
SUBSYSTEM=="net", DRIVERS=="?*", ATTRS{address}=="00:0c:29:0b:02:d2", NAME="eth0"
These seemed to be silently ignored.
After an emerge --sync; emerge -u world last [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been struggling for a while trying to get udev to maintain device names for vmxnet devices when running in a virtual machine. Well, I finally figured it out. The <code>75-persistent-net-generator.rules</code> script in Gentoo was making rules that looked like:</p>
<p><code>SUBSYSTEM=="net", DRIVERS=="?*", ATTRS{address}=="00:0c:29:0b:02:d2", NAME="eth0"</code></p>
<p>These seemed to be silently ignored.</p>
<p>After an <code>emerge --sync; emerge -u world</code> last night, the vmware devices started getting IDs following the highest-numbered eth device. These rules would be added to <code>70-persistent-net.rules</code>, and on the next boot the devices would move up even higher, causing all network device config settings to be ignored.</p>
<p>I noticed that the new rules added to <code>70-persistent-net.rules</code> were of the form:</p>
<p><code>SUBSYSTEM=="net", DRIVERS=="?*", ATTR{address}=="00:0c:29:0b:02:d2", NAME="eth0"</code></p>
<p>(ATTRS was replaced with ATTR), which just means the match is done on the specific node rather than checking all of the parents.</p>
<p>After a lot of painful attempts to fix this, I finally found the problem. Apparently the DRIVERS key is unset at this point for the vmxnet driver. I removed that test, so that I have:</p>
<p><code>SUBSYSTEM=="net", ATTR{address}=="00:0c:29:0b:02:d2", NAME="eth0"</code></p>
<p>which now works.</p>
<p>Phew!</p>
]]></content:encoded>
			<wfw:commentRss>http://carpe-cocoa.com/2007-09-16/vmware-network-devices-and-udev/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

