[OpenWrt-Devel] [PATCH procd] Add ctrlaltdel handler to procd

Stam, Michel [FINT] M.Stam at fugro.nl
Tue Oct 7 11:08:10 EDT 2014

Hello John,

I saw you had reworked my ctrl-alt-del patch for procd. Ok, but
unfortunately, it does not work for me.

What happens; when I press ctrl-alt-del on the unit, I get an
"attempting to kill init" panic.

This happens because the procd process exits. The kernel does not like
its init process dying.

If I look in procd.c, I see:

    if (getpid() == 1) {

procd_shutdown( ) is called, I see this on the console. But it
indirectly fires off a runqueue which should be handled from the
uloop_run( ) call. This takes care of running the shutdown scripts. But
the uloop has already been cleaned up by uloop_done( ), because the
uloop_run( ) was interrupted by the SIGINT.

Thus this runqueue is never handled. Because of this, its rcdone( ) is
never called (inittab.c), which should invoke procd_state_next( ), which
then moves procd into killing the processes and calling the reboot( )
system call.

It is important that procd does not exit before the reboot( ) system
call is called thus remaining in the uloop_run( ) and letting the loop
run its course, but without grabbing SIGINT back from libubox/uloop, I
would have no idea how to fix this. 

My fix, by adding something to libubox to unhook SIGINT so the
application can catch it was not pretty, but it did solve this problem.
Another problem would be adding a process which grabs SIGINT back from
uloop( ) but this sounds a bit hackish to me.

Any suggestions?

I have finished the /proc/cmdline patch, but I'm hanging on to it as
testing my terminal fix is a tad difficult if I can't get the reboot
working properly.

Michel Stam

-----Original Message-----
From: Michel Stam [mailto:m.stam at fugro.nl] 
Sent: Thursday, October 02, 2014 14:51 PM
To: openwrt-devel at lists.openwrt.org
Cc: Stam, Michel [FINT]
Subject: [PATCH procd] Add ctrlaltdel handler to procd

Procd, up until now, did not support the ctrlaltdel handler. Thus, the
system would immediately reboot upon the three-finger salute, and no
shutdown scripts would be run. This patch adds the handler for the
/etc/inittab entry, so that /sbin/reboot can be run and in turn the
shutdown scripts can be invoked.

Signed-off-by: Michel Stam <m.stam at fugro.nl>
 procd.c  | 1 +
 signal.c | 3 +++
 2 files changed, 4 insertions(+)

diff --git a/procd.c b/procd.c
index ad80284..6ec7cd0 100644
--- a/procd.c
+++ b/procd.c
@@ -62,6 +62,7 @@ int main(int argc, char **argv)
+	uloop_release_sigint();
 	if (getpid() != 1)
diff --git a/signal.c b/signal.c
index 74cabcb..6c00fd9 100644
--- a/signal.c
+++ b/signal.c
@@ -36,6 +36,7 @@ static void signal_shutdown(int signal, siginfo_t
*siginfo, void *data)
 	char *msg = NULL;
 	switch(signal) {
+	case SIGINT:
 	case SIGTERM:
 		event = RB_AUTOBOOT;
 		msg = "reboot";
@@ -91,4 +92,6 @@ void procd_signal(void)
 	sigaction(SIGHUP, &sa_dummy, NULL);
 	sigaction(SIGKILL, &sa_dummy, NULL);
 	sigaction(SIGSTOP, &sa_dummy, NULL);
+	sigaction(SIGINT, &sa_shutdown, NULL);
+	reboot(RB_DISABLE_CAD);
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org

More information about the openwrt-devel mailing list