Barnoid’s Knowledge Base

Bits of Collected Wisdom

April 21st, 2007

vmplayer on Gentoo Linux 2.6.20

If vmplayer fails to compile on your 2.6.20 kernel with the following error

Extracting the sources of the vmmon module.

Building the vmmon module.

Building for VMware Player 1.0.2 or 1.0.3 or VMware Workstation 5.5.2 or 5.5.3.
Using 2.6.x kernel build system.
make: Entering directory `/tmp/vmware-config1/vmmon-only'
make -C /lib/modules/2.6.20-gentoo-r6/build/include/.. SUBDIRS=$PWD SRCROOT=$PWD/. modules
make[1]: Entering directory `/usr/src/linux-2.6.20-gentoo-r6'
CC [M]  /tmp/vmware-config1/vmmon-only/linux/driver.o
In file included from /tmp/vmware-config1/vmmon-only/linux/driver.c:85:
/tmp/vmware-config1/vmmon-only/./include/compat_kernel.h:21: error: expected declaration specifiers or ‘...’ before ‘compat_exit’
/tmp/vmware-config1/vmmon-only/./include/compat_kernel.h:21: error: expected declaration specifiers or ‘...’ before ‘exit_code’
/tmp/vmware-config1/vmmon-only/./include/compat_kernel.h:21: warning: type defaults to ‘int’ in declaration of ‘_syscall1’
make[2]: *** [/tmp/vmware-config1/vmmon-only/linux/driver.o] Error 1
make[1]: *** [_module_/tmp/vmware-config1/vmmon-only] Error 2
make[1]: Leaving directory `/usr/src/linux-2.6.20-gentoo-r6'
make: *** [vmmon.ko] Error 2
make: Leaving directory `/tmp/vmware-config1/vmmon-only'
Unable to build the vmmon module.

change dir to /opt/vmware/player/lib/modules/source and untar vmmon.tar

# cd /opt/vmware/player/lib/modules/source/
# tar xvf vmmon.tar
vmmon-only/
vmmon-only/autoconf/
vmmon-only/autoconf/geninclude.c
vmmon-only/autoconf/epoll.c
...

next, edit the file vmmon-only/include/compat_kernel.h and add the following preprocessor statements (in bold font)

/*
* compat_exit() provides an access to the exit() function. It must
* be named compat_exit(), as exit() (with different signature) is
* provided by x86-64, arm and other (but not by i386).
*/
#define __NR_compat_exit __NR_exit
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
static inline _syscall1(int, compat_exit, int, exit_code);
#endif

save, exit the editor, rename the original tarball and create an updated vmmon.tar tarball:

# mv vmmon.tar vmmon.orig.tar
# tar cvf vmmon.tar vmmon-only

now run vmware-config.pl again

# /opt/vmware/player/bin/vmware-config.pl
...
The configuration of VMware Player 1.0.3 build-34682 for Linux for this running
kernel completed successfully.

You can now run VMware Player by invoking the following command:
"/opt/vmware/player/bin/vmplayer".

Enjoy,

--the VMware team
April 20th, 2007

Courier-IMAP: Updating/Creating an X.509 Certificate for TLS Connections

To update the expired X.509 certificate of your courier-IMAP TLS connection, perform the following steps as root

First, get the location and filename of the server’s certificate and delete/rename it:

# cd /etc/courier-imap
# grep TLS_CERTFILE= imapd-ssl
TLS_CERTFILE=/etc/courier-imap/imapd.pem
# mv imapd.pem imapd.pem.old

Next, verify that the information in imapd.cnf is correct

# cat imapd.cnf

RANDFILE = /usr/share/imapd.rand

[ req ]
default_bits = 2048
encrypt_key = yes
distinguished_name = req_dn
x509_extensions = cert_type
prompt = no

[ req_dn ]
C=US
ST=California
L=San Fransisco
O=ACRL Server
OU=Advanced Compiler Research Lab
CN=aces.example.com
emailAddress=postmaster@aces.example.com

[ cert_type ]
nsCertType = server

Finally, generate a new certificate by executing mkimapdcert and restart the IMAP server:

# mkimapdcert
Generating a 2048 bit RSA private key
...........................................+++
..............+++
writing new private key to '/etc/courier-imap/imapd.pem'
-----
512 semi-random bytes loaded
Generating DH parameters, 512 bit long safe prime, generator 2
This is going to take a long time
............+................+....................+.+...............++*++*++*++*++*++*
subject= /C=US/ST=California/L=San Francisco/O=ACRL Server/OU=Advanced Compiler Research
Lab/CN=aces.example.com/emailAddress=postmaster@aces.example.com
notBefore=Apr 20 00:41:18 2007 GMT
notAfter=Apr 19 00:41:18 2008 GMT
SHA1 Fingerprint=9EF:9A:9F:8D:D5:D6:57:AB:15:83:12:F8:83:F1:33:1D:7E:E8:2A:F0
# /etc/init.d/courier-imapd-ssl restart
* Stopping courier-imapd over SSL ...               [ ok ]
* Starting courier-imapd over SSL ...               [ ok ]

Done!

January 4th, 2007

Services stop logging after running logrotate

For services that log through syslog it won’t help to restart them after rotating their logs - as long as syslog is not restarted, nothing will be logged. If you don’t want to restart syslog several times while logrotate processes your configuration files in /etc/logrotate.d/, restart syslog after running logrotate in the cron script:

# /etc/cron.daily/logrotate.cron
#!/bin/sh
/usr/sbin/logrotate /etc/logrotate.conf
/etc/init.d/syslog-ng reload > /dev/null 2>&1 || true

As far as I can tell, logrotate does not have a global ‘postrotate’ option, so adding the line to the cron script seems to be the only solution.

January 1st, 2007

du: fts_read failed: Permission denied

du dies with an

du: fts_read failed: Permission denied

error when it encounters a directory with no eXecute bit set on a ReiserFS partition.

December 5th, 2006

Portage in a File

Here’s how to store portage in a file. Ext2/3 filesystems on a 2GB partition do not have enough inodes to store the , use reiserfs, for example.

/ # dd if=/dev/null of=/usr/portage.disk bs=1M count=0 seek=2048
/ # mkreiserfs -f /usr/portage.disk
/ # mkdir -p /usr/portage
/ # mount /usr/portage.disk /usr/portage -o loop,notail,noatime,nodev

The portage file is limited to 2GBs, hence we have to move the distfiles directory (default: /usr/portage/distfiles). This can be done either by editing make.conf and specify a new location or creating a distfiles directory somewhere else and have /usr/portage/distfiles link to it:

/ # mkdir -p /var/tmp/portage/distfiles
/ # cd /usr/portage
/usr/portage # ln -s /var/tmp/portage/distfiles

Finally, add a line to /etc/fstab to have the portage disk mounted at boot time:

/usr/portage.disk    /usr/portage    reiserfs    loop,notail,noatime,nodev,noexec 0 0

Done.

November 29th, 2006

WordPress Stopped Working?

If your WordPress blog has stopped working with an “It doesn’t look like you’ve installed WP yet. Try running install.php” error and you’re using mysql, make sure you didn’t accidentially upgrade from mysql 4.x to 5.x. Starting with version 5, mysql does no longer trim spaces from varbinary fields, however, WordPress expects that (incorrect) behavior.

Until the WordPress guys fix the table structure (i.e. use varchar instead of varbinary fields for string fields), you’ll have to go with mysql 4.x.

November 29th, 2006

Korean Text Not Displayed Correctly

If your Korean fonts look fugly, such as in this example here, make sure to remove the unicode USE flag from media-fonts/baekmuk-fonts

# echo "media-fonts/baekmuk-fonts -unicode" >> /etc/portage/package.use

and re-emerge them

# emerge -av baekmuk-fonts

Thanks to the guys at gentoo.or.kr for helping me with that one.

September 22nd, 2006

Linux: Burn Audio CDs

If your music is in mp3/ogg format, you’ll need to convert the files to PCM format first.

For mp3 files use one of the following two commands to convert song.mp3 to song.mp3.wav:

# lame --decode song.mp3 song.wav
# mpg123 -s song.mp3 | sox -t .raw -r 44100 -sw -c 2 - song.wav

And for ogg:

# ogg123 -d wav song.ogg -f song.wav

If necessary, convert your wav files to 16bit stereo, 44.1kHz with

# sox song.wav -r 44100 song.new.wav resample

Audio CDs can be written in TAO (track-at-once) or DAO/SAO (disk-at-once/session-at-once) mode. TAO mode introduces 2 second gaps between the tracks, whereas DAO/SAO does not.

To test-burn your wav files using DAO/SAO mode run (replace /dev/hdX with your CD-burner’s device node)

# cdrecord dev=/dev/hdX fs=4096k -v -useinfo -dao -pad -audio -dummy song1.wav song2.wav song3.wav [...]

If everything goes well, re-run the command withouth the -dummy argument to write your audio CD.

For TAO mode use:

# cdrecord dev=/dev/hdX -v -pad -audio -dummy song1.wav song2.wav song3.wav [...]

Remove the -dummy argument and re-run the command to burn the CD.

Links:

September 20th, 2006

On Pipes and Forks: Read (uncompressed) data directly from compressed files

Sometimes you’ve got data in a compressed form, but you need to read and process the (uncompressed) data in a program. If, as in my case, the uncompressed data (a program execution trace) is around 8 GB, and the compressed trace only 400MB big, uncompressing that data to disk, reading it and, after processing, deleting it is a big hassle.

It would be nice to directly uncompress and read the data from within the program…and luckly this is actually very simple:

Let’s say, we have a compressed file, trace.dat.gz, then we need to read from.

The code to read the decompressed data goes something like this:

FILE *trace = fopen(filename, "r");

while ((res = fscanf(trace, "%s "lx %lx", &status, &adr, &data)) == 3) {
    /* process data */
}

fclose(trace);

The trick to directly read from the compressed file is to execute a process that decompresses the data and directly feeds it into our program. That’s what pipes & fork are for:

int pfd[2];
FILE *trace = NULL;
if (pipe(pfd) != 0) return false;
pid_t cpid = fork();
if (cpid == 0) {
    // child process: redirect pipe to stdout & start the decompressor
    close(pfd[0]); dup2(pfd[1], 1); close(pfd[1]);
    excelp("gunzip", "gunzip", "-c", filename, NULL);
    exit(0);
} else {
    // parent: read from the pipe
    close(pfd[1]);
    trace = fdopen(pfd[0], "r");
}

while ((res = fscanf(trace, "%s "lx %lx", &status, &adr, &data)) == 3) {
    /* process data */
}

fclose(trace);
close(pfd[0]);

That’s it! Our program now automatically runs “gunzip” on the compressed data before piping it into our program.

September 20th, 2006

GCC: Compilation of 4.1.1 fails with HARDENED 3.4.6

ok, so you finally do the GCC 4.1.1 update that is basically forced upon us and end up with:

# emerge -uv gcc
/var/tmp/portage/gcc-4.1.1/work/build/i686-pc-linux-gnu/libstdc++-v3/include/limits:990: error: stray '\226' in program
/var/tmp/portage/gcc-4.1.1/work/build/i686-pc-linux-gnu/libstdc++-v3/include/limits:1047: error: stray '\374' in program
/var/tmp/portage/gcc-4.1.1/work/build/i686-pc-linux-gnu/libstdc++-v3/include/limits:1104: error: stray '\226' in program
...
!!! ERROR: sys-devel/gcc-4.1.1 failed.
Call stack:
ebuild.sh, line 1546:   Called dyn_compile
ebuild.sh, line 937:   Called src_compile
ebuild.sh, line 1255:   Called toolchain_src_compile
toolchain.eclass, line 24:   Called gcc_src_compile
toolchain.eclass, line 1534:   Called gcc_do_make
toolchain.eclass, line 1408:   Called die

!!! emake failed with profiledbootstrap
!!! If you need support, post the topmost build error, and the call stack if relevant.

It turns out that the “HARDENED” gcc 3.4.6 cannot compile gcc 4.1.1.

Solution: re-emerge the old gcc without the HARDENED flag

# emerge --oneshot =gcc-3.4.6-r1
# env-update && source /etc/profile

and then, finally

# emerge --auv gcc

Happy compiling!