A couple of days ago i remembered of the old days using my glorious ThinkPad T42, one of the most awesome laptop I ever had.
Among other things I used to run, there also was the knockAge script.
KnockAge is well explained in this article: “Knock-based commands for your Linux laptop“. KnockAge is a tool written to exploit functionalities of ThinkPads’ HDAPS (Hard Disk Active Protection System), allowing ThinkPad owners to define sequences of knocks on their laptop and bind commands to them, to be executed when a certain sequence of knocks is detected.
Installation of the script is simple,and discussed in the linked article, so I won’t repeat it here.
What I want to write about is that some users including me experienced a bug in the knockAge.pl. The bug comes out as a stuble error message:
Use of uninitialized value in system at ./knockAge-0.1.pl line 236.
I found at least five posts on the Internet asking for help about this.
I decided to dig the sources, face the bug and fix it.
So, what’s in line #236 ? There’s a call to system, and an access to a hash data structure. In order to see what’s going wrong, I need to see where is the undefine data. To do so, I used Data::Dumper and feature ‘say’ (it’s handy). Data::Dumper will do the trick.
Let’s give a look at it (line #240 is actually line #236 after some import and call to Dumper):
They almost came out from nowhere!
The bug is in config-file reading subroutine: my ~/.knockFile ends with a newline (‘\n’), and the script treats that completely blank line as a regular line, trying to parse it as any other regular line and thus filling the hash-based data structure with undefined data.
Let’s fix it! In order to fix it, I have to check the line is not an empty line.
Here is my version, patched:
Complete, patched source code can be found at:
Hope it helps!