20050623

More on Building Python for Solaris 10 on SPARC

Continuing the building Python saga.

Surprisingly, Python and g++ don't play well together on Solaris 10. For example, this simple file:

#include "Python.h"
#include
Will not compile with g++, spewing out errors like:
$ g++ -m64 -I/usr/local/64/include/python2.4 -c test.cc
In file included from /usr/local/64/include/python2.4/Python.h:8,
from test.cc:1:
/usr/local/64/include/python2.4/pyconfig.h:844:1: warning: "_XOPEN_SOURCE" redefined
:84:1: warning: this is the location of the previous definition
In file included from test.cc:2:
[...]../include/c++/3.4.4/cwchar:145: error: `::btowc' has not been declared
[...]../include/c++/3.4.4/cwchar:150: error: `::fwide' has not been declared
...

This is a result of g++ requiring _XOPEN_SOURCE to be 500 (bugzilla; it looks like this won't be fixed), whereas Python defines it to be 600. This is corrected in Python's configure script on Solaris 8 and 9, but not 10.

Unfortunately, Python's configure also defines _XOPEN_SOURCE_EXTENDED which Solaris 10's feature tests header (/usr/include/sys/feature_tests.h) uses to force the ABI version backwards. Anyway, apply the patches listed here (which should be in the next versions of Python) and re-configure, re-build and re-install Python and everything is happy again!

20050615

Building Python for Solaris 10 on SPARC

Building python seems to be harder than it ought to be, especially since despite using an autoconf-generated configure script, it is not consistently used.

I want both 32 and 64-bit builds of Python, I want them to co-exist happily in /usr/local and I want shared library versions. Is that too much to ask? Possibly.

Hopefully these notes will help someone else in the future.

Here's the configure command I had to use to get Python 2.4.1 to compile using Sun's Sun Studio 9 compilers:

$ bash ../Python-2.4.1/configure CCSHARED="-KPIC" \
LDSHARED="cc -xtarget=native -G" LDFLAGS="-xtarget=native" \
CC="cc" CPP="cc -xtarget=native -E" BASECFLAGS="-xtarget=native" \
OPT="-xO5" CFLAGS="-xtarget=native" CXX="CC -xtarget=native" \
--prefix=$HOME/python-32-2.4.1 --enable-shared --without-gcc \
--disable-ipv6
And that was just the 32-bit version.

  • I have to run configure from bash rather than the default shell since there's a reliance on test -e which doesn't exist in Solaris sh.
  • The CCSHARED is required to make it build with position-independent code, why configure didn't detect this I don't know.
  • There appears to be a bug in Sun Studio 9, requiring a plethora of -xc99=none flags to work around problems with configure and Solaris 10 headers, but using Sun Studio 10 fixes that.
  • Why BASECFLAGS? I don't know, it's undocumented but it seems required (it seems to be used by the module builder, surely this should be documented!).

Then it's the usual:

$ gmake -j 6
$ gmake test
$ gmake install
to build and install (getpwd fails the test for some reason).

To get a 64-bit version to build here's the configure command:

$ bash ../Python-2.4.1/configure CCSHARED="-KPIC" \
LDSHARED="cc -xtarget=native64 -G" LDFLAGS="-xtarget=native64" \
CC="cc" CPP="cc -xtarget=native64 -E" \
BASECFLAGS="-xtarget=native64" OPT="-xO5" \
CFLAGS="-xtarget=native64" CXX="CC -xtarget=native64" \
--prefix="$HOME/python-64-2.4.1/64" --enable-shared \
--without-gcc --disable-ipv6
Note the similarity with the previous 32-bit configure, except:
  • I've used a different prefix, so the 32-bit and 64-bit versions can be tested separately before being combined with stow.
  • In fact, the prefix is now completely independent of all 32-bit programs. Try as I might, several times, over several days, I simply could not make a multi-arch build that would live together happily (e.g., using the with-suffix=-64, libdir and includedir options, setting LIBDIR etc manually).
  • I don't use --exec-prefix since the Python Makefile has hard-coded expansions for some variables. For example the pyconfig.h header and the libpython2.4.so library are installed in precisely the wrong place, instead of paying attention to configure arguments of libdir and includedir. It does this because the Makefile.pre.in they have the following:
    LIBDIR=  $(exec_prefix)/lib
    MANDIR= @mandir@
    INCLUDEDIR= @includedir@
    CONFINCLUDEDIR= $(exec_prefix)/include
    SCRIPTDIR= $(prefix)/lib
    So you cannot override the locations of LIBDIR, CONFINCLUDEDIR, and SCRIPTDIR to be precisely where they should be.

There is also a bug in the build scripts, with an easy fix:

--- Lib/distutils/command/build_scripts.py~     2004-11-11 09:23:15.000000000 +1100
+++ Lib/distutils/command/build_scripts.py 2005-06-15 12:50:51.925373000 +1000
@@ -104,7 +104,7 @@
outf.write("#!%s%s\n" %
(os.path.join(
sysconfig.get_config_var("BINDIR"),
- "python" + sysconfig.get_config_var("EXE")),
+ "python" + str(sysconfig.get_config_var("EXE"))),
post_interp))
outf.writelines(f.readlines())
outf.close()
This is probably because the suffix -64 is interpereted as a number. This doesn't really matter to me anymore since I now install in a completely separate prefix which is independent of all 32-bit programs.

The build, test and install also required some rejigging, thanks to the hard-coded value of (undocumented) RUNSHARED (rather than being configurable).

$ gmake -j 6 RUNSHARED="LD_LIBRARY_PATH_64=`pwd`"
$ gmake RUNSHARED="LD_LIBRARY_PATH_64=`pwd`" test
$ gmake RUNSHARED="LD_LIBRARY_PATH_64=`pwd`" install
LD_LIBRARY_PATH_64 is the Solaris 64-bit linker library path.

I then create symlinks so the 64-bit binaries are available:

$ cd $HOME/python-64-2.4.1
$ mkdir bin
$ cd bin
$ ln -s ../64/bin/python python-64
$ ln -s ../64/bin/python2.4 python2.4-64

Both 32 and 64-bit packages are stow-ed into /usr/local.

Since the 64-bit package puts the shared libraries in a new directory we have to add this directory to the runtime linking path:

# crle -64 -u -l /usr/local/64/lib

20050609

Permission weirdness in Solaris 10

I recently upgraded our two Sun machines from Solaris 9 to Solaris 10. That is a story in itself, which I probably won't bother to tell, but one of the machines upgraded fine using lu(1M) while the other had no end of problems, and I finally upgraded it by doing a full install into a new partition and copying across the various changes we had made (e.g., NIS+ user database, NFS exports, sendmail, NTP, backups, cron, mailman, etc etc).

Anyway, it seems pretty happy now, which is good.

I was doing some testing, and I had the following behaviour:

$ cd /opt/tmp
$ mkdir test
$ rmdir test
$ mkdir test
$ rm -r test
rm: cannot determine if this is an ancestor of the current working directory
tmp
$
That is, I could remove a directory using rmdir but not using rm -r (this was as an unprivileged user).

I did a truss(1) and got the following:

...
lstat64("tmp", 0xFFBFF6C8) = 0
resolvepath("tmp", "tmp", 1024) = 3
getcwd("/opt/tmp", 1024) = 0
open64(".", O_RDONLY) = 3
stat64(".", 0xFFBFF1D0) = 0
chdir("..") = 0
lstat64(".", 0xFFBFF1D0) = 0
chdir("..") Err#13 EACCES [file_dac_search]
...

After doing some googling I decided it was probably a mount-related problem: /opt is a separate partition to /. Perhaps the permissions of the /opt mount point in the / partition were bad.

The visible permissions of /opt were fine:

$ ls -ald /opt
drwxr-xr-x 24 root sys 512 May 6 16:05 /opt
$

But how to check and/or change the permissions of a mount point without unmounting the target? This would have meant stopping a whole heap of services that are running from /opt.

Jason suggested to use NFS to mount / by itself in some other directory and check it:

# share -F nfs -o rw=localhost,root=localhost /
# mount -F nfs -o vers=3 localhost:/ /mnt
The -o vers=3 is to get around some permission weirdness with NFS version 4 (the default version in Solaris 10). Perhaps I need to set NFS_MAPID_DOMAIN to something sensible (like anu.edu.au) in /etc/default/nfs.
# ls -ld /mnt/opt
drwx------ 2 root other 512 May 4 11:48 /mnt/opt
Sure enough, the permissions for /mnt/opt were wrong. To fix:
# chmod go+rx /mnt/opt
# umount /mnt
# unshare /

And everything is fine, I can now do rm -r within /opt.

How did this happen, and why didn't I notice it before? This was on the machine that was live-upgraded, so perhaps the permissions have been "wrong" for quite some time and it didn't matter in Solaris 9 (i.e., this permissions particular corner case wasn't checked by the kernel), or perhaps there is a bug in live-upgrade itself, causing mount points to get weird permissions.

20050401

Using a hash as your username

A basic spam filter

People I know have been starting to use "keyboard smashes" as usernames. You know, something like awe9pq325409awe@yahoo.com (I don't know if that's a real username, sorry to the owner if it is). This is in order to avoid spammers using a dictionary attack for sending email; in this case, the longer the better to avoid spam.

Which gave me an idea for reducing spam:

  • Create a "public" username, such as "G0D".
  • Run your "public" username through a hash (such as MD5 or SHA-1) to produce your "private" username. e.g., on Unix: echo -n "G0D" | sha1sum.
  • Create an account on somewhere such as mail.yahoo.com with the "private" username (unfortunately, GMail only accepts 30 character usernames, so it won't do for this).
  • Publish your public username to your friends, and how you generate the private one.
  • Never publish the private username.

Well, I created one on Yahoo mail, try emailing me at

echo `echo -n '/lib' | sha1sum | cut -d' ' -f1`@yahoo.com.au
.

Okay, so it's probably not original, and probably not that useful, but fun nonetheless. Not nearly as useful as Yahoo mail's AddressGuard (tm), which lets you create disposable email addresses.

[oops, updated to fix the email address, I'm using yahoo.com.au!]

Or alternatively try this address

echo `echo -n /lib | sha1sum | cut -c1-30`@gmail.com

20050329

The Algebraist, by Iain M. Banks

A standalone science fiction novel

In the past I've found Iain Banks' Culture novels a bit too weird for my taste, but The Algebraist (not a Culture novel) is excellent. It is set in a far future, and with plenty of history behind it to drive the plot (billions of years of it, in fact). Humans are one of the few races allowed to communicate with the extraordinarily long-lifed Dwellers (one of the "slow"). This is the story of a triangular clash between the Dwellers and several "quick" cultures, eager for technology that the Dwellers may or may not have.

Highly recommended.

Misspent Youth, by Peter F. Hamilton

A short (for PFH) novel of the near future.

Unlike his other sprawling novels, this is a fairly brief exploration of the effects regeneration (essentially, rebuilding the body) have on society and in particular the family of the first man to have the procedure. Also has some pointed comments about the future of England and Europe.

A good read.

Trip to Sydney to see the Lord of the Rings exhibition and the Lion King

Sat-Sun March 12-13 2005

A group of me and my friends went up to Sydney to see the Lord of the Rings exhibition at the Powerhouse Museum and the Lion King musical at the Capitol Theatre.

Firstly, the LotR exhibition: this was pretty cool, with lots of costumes, armour, jewellery, drawings, photos, and models that were used in the film trilogy. An astounding amount of work went into this stuff, amazing. Peter Jackson was there while we were there, which was pretty weird (I didn't see him, but a couple of my friends did; apparently he's lost a lot of weight).

While the exhibition was great, unfortunately, the merchandise was utterly crap. Really, really crap. Full of badly made models, cheap jigsaws and children's games. Not even a good t-shirt among it.

The Lion King show (based on the Disney film, and pretty much exactly the same plot line) was fantastic. In particular the costuming (including an excellent puppet cheetah) was great. A lot of fun, and highly recommended.

Unlike the LotR exhibition, the merchandise was pretty good too (unfortunately that's a Flash-only site, so I don't know what it has on it).

20050318

The Goodies, (Still A)Live on Stage

9:30 pm, Thursday March 10 2005

The Goodies came out to Australia for just a few shows, and I was lucky enough to go to the second Canberra show (the first was at 7 pm!).

The show consisted of the Goodies presenting a "question" that they had been asked, and them answering it in various funny ways.

This was a great fun show, the boys are looking much older but they sound just the same.

My smile muscles still hurt the next day, that's how funny it was!

The Trinity Trilogy, by Fiona McIntosh

Betrayal, Revenge, Destiny

Fiona McIntosh is an Australian author of fantasy, I hadn't read any of her books before.

This is reasonably well written fairly standard fantasy.

The plotting in the first book screams "first novel" to me: for example, there's not enough background, and the main character gets a new best friend in a day or two.

The other two books are much better, with some interesting plot twists.

Entertaining.

The Orphans Trilogy, by Sean Williams and Shane Dix

Echoes of Earth, Orphans of Earth, Heirs of Earth

Sean Williams and Shane Dix re-unite after their excellent Evergence trilogy.

Like the Evergence trilogy, this is set in a "real" future, where there are Powers (with a capital P) beyond the ken of man.

The series is full of flawed characters (seriously flawed in many cases, since they're essentially buggy programs) trying to overcame major adversity (ok, the destruction of Earth and almost all real humans is pretty adverse).

Highly recommended.

20050218

ANU Film Group 2005 Semester 1 Calendar

The ANU Film Group resumed showing films this week. Here is an ICal calendar of the program that I whipped up today.

V1280 photos

In reference to my earlier message regarding the death of a CPU board on our Sun V1280, here are some photos. (all photos here)

Here's the new board, sans RAM:

Here's the old board, with RAM:

Insertion of the new board, demonstrating the anti-gravity device:

A close-up of one of the CPUs in the dead board:

20050217

A board has died, long live the new board!

Our group has a Sun V1280 entry-level midrange server, for computational chemistry, software development and experiments.

It has 12 900 MHz UltraSPARC III Cu processors and 24 GB of RAM (3 CPU boards with 4 CPUs and 8 GB each). It's a pretty cool machine.

Last Friday night, it rebooted without warning (and without crashing). It seems that something went wrong with one of the CPU boards, so the system controller forced a reset. It came up with only 8 CPUs and 16 GB: one of the CPU boards failed POST.

Thankfully we have Sun support, so they (eventually) diagnosed the problem and shipped us a replacement board (along with a replacement power supply for one whose fan was making funny noises).

I was hoping to be able to utilise the V1280's (and Solaris') hot-swappability when replacing the CPU board. Unfortunately the dead board was so broken the system controller (lights-out-manager, which appears to be an UltraSPARC IIe) couldn't turn the power off to the dead board only. So I had to bring the whole machine down in order to replace it.

The replacement system board had 4 900MHz CPUs installed (the CPUs aren't user-serviceable components), but no RAM, so I had to move 32 sticks (256 MB each) of RAM from the dead board to the new board. Ouch thumbs.

Pictures to follow

20050214

MTB Ride: Black Mountain to Mount Stromlo (and back)

Yesterday, Victoria and I did a nice ride from Black Mountain to Mount Stromlo.

We followed part of leg 5 of the Triple Triathlon, starting from Rani Road (soon to be demolished and covered over by the great Gungahlin Drive Extension (GDE)) and over Dairy Farmer's Hill, down to Coppins Crossing, up over Bluett's (the impossible climb, as far as I am concerned!), and up the back of Mt Stromlo to the top.

There we found that the cafe is now re-opened: Michael's of Stromlo (website is currently empty).

(The Red-Belly Black Cafe used to have a cafe on top of Mt Stromlo, but it was devastated by the 2003 bush-fires.)

After riding for a few hours in fairly warm conditions, we decided that lunch at the top of Mt Stromlo was ideal. We could then cruise back to Black Mountain along the bike path.

Michael's isn't up to the standard of the Red-Belly Black, but it is cheaper. We ordered two "Hamburgers with Pineapple, Bacon and Cheese". The lady at the counter said, "do you want egg with that?", to which we replied, "yes, please!". Some twenty minutes later the burgers arrived (there was a warning in the menu saying to expect delays in delivery, which I had thought at the time was weird). Delivered as just an open burger with a good solid bun and plenty of crispy bacon, beetroot, pineapple, cheese, lettuce, and a good patty. I put the two parts together and devoured, although I did have some containment issues towards the end. Yum. Not bad for $5 each, with a fantastic view (the menu also states, "the cafe with the million-dollar view").

If I recall correctly, Michael's is now open Wednesday to Sunday, 10am - 5pm. A good place for a pit-stop.

After finishing lunch, we hurtled down the Mt Stromlo road. I hadn't ridden up or down the main road since the fires (I did leg 5 of the triple tri last year, but that goes down fire trails so the view is a bit different since the condition of the trails is so bad that you're looking at the ground all the time). I was surprised at the view you get going down the road now, since all the trees have been either burnt or chopped down. It's sad, but the view is incredible.

An uneventful ride home along the bike path. Despite being tired it took us less than half the time of the ride out. I think I need to do some more riding before I do all 3 legs of the Triple Quad on March 20.

20050210

Pseudo-terminals and Xterms

Ok, so I've been trying to work out a nice way to get input and output from our simulator separate to the input and output to the simulated program. This is particularly important if we want to have user control of the simulator while the simulation is running.

This is exactly what pseudo-terminals are good for. On Solaris, see ptm(7D) and pts(7D) (or go to Sun's online web-pages: ptm(7D).

Essentially a pseudo-terminal is like a bidirectional pipe(2), but also with terminal semantics, so there are special characters so the user can do things like backspace, line erase, etc.

A pseudo-terminal has a master end and a slave end. The master end is where the user is (expecting output and reading user input), the slave end is where the program is (expecting user input and writing output). The slave end will respond to the usual terminal ioctl(2)'s that the program wants to use (for example, TCGETS, in order to get a copy of the termios structure from the terminal). It turns out (see below) that this ordering (master=user, slave=program) is crucial.

Ok, so I could use a pseudo-terminal, but I still needed a way for the user to input into that pseudo-terminal: I wanted to use the actual terminal for simulator input and control. It turns out that xterm(1) has a switch exactly for this purpose: -Sccn. The manpage says:

     -Sccn   This option specifies the last two  letters  of  the
name of a pseudoterminal to use in slave mode, plus
the number of the inherited file descriptor. The
option is parsed ``%c%c%d''. This allows xterm to
be used as an input and output channel for an exist-
ing program and is sometimes used in specialized
applications.
However, modern pseudo-terminals are created using the /dev/ptmx and ptsname(3C) interface (rather than using the old, BSD-style search through /dev/ptyXY where X is [pqrs...] and Y is [0-9a-f]. The -Sccn switch was designed for ye-olde BSD type of pseudo-terminal days.

It turns out that newer versions of xterm know about this, and have extended the switch to allow -Sccc.../d where the ccc...'s are the trailing part of the slave device name (the basename) and the d is the device descriptor (with a / between them to separate them). However, Solaris's xterm doesn't support that.

But it also turns out that xterm ignores the cc characters these days anyway. How did I find this out? I read the source. Yuck, but true. Although I didn't read the source for the Solaris version of xterm it seemed likely that it ignored it too. Especially since Solaris's CDE terminal dtterm(1) also had a similar -Sccn switch and an extension switch:

        -Sc.n
Equivalent to -Sccn, but provided for systems with
a larger pseudo-terminal device name space. The c
argument specifies the last component of the
pseudo-terminal device slave name. The terminal
emulator ignores this value and the value may be
empty. The n argument specifies the number of the
file descriptor that corresponds to the pseudo-
terminal device's already opened master side.

So I wrote a little program to test this out. See pseudo.c.

When I first tried this I was getting really weird results: the xterm wouldn't show anything the user typed, but the characters would flow one-by-one to the parent program (i.e., not line-based as I expected). Also, anything I wrote back from the parent program would not only get printed on the xterm window, but would also end up back in the input of the parent program's end of the pseudo-terminal.

After much fiddling and thinking, I realised that what I wanted to do with the pseudo-terminal is different to most examples of it: I wanted to give the master to the child program, not the slave: I wanted the child to be the user input and the parent to simply be a proxy between the user and the simulated program (going back to the original simulation IO problem). So after simply switching slave and master, the program worked as expected.

However, I also got an additional line of input (both appearing in the xterm and in the parent program's pseudo-terminal input). This line contained a hexadecimal number. After reading the xterm source, it turns out it writes the X-window id of itself to the terminal so the parent program can control it if it wants to. That also appears in the xterm itself since by default user input is echoed (terminal control local flag ECHO).

I'm not interested in the xterm's X-window id, and I figure it could be confusing to see an xterm pop up with 0xc0002 or somesuch in it. So there's some fudging going on that ensures that we don't see it: Firstly, before forking the child I get the pseudo-terminal (default) settings, and then I clear ECHO. So when the xterm pops up, it will write its X-window id, but it won't appear in the xterm. Then post-fork, the parent reads and discards a line from the xterm: this should be the xterm's window id. The parent then restores the original terminal settings, so ECHO is set if it was already, which appears to be the default.

To get this working I did a lot of reading: Stevens' "Advanced Programming in the UNIX Environment", the Solaris man-pages, and the sources to xterm (CVS) and expect (CVS).

Chainfire, by Terry Goodkind

Book 9 of the Sword of Truth

This is the first book of a trilogy that will complete the Sword of Truth series. Firstly, I have to say straight up, that the first book of the Sword of Truth, "Wizard's First Rule" is my favourite book. If you haven't read it, beg, borrow or buy it, and read it.

The rest of the series hasn't quite been up to the standard of Wizard's First Rule, but they've been pretty damn good reads nonetheless. While the first book was fairly standalone, the rest have clearly been part of an overall series. They have all been leading to a final confrontation between Richard Rahl and the Imperial Order (Emperor Jagang, the dreamwalker).

This book starts with Kahlan, Richard's wife and a major part of the series, going missing. And no-one but Richard remembers her. (that much is on the blurb on the back, no spoilers there, however: spoiler may be below!)

I found this extremely readable, as usual for Terry Goodkind's novels. While I occasionally got annoyed with his long soliloquies talking about the philosophy of freedom (somewhat preachy and repetitive) the story is intriguing. I particularly enjoyed the linking back to the first book with the Boxes of Orden, and since this will clearly be a big part of the next two books I think that will make a nice wrap-up to the series.

Highly recommended.

Pandora's Star, by Peter F. Hamilton

Book 1 of the Commonwealth Saga.

Finished this last week. Very good read, excellent world-building, with an interesting plotline and (mostly) believable vision of the future. The ending is intriguing, leaving you waiting for the next one (Judas Unleashed, due October 2005).

Highly recommended.

20050209

migraines suck

my first blog post.

had a migraine last night, after playing two games of ultimate in fairly stifling heat. i think this is the first migraine i've had in maybe 5 years. migraines suck big time.

i know when they're coming around because i start not seeing things: that is, there are gaps (white splotches) in my vision. all i can do then is go lie down somewhere quiet and close my eyes and hope i can get to sleep.

thankfully i got to sleep through most of it.

still had a headache all day today, but i came in to work for a few hours because it was andrew's mid-term seminar, and i'm on his supervisory panel. it went well, as expected.

so i decided to be a sheep and do a blog. yeah, that follows.