15th of May 2005
Fork-Bomb
That was a little silly. I just, essentially, fork-bombed my own machine as "root". I have a script which resets the permissions of a set of files on the hard-drive which has to be ran as root. Unfortunately I always forget to "su" to root before running it, so I added a line at the start of the script to check for this eventuality and automatically run the script again as root:
if [ "$USER" != "root" ]; then
su -c "~matt/bin/set_permissions"
else
# This calls a function which does the work
setPerms ~uploads/
fi
(Formatting slightly buggered up by my blog, I'll have to look into fixing that at some point. It might look alright on the RSS feed though, not sure...)
Basically this should run as me (matt) then ask for the root password. When getting the root password it should then rerun itself using "su" to become root. The problem is, unknown to me, su doesn't alter the variable $USER so, having become root, the script thought it was still running under a non-privileged account, and so would rerun the "su" command. No problem, or so you might think. Except, of course, when ran as root the "su" command doesn't need a password, and so it doesn't ask for one.
What happened was the script repeatedly ran su and told it to re-execute itself, so the script went around in a loop constantly forking itself and instances of the "su" command.
The machine wouldn't even shut down. In the end I had no choice other than to flick the switch on it. D'oh.