My first patch to OpenBSD

Several days ago, I come across 2 posts which introduce OpenBSD Hackathon: Historical: My first OpenBSD Hackathon and Michael W. Lucas: Visiting the OpenBSD t2k13 Hackathon. From the reading, I find OpenBSD is a really distinctive and amazing project, especially after browsing its neat code mirror in github, which makes sure my assumption. So I decided to make my hands dirty on it.

Last weekend, I installed OpenBSD on an old machine, and checked out its fresh code from CVS repository. Because I think reading its code can let me get a better understanding about OpenBSD, even Unix philosophy, I decides to take the dmesg as the first experiment. During the reading, the following code gave me a hit unexpectedly:

......
mib[1] = startupmsgs ? KERN_CONSBUFSIZE : KERN_MSGBUFSIZE;
len = sizeof(msgbufsize);
if (sysctl(mib, 2, &msgbufsize, &len, NULL, 0))
    err(1, "sysctl: KERN_MSGBUFSIZE");
......
mib[1] = startupmsgs ? KERN_CONSBUF : KERN_MSGBUF;
len = msgbufsize;
if (sysctl(mib, 2, bufdata, &len, NULL, 0))
    err(1, "sysctl: KERN_MSGBUF");
    ...... 

The err() function always reports KERN_MSGBUFSIZE error even it is actually KERN_CONSBUFSIZE. So it should be a bug, at least should be an enhancement. I followed Preparing a diff and Making your first patch (OpenBSD) to submit my first OpenBSD patch. Guess what? just few hours later, dmesg source file was changed base on my code. Although the final modification is not my code, it is still a great pleasure that I contribute my own effort to help make OpenBSD better!

The timezone issue of installing OpenBSD in VirtualBox

I tried to use OpenBSD in VirtualBox. During installation, it prompted me:

Time appears wrong. Set to ‘Sat Aug 19 11:56:42 +08 2017’? [yes]

Since my server is UTC+8 timezone, I select “yes”. But after rebooting, the date command showed wrong info:

#date
Sat Aug 19 20:01:00 +8 2017
#date
Sat Aug 19 12:01:05 UTC 2017

Actually, my current host time should be 12:01:05 UTC+8. The VirtualBox seemed consider the host time as UTC time, and added another 8 hours. After discussing in the mailing list, the correct answer was found. I should tick “Hardware clock in UTC time” in setting:

Capture

According the manual:

If checked, VirtualBox will report the system time in UTC format to the guest instead of local (host) time. This affects how the virtual real-time clock (RTC) operates and may be useful for Unix-like guest operating systems, which typically expect the hardware clock to be set to UTC.

OpenBSD should consider time reported by VirtualBox as UTC time. So if this option is not checked, the VirtualBox will report local time to OpenBSD, OpenBSD misunderstands it as UTC time and add additional 8 hour to local time. This can explain what I have seen.

Reference:
Set date during OpenBSD installation.