Stopping laptop suspend on Ubuntu Linux

Filed under: linux — jlm @ 21:15

The default configuration for Ubuntu is to suspend the laptop any and every time the lid is closed, regardless of whether it’s on AC power or using an external display and keyboard, which is pretty annoying but up until Oneiric the setting wasn’t too difficult to discover and override. With Oneiric, Ubuntu reset the suspend options during the upgrade and removed it from GUI accessibility (Options are bad! Everyone uses computers the same way! No one uses an external KVM with a laptop! Gag.), but 5 seconds of web search reveals how to set it with the command line: gsettings set org.gnome.settings-daemon.plugins.power lid-close-ac-action nothing

Except one problem. This only affects the PM settings if you’re logged in to the primary X console. I also want to be able to use my laptop headless. What to do when not logged in was set under “system” (as opposed to “user”) options in the no-longer-available GUI, but no references I found told how to set it from the command line. This is done by running gsettings set as a system user unsurprisingly, but unfortunately, gsettings doesn’t work from sudo or su, because gsettings wants to start up dbus because … I’m not sure why. And it won’t run without X, and gsettings won’t run without dbus. So, how do you run something non-graphical with dbus access? That turns out to be with the dbus-launch command, which can figure out it’s not in X unlike whatever gsettings is doing to start dbus, so what we want is sudo dbus-launch gsettings set org.gnome.settings-daemon.plugins.power lid-close-ac-action nothing

Ha ha, no. That changes the setting for the root user, but the laptop still suspends. This turns out to be because the setting used when awaiting login aren’t root‘s, but gdm‘s. So that means to stop the suspending, we do sudo -u gdm dbus-launch gsettings set org.gnome.settings-daemon.plugins.power lid-close-ac-action nothing

Ha ha, no. See, the documentation on whose settings are used is wrong. It’s not gdm‘s settings that are used at all. (That’s whose was used up to Natty.) If you look at your passwd file, you’ll see there’s a new display-manager user in addition to gdm now: lightdm. What the docs don’t say is that it’s that user whose settings are used now. So, no more teasing, this is the command which keeps your laptop powered on: sudo -u lightdm dbus-launch gsettings set org.gnome.settings-daemon.plugins.power lid-close-ac-action nothing


RSS death, the Javascript trap, and SaaS

Filed under: web — jlm @ 12:34

I read this recent post by Vambenepe on the campaign to kill RSS, and it bothered me. RSS/Atom is what makes a dynamically updating web usable, and here it as an open, decentralized protocol was being replaced by closed SaaS offerings under central control. For a reason I wasn’t sure of, it reminded me of Stallman’s anti-SaaS essay “The JavaScript Trap” from some time ago. That essay didn’t sit right with me: Because your software comes from a webserver on demand, instead of being pre-installed locally, doesn’t make it or what it does any more or less free, and Stallman’s solution of blocking javascript not tagged as being under a free-software license is impractical. And indeed, in the years since, we’ve seen plenty of open source javascript code written and published, coexisting alongside a vibrant ecosystem of proprietary javascript code, just like we have with client application software.

But it finally gelled: The problem with SaaS is that it welds the data to the code.

Let me explain using “traditional” software applications as an example. You have documents you edit in Microsoft Word. These documents are .doc files which are on your disk drive and you can do anything to them that you can do with any other file: Copy it, delete it, encrypt it, archive it to tape, attach it to an email, etc. All outside of Word. If Microsoft does something to annoy you, you can even edit the documents in WordPerfect or AbiWord or OpenOffice or anything else which understands the .doc file format, which there are plenty of because file formats aren’t protectable as intellectual property.

Contrast this with the SaaS situation: You can’t give a WebDAV address to Google Docs for a document you want to edit in that webapp, and have it open and save to that file. You can’t manipulate your Docs files at all, except through the webapp. The only way you can (eg) attach it to an email is to be using Google’s email webapp, and hope that Google’s programmers have provided integration between them (at time of writing, they haven’t).

In short, if you want to use Google’s word processor, you have to use Google for its data store. You can’t say “I love Google Docs’ UI, but I prefer to use Amazon for data storage.” SaaS leverages control or preference of one aspect (the code) into use of another aspect (the data). Why should the SaaS provider have custody of your files? You can store your data with any number of hosts, and the “cloud” lets you access that data from any client machine. But not if you want to access a webapp. Then it’s only if your data is hosted with the SaaS provider. And that’s the real Javascript trap.

Update: Seems Steve Wozniak has some concerns along these lines, about you not controlling data you upload to a cloud store.

Update 2: Now Wired is sounding this alarm, with the focus on data security.


Recommended software: disper

Filed under: linux — jlm @ 12:23

One of the common use cases for laptops is to plug into an external display at a docking station or with a projector, and unplug and use the internal display, then plug into another external display, then later back to the internal display, and keep on cycling like this. Unfortunately, Linux distributions haven’t supported switching displays very easily.

Enter disper to save the day. This is a command-line (and so easily scriptable) tool to switch the display in use. For example, to make only the internal display active, run disper -s. For only the external display, disper -S. And to toggle between them, disper --cycle-stages='-s:-S' -C. So when I want to bind one of the special laptop function keys to alternate between external-display-active-only and internal-display-active-only in Gnome, I run gnome-keybinding-properties, add a custom shortcut to run disper --cycle-stages=-s:-S -C, and bind that to XF86LaunchA. Voilà, with one keypress I can switch between the laptop’s screen and the projector. Other flags to disper let you activate both displays, etc.


Better SelectableChannel registration in Java NIO

Filed under: programming — jlm @ 12:01

Java NIO’s Selector class is surprisingly difficult to use with multiple threads. Everyone that tries it encounters mysterious blocking, much of which is due to it sharing a lock with SelectableChannel.register. So, if you happen to try to register a channel in a thread other than the selector thread, it blocks that thread until the select is done. Boo.

So, this is a NIO rite of passage of sorts, finding this misfeature and then looking up how to work around it. The usual answer is to keep a ConcurrentQueue of pending registrations, and have your select loop process that queue between select calls. Uggggleeee. It occurred to me that using a synchronization lock, we can do better.

To register a channel and get the SelectionKey:

  synchronized(registerLock) {
      key = channel.register(selector, operations, attachment);

And in the select loop:

  // before
  synchronized(registerLock) {}
  // between
  numEvents = selector.select(timeout);
  // after

If the loop is before or after when our registration block takes the registerLock, we’re fine, as having the registerLock prevents the loop from reaching select until we’ve registered and released the lock. If the loop is inside select(), then the wakeup() will cause it to exit select, and it won’t re-enter because we hold the registerLock, so we’re fine.

The tricky case is when the loop has the registerLock or is between releasing the registerLock and entering select(). In these cases, the registration block takes the registerLock and races with the loop over select() and wakeup(). Fortunately, the NIO designers anticipated that programmers would have a desire to ensure a Selector wasn’t selecting, even if the wakeup was called in the window between checking it was okay to enter select and actually entering it. Selector.select() returns immediately if wakeup() had been called after that Selector’s prior select(). So, our race doesn’t matter, the select() always exits, and we’re safe.

This is so much simpler than building up a queue of registrations and processing them in the select loop, and we get the SelectionKey right away, I wonder if I’m missing something. Why is the textbook technique to use a ConcurrentQueue, instead of a synchronization lock like this?


Linux distribution switch, 2011 edition

Filed under: linux — jlm @ 23:15

I switched to OpenSuSE tonight.
PCLinuxOS had been grating on me for the last few months, since they decided to drop most of their man pages in favor of entering “man foo” into Google. But after an ordinary update, tonight I discovered that the new kernel hung on boot. To my distress, GRUB didn’t list any previous kernels when I intercepted its autoboot. After trying and failing to get grub to show me any files on the filesystem so I could select another kernel from /boot to boot from (why is this so hard?), I booted from a rescue disk… and discovered that there was only one kernel version in /boot, PCLinuxOS had been deleting the previous versions. This bad practice dismayed me, it’s standard for distributions to keep the previous one or two kernels around, in case of a case like this, where a kernel that doesn’t boot on someone’s hardware get pushed.
I’d been meaning to try out SuSE again for a while, and this pushed me over. I backed up my disk and did a clean install.
We’ll see how the new distribution goes.


How to shoot yourself in the foot with Python

Filed under: programming — jlm @ 21:40

Accidentally compare a character and an integer.
$ python -c 'print "\0" > 1024'

Wait, what? Any character is larger than any integer? Why are chars and ints intercomparable then? Shouldn’t I get either a type error or a meaningful comparison? This seems like it’s guaranteed to be wrong!


Got an Eee? Forget Easy Peasy

Filed under: linux — jlm @ 00:56

So, I just upgraded Easy Peasy on my Eee. And surprise, surprise, it broke WiFi again.
Fortunately, there’s a user-contributed fix available, like the other times this has happened!
Unfortunately, the maintainers aren’t adopting it, also just like the other times!

This is a distribution targeting one specific line of netbooks, and in every version of it, WiFi doesn’t work. Scrapheap time for Easy Peasy.


Prisoners’ dilemma and web advertising

Filed under: web — jlm @ 19:20

I use AdBlock Plus; I installed it after certain weight loss ads featuring ugly jiggling fat bellies started appearing all over the web, making browsing disgusting. Many people find that web ads make their browsing experience unpleasant in various ways, so adoption of AdBlock Plus and other blockers have been increasing significantly recently. This in turn has web publishers worried, because they see all these visitors showing up on their sites with the ad blockers, so they’re not getting the ad revenue they planned on, and that means more red ink on their balance sheets. (See this current Ars Technia article.) But when I turn ABP off, the web becomes intolerably hostile: Sites are slower, and when they do load they’re full of flashing ads and I get ad copy playing over my speakers and popping up over the text I came to the page to read. So now visitors are fed up, they block all that crap, and publishers can’t make their ad money, they shut down, visitors have no where to go, and everybody loses.

What happened? It was supposed to be visitors get “free” content because the publishers are ad supported, and this worked for a while. But this relies on the implicit social compact that visitors don’t block ads, which has as its unstated counterpart that publishers don’t make their ads so intrusive that visitors get annoyed by them. So I think we have a situation similar to a prisoners’ dilemma: visitors can defect by blocking ads, improving their own browsing experience but denying publishers their ad revenue; publishers can defect by showing intrusive ads, bringing in more revenue but destroying the visitors’ browsing experience. (It’s not quite a PD, because the payoffs are the same when the visitors defect regardless of whether the publishers do.) It seems to me that the publishers defected first, coveting the additional money from the worse ads, and we’re now seeing a tit-for-tat from the visitors, fueled by annoyance at the publishers’ defection.

And my experiment of turning ABP off shows that the publishers are still defecting, and defecting “harder” than before. Whatever your position on the morality of browsing with ads blocked, I think we’re going to see more visitors turning to blocking as long as intrusive ads are ubiquitous in web publishing. If the publishers go back to simple ads, which don’t move and flash and pop-over and piss users off, then publishers won’t see new internet users installing ad blockers, and us existing ad block users will be more inclined to turn our blockers off. But we’re going to continue defecting as long as the publishers are.

The Ars Technia article is titled “Why Ad Blocking is devastating to the sites you love”, but from the other side it could be called “Why intrusive advertising is destroying your users’ tolerance for your business model”. The publishers defected long before the visitors did, and turned a deaf ear to user complaints, and so I’m unsympathetic to cries from them that we’re now defecting too. Publishers have been pissing in the pool for years, and now they’re surprised users are putting on full-body wet-suits? Blame us ad-blockers all you like, but until you look in the mirror and make the web tolerable to surf without an ad blocker, the situation won’t get better for either of us.


twitcode: automatic AFS Kerberos ticket renewals

Filed under: programming — jlm @ 17:29

If you’re a user of AFS with Kerberos, you’ve no doubt been annoyed at your ticket expiring and having to run aklog to get a new one. You may have tried to script running aklog automatically periodically, but been stymied that aklog won’t refresh an about-to-expire ticket. So, you have to scrape the output of klist for the expiration time and wait until then — easy enough. So simple that my script to do so, nicely indented and with declared integer variables for now and then weighed in at a paltry 353 bytes.

So, I figured if I inlined everything, I could fit it in a twitter post. And lo, it does:

while sleep $((`date -d "$(klist -5 | tail -1 | awk '{ print $3 " " $4 }')" +%s` - `date +%s`)); do aklog; done

That’s 112 characters, including unnecessary spaces for readability and the trailing newline, leaving plenty of room for extras you might think up.

Now, if only I could fit all this commentary in a twitter post…


Dire time for webcomics?

Filed under: web — jlm @ 13:06

This recession has been bad news all around, with many businesses shuddering their stores and swathes of jobs lost. I’ve noticed several webcomics I’ve been following for a long time have recently shut down too. Bruno the Bandit announced its effective cessation mid-story. Angband: Tales from the Pit had an ending storyline for its wrap up. User Friendly has gone into repeats. Homestar Runner has quietly stopped updating. There’s a constant rise and fall in this “industry”, low entrance costs means competition is heavy, but I’m sad to see long-time players bow out in succession.

Powered by WordPress