Advanced Namespace Tools blog

17 December 2017

Updating ANTS via diff/patch scripts

I had another longer than intended break from ANTS/plan 9 development, so that means another round of updating systems and updating ANTS to build, install, and work with latest 9front. I had already put a bit of effort into making this process easier, by preparing a script that generates a set of diff files of ANTS modifications from the original versions. The next step is creating a script that uses those diff files to automatically update the current 9front version with the ANTS modifications.

This type of procedure is not, of course, fully reliable. Since diff/patch doesn't actually understand source code in any way, even if it can patch files successfully, there is no guarantee things will compile, or if they compile, that they will work properly. An automated process like this cannot substitute for the work of understanding changes to 9front and how they interact with the ANTS modifications. It can, however, automate some trivial busywork and serve as a starting point.

Updating part 1: find errors by attempting a build

I start in the simplest possible fashion: just trying to build ANTS against the current 9front tree. Unsurprisingly, this grinds to a halt amidst a slew of errors.

getqlp: incompatible type signatures 111c6c2b(util.8) and a3ca55bd(/386/lib/libc.a(qlock)) for qlock
qlock: incompatible type signatures 111c6c2b(util.8) and a3ca55bd(/386/lib/libc.a(qlock)) for qunlock

Interestingly, this error is a bit different than what I was expecting - it is a linking error. What is going on is that ANTS now has a slightly modified libc needed to support the new rfork flag used by private srv namespaces. There is some poor sequencing in the current build script, where that libc is only copied into the main system at the point that the modified version of rc is built. That means everything compiled after that modification will be in conflict with the pre-existing compiled libraries. The solution is to either move the modified libc in/out for building the modified rc, or force a full library rebuild. The former solution is certianly more minimal, but in theory the new rfork flag should be available to any application that wants to use it, so the latter makes more sense overall, and is what I chose to do.

Updating part 2: creating a patching script

Because the diffing script already exists, making a patching script is mostly a matter of using it as a template and performing the corresponding actions. The desired flow is:

copy current patched versions such as foo.c to foo.c.old
copy the current system files from /sys/src into the ants patched directory
apply the diffs stored in the diffs directory to the current versions

This was all just some snarf/paste/sed/tweak munging of no particular interest. The main issue that cropped up trying to run the script was that the kernel formerly known as 'pcf' is now known as 'pc' so the filenames need to be changed to reflect this, along with references to 9pcf in the build script. Next, I'll make an attempt to build using the newly patched files.

Success! At building a modified 9pc kernel, at least, the real tests will be rebooting and checking functionality.

Updating part 3: testing and debugging

The reboot was more or less successful. There was an error printed in early bootup about xd not existing, but other than that things have been working as expected. Since the error was printed during the portion of bootup where drive partitions are being enumerated, I suspect it has to do with the difference between the original (slightly modified) bootup script and the ANTS plan9rc script. Adding 'bootcmd=plan9rc' to the plan9.ini fixed the error, but leads me to believe that the 'no xd' errors are a pre-existing bug in what ANTS provide to the early boot environment and the assumptions of the standard bootscript.

After fixing the 'no xd' error, I also noticed that the modified bootrc script (as opposed to the standard ANTS plan9rc script) has an outdated use of p9sk1 rather than dp9ik for the early namespace key. Another simple fix.

Apart from that, not much has needed work. A manual inspection of the diffs files to make sure they looked sane revealed that I had left an accidental reference to the old pcf kernel config file in, so that generated another fix and rerun of the diffing script. Given how much time I used to invest in laboriously snarf/pasting my modifications into new 9front versions, I'm a bit chagrined that I hadn't created a semi-automated diff/patch updating system previously. Despite that fact that some supervision and double-checking is necessary, it is probably a lot less error prone than doing it all by hand.

The mycroftiv/antsexperiments bitbucket repo is now set up to build properly against 9front revision 6268. All that remains to be done is deciding exactly how the website should be updated. I generally try to sync the plan9ants repository to the most recent 9front iso image, and let antsexperiments diverge from that and/or track hg tip, but it seems like unnecessary work to create a slightly different version based on an iso which is older than the hg tip I was using as my update basis. Perhaps I should just change the instructions to tell the user to install from the iso and update to 9front tip.