logging the foreground process in X11
Inspired by a similar New Old Thing post, Logging the foreground process as it changes, I thought I’d try my hand at a similar tool for X11. (No doubt such a thing already exists, didn’t look.) I’m not interested in the process that’s running on the CPU, which is closer to top’s job, but the name of the window I’m looking at.
The basic structure is pretty similar to the Windows sample program. We ask the X11 server for focus change events and print them out. We also have to ask for window creation events so we can track new windows as they show up. Here’s the source: windowlistener.c
A few other things to note. I spend most of my time in an xterm, so just knowing I switched between three different xterms doesn’t tell me much. Fortunately, it’s pretty easy to give each xterm a title that changes to reflect the current directory or file being edited. OpenBSD’s sample .kshrc file (/etc/ksh.kshrc) sets up aliases for common commands like cd and ssh that reset the xterm title. vim can do the same by adding set title
to .vimrc, and then you’ll want to create an alias that resets the title after exiting vim.
Exercises: Add timestamps. Add a timeout and poll the current window title, so that title changes without focus changes (editing a new file) are detected.
Windows USB craziness
I’ve noticed this before, but since I just bought a new USB hub I was able to reconfirm. With science. Windows apparently treats every USB device/port combo as a unique device for which it needs to install drivers (which also requires searching the great driver database in the cloud). I plug my keyboard into port 1, tick tock tick tock, the driver is installed. Unplug, plug it into port 2, tick tock tick tock all over again. It’s the same keyboard that was plugged into port 1 seven seconds ago! It’s the same hub! Why does it need a special driver? It doesn’t, of course, but Windows still insists on searching for a new driver even though it looked less than thirty seconds ago. Plugging the keyboard back into port 1 doesn’t trigger a search, of course. Now it remembers! Why are these lookups being cached with a key that involves the port? Isn’t the whole point of USB that I can plug anything into any port?
Antiviral
The movie’s premise is that in the near future people will pay money to be infected with viruses from celebrities. “From their body to yours.” You can tell it’s the near future because it looks like today except everything is white. The movie starts off as a possible parody commentary on the cult of celebrity and famous for being famous, but then integrates an actual plotline and turns into a corporate espionage thriller. There’s also some cool ideas about copy protection. Well produced, scripted, and paced. Keeps the overt messaging to a minimum while still being thought provoking. And not just entertaining, but educational. I learned that multicolored tulip flowers are the result of infection with a plant virus.
Tagged: moviereview
i disregard your request
I hate Sprint with the burning fury of a thousand suns, but I have to admit their latest ad series featuring James Earl Jones and Malcolm McDowell is fantastic. My favorite is Steve’s Facebook Post.
flak is back
Last night, a flak link escaped into the twitterverse where it was discovered by a “Google-HTTP-Java-Client/1.17.0-rc (gzip)” (whatever that is), which then proceeded to send flak a serious of cruel and unusual requests. Like the unique snowflake it is, flak’s HTTP parsing is rather delicate. In this case, sending a cookie without a value invoked the dreaded “table index is nil” error and crashed the process. Now, flak cannot be laid low by any one rogue request because it is powered by a whole host of processes, but after the relentless onslaught of four such requests, everything was dead.
Bug fixed. Another related bug found and fixed. And we’re back online. Until the next bug.
vmtimed
My laptop spends a lot of time running Windows, with OpenBSD in a VM, which I imagine works better than trying to run Windows in QEMU. As described, the problem is the clock drifts. A lot. If my laptop is suspended eight hours overnight, there’s no way ntpd is going to fix that before my coffee is ready unless I plant the coffee beans and wait for them to turn into second generation beans. A previous fix for ntpd also didn’t garner much love. Nobody knows how hard my life is...
Third time’s the charm. I’m going back to the original idea of using the vmt timedelta sensor. Many times I resume my laptop outside my house, so it’s best not to depend on network access, particularly to my router’s ntpd. The Windows host keeps accurate enough time. All that’s needed is a small program to read the sensor and reset the time whenever it’s wrong. It’s called vmtimed because vmttimed looked awkward. The vmt sensor only updates itself every 15 seconds, so vmtimed does the same and spends the rest of its time sleeping. If the time is off by 60 seconds, we reset to whatever it should be.
is your stack protector working?
Veracode has a new blog post, A Tale of Two Compilers, about differing behavior when two compilers are faced with a subtle buffer overflow. It’s somewhat tangential to the main point, but I noticed that even though the compilers Veracode tested had stack overflow protection enabled, neither detected the bug or prevented the exploit. Detection and prevention of precisely this bug was a headline feature of the original ProPolice implementation. The version of gcc used in OpenBSD has changed several times since then, so I tested it to make sure it still works.
more...
performant
While writing about sem_open, I initially used the word performant, until spell check complained. The internet confirms it’s not a real word, despite being easily understood. Suggested replacements are fast or efficient, but neither captures the entire range of meaning that performant has. One could say fast and efficient, but that sounds redundant and wordy. Why use three words when one will suffice? (I settled on efficient.)
It’s like somebody revokes the word status from lanky and says to use tall or skinny. Or tall and skinny. How about using the word that means what I want?
Dictionary be damned, I’m going to start using performant. It’s a perfectly performant word.
sem_open named semaphores
Support for shared named semaphores, ala sem_open
, recently arrived in OpenBSD. (OpenBSD already supported single process thread shared semaphores, ala sem_init
, and the old school SysV semaphores, ala semget
.) There are still a few tweaks being made, but the internal design hasn’t changed in 24 hours so I figure it’s safe to discuss the implementation.
more...