Cobwebs

So I haven’t kept up with this blog, but I haven’t been offline completely.

These days, most of my tinkering happens over at SDF, a public-access Unix system that’s pretty much one of the quieter, less commercialized corners of the web. I’ve also been toying with a static site blog generated using Jekyll there, but I don’t know if I care to continue the experiment in handcrafting. I have some basic web UI skills but designing my blog’s layout from scratch is not really my thing.

Published in: on July 22, 2010 at 8:42 am  Leave a Comment  

Madwifi is incompatible with the ath9k kernel driver

The ath9k driver was merged into Linux kernel 2.6.26. If you switch from the madwifi project to this new kernel driver, don’t forget to change your wireless driver settings from madwifi to wext too. If you’re using wpa_supplicant, for example, /etc/conf.d/net should now read:

wpa_supplicant_wlan0="-Dwext"

Otherwise, you will end up with the following errors:

Dec 2 01:39:00 gentoo [ 299.964138] wlan0: privacy configuration mismatch and mixed-cell disabled - disassociate
Dec 2 01:39:00 gentoo [ 299.965870] wlan0: mismatch in privacy configuration and mixed-cell disabled - abort association

Published in: on December 2, 2008 at 7:52 am  Leave a Comment  

Open Sound System (OSS) 4.1 in Gentoo Linux

NOTE: This was originally entitled “How to get a working microphone on a Toshiba Satellite M305D-S4829.” I have slightly updated the post title and introduction to better reflect the contents of the post.

In a nutshell, consider switching to OSS 4.1 if your sound card has a buggy ALSA driver. My laptop has:

00:14.2 Audio devide: ATI Technologies Inc SBx00 Azalia (Intel HDA)

With the ALSA drivers, I could hear sound but I couldn’t get internal or external microphones to work. After several hours of tinkering with ALSA, switching to OSS 4 was a relief! With minimal setup, it fixed my microphone woes and incidentally gave me better sound quality. I imagine (at least) all Intel HDA sound cards with Conexant Hermosa chipset would benefit from this approach.

Now, if you’ve poked into the sound card support in the kernel before, you might be wondering why a system marked with a huge DEPRECATED tag can have better support than the ALSA driver. The history of OSS is a bit convoluted (see here if you really want to know) but in short, the Linux kernel was frozen at OSS 3.8 when the OSS programmers decided to switch to a closed-source development model. Several years and a failed attempt at commercialization later, OSS is back under a BSD license, with greatly improved features and code.

Here’s how to install it on Gentoo Linux:

Kernel Configuration

You MUST disable kernel level sound card support, or else the OSS modules will have trouble loading.

Device Drivers
< > Sound card support

Rebuild your new kernel, reboot into it, then continue.

OSS Installation

If you’ve never set up an overlay before, follow this guide to install layman first.

Emerge mercurial:

$ sudo emerge -av mercurial

Grab the OSS overlay:

$ sudo layman -a oss-overlay

Emerge media-sound/oss or media-sound/oss-devel according to your preference. The stable version is 4.0 while the development version is 4.1.

By default, the development version will pull from the mercurial repository, but you can change that by adding this line to /etc/portage/package.mask:

=media-sound/oss-devel-9999

If you are running the stable portage branch, you will definitely have to play with your keywords in /etc/portage/package.keywords to get everything to emerge. I’m using unstable on my laptop so I’m not sure what exactly is masked.

Configuration

Once the packages have been emerged, configure OSS and run it:

$ sudo /usr/sbin/ossdetect
$ sudo /usr/sbin/soundon

At this point you can use osstest to verify that your speakers are working properly, ossrecord and ossplay to test the microphone input, and ossxmix to set the mixer levels. If all goes well, you can then add it to your default runlevel:

$ sudo rc-update add oss default

And that’s it. Rebuild your audio programs with the oss USE flag if they don’t have it, and enjoy your fully working sound card.

Published in: on November 30, 2008 at 10:41 am  Comments (3)  

VirtualBox Guest Additions, the Gentoo Way

It is possible to install VirtualBox guest additions through portage.

  1. Add the following lines to /etc/portage/package.keywords:

    >=dev-util/kbuild-0.1.4
    =app-emulation/virtualbox-guest-additions-2.0.2
    =x11-drivers/xf86-input-virtualbox-2.0.2
    =x11-drivers/xf86-video-virtualbox-2.0.2

  2. Emerge the kernel sources.

    $ sudo emerge gentoo-sources

  3. Configure and build the kernel. The exact steps are outside the scope of this post but you could follow the configuration settings here. (Installing the kernel created by this step is optional. You only have to execute make.)
  4. Emerge the guest additions.

    $ sudo emerge virtualbox-guest-additions xf86-input-virtualbox xf86-video-virtualbox

  5. Add virtualbox-guest-additions to the default runlevel.

    $ sudo rc-update add virtualbox-guest-additions default

  6. Reboot (or run /etc/init.d/virtualbox-guest-additions start) to get things working.
Published in: on October 29, 2008 at 3:18 am  Comments (1)  

Nifty PHP Functions of the Day

Published in: on October 22, 2008 at 8:57 am  Leave a Comment  

Adventures in PHP Language Parsing

It was supposed to be simple. I wanted to find a PHP parser to help me pinpoint unused XSL resources.

After eight hours of tinkering I have discovered that:

  • phpParseTree, which seemed to be the closest fit to what I want, is unfortunately buggy and unmaintained.  The Windows DLL kept complaining about unexpected T_DOC_COMMENT tokens; the Linux version I built from source experienced segmentation faults and memory corruption.  It seems to work well enough on simple PHP examples, but I need something more robust for our codebase.
  • YAXX, the bison extension which phpParseTree uses as a base, is also unmaintained.  I tried using it with both the latest and the recommended versions of bison, but I kept getting this error:

    zend_language_parser.y: fatal error: invalid token in skeleton: @output @output_parser_name@

  • PHPLint would be more useful if it didn’t have special formatting requirements.
  • PHPUnit has nifty support for various code metrics in later versions. We need to upgrade.
  • php-ast looked promising, but it was only available through its subversion repository.  Building that from source is more of a fuss than I can be bothered with at the moment.
  • There are many other alternatives for lexing and parsing out there, each with its own quirks and limitations.  I’ve checked out ANTLR, racc, ragel, Treetop, and even the classic lex and yacc combination.  I might go back to play with Treetop when I have the time.
  • Windows is a terrible platform for working with things that need to be built from source.  Then again, I already knew that.

Next candidate: phc, billed as an open source PHP compiler.  More as soon as I manage to get it working.

Published in: on October 22, 2008 at 7:21 am  Leave a Comment  

BASH Redirection Cheat Sheet

Operator Effect
> redirect standard output into a file, overwriting existing content
>> redirect standard output into a file, appending to existing content
< redirect contents of file into a command
&> redirect standard output and standard error into a file

Reference: Redirection and Process Substitution at SS64.com

Published in: on October 16, 2008 at 7:28 am  Leave a Comment  

Manually Installing Ruby in Windows Vista

Follow these steps to install versions not supported by the one-click installer.

  1. Download the version you want at the official Ruby website.  Make sure to select a Windows binary archive, not a source code archive.
  2. Extract the contents of the archive to the directory of your choice (e.g. c:\ruby).
  3. Add the Ruby binaries to your system path.  In Windows Vista, open the Start Menu, right-click Computer, then select Properties > Advanced System Settings > Environment Variables.  Append ;c:\ruby\bin to the PATH system variable. (If you extracted Ruby to a different location, modify your entry accordingly.)
  4. Click OK to save your settings.
  5. Get http://www.zlib.net/zlib123-dll.zip.  
    Extract zlib1.dll to your Ruby installation’s bin directory, then rename it to zlib.dll.
  6. Get version 1.2.0 of RubyGems (1.3.0 doesn’t work on Windows as of this writing).  Make sure to select one of the source archives, not the update gem.
  7. Extract the contents of the archive to a temporary directory, then run setup.rb.
  8. Go back to the Environment Variables tab in step 3.  Create a new system variable called RUBYOPT and set its value to –rubygems.
  9. Open a command prompt window and run gem install rake.

You should now have a working installation of your desired version of Ruby.

Published in: on October 2, 2008 at 9:11 am  Comments (3)  

Gentoo in Sun VirtualBox: Post-Installation

I installed Gentoo 2008.0 using the GUI installer without a hitch, but a few issues surfaced after reboot.

Networking is disabled

The appropriate network module is not loaded by default. To fix this for the current session, execute modprobe pcnet32. Add pcnet32 to /etc/modules.autoload.d/kernel-2.6 to load it automatically at startup.

This page outlines a different fix, which involves building a custom kernel. Unfortunately, doing this after the GUI installation causes the following problem.

Block device names change mysteriously

Even with the virtual SATA controller disabled, the kernel generated by genkernel named my block devices /dev/sda and /dev/sdb. I still don’t know why this happens, or why the custom kernel produced by the HOWTO above names them /dev/hda and /dev/hdb.

It was easy enough to deal with GRUB configuration, but the fstab entries posed a problem. One solution is to use labels instead of block device names in fstab to find the partitions.

First, apply a unique label to all partitions referenced in /etc/fstab:

  • For ext2 and ext3 partitions, use e2label <device> <label>.
  • For swap partitions, use mkswap -L <label> <device>. Turn off the partition first with swapoff <device> if necessary.

Use blkid to confirm that the labels are set correctly:

$ sudo /sbin/blkid
/dev/hda1: LABEL="boot" UUID="8a9ce81b-4fdd-4861-8d5c-215bbcabe47e" TYPE="ext2"
/dev/hda2: TYPE="swap" LABEL="swap" UUID="90a15ec6-1d7c-434a-a037-40c2408a5b65"
/dev/hda3: LABEL="root" UUID="29e918dd-1307-4758-9bdf-b3984dbafeb1" SEC_TYPE="ext2" TYPE="ext3"
/dev/hdb1: LABEL="home" UUID="cbbf5a7c-9626-4349-920a-d96e2ebf0e78" SEC_TYPE="ext2" TYPE="ext3"

Now edit /etc/fstab to use (for example) LABEL=root instead of /dev/hda3.

The system should be able to find the partitions no matter what the kernel decides to name them. I kept the generic kernel beside the custom kernel since I also hoped to build a stage4 for another PC.

Xorg doesn’t work

Installing the VirtualBox guest additions fixed this.

Published in: on July 10, 2008 at 5:02 pm  Comments (3)  

The Law of Demeter

  • You can play with yourself.
  • You can play with your own toys (but you can’t take them apart).
  • You can play with toys that were given to you.
  • And you can play with toys you’ve made yourself.

Fortunately, Ruby’s standard libraries include a library to quickly define delegations.

Published in: on June 14, 2007 at 7:01 am  Leave a Comment