Package: sysrqd
Version: sysrqd9-2
Severity: wishlist
Tags: patch

Hi,

the appended patch includes an additional, very simple interface to 
the 'shutdown'
command in sysrqd. It allows to shut down or reboot a remote machine by
executing a command like
sysrq> -<shutdown-option><minutes>

where <shutdown-option> is one of the shutdown options '-r', '-h' etc. and
minutes is a mandatory one digit number defining the timeout in minutes.
For example "-h6" causes a shutdown and halt in 6 minutes.

The reason to have such a facility in sysrqd is 

1. that sometimes an orderly shutdown (with proper stopping of network 
connections) 
   is possible after a remount-ro (u)
2. this daemon seems to be the best place (except maybe a remote ssh key
   for root?!) to have some kind of remote shutdown command for a 
   small set of computers which are all booted and shut down at the same
   time.
 
Greetings,

Onno


-- System Information:
Debian Release: 4.0
  APT prefers stable
  APT policy: (900, 'stable'), (450, 'testing'), (225, 'unstable')
Architecture: amd64 (x86_64)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.6.22-2-amd64
Locale: LANG=de_DE.UTF-8, LC_CTYPE=de_DE.UTF-8 (charmap=UTF-8)
diff --git a/sysrqd.c b/sysrqd.c
index af19f20..00cecf5 100644
--- a/sysrqd.c
+++ b/sysrqd.c
@@ -101,9 +101,27 @@ read_cmd (int sock_client, int fd_sysrq)
       if(buf == '\n')
 	write_prompt (sock_client);
 
-      if((buf >= 48 && buf <= 57) ||
+      if((buf >= 48 && buf <= 57) || /* letter: commands to sysrq */
 	 (buf >= 97 && buf <= 122 ))
 	write(fd_sysrq, &buf, 1);
+      else if (buf=='-') { /* '-' for shutdown/reboot */
+	char act;
+	read(sock_client, &act, 1);
+	if (act!='h' && act!='r' && act!='H' &&
+	    act!='P' && act!='c')
+	  continue;
+
+	if (act!='c') {
+	    /* read delay argument (in minutes) */
+	    read(sock_client, &buf, 1);
+	    if (buf<'0' || buf>'9')
+		continue;
+	} else buf=' ';
+	
+	char cmd[50];
+	snprintf(cmd, 50, SHUTDOWN_CMD, act, buf);
+	system(cmd);
+      }
     }
   while(read (sock_client, &buf, 1) && buf != 'q');
 }
diff --git a/sysrqd.h b/sysrqd.h
index c6fe770..4d52dbf 100644
--- a/sysrqd.h
+++ b/sysrqd.h
@@ -7,5 +7,6 @@
 #define AUTH_FILE "/etc/sysrqd.secret"
 #define BINDIP_FILE "/etc/sysrqd.bind"
 #define PID_FILE "/var/run/sysrqd.pid"
+#define SHUTDOWN_CMD "/bin/bash -c \"/sbin/shutdown -%c %c&\""
 #define SYSRQD_PRIO -19
 #define SYSRQD_LISTEN_PORT 4094

Reply via email to