<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4189227340735914294</id><updated>2011-10-19T22:04:10.224-04:00</updated><category term='openbsd apue'/><category term='python'/><title type='text'>software panacea</title><subtitle type='html'>there are no silver  bullets</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://kernelsyscall.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4189227340735914294/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://kernelsyscall.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>mythical programmer</name><uri>http://www.blogger.com/profile/13048029500529995452</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>4</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4189227340735914294.post-7191271685229769001</id><published>2009-11-17T20:47:00.000-05:00</published><updated>2009-11-17T20:56:37.636-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python'/><title type='text'>Tracking down a fd leak</title><content type='html'>Once in a while, a system I worked on would generate a lot of these two errors at the same time.&lt;br /&gt;&lt;div style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;IOError: [Errno 24] Too many open files&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;can't create socket&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;I know, it's "everything is a file" in unix so that explains "can't create socket". &lt;br /&gt;&lt;br /&gt;I knew it was leaking file descriptors but I had to find the source.&amp;nbsp; The corporate environment once again poses additional challenges. Corporate Policy prevents me from poking around on production servers.&lt;br /&gt;&lt;br /&gt;Thankfully I have an awesome XML-RPC console built-in my application. It runs regular python code within the server process. The application and it's designers deserve far more credit than I gave them in a previous post. This feature is a god send.&lt;br /&gt;&lt;br /&gt;&lt;div style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;gt;&amp;gt;&amp;gt; import os&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;gt;&amp;gt;&amp;gt; os.listdir('/proc/%s/fd' % os.getpid())&lt;br /&gt;&lt;/div&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;['0', '1', '2', '3', '4', '5', ... '889']&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Uh oh! This isn't good. What are these files?&lt;br /&gt;&lt;br /&gt;&lt;div style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;gt;&amp;gt;&amp;gt; data = os.fdopen(889).read()&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;gt;&amp;gt;&amp;gt; send_mail('mycorporateemail@email.com', 'Your file', 'Empty body', attachments={'data.bin': data})&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;After a few misguided attempts I open this file as a with Microsoft Word. It is an attachment an agent made when submitting a new client.&lt;br /&gt;&lt;br /&gt;I quickly need to understand how attachments are generated in our framework. It was written with layers of WSGI which is a good thing because WSGI is simple to understand.&lt;br /&gt;&lt;br /&gt;The application uses the standard python module cgi.FieldStorage to handle form attachments. The class documentation reads:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;i&gt;This version opens a temporary file for reading and writing,&lt;/i&gt;&lt;br /&gt;&lt;i&gt;and immediately deletes (unlinks) it.  The trick (on Unix!) is&lt;/i&gt;&lt;br /&gt;&lt;i&gt;that the file can still be used, but it can't be opened by&lt;/i&gt;&lt;br /&gt;&lt;i&gt;another process, and it will automatically be deleted when it&lt;/i&gt;&lt;br /&gt;&lt;i&gt;is closed or when the current process terminates.&lt;/i&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;Closing the "file" contained in cgi.FieldStorage, does not release the file descriptor as stated. I have not determined if this is a bug in python or my application. However, I patched my application by adding a __del__ method to our request object. The object holds a reference to the file, and my __del__ will os.close the file's fd number. This is the only time I've ever had to implement __del__. I was thankful that the request object was not involved in a circular reference leak.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4189227340735914294-7191271685229769001?l=kernelsyscall.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kernelsyscall.blogspot.com/feeds/7191271685229769001/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4189227340735914294&amp;postID=7191271685229769001' title='45 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4189227340735914294/posts/default/7191271685229769001'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4189227340735914294/posts/default/7191271685229769001'/><link rel='alternate' type='text/html' href='http://kernelsyscall.blogspot.com/2009/11/tracking-down-fd-leak.html' title='Tracking down a fd leak'/><author><name>mythical programmer</name><uri>http://www.blogger.com/profile/13048029500529995452</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>45</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4189227340735914294.post-6866250431534248266</id><published>2009-11-14T10:11:00.000-05:00</published><updated>2009-11-14T10:11:38.123-05:00</updated><title type='text'>tomato router firmware is awesome</title><content type='html'>I've tried a few different firmwares for my linksys wrt54g router and I finally settled on the &lt;a href="http://www.polarcloud.com/tomato"&gt;tomato firmware&lt;/a&gt;. It's far better than others I've tried. Here's what sets it apart:&lt;br /&gt;&lt;br /&gt;* The system is responsive and fast&lt;br /&gt;* The web interface is well thought out and designed&lt;br /&gt;* The setup and configuration processes work well and are full-featured&lt;br /&gt;* It has nice graphs and reports about bandwidth usage built-in&lt;br /&gt;&lt;br /&gt;I highly recommend it.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4189227340735914294-6866250431534248266?l=kernelsyscall.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kernelsyscall.blogspot.com/feeds/6866250431534248266/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4189227340735914294&amp;postID=6866250431534248266' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4189227340735914294/posts/default/6866250431534248266'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4189227340735914294/posts/default/6866250431534248266'/><link rel='alternate' type='text/html' href='http://kernelsyscall.blogspot.com/2009/11/tomato-router-firmware-is-awesome.html' title='tomato router firmware is awesome'/><author><name>mythical programmer</name><uri>http://www.blogger.com/profile/13048029500529995452</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4189227340735914294.post-369967286545363268</id><published>2007-08-01T13:29:00.000-04:00</published><updated>2007-08-01T13:31:38.920-04:00</updated><title type='text'>search and replace on many files in vim</title><content type='html'>I'm posting this so I can catalog this tip for my own future reference,&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;blockquote&gt;&lt;span style="font-family:courier new;"&gt;argdo! %s/&lt;label&gt;{%= \(.*\)\.label&lt;br /&gt;%}&lt;\/label&gt;/{% label \1 %}/ge update&lt;/span&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4189227340735914294-369967286545363268?l=kernelsyscall.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kernelsyscall.blogspot.com/feeds/369967286545363268/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4189227340735914294&amp;postID=369967286545363268' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4189227340735914294/posts/default/369967286545363268'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4189227340735914294/posts/default/369967286545363268'/><link rel='alternate' type='text/html' href='http://kernelsyscall.blogspot.com/2007/08/search-and-replace-on-many-files-in-vim.html' title='search and replace on many files in vim'/><author><name>mythical programmer</name><uri>http://www.blogger.com/profile/13048029500529995452</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4189227340735914294.post-6927274888551966700</id><published>2006-12-19T19:43:00.000-05:00</published><updated>2009-02-24T18:40:32.462-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='openbsd apue'/><title type='text'>Compiling APUE source on OpenBSD</title><content type='html'>I got the books source code from http://www.apuebook.com/ and tried to compile it under OpenBSD.&lt;br /&gt;&lt;br /&gt;The first thing I tried was make the main Makefile include 'freebsd.mk', but some files still wouldn't compile.&lt;br /&gt;&lt;br /&gt;As a result, I removed socket/recvfd2.c and socket/sendfd2.c from the build because OpenBSD does not support SO_PEERCRED. It provides getpeereid(2), which I will look up later.&lt;br /&gt;&lt;br /&gt;Next, OpenBSD doesn't provide the POSIX.2001 pseudo-terminal functions grantpt(), ptyname(), posix_openpt(), unlockpt... a bit of googling brought up this short thread:&lt;br /&gt;http://marc.theaimsgroup.com/?l=netbsd-tech-kern&amp;m=108534411826666&amp;amp;w=2&lt;br /&gt;&lt;br /&gt;After reading it, I gather that not providing those functions is a good thing: one less suid binary in the system. Better yet, the same functionality it still provided by OpenBSD, Quoting from same post:&lt;br /&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;pre&gt;&lt;blockquote&gt;OpenBSD implemented a different (better) way of doing this, by adding&lt;br /&gt;/dev/ptm, and getting the master, slave fd's and the master and slave&lt;br /&gt;names through an ioctl(3), doing the chown/chmod's in the process.&lt;br /&gt;&lt;br /&gt;The posix way, requires a userland setuid program ``pt_chown'' to do&lt;br /&gt;the nasty chown job, which is called from grantpt(3).&lt;/blockquote&gt;&lt;/pre&gt;&lt;/pre&gt; &lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4189227340735914294-6927274888551966700?l=kernelsyscall.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kernelsyscall.blogspot.com/feeds/6927274888551966700/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4189227340735914294&amp;postID=6927274888551966700' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4189227340735914294/posts/default/6927274888551966700'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4189227340735914294/posts/default/6927274888551966700'/><link rel='alternate' type='text/html' href='http://kernelsyscall.blogspot.com/2006/12/compiling-apue-source-on-openbsd.html' title='Compiling APUE source on OpenBSD'/><author><name>mythical programmer</name><uri>http://www.blogger.com/profile/13048029500529995452</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
