guest - flak

sometimes syscalls restart

Yesterday Reyk fixed a tiny bug in vmd. It wasn’t possible to kill the process by pressing ^C. As explained in the commit, the accept4 system call was being restarted after the signal.

By default, most signal handlers that a program establishes have the SA_RESTART flag set, which causes an interrupted system call to be restarted. Actually, by default signals are either ignored or cause the program to terminate, so this isn’t a problem at all, but any handler installed by calling signal sets this flag. More control over signal actions is possible using the appropriately named sigaction function.

On the kernel side, system calls that need to block call tsleep which usually waits for a corresponding wakeup or a timeout to expire. However, it may also return an error (ERESTART) if it’s interrupted by a signal. Most system calls don’t inspect the error code, they simply pass it along. But when the kernel is about to return to userland, it will notice this error code and run the syscall again.

Among the system calls that handle ERESTART specially are poll, select, and kevent. All of them check for ERESTART and immediately map it to EINTR so it gets returned to userland.

Back in vmd, it had installed a SIGTERM handler that set a quit flag variable to true, but was getting stuck in accept. The code looking at quit never had a chance to run. The fix was to add a call to poll before accept.

Most of the time the default behaviors make sense. Restarting system calls prevents a lot of spurious failures from propagating. Applications that install signal handlers usually use one of the interruptible functions in the core of their event loop. vmd happened to be an exception, that only needed to handle one event and tried to take a shortcut.

Posted 2015-11-24 17:52:49 by tedu Updated: 2015-11-24 17:52:49
Tagged: c openbsd programming

going full pledge

Looking at Theo’s status of pledge update there’s a lot of programs on the list, including some which may seem a bit silly. But the effort has turned up some interesting bugs and misfeatures along the way.

A few programs probably don’t need pledge. One might argue if you have exploitable bugs in id, you have more serious problems than that. However, the effort to throw pledge into everything proves that the concept can work. It doesn’t just work for the first five programs tested, then it turns out nobody wants to expend the effort getting the next five fixed. If you can get to a hundred, I’m more confident the next hundred probably won’t be so bad either. At the very least, it gives us a nice number to brag about that’s bigger than the other guy.

Continue reading going full pledge...

Posted 2015-11-20 18:33:58 by tedu Updated: 2015-11-20 18:33:58
Tagged: openbsd


Previous post on rough code had some notes notes on a few of the issues we faced at ü2k15. I also collected some notes and links about utf-8 and unicode that weren’t directly OpenBSD related.

This post by Solar Designer covers the history of control codes and introduces some of the challenges posed by utf-8 support. There’s also a lot of detail in the followup email by Rich Felker, and the rest of the thread as well. Some more info about ANSI escape sequences, unicode terminals, and control sequences.

Continue reading utf-achtung...

Posted 2015-11-19 06:30:21 by tedu Updated: 2015-11-19 06:30:21
Tagged: software

rough code and working consensus

On their better days, standards groups follow a principle of rough consensus and working code. Somebody builds something, announces it to some friends and maybe a few competitors, and says, hey, if you build something similar, it’s possible for our implementations to interoperate. Everyone’s a winner. Sometimes the design isn’t perfect, but the fact that at least one person/group has built an implementation is an existence proof that it can be built. Valuable knowledge to have.

On their lesser days, standards groups follow a process that looks more like a political pork swap, trading favors and votes for pet features until the end result is a congealed mass of hopes and dreams. Then the committee reconvenes five years later to standardize whatever ended up getting built, trying to salvage the bits and pieces into a cohesive whole.

Continue reading rough code and working consensus...

Posted 2015-11-17 14:48:21 by tedu Updated: 2015-11-19 06:31:18
Tagged: openbsd programming thoughts

sct - set color temperature

The recent fuss about f.lux on iPhone made me take another look at desktop solutions for shifting the screen’s color temperature. f.lux is only available as a linux binary, but there’s a program called redshift that may work.


Let’s try installing redshift package, on my regular desktop machine with other desktop like software on it.

Continue reading sct - set color temperature...

Posted 2015-11-16 16:34:12 by tedu Updated: 2015-11-20 23:38:16
Tagged: openbsd programming software x11

starting from scratch bugs

Or everything I didn’t know about unix. The OpenBSD source tree has lots of example code for solving any number of problems, but I like to do things my own way. Occasionally this means something gets overlooked. A few examples. Previous thoughts on rewrites and reuse: out with the old, in with the less and hoarding and reuse.

Quite a few programs contain variations of the same parse.y file. This file originated in pfctl (649 revisions!) but spread to bgpd, relayd, and smtpd, among many other places. The grammar changes every time of course, but the lexer that drives it stays mostly the same. parse.y also implements a few other grammar niceties, like including other files and setting macros (variables). This gives a consistent feel to each config file.

Continue reading starting from scratch bugs...

Posted 2015-11-04 06:11:05 by tedu Updated: 2015-11-04 06:11:05
Tagged: c openbsd programming

pinboard tips for web design

A few funnies sprinkled with a bit of insight and disappointment. And regret.

It’s 2015. Your team has to wake up determined and put in one hell of a work week to get web pages to render slowly. And yet so many succeed. tweet.

My modest proposal: your website should not exceed in file size the major works of Russian literature. Anna Karenina, for example, is 1.8 MB. tweet.

If your design team insists on including a lot of Javascript cruft and CSS resets, make them write it all out longhand with a quill pen. tweet.

Two steps to better mobile design: 1) Make sure that the most critical elements of the page download and render first. 2) Stop right there. tweet.

If you’re a web designer/front-end developer, It may help to think of the fan on your laptop as a shaming rather than a cooling device. tweet.

The only honest measure of page load speed: time from initial TLS handshake to when the user has finally stopped closing all the ads. tweet.

More generally, there should be an attribute <img src=“…” wank=“yes” /> to allow non-designers’ browsers to only load useful images. tweet.

Astonished to find that a blog site needs a Bloom filter daemon and has Product Scientists. “On the web we want to stay close to the metal” tweet.

I move that the web get faster as computers and networks get faster. tweet.

“We aspire to simple, powerful, yet revenue-free systems that can turn a 500 word blog post into a multi-megabyte user experience” tweet.

Posted 2015-11-04 06:10:03 by tedu Updated: 2015-11-04 06:10:03
Tagged: quote rants web

iphone 6s plus

Replaced my 5s with the new top of the line, 6s plus. Kind of an awkward name. I propose 7P and 7Ps for the next gen.

History: iPhone (no suffix), 4 (quite the upgrade!), 5, 5s (purchased in store on 6 release day to emergency replace 5; that was fun), 6s plus.

I was waiting to see if a new 5 sized phone would trickle down the line, but it appears it’s all big phones from now on. Given the choice between larger and much larger, though, I went with much larger. I spent a fair bit of time reading on my phone and was tired of squinting. Curiously, I bought an iPad for much the same reason, as a dedicated viewing device, but it’s not always with me. At this point I think I’d even consider an iPad mini if they made one with full phone functionality (not just skype or whatever). Can’t quite live without a phone (or can I???), but if it’s only 1% of what I do with the device, maybe it’s time to stop selecting form factors for that purpose.

Continue reading iphone 6s plus...

Posted 2015-10-30 01:44:46 by tedu Updated: 2015-10-30 01:44:46
Tagged: gadget review

bring your own customer service

Skip the middleman to save time and money by simply telling your customers exactly what you would have told your customer service team. Simple direct communications mean nothing gets lost in translation. Not even funtioning.

Best of all, if they screw up, it’s their own fault.

Posted 2015-10-23 17:42:54 by tedu Updated: 2015-10-23 17:44:28
Tagged: bugs web