The following C code is valid (and compiles):

#include <stdio.h>
int main(int argc, char *argv[])
   int= 10;
   while ()
      printf("Hello World!\n");--;

Warning: Contains unicode characters.
Also, not tested on gcc, just msvc (which compiles it quite happily).

And as one of my colleagues has just pointed out, more whimsically:

#include <stdio.h>
int main(int argc, char *argv[])
   int= 10;
   while ()
      printf("Hello World!\n");--;

While happy, print. Excellent.

KVM/QEMU guest not shutting down?

One of my KVM/QEMU guests wasn’t shutting down correctly when the host issued the ACPI shutdown command.
Having checked that the guest’s XML definition included the <acpi/> tag in the <features>…</features> section, and that acpid was installed on the guest and that acpi-tools was installed on the guest, I realised that this was an Ubuntu 14.04 client O/S and therefore that it was doing something other than shutdown when it was told to. I believe that this will only happen on the “client” installs of Ubuntu – installing the server grade Ubuntu will not do this, although I’ve not confirmed this.
Essentially, the problem is that when the ACPI command to shutdown is received, the client version of Ubuntu will notice, and instead of actioning the request, will display a dialogue box on the console to the effect of “What do you really want to do, shutdown, restart, log-off or lock the screen?”. To change this, edit the file /etc/acpi/events/powerbtn (as root) and comment out the line reading:

add below it the line:


This will instruct the computer to poweroff when the power button ACPI event is received. Like I said, probably only a problem for the non-server versions of Ubuntu. Serves me right for not installing the correct Server OS, I suppose…

Netgear switch (specifically GS724T) and LACP/Jumbo Frames

If you’ve got a Netgear Smart switch with the LAG feature (I’ve just got a GS724Tv3), *and* you use jumbo frames on your network, beware of a really nasty gotcha in the switch’s management interface.
When you enable Jumbo frames on the ports in the switch, you enable 9216 as the maximum frame size on all the ports and then set up the LAG.
What you must *also* do is, once the LAG is created, is to go back to the ports page, and hit the LAGS “page” (not exactly obviously signposted as such, but at the top of the ports table, above the “Description” header there’s a LAGS link. Click that, then enable 9216 bytes across the LAG that you created. This is the critical step, and means that although the ports were configured for 9216 byte packets, when the LAG was created it didn’t propagate this frame size to the LAG from both the ports.

If you find this and it helps, you’re welcome.
My Synology NAS (DS412+) works in link aggregation mode with jumbo frames enabled flawlessly, once I’d figured out that the LAG is created as a virtual port and you need to make the non-obvious adjustment.

VirtualBox 4.3 with 64bit guests

For anyone else having issues with Virtualbox guests detecting ony a 32bit CPU (despite having ticked the “I/O APIC” option in Settings->System on the motherboard tab, I had the same problem, until I enabled a couple of options in the VMs settings via the command line. This was on Ubuntu 13.10 host:

sudo VBoxManage modifyvm “Test W7″ –acpi on
sudo VBoxManage modifyvm “Test W7″ –longmode on

I would guess that it was the second of these commands which made it work, but I present both “just in case”.

It turns out that unless you tell the wizard that you’ve got a 64 bit guest at the time that the VM is created (in this case, I was re-using an old one) then VB doesn’t actually enable 64bit CPUs for the guest. –longmode on (above) is what does the business in this case.

Linux network bridge devices.

When you’re setting up a virtual machine on Linux using KVM/QEMU, you’ll more than likely need to setup a bridged network device.

I’ve done this now a couple of times, and both times the network has “hung” during bootup.  It seems that this is because I’m also enabling an MTU size of 9000 (Gigabit ethernet with jumbo frames) using the mtu stanza in the br0 section of /etc/network/interfaces.

This is Not The Done Thing, by all accounts.  When setting up the MTU on a bridge device, one apparently needs to use the post-up stanza to add the command

ifconfig eth0 9000

to the interface. This sets the mtu on the interface which br0 is bridging – in my case eth0, you’ll need to edit to suit your configuration.

This will solve the long bootup problem, and cause jumbo frames to be enabled at the point the interface is brought up. When connecting to my iSCSI target on the SAN, this makes the transfers no end quicker.

Updating PHP (or adding modules)

My first instinct when wanting to add a module to PHP is to hit the shell.  However, in cPanel, this is somewhat harder to do.  Especially as on my CentOS 5.4 x_64 build, yum appears to be broken irretrievably – I’ve installed the EPEL repo, but cannot select any software to install from it (I was after the php-mbstring package, I understand).

However, cPanel to the rescue.  Hit WHM as your root user, and go to “Software”.  In there, is an “Easy Apache” section.  Go through the “wizard” presented, and fill in the details you want (I’d base the settings on the existing build if I were you).  In step 5, use the “exhaustive options list” and select all the modules you want.

Having filled in the configuration filename, description and extended description boxes, push the “build” button and let cPanel chunter away for a bit.  You’ll then be asked about suExec and default PHP handlers for .php types.  Accept the defaults (or the settings you had last time if you’re conservative, although for me, these were the same) and away you go.  I’ve now got mysqli and mbstring (why aren’t these default modules anyway?) installed on the server.  No yum needed, Hurrah!

Linux clipboards.

Linux has – for historical reasons – two clipboards.  One is the one that old X hands will know and love, the other is the new one.  And the two are completely separate.  If you put text in the copy-buffer (the X windows style clipboard), then you attempt to paste out into a new-style application, nothing will happen.  Likewise the other way around, copy out of an application that uses the new style clipboard and the X applications won’t know there’s any text in the clipboard.  Because there isn’t.

So.  How to get around this problem?  On debian/ubuntu, there’s a package (which isn’t installed by default) available to install.  autocutsel.  It’s a background application which knows about both styles of clipboard and attaches to both.  When one changes, it’ll synchronise the two clipboards.

Downside?  If you’re used to two clipboards and know which applications use which clipboard (and you exploit this mercilessly) then you’re going to lose the contents of the “other” clipboard with this running.  Enough of a bummer to stop me using it?  Nope.  It’s a beautiful little application which allows me to copy and paste between all my applications – including those pesky mono applications.  Yay!

The problem with Linux and proprietary modules

A kernel upgrade (from 3.5.0-18 to 3.5.0-19) has just borked my two binary modules that I load.  The video card and the wireless network. So absolutely nothing to worry about there then. Just the two most important pieces of a modern Linux system.

The video card problem manifested by the window manager (compiz) crashing, so there were no title bars, the launcher had gone and the task panel was absent. Absolute PITA getting anything to run, and god help you if X decided that the window you wanted to type into just isn’t going to accept focus!

Firstly, after a kernel upgrade, one always needs the correct kernel headers to compile the wrappers for the modules:

apt-get install linux-headers-$(uname -r)

The wireless network card was taken care of by the following two commands:

/usr/bin/apt-get purge bcmwl-kernel-source broadcom-sta-common broadcom-sta-source
/usr/bin/apt-get install b43-fwcutter firmware-b43-installer

The ATI module was done by just running the ATI proprietary driver installer again (which I had lying about in my home directory).

All from a text-console, of course. I was lucky in that my laptop has both wired and wireless. If you’ve only got wireless network connectivity, you’ll need to download the .deb files that apt gets above and install them manually with dpkg.

Adding a script to debian/ubuntu startup. Also, setting numlock state in X

sudo update-rc.d /etc/init.d/<scriptname> defaults

Also, for those newfangled keyboards without a numlock key (irritating, isn’t it?) then you need the numlockx binary, from debian/ubuntu package numlockx.

Just run “numlockx toggle” to toggle the current state of the numlock key – or “numlockx on” or “numlockx off” to set the state explicitly.

Now, combine that with the startup script hint above, and you’ve got a numpad again.  Top stuff…

Alternatively, you can – it seems – go to the system settings tab in Ubuntu, choose Keyboard, choose “Layout Settings”, click “Options” and in “Miscellaneous compatibility options”, select the “Numeric keypad keys always enter digits (as in Mac OS)”.  This has much the same effect.  But you don’t learn anything about the ubuntu startup scripts this way 😛

Ubuntu 12.04 post-install tweaks.

Uninstall gnome-screensaver, install ubuntu packages:

After installing rss-glx, you’ll need to run glx_install to install the rss screensavers. And that’s Really Slick Screensavers, not RSS

You’ll also need to setup the screensaver to auto-start when you log-in.  Search for “Startup” in Unity, then add an item in that utility, pointing to /usr/bin/xscreensaver

Additionally, you’ll (probably) want to remove the unity-lens-shopping package too – it slows the unity search panel down massively, and – for me at least – will never do anything useful. If I want to search amazon, I’d be on the amazon website.

Other packages you’ll be wanting at some point:

mono-complete (required by keepass2; don’t just install the ‘mono’ package)

There’s massive kinks involved with keepass2 on linux (because of mono) – and the fact that Ubuntu has a script to start keepass2 (/usr/bin/keepass2 is a shell script, and so is not what you configure the keefox plugin for the location of KeeFox (that’d be /usr/lib/keepass2 instead).

Add another auto-startup for keefox by adding /usr/bin/keefox2 in the startup programs (like you did for xscreensaver, above).

I’m sure there’s more, but that’ll do for now. When something occurs to me, I’ll put it up here.

So far, though, Ubuntu 12.04 has just workedTM for me on this HP laptop.

Gah, Damn, Sod It.

Microsoft Visual Studio (up to 2008, don’t have 2010 so can’t test it) don’t support unicode correctly.
They expect to see UTF-16LE encoded text (must have the correct format BOM too).
If you present them with UTF-16BE (with the correct BOM) then they corrupt the file by assuming it’s LE encoded.
This means that a file written using perl with the :encoding(utf-16) will not be read correctly, you’ll get garbage in the editor, and the compiler will emit strange errors.
If the file is output from perl using the :encoding(utf-16le) method, then the file is *still* corrupt. However, this time it’s Perl’s fault as it’s not written out the BOM to the file.
This last point is relatively easily worked-around in perl, but it’s still bad that it’s not standards compliant, just like Visual Studio isn’t.

Gah! We can’t win.

Windows 7 & ipv6

My windows 7 has been native ipv6 (dual stacked with legacy ip addresses) for quite some time. I’ve only just discovered how to get it to use a static IPv6 address over the autoconfigured IPv6 address (the reason is that the statically allocated ipv6 address is way more memorable than the MAC address of the windows 7’s wireless adapter).

Anyway; basically Windows 7 likes to use the autoconfigured ipv6 address in preference; we need to tell the stupid thing that the static one should be the default.
In an administrator command prompt, type:

netsh interface ipv6 show interfaces

And look for the interface name for the adapter that’s currently connecting you to the internet.

Using this name, type in the command:

netsh interface ipv6 sey interface "<interface name>" advertise=enable managed=enable

Replace <interface name> with the name you found in step 1.  Keep the quotes, lose the angle brackets.

This will tell windows that you really know what you’re doing, and it can use the ipv6 address in the network connection’s ipv6 static dialog box (which you’d already configured fully, right?) and forget about that monstrousity it auto generated from the MAC address.  Job done.

Testing syntax highlighter

  1. #include <streams>
  3. int main(int argc, char * argv[])
  4. {
  5.    cout << "Hello World!\n";
  6. }

Well, that works ok. Except that wordpress seems to insert a space between the stream output operator characters. And also thinks that <stream> is an HTML tag that needs closing. So it’s a bit of a nightmare really. But I think it’s workable. Not that I’m planning to put code up here, of course…
EDIT: Solved. Use the attribute ‘escaped=”true”‘ and use only HTML entities in the source. Coolio. Excellent plugin. WP-Syntax

IPv6 is here – happy days!

Well, ipv6 works. This may not come as a big surprise to some of you, but more specifically, I’ve got native IPv6 working on my ADSL line. Thanks to my ISP, I’ve managed to set up the ADSL modem to be bridged, and my main router uses PPPoE to connect to them to achieve connectivity.
The router is an RB750 which for 40 quid all-in is quite a bargain, by the way – and in version 5 of the OS it runs, it’ll do ipv6 over ppp! So I got the allocation from the ISP, plugged in the relevant things into the router (not forgetting the all important ::/0 default route to direct packets up the PPPoE link, thanks to Michael for the tip) and it’s all working. resolves, connects, and displays a page.
Even better, so does

IPv6 on the horizon

In the latest of the sporadic updates, I’m preparing my home internet for IPv6 with the little routerbox. I’ve enabled PPPoE logins, and my ISP is preparing a set of IPv6 addresses to route at me. With any luck, I’ll be IPv6 enabled by next week. This site is hosted elsewhere, I’ve got no idea when they’re going to do their migration, but all my sites hosted at home will be available on the next gen internet protocol.

Oh, and advice to ZyXEL P660R-D1 ADSL modem owners: If you’re thinking of going from routing mode to bridging mode (for PPPoE clients behind the modem), do a modem reset beforehand – my device failed to work in PPPoE bridging mode until I’d factory reset it. I suspect that this was down to the fact I’d got static routing rules in the device, but I can’t be sure about that, and I am disinclined to debug the kit.

Good times!

New router update

The Routerbox 750 has arrived, and is now configured.  The packets that comprise this post are flowing through it now 😀

It’s different enough from anything I’ve seen before that the specifics of it threw me for a bit, but it’s all configured and works.  And it’s way faster than the old firebrick was – I’m seeing webpages load a lot faster than they did before, it’s actually a very noticeable speedup.

The only thing I need to say to anyone getting one is that the default gateway is a pig to make work – it’s not just good enough to put in the IP address, you have to also populate the interface too.  But that done, it’ll work like a champ.

I’m a happy camper 😀

New router

I’m in the market for a new router at the end of the month, I think; the one I’ve got is yonks old and it’s routing speed isn’t brilliant.  Superb web configuration, dead easy to use, but it’s throughput is limited to 10Mbit/S.  This was plenty fast enough in the days of ADSL, when 8Mbit/S was all we could get into the home, but these days it’s a little bit slow, what with line speeds being up to 21Mbit/S (on BT’s ADSL anyway).

I think I’ve narrowed the choice down to one of these routers from; there’s a couple of resellers in the UK.  Couple that board with one of their wifi adapters and it’s a neat little 197Mbit/S router – should be futureproof unless I get fiber to the home at some point 😉

Ok, it’s a bit DIY, but I don’t have a problem with that.  I quite fancy a nice handmade teak box for the thing…

UPDATE: One of the UK distributors is selling the RB750 for £39 including a box, the OS, PSU, P&P and VAT. For that price, I’ve bought one.  It’s slower than the 433AH (above) but it’s still in the same ballpark.  Good enough for what I want, and cheaper if I don’t like it, and end up getting rid…