Getting power button events with HAL

Posted by orospakr, Fri May 30 13:10:00 UTC 2008

I needed to teach the product I’m working on about the ACPI power button, so I fired up dbus-monitor --system to see what events are emitted when the button is pressed. It was easy to find the device in question in d-feet afterwards. Unfortunately, the HAL device objects (/org/freedesktop/Hal/devices/computer_logicaldev_input_N) that emit the events for the various ACPI buttons change between machines and even between reboots, so it’s necessary to dynamically discover them by querying HAL for all devices with the “button” capability.

This little spike solution prints out messages to stdout whenever certain special ACPI keys on your keyboard are pressed (on my Lenovo ThinkPad T61, it shows the power button, the volume buttons, the Fn-key chords for changing backlight, etc.):

 
import gobject
import dbus
import dbus.mainloop.glib

def getButtonCondition(condition, btn):
    print "Condition: %s, button: %s" % (condition, btn)

mainloop = gobject.MainLoop()
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()

hal_manager_proxy = bus.get_object('org.freedesktop.Hal',
                                   '/org/freedesktop/Hal/Manager')

hal_manager = dbus.Interface(hal_manager_proxy, dbus_interface='org.freedesktop.Hal.Manager')

button_paths = hal_manager.FindDeviceByCapability('button')

button_proxies = []
buttons = []

for p in button_paths:

    button_proxy = bus.get_object('org.freedesktop.Hal', p)

    button = dbus.Interface(button_proxy, dbus_interface = 'org.freedesktop.Hal.Device')
    button.connect_to_signal("Condition", getButtonCondition)
    button_proxies.append(button_proxy)
    buttons.append(button)

mainloop.run()

0 comments | Filed Under: code | Tags:

Relpats NG, Page 10

Posted by orospakr, Tue Jan 08 11:42:00 UTC 2008

So, “The Creator” himself, Relpats, has done a new collection of riddles.

People were collaborating on the final problem of the original Relpats puzzle on a web-based forum, and it proved quite useful. A few friends and I have decided that page 10 is likewise worthy of a group effort, and the old forum is no longer available. So, here’s a new one:

Relpats Page 10 Forum.

0 comments | Filed Under: | Tags:

So, how much does Vista's UAC really solve?

Posted by orospakr, Fri Jan 04 20:01:00 UTC 2008

So, I was hacking on some code on Windows the other day. The DRM for a piece of proprietary software I had a legitimate license for wasn’t working, and thus I had to seek out some… licencing facilitation software. Since such software usually originates from the sketchier regions of the Internet, I ended up infecting my copy of Vista with a trojan horse. That’s one demerit point on my Geek Licence!

Here’s the manifest from the executable:

 
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <assemblyIdentity version="1.0.0.0"
     processorArchitecture="X86"
     name="Installer"
     type="win32"/>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel
          level="asInvoker"
          uiAccess="false"/>
      </requestedPrivileges>
    </security>
  </trustInfo>
</assembly>

For those without Windows-fu, the manifest is basically a PE resource containing some XML metadata that describes the executable. They first found use with the release of XP, where they were primarily used by software developers to ask Windows to dynamically load version 6 of the Common Controls library (which also saw its debut in XP) instead of the venerable version 5. The practical upshot of all this was that it gave you the nice new Windows themed controls, without any ABI changes. Microsoft obliged developers to explicitly specify their desire for version 6 so that they could basically ship version 5 as is, to avoid any compatibility issues.

Returning to the trojan hourse, I assume they were trying to intentionally prevent Vista’s UAC feature from asking the user for extra permissions. This actually makes sense because most malware authors’ goals do not include completely compromising the user’s machine, but rather the purpose of creating botnets, which don’t need administrator access to commit their nefarious deeds. All they need to do is stay resident and use the network, all of which the regular Windows limited account allows them to do.

0 comments | Filed Under: code | Tags:

Setting Emacs 22 for Windows' font to Consolas

Posted by orospakr, Thu Jan 03 15:16:00 UTC 2008

Emacs 22 for Windows, unlike its X11 counterpart, supports anti-aliased TrueType fonts.

Thus, it looks much better if you set it to use the shiny new Consolas monospaced font included with Vista (or indeed, any other TrueType font you care to use):

Add this to ~/.emacs:

(set-face-font 'default "-outline-Consolas-normal-r-normal-normal-15-112-96-96-c-*-iso8859-1")

0 comments | Filed Under: code | Tags:

It lives!

Posted by orospakr, Tue Dec 11 22:16:00 UTC 2007

My broken-yet-cached copy of Mephisto has been repaired. Turns out it was frozen to an old version of Rails, d’oh!

(it had also gotten stuck half way between two migrations)

0 comments | Filed Under: test | Tags:

Zimbra

Posted by orospakr, Fri Aug 03 01:59:00 UTC 2007

So, I’ve finally set up Zimbra, after a bit of equivocating on whether to use it in the first place.

It’s really slick; imagine a Free Software[1] replacment for GMail, Google Reader, and Google Gears, along with all the enterprisey management stuff that the likes of Active Directory/Exchange, Groupwise, and Notes have. It takes care of all the thorniness of setting up a the Postfix MTA, and gives you advanced calendaring features (and it can sync up with webcal ics calendars, too!).

It seems to take a best-of-both-worlds approach on several issues: the concept of tagging is pervasive throughout the interface, yet the classic Folders-based paradigm remains intact; it provides both SOAP and RESTful interfaces to its datastore; it’s (mostly) Free Software while providing a commercial subscription model attractive to the more traditional managers.

[1] Actually, there is one slight issue of contention; Zimbra’s internals are MPL licensed, but the GUI component is licensed under the so-called “ZPL”, which is actually the MPL with a badgeware clause added. The whole attribution argument is a shitfest I don’t want to get involved with, but I do prefer pure Free Software licenses over badgeware licenses; licenses that place limits on your ability to modify software present a slippery slope, as today it may only be display-logo-please requirements, and tomorrow it could be nasty DRM or patent clauses.

0 comments | Filed Under: | Tags:

The Free Software distribution model

Posted by orospakr, Fri Aug 03 01:58:00 UTC 2007

Someone on KernelTrap claimed that Windows has a superior distribution model for third party software.

This is a faulty claim, on several levels:

  • There is no real standard for application distribution on Windows, save from a few common idioms and libraries like InstallShield.
  • On GNU/Linux, the distribution model tends to be entirely different. Users generally get all their software, in the entire stack all the way from the kernel to the desktop applications, from a single distributor. Thus, there is a common infrastructure for dependency management, filesystem structure, and configuration file management. Not only does this normalized interface for software management allow for a cleaner user experience in managing and updating their software, but the distributor can perform integration testing. The fact that all this code is Free Software is what enables this distribution model.

apt-get install vlc

Easy!

I suspect that the issues they had (complaining that VLC was difficult to install, etc.) probably arose from them attempting to use stuff that simply wasn’t ready yet at the time. If one elects to be on the bleeding edge, expect a bit of pain.

2 comments | Filed Under: | Tags:

AACS can eat my shorts

Posted by orospakr, Fri May 04 11:18:00 UTC 2007

09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0.

1 comment | Filed Under: | Tags:

Building CSound

Posted by orospakr, Tue Feb 27 02:47:00 UTC 2007

Just a quick note to myself and others who might want to run TamTam under sugar-jhbuild:

scons buildInterfaces=1 dynamicCsoundLibrary=1
sudo ./install.py

appears to be correct incantation to install CSound.

It might also be necessary to remove “import csnd” (which was for importing the old CSound python binding) from Util/CSoundClient.py in TamTam itself.

Don’t assume this will actually help you run TamTam itself, though, as the whole thing promptly dies with a floating point exception (logged as signal 8 in the Developer’s Console) on my laptop. :(

0 comments | Filed Under: olpc | Tags: