summary refs log tree commit diff
path: root/src/runit.c
diff options
context:
space:
mode:
authorGerrit Pape <pape@smarden.org>2001-12-30 16:28:53 +0000
committerGerrit Pape <pape@smarden.org>2001-12-30 16:28:53 +0000
commit2ff91a26d1ba9d7d374c8216dbbf0d12465f500a (patch)
treeef4d72f5cd5df0fb9622bed4055cab4fef5d79e5 /src/runit.c
parenta7cbf375a3f7407b8c809a27ea3f241b0a2248ec (diff)
downloadrunit-2ff91a26d1ba9d7d374c8216dbbf0d12465f500a.tar.gz
runit-2ff91a26d1ba9d7d374c8216dbbf0d12465f500a.tar.xz
runit-2ff91a26d1ba9d7d374c8216dbbf0d12465f500a.zip
runs on openbsd 2.9.
Diffstat (limited to 'src/runit.c')
-rw-r--r--src/runit.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/runit.c b/src/runit.c
index 4278fd5..d734de7 100644
--- a/src/runit.c
+++ b/src/runit.c
@@ -3,6 +3,7 @@
 
 #include <sys/types.h>
 #include <sys/reboot.h>
+#include <sys/ioctl.h>
 #include <signal.h>
 #include <unistd.h>
 
@@ -54,6 +55,7 @@ int main (int argc, const char * const *argv, const char * const *envp) {
   int st;
   iopause_fd x;
   char ch;
+  int ttyfd;
 
   if (getpid() != 1) {
     strerr_die2x(111, FATAL, "must be run as process no 1.");
@@ -72,6 +74,15 @@ int main (int argc, const char * const *argv, const char * const *envp) {
   sig_block(sig_pipe);
   sig_block(sig_term);
 
+  /* console */
+  if ((ttyfd =open_write("/dev/console")) != -1) {
+    if (ioctl(ttyfd, TIOCSCTTY, (char *)NULL) != -1) {
+      dup2(ttyfd, 0); dup2(ttyfd, 1); dup2(ttyfd, 2);
+      if (ttyfd > 2)
+	close(ttyfd);
+    }
+  }
+
   /* create selfpipe */
   while (pipe(selfpipe) == -1) {
     strerr_warn2(FATAL, "unable to create selfpipe, pausing: ", &strerr_sys);
@@ -82,14 +93,20 @@ int main (int argc, const char * const *argv, const char * const *envp) {
   ndelay_on(selfpipe[0]);
   ndelay_on(selfpipe[1]);
 
+#ifdef RB_DISABLE_CAD
   /* activate ctrlaltdel handling */
-  reboot(0);
+  if (RB_DISABLE_CAD == 0)
+    reboot(0);
+#endif
 
   strerr_warn3(INFO, "$Id$",
 	       ": booting.", 0);
 
   /* runit */
   for (st =0; st < 3; st++) {
+    /*
+      if (st == 2) logwtmp("~", "reboot", "");
+    */
     while ((pid =fork()) == -1) {
       strerr_warn4(FATAL, "unable to fork for \"", stage[st], "\" pausing: ",
 		   &strerr_sys);
@@ -164,6 +181,14 @@ int main (int argc, const char * const *argv, const char * const *envp) {
 #endif
 	continue;
       }
+      /* console */
+      if ((ttyfd =open_write("/dev/console")) != -1) {
+	if (ioctl(ttyfd, TIOCSCTTY, (char *)NULL) != -1) {
+	  dup2(ttyfd, 0); dup2(ttyfd, 1); dup2(ttyfd, 2);
+	  if (ttyfd > 2)
+	    close(ttyfd);
+	}
+      }
       if (st != 1) {
 	strerr_warn2(WARNING, "signals only work in stage 2.", 0);
 	sigc =sigi =0;
@@ -250,6 +275,9 @@ int main (int argc, const char * const *argv, const char * const *envp) {
     }
   }
 
+  for (;;) {
+    sig_pause();
+  }
   /* not reached */
   strerr_die2x(0, INFO, "exit.");
   return(0);