Messages in this thread | | | Date | Tue, 15 Jul 1997 20:06:40 +0200 (MEST) | From | Hubert Mantel <> | Subject | Re: What to do on ctrl-alt-del? |
| |
On 15 Jul 1997, Matthias Urlichs wrote:
> Hubert Mantel <mantel@suse.de> writes:
[...]
> > init is started. Before that there is no process with pid 1. If the user > > presses ctrl-alt-del the system will reboot immediately and may trash your > > filesystems (for example when performing an update of the system). > > > Of _course_ there is a process with PID 1. It's just a simple shell script > (or whatever) though, not a full-blown init.
Ok, this is the complete output of a typical install:
PID TT STAT TIME COMMAND 1 ? SW 0:01 swapper 2 ? SW 0:00 kflushd 3 ? SW< 0:00 kswapd 4 ? SW 0:00 nfsiod 5 ? SW 0:00 nfsiod 6 ? SW 0:00 nfsiod 7 ? SW 0:00 nfsiod 8 1 S 0:01 linuxrc 17 ? S 0:00 update (bdflush) 18 2 S 0:00 bash 20 5 S 0:00 bash 21 6 S 0:00 bash 24 1 S 0:00 /sbin/YaST 42 2 R 0:02 ps -ax
Linuxrc has spawned the bashes. Ok, you're right, there _is_ pid 1, but it is not init and it is not linuxrc. So if ctrl-alt-del is pressed, the machine will reboot. And you have no chance to prevent this.
> If you want to survive a control-alt-delete with such a shell, then trap > the signal you get when the user pushes control-alt-delete. (And do tell > the kernel to send you a signal, of course.)
This is exactly the problem: You do not get the signal when the user presses ctrl-alt-del. There is no way to tell the kernel to send you a signal. If you disable ctrl-alt-del (using reboot(2)), a signal will be sent to pid 1. This pid is hardcoded in the kernel. This is exactly the reason why I wanted to address the problem and change the current behaviour (send SIGINT to the process that has disabled ctrl-alt-del).
From "man 2 reboot":
If flag = 0, then CAD is disabled and a signal is sent to process ID 1.
And indeed, from ./kernel/sys.c:
void ctrl_alt_del(void) { if (C_A_D) { #ifdef CONFIG_SCSI_GDTH gdth_halt(); #endif hard_reset_now(); } else kill_proc(1, SIGINT, 1); }
You see, the signal is sent to pid 1. Unconditionally.
> The shell does have a 'trap' builtin, after all...
Linuxrc is not necessarily a shell script. In this case it is a binary. Even if it were a shell script, the trap would not help because the signal is not delivered to the script.
> Matthias Urlichs \ noris network GmbH / Xlink-POP Nürnberg
Hubert mantel@suse.de --- RC5 contest: 72,057,594,037,927,936 keys can't ALL be wrong.
| |