Software Woes

Rants, tips and tricks



Sunday, October 26, 2008



PHP destructor vs shutdown function

I found an interesting problem. In some of my PHP classes I needed to ensure that destructor is called, even if user aborts the execution. Well, I learned that user cannot actually abort it since clicking the Stop button in your browser does not stop PHP, it keeps going until either the script finishes (destructor gets called) or PHP timeout is reached (destructor is not called).

I got worried about this second case. After some time investigating, reading comments in PHP online manual (that's why it's better to use online than offline manual for PHP) I got to the following solution:


public function __construct($canvasWidth, $canvasHeight, $tickness)
{
...
register_shutdown_function(array(&$this, "shutdown"));
}

public function shutdown()
{
...do the stuff you would do in destructor
}


The only problem with this could be if your object gets destroyed before script is complete. So, make sure you either implement some safeguard code, or ensure object's lifetime is 'till the end of script.



Friday, October 24, 2008



How to lock KDE session when power button is pressed?

I have a kid that likes to play around my laptop while I work on it and sometimes presses the power button. Default setup on Slackware 12.1 is that laptop starts the shutdown sequence right away. No need to mention how frustrating can that be if you're in middle of something.

I decided to search for a way to prevent this from happening and have my screen lock instead. I searched a little bit, and here's a nice way to do it.

To lock out KDE user session from the command line, you can use this command:


/usr/bin/dcop --all-users --all-sessions kdesktop KScreensaverIface lock


Now, we need to make sure this gets called when power button is pressed. Make sure that 'button' module of your kernel is loaded (you can check with 'lsmod' and load it with 'modprobe' if needed), and then go and edit this file:


/etc/acpi/acpi_handler.sh


Here's what I have in it now:

#!/bin/sh
# Default acpi script that takes an entry for all actions

IFS=${IFS}/
set $@

case "$1" in
button)
case "$2" in
power) /usr/bin/dcop --all-users --all-sessions kdesktop KScreensaverIface lock
;;
*) logger "ACPI action $2 is not defined"
;;
esac
;;
*)
logger "ACPI group $1 / action $2 is not defined"
;;
esac


And enjoy :)



Thursday, October 09, 2008



Regexxer on Slackware 12.1

It seemed easy. You just need: libsigc++ 2, gtkmm 2, libglademm 2.4.0, gconfmm 2.6.1 and PCRE. Some of those I already had, so I only needed libglademm and gconfmm.

The first one installed without problems: single tarball,
$ configure --prefix=/usr
$ make
# make install

Fine!

The other one (gconfmm)... well, it turns out you need gconf for that, I did not have it, so hop to the Gnome website.

Done? No, not yet, gconf requires ORBit2, so let go for that one as well.

Now, after running configure, I started make. Since I have dual-core CPU I used make -j2 but it seems I found some bug in make (!?) since it got stuck for 10+ minutes at one single point of compiling, with both CPU cores at 100%. So, I killed it with Ctrl+C and run just make. That went fine and finished in about 2 minutes.

By some magic, I managed to pick the compatible versions, here they are:

regexxer-0.9
libglademm-2.6.5
ORBit2-2.13.3
GConf-2.21.90
gconfmm-2.24.0

I created Slackware .tgz packages for all this, download is here:

http://www.guacosoft.com/workrave

Enjoy!