"The Linux Gazette...making Linux just a little more fun!"


(?) The Answer Guy (!)


By James T. Dennis, tag@lists.linuxgazette.net
LinuxCare, http://www.linuxcare.com/


(?) How to Make a Shell Script "Unbreakable"

From Nick Moffitt on Mon, 29 Mar 1999

(?) How do I get a shell script to ignore ^C and ^Z?

"The software is intended to be as unobtrusive, unintrusive and unconstraining as possible. In software as elsewhere, good engineering is whatever gets the job done without calling attention to itself."
-- Cynbe ru Taren, on Citadel (http://zork.net/cit/citadel.txt)

(!) Well, with limitations you can do it with the following:
trap ""  2  20
As in this simple script example:
#!/bin/bash
trap ""  2 20
while : ; do
	echo -n .
	sleep 1
	done
All I'm doing is setting the INTerrupt and terminal stop signal handlers to a null string (to ignore [Ctrl]+[C]) and [Ctrl]+[Z]).
The rest of the script just prints an endless stream of dots at one second intervals to give you a chance to play with the keyboard.
You see, your default terminal settings "cook" the [Ctrl]-[C] into a SIGINT (generate a interrupt signal to the foreground task) and [Ctrl]-[Z] to a SIGTSTP. The default signal handlers for these "cancel/exit" and "suspend" respectively.
This technique will also prevent 'kill -INT' and 'kill -TSTP' from having their normal affect on these processes.
You could also do something like this using
		stty susp 0 intr 0
... which merely changes the terminal settings so that these keystrokes are no longer "cooked" into their usual signals.
I believe that these tricks are inherently subject to race conditions (there is a finite and "exploitable" amount of time between the start of the script's execution and the time that these commands have their effect.
So I think that they should not be used in any attempt to provide security through some notion of an "unbreakable" shell script.


Copyright © 1999, James T. Dennis
Published in The Linux Gazette Issue 41 May 1999


[ Answer Guy Index ] 1 2 3 4 5 6


[ Table Of Contents ] [ Front Page ] [ Previous Section ] [ Next Section ]