bugfixed ‘find lowest subprocess’

It turns out there’s a bug, due primarily to testing on zsh and putting the script into bash.

function find_lowest_subprocess() {
local -i parent=$1
local pids
typeset -a pids
pids=($(pgrep -P $parent))
while ((${#pids[@]} > 0)); do
if ((${#pids[@]} > 1)); then
parent=${pids[0]}
local i=0
while ((i < ${#pids[@]})); do
local sub=$(pgrep -P ${pids[$i]})
[[ -n $sub ]] && parent=$sub
((i=i + 1))
done
else
parent=$pids
fi
pids=($(pgrep -P $parent))
done
echo $parent
}

Someone, somewhere forgot about the parenthes around the array assignments. Shame on me!

Shim me baby one more time

I was reading the ‘Basics on how shims work‘, and all I could think about was the old linux/unix trick of using LD_PRELOAD to intercept library calls in dynamically linked applications (used to great effect to bypass timebombed applications).
It is one of the reasons why I think that static linking is just horrible – after all, it breaks things, and makes you have to use terribly complicated tricks like disassembling and binary patching to fix problems because you don’t have the source code. You don’t get the advantages of page sharing, which is kind of important when you consider how many libraries are loaded by the typical gnome application (last check on nautilus was 117 libraries, excluding VDSO and the binary itself, firefox has 151, excluding fonts and other pango related nonsense). Yes, indeed, winners don’t use static linking.
As a tangent, it’s one of the reasons for not using application compression tools on binaries – after all, the only thing you save is on the distribution size, not on the run-time. The binary itself acts like a static linked blob, and doesn’t share the text segment (program code) amongst the other instances, like other binaries, so every instance can use a lot of private memory, leaving less physical memory on the machine for other things like playing high resolution video.

Ooooooh, these licenses will kill me

The GPL is a difficult beast.
all those MODULE_EXPORT_GPL symbols.
F**k them.
I’m just going to release a patch that remaps them all to MODULE_EXPORT.
The patch is GPL.
F**k you I’m a pragmatist, not an idealist.
This was written at 3am, I am drunk and I’m bitter. You know who I am.
I don’t prefix my posts with ‘yes, I drink…’, you should know what I’m like, after all; you’re here

For a text mode browser links is pretty useful

How can you tell if your website is usable by anyone? Well one of the simplest ways is to use a text mode browser. It gives you a good idea as to how easy it is to navigate without having to spend the effort getting in a UI designer at infinity$/hour just to tell you that your links should be purple, and not help you in the least bit.
links is a pretty damned good text mode browser. It makes it obvious if you’ve made a mess of the UI for navigating, which is always a good thing. It makes it obvious when you’ve forgotten to put the bloody ALT tags into all your images – like a good designer should. Spacer gifs are evil and must be stopped 🙂

updating the /usr/local install tool

We need to extend the linkit script to support (a) Solaris and (b) spaces/escape characters in the file name.

Sorry, my shell environment just isn’t cooperating with me – BASH_ARGV[0] == {}, yet I cannot dereference the variable correctly no matter what I try. No wonder people use perl. God this is so frelling irritating.

Updated UI Design guidelines

Some of the locations have changed, some have been removed (XP)

  • Apple Mac OS X Human Interface Guidelines
  • Microsoft Vista ‘Design Guidelines’
  • Palm OS Application Design Guidelines Pre PalmOS 6
  • Java Look and Feel Guidelines (Version 2)
  • Gnome Human Interface Guidelines (Gnome-HIG)
  • Baggy sweatshirt problem

    <ramble>
    It’s a problem when programming. You don’t have to make a one size fits all solution to a problem. It just isn’t worth the effort. I’m being reminded of the Simpson’s episode parodying Mary Poppins… ‘If you cut every corner you’ll have more time to play’. i.e. if you can get away with it then fake it.
    Polishing crap still leaves you with crap. Spend a half an hour experimenting with something to decide if it will work.
    Learn to shoot your baby in the crib or It’s too easy to get locked into a commitment that is really too much work…. i.e. even when you’re half way through the experiment and you realize it’s going to drive you mad trying to get it to work then issue a big old ‘rm -rf’.
    </ramble>

Continuing the drama of little snippets of shell

This little piece of shell script attempts to find the ‘lowest subprocess’ of a passed in process. It works well with a straight tree of processes, and if there are the occasional pipes in the command tree then it will miss them most of the time.
Maybe tomorrow I’ll talk about how to fix it.

function find_lowest_subprocess() {
local -i parent=$1
local pids
typeset -a pids
pids=$(pgrep -P $parent)
while [[ -n "$pids" ]]; do
if (( ${#pids[@]} > 1 )); then
local i=0
while (( i < ${#pids[@]} )); do
local sub=$(pgrep -P ${pids[$i]})
[[ -n $sub ]] && parent=$sub
((i=i + 1))
done
else
parent=$pids
fi
pids=$(pgrep -P $parent)
done
echo $parent
}

Differences between the busybox shell and the real bourne shell

Feature Bourne Shell Busybox Shell Bash
Subprocess Execution “ (the backtick) “ or $() As Busybox
Math Evaluation use expr (not builtin) $(( )) As Busybox; adds ((var=math))
Constants None None typeset -r
Integers None None typeset -i
Evaluation [ [ [
Extended Evaluation /bin/[[ (1) /bin/[[ (1) [[


(1)
The [[ operator is not the same as the program /bin/[[ as a program you need to still use double quotes around the variables to be expanded; thus defeating the reason for having them in the first place.

For Example:

# file="/tmp/let me go"
# touch "$file"
# [[ -e $file ]] && echo "There"

Yields [Busybox]:

[[: me: unknown operand

– as $file is word split before handing it to the command [[

Yields :

There

– due to $file not being split when passed to the test -e.

the fact that they’re on holiday is an advantage

being at work again raises a few interesting issues. One of them involves the period over Christmas. It seems like there’s nobody in the office (I am one of three/four). I have 0.6 days holiday left and I am troubled. Damn my work related guilt.