<?xml version="1.0" encoding="utf-8" ?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Fun with ones and zeros - bugs</title>
<subtitle>Barry&#039;s notes on computer software and hardware</subtitle>
<link href="/blog/tags/bugs"></link>
<updated>2026-05-28T06:53:02-07:00</updated>
<id>urn:uuid:139ed827-923b-d5e7-502d-a8c4271f61d1</id>
<entry>
<title>Simple debugging output in C</title>
<link href="/blog/entries/simple-debugging-output-c"></link>
<id>urn:uuid:bf565953-5281-1ae6-365b-91c3ba4dce0a</id>
<updated>2011-04-03T18:35:29-07:00</updated>
<author><name>Barry Pederson</name>
<email>bp@barryp.org</email>
</author>
<content type="html">&lt;p&gt;I don&#039;t do a whole lot of C programming, but when I do it tends to be in difficult environments like Apache modules or Samba VFS modules, where you can&#039;t just do simple printfs to get some output from your program.&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;I&#039;ve come up with this small chunk of code I can plop in a C file to allow for optionally writing out useful information to a file somewhere on the disk.&lt;/p&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre&gt;&lt;span class=&quot;cp&quot;&gt;#ifdef DEBUG_FILENAME&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;    #include &amp;lt;stdarg.h&amp;gt;&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;    #include &amp;lt;stdio.h&amp;gt;&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;    #include &amp;lt;time.h&amp;gt;&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;    #define QUOTE(name) #name&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;    #define STR(macro) QUOTE(macro)&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;debug_log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;msg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;...)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;timestamp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// really only need 21 bytes here&lt;/span&gt;
        &lt;span class=&quot;kt&quot;&gt;time_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;now&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;kt&quot;&gt;va_list&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;kt&quot;&gt;FILE&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;now&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;time&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;strftime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;timestamp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;sizeof&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;timestamp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;%Y-%m-%d %H:%M:%S &amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;localtime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;now&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fopen&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;STR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;DEBUG_FILENAME&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;a&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;fputs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;timestamp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;va_start&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;msg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;vfprintf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;msg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;va_end&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;fputc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sc&quot;&gt;&amp;#39;\n&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;fclose&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;#else&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;    #define debug_log&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;#endif&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Within your program, you&#039;d just sprinkle in calls to &lt;code&gt;debug_log()&lt;/code&gt; with a format string and optional arguments, such as:&lt;/p&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;debug_log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;Currently, x=%d, y=%d&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The code can then be enabled and configured to output to &lt;code&gt;/tmp/foo.log&lt;/code&gt; (for example), by adding either&lt;/p&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre&gt;&lt;span class=&quot;cp&quot;&gt;#define DEBUG_FILENAME /tmp/foo.log&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;to the top of your source file, or even more slickly for some things, from the commandline with&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;cc -DDEBUG_FILENAME=/tmp/foo.log myprogram.c
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When the program is run, in your &lt;code&gt;/tmp/foo.log&lt;/code&gt; file you&#039;d find something like:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;2011-04-03 20:30:05 Currently, x=5, y=10
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you don&#039;t define &lt;code&gt;DEBUG_FILENAME&lt;/code&gt;, the code basically goes away, shouldn&#039;t take up any space in your binary at all.&lt;/p&gt;</content>
</entry>
<entry>
<title>RabbitMQ FreeBSD port </title>
<link href="/blog/entries/rabbitmq-freebsd-port"></link>
<id>urn:uuid:442f8d64-6fb8-4c8a-982f-361754691dce</id>
<updated>2008-09-01T17:29:06-07:00</updated>
<author><name>Barry Pederson</name>
<email>bp@barryp.org</email>
</author>
<content type="html">
&lt;p&gt;I was happy to see a FreeBSD port added for RabbitMQ, &lt;a href=&quot;http://www.freshports.org/net/rabbitmq&quot;&gt;net/rabbitmq&lt;/a&gt;,  although I found a couple problems with it:  it doesn&#039;t start automatically when your machine or jail boots, and when building the &lt;a href=&quot;http://hopper.squarespace.com/blog/2008/1/12/introducing-the-erlang-amqp-client.html&quot;&gt;rabbitmq-erlang-client&lt;/a&gt;, it errors out with:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;src/amqp_channel.erl:28: can&#039;t find include lib &amp;quot;rabbitmq_server/include/rabbit.hrl&amp;quot;
src/amqp_channel.erl:29: can&#039;t find include lib &amp;quot;rabbitmq_server/include/rabbit_framing.hrl&amp;quot;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I worked on the port a bit, and submitted a bug report and patch, &lt;a href=&quot;http://www.freebsd.org/cgi/query-pr.cgi?pr=127033&quot;&gt;ports/127033&lt;/a&gt;, that fixes these problems.
&lt;/p&gt;


</content>
</entry>
<entry>
<title>Full Text Searching with SQLite</title>
<link href="/blog/entries/full-text-searching-sqlite"></link>
<id>urn:uuid:40094c14-09b7-245c-cb8a-1289d723898e</id>
<updated>2006-12-03T16:20:17-08:00</updated>
<author><name>Barry Pederson</name>
<email>bp@barryp.org</email>
</author>
<content type="html">
&lt;p&gt;I&#039;d like to add a search feature back on this site.  Previously, I had an arrangement setup with PyBlosxom and ht://Dig, but now that it&#039;s Django-powered, I&#039;d like to do something that worked directly from the database instead of crawling the site like ht://Dig did.
&lt;/p&gt;
&lt;p&gt;After looking a while at various text search engines, I remembered seeing that &lt;a href=&quot;http://sqlite.org&quot;&gt;SQLite&lt;/a&gt; just added an &lt;a href=&quot;http://www.sqlite.org/cvstrac/wiki?p=FtsOne&quot;&gt;FTS1&lt;/a&gt; module in version 3.3.8, which sounds pretty easy to use.  Unfortunately the FreeBSD port &lt;code&gt;databases/sqlite3&lt;/code&gt; doesn&#039;t build with that feature.
&lt;/p&gt;
&lt;p&gt;After poking around a bit, I got it to build with FTS manually, and after a whole bunch more messing around, came up with a patch to add an option to the port to build sqlite3 with FTS.   The patch has been submitted to the FreeBSD bug tracker as &lt;a href=&quot;http://www.freebsd.org/cgi/query-pr.cgi?pr=ports/106281&quot;&gt;ports/106281&lt;/a&gt;.  Hopefully I have all my ducks lined up on that.
&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;Anyhow, in testing the FTS a bit, I found one thing they only hint at on the SQLite website.  There&#039;s a &lt;a href=&quot;http://www.tartarus.org/~martin/PorterStemmer/index.html&quot;&gt;Porter stemmer&lt;/a&gt; built in, even though the wiki says: &amp;quot;The module does not perform stemming of any sort.&amp;quot;  You activate it by adding &lt;code&gt;tokenize porter&lt;/code&gt; to the table declaration, for example (adapted from their example).
&lt;/p&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;CREATE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;VIRTUAL&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;TABLE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;recipe&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;USING&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;FTS1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ingredients&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tokenize&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;porter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;once you&#039;ve done that, and inserted some sample data:
&lt;/p&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;INSERT&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;INTO&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;recipe&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;VALUES&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;broccoli stew&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;broccoli peppers cheese tomatoes&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;the searches don&#039;t have to be quite as exact, for example:
&lt;/p&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;SELECT&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;FROM&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;recipe&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;WHERE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ingredients&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;MATCH&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;pepper&amp;#39;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;hits the &#039;broccoli stew&#039; recipe even through it has &#039;peppers&#039; and you searched for &#039;pepper&#039;.
&lt;/p&gt;
&lt;p&gt;Not sure why the Porter stemmer isn&#039;t documented in the SQLite wiki, perhaps it&#039;s still a work in progress or being changed for &lt;a href=&quot;http://www.sqlite.org/cvstrac/wiki?p=FtsTwo&quot;&gt;FTS2&lt;/a&gt;.
&lt;/p&gt;
</content>
</entry>
<entry>
<title>Django, SCGI, and AJP</title>
<link href="/blog/entries/django-scgi-and-ajp"></link>
<id>urn:uuid:e96047c1-a7d9-4f2a-c585-2270fe3d378d</id>
<updated>2006-11-20T18:33:44-08:00</updated>
<author><name>Barry Pederson</name>
<email>bp@barryp.org</email>
</author>
<content type="html">
&lt;p&gt;I&#039;ve been doing a lot with Django lately, and initially set it up using mod_python as the Django docs recommend, but still have some &lt;a href=&quot;/blog/entries/backend_protocols/&quot;&gt;reservations&lt;/a&gt; about that kind of arrangement.  I&#039;d like to go back to running it under SCGI or something similar.   &lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;Django has support builtin for FastCGI, but after trying to install mod_fastcgi in my Apache 2.0.x setup, decided it was a PITA.  mod_scgi is quite easy to setup  in Apache (even though the documentation is mostly nonexistent).  After finding where Django implements its FastCGI support using the &lt;a href=&quot;http://www.saddi.com/software/flup/&quot;&gt;flup&lt;/a&gt; module, I saw that with just a few minor tweaks Django could be made to support all of flup&#039;s protocols, including SCGI and AJP (Apache Jserv Protocol).
&lt;/p&gt;
&lt;p&gt;AJP turns out to be very interesting because it&#039;s included standard with Apache 2.2 as &lt;a href=&quot;http://httpd.apache.org/docs/2.2/mod/mod_proxy_ajp.html&quot;&gt;mod_proxy_ajp&lt;/a&gt;, and can work with &lt;a href=&quot;http://httpd.apache.org/docs/2.2/mod/mod_proxy_balancer.html&quot;&gt;mod_proxy_balancer&lt;/a&gt; - meaning you could setup multiple Django instances and have Apache share the load between them.
&lt;/p&gt;
&lt;p&gt;After testing a bit, I &lt;a href=&quot;http://code.djangoproject.com/ticket/3047&quot;&gt;submitted a patch&lt;/a&gt;, and will probably switch to running my Django sites as AJP servers managed by daemontools, and frontended by Apache 2.2
&lt;/p&gt;


</content>
</entry>
<entry>
<title>mod_python segfault fixed
</title>
<link href="/blog/entries/mod_python_segfault_3"></link>
<id>urn:uuid:fe7e44e0-0e7a-70a1-0acf-5c0dba30b15e</id>
<updated>2006-02-12T19:40:49-08:00</updated>
<author><name>Barry Pederson</name>
<email>bp@barryp.org</email>
</author>
<content type="html">
&lt;p&gt;
Just as a followup, it seems the segfault in mod_python on FreeBSD I &lt;a href=&quot;/blog/bugs/mod_python_segfault.html&quot;&gt;mentioned before&lt;/a&gt;
was &lt;a href=&quot;http://www.mail-archive.com/python-dev@httpd.apache.org/msg01062.html&quot;&gt;found&lt;/a&gt; and fixed.
Turns out to not be any kind of pointer/memory corruption like I thought, but rather a mishandled
return code from an APR (Apache Portable Runtime) function.  Oh well, I got to play with gdb, ddd, and valgrind a bit, which 
is good stuff to be familiar with.
&lt;/p&gt;



</content>
</entry>
</feed>