Tuesday, July 26, 2011

Singleton bash script

Sometimes it's important to make sure only one copy of a shell script runs at any given time. Here's an elegant way to find and kill any other processes running as the same name as your script:
kill $(pidof -x -o '%PPID' $0) >/dev/null 2>/dev/null

Monday, July 25, 2011

nVidia EVGA g210 card: HDMI audio and sync-to-vblank in lucid

To get the HDMI audio to work on this g210 video card in Ubuntu Lucid (10.04), I first had to add this PPA and install updated alsa modules:
add-apt-repository ppa:team-iquik/alsa
add-apt-repository ppa:ubuntu-audio-dev/ppa
apt-get update
apt-get upgrade
apt-get install linux-alsa-driver-modules-$(uname -r) --force-yes

Then I had to set the module options correctly for my card:
$ more /etc/modprobe.d/sound.conf 
options snd-hda-intel enable_msi=0 probe_mask=0xffff,0xfff2

Once I did all that, I saw a single HDMI audio output:
$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: SB [HDA ATI SB], device 0: VT1828S Analog [VT1828S Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: SB [HDA ATI SB], device 1: VT1828S Digital [VT1828S Digital]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: SB [HDA ATI SB], device 2: VT1828S HP [VT1828S HP]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: NVidia [HDA NVidia], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

And could test it:
speaker-test -c2 -twav -Dplughw:1,3

(Before I got the module options correct, I saw several HDMI audio outputs, and none of them would work.)

To get it to work with flash (for things like youtube), I had to create an /etc/asound.conf:
$ more /etc/asound.conf 
pcm.!default hdmi:NVidia
pcm:iec958 hdmi:NVidia

Then audio worked all the way. One annoyance is that the module hangs for ~5s when loading, so it increases my boot time.

Now that I could hear the youtube videos, I just had to get rid of the annoying tearing artifacts by telling the graphics to sync to the vertical blank interval. To do that, I enabled "Sync to VBlank" in "X Server XVideo Settings" and "OpenGL Settings", then installed compizconfig-settings-manager, ran "ccsm" and enabled it under General... General... Display Settings.

Saturday, July 16, 2011

Building gnome from git on Ubuntu Lucid

Lately I've been trying to build gedit from its source repository so that I can help improve it.

It's been hugely painful, I'm sad to say. Downloading from git and running autogen.sh, I got errors about my gnome libraries not being new enough. Fair enough, so I installed Ubuntu Natty on a spare hard disk. No luck, so I updated to the alpha of Ubuntu Oneiric. That actually worked OK, except that Oneiric is so alpha that it's very unstable.

Finally I asked on IRC, and the devs told me I needed to build with "jhbuild", the build manager for gnome. That failed on my Hardy machine, but that's no big deal since Hardy is pretty ancient now.

Lucid it is! I did a clean install on a separate hard disk, and started in with jhbuild. I used the sample.jhbuildrc file, pointing the install directories to my home directory instead of /opt. It chugged along for a while, checking out and building all of gedit's dependencies. Then it bombed while building gtk+/gdk with:
/usr/share/gir-1.0/GdkPixbuf-2.0.gir: Incompatible version 1.0 (supported: 1.2)
The folks at irc.gnome.org helped me trace the problem to jhbuild/config.py, which sets XDG_DATA_DIRS around line 368. Prepending /usr/share to XDG_DATA_DIRS means that the system data dirs take precedence, and thus the GdkPixbuf compiled by jhbuild doesn't get detected.

Commenting out the XDG_DATA_DIRS stuff and adding this to my .jhbuildrc solved the problem:
addpath('XDG_DATA_DIRS', os.path.join(prefix, 'share'))
addpath('XDG_DATA_DIRS', os.path.join(prefix, 'usr/share'))

Also, it looks to me like there's a bug in the XDG_CONFIG_DIRS around line 378, where it prepends /etc to XDG_DATA_DIRS instead of XDG_CONFIG_DIRS.

Apart from that, I've had to babysit jhbuild as it builds NetworkManager, libproxy and just about everything else in gnome, occasionally bombing out until I track down the right -dev packages to install.

Friday, July 15, 2011

Oneiric Ocelot installer failure

Running the daily desktop build of the not-yet-released Ubuntu Oneiric (11.10), I kept getting install failures. /var/log/syslog showed that the problem was in /usr/share/ubiquity/install.py line 372. It was failing because the unlink / readlink / symlink wasn't working on /var/run and /var/lock.

Editing it as root, I changed it to:
  print "Can't unlink " + targetpath

  linkto = os.readlink(sourcepath)
  os.symlink(linkto, targetpath)
  print "symlink " + sourcepath + linkto + targetpath

And then it seemed to work.

Wednesday, July 06, 2011

Native android C program using ndk (update for android-ndk-r5c-linux-x86)

Back in August 2010, I posted "Native android C program using ndk", wherein I described how to compile C programs as native Android binaries.

The paths changed a lot with android-ndk-r5c-linux-x86, so I updated agcc.pl and called it agcc2.pl.

Make sure you update the path to your NDK install in that script, but then you should be able to use it to compile the "hello, world" program as described in the original blog post.