summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--doc/index.html96
-rw-r--r--doc/upgrade.html2
-rw-r--r--man/runsv.89
-rw-r--r--package/CHANGES11
-rw-r--r--src/runit.c196
-rw-r--r--src/runsv.c30
6 files changed, 174 insertions, 170 deletions
diff --git a/doc/index.html b/doc/index.html
index 5a9dd63..2474ca5 100644
--- a/doc/index.html
+++ b/doc/index.html
@@ -110,6 +110,55 @@ automatically.
 <i>runit</i> is optimized for reliability and small size.
 The amount of code in process no 1 should be minimal.
 <hr>
+See <a href="install.html">How to install runit</a> for installing
+<i>runit</i>, and <a href="replaceinit.html">How to replace init</a> for
+configuring <i>runit</i> to run as process no 1.
+See <a href="useinit.html">How to use with current init</a> if you want to
+use <i>runit</i> without replacing the current init scheme.
+Please read the list of
+<a href="faq.html">Frequently asked questions with answers</a>.
+<hr>
+If <i>runit</i> on Linux is compiled and linked with the
+<a href="http://www.fefe.de/dietlibc/">dietlibc</a>, it yields in a
+statically linked <tt>runit</tt> binary of 8.5k size and this
+<tt>ps axuw</tt> output on my system:
+<pre>
+ USER       PID %CPU %MEM   VSZ  RSS TTY      STAT START   TIME COMMAND
+ root         1  0.0  0.0    20   16 ?        S     2002   0:02 runit
+</pre>
+I recommend doing this; for instructions, see
+<a href="usedietlibc.html">How to use dietlibc</a>.
+<hr>
+The following distributions are known to include or package <i>runit</i>:
+<ul>
+<li><a href="http://packages.qa.debian.org/runit">
+Debian GNU/Linux</a> (as alternative init scheme)
+<li><a href="http://http://www.freshports.org/sysutils/runit/">
+FreeBSD</a>
+<li><a href="http://www.openbsd.org/cgi-bin/cvsweb/ports/sysutils/runit/">
+OpenBSD</a>
+<li><a href="http://pkgsrc.se/wip/runit/">
+NetBSD</a>
+<li><a href="http://annvix.org/">
+Annvix</a> (as default init scheme)
+<li><a href="http://packages.ubuntu.com/runit">
+Ubuntu</a> (as alternative init scheme)
+<li><a href="http://packages.gentoo.org/search/?sstring=runit">
+Gentoo</a>
+<li><a href="http://www.smeserver.org/">
+SME server</a>
+<li><a href="http://www.opensde.org/">
+OpenSDE</a>
+<li><a href="http://www.t2-project.org/">
+T2</a>
+<li><a href="http://zinux.cynicbytrade.com/">
+Zinux Linux</a> (as default init scheme)
+<li><a href="http://www.gobolinux.org/">
+GoboLinux</a>
+</ul>
+If you know of more distributions, please
+<a href="mailto:supervision@list.skarnet.org">let me know</a>.
+<hr>
 <b><i>runit</i> in use</b>:
 I replaced <i>sysvinit</i> successfully with <i>runit</i> on several server
 systems and a laptop running Debian/GNU Linux sarge, woody, and potato.
@@ -178,56 +227,9 @@ Here is an example:
                           `-tcpsvd---bincimap-up---bincimapd
 </pre>
 <hr>
-See <a href="install.html">How to install runit</a> for installing
-<i>runit</i>, and <a href="replaceinit.html">How to replace init</a> for
-configuring <i>runit</i> to run as process no 1.
-See <a href="useinit.html">How to use with current init</a> if you want to
-use <i>runit</i> without replacing the current init scheme.
-<hr>
-If <i>runit</i> on Linux is compiled and linked with the
-<a href="http://www.fefe.de/dietlibc/">dietlibc</a>, it yields in a
-statically linked <tt>runit</tt> binary of 8.5k size and this
-<tt>ps axuw</tt> output on my system:
-<pre>
-  USER       PID %CPU %MEM   VSZ  RSS TTY      STAT START   TIME COMMAND
-  root         1  0.0  0.0    20   16 ?        S     2002   0:02 runit
-</pre>
-I recommend doing this; for instructions, see
-<a href="usedietlibc.html">How to use dietlibc</a>.
-<hr>
 See <a href="http://smarden.org/runit/">http://smarden.org/runit/</a>
 for recent informations.
 <hr>
-The following distributions are known to include or package <i>runit</i>:
-<ul>
-<li><a href="http://packages.qa.debian.org/runit">
-Debian GNU/Linux</a> (as alternative init scheme)
-<li><a href="http://http://www.freshports.org/sysutils/runit/">
-FreeBSD</a>
-<li><a href="http://www.openbsd.org/cgi-bin/cvsweb/ports/sysutils/runit/">
-OpenBSD</a>
-<li><a href="http://pkgsrc.se/wip/runit/">
-NetBSD</a>
-<li><a href="http://annvix.org/">
-Annvix</a> (as default init scheme)
-<li><a href="http://packages.ubuntu.com/runit">
-Ubuntu</a> (as alternative init scheme)
-<li><a href="http://packages.gentoo.org/search/?sstring=runit">
-Gentoo</a>
-<li><a href="http://www.smeserver.org/">
-SME server</a>
-<li><a href="http://www.opensde.org/">
-OpenSDE</a>
-<li><a href="http://www.t2-project.org/">
-T2</a>
-<li><a href="http://zinux.cynicbytrade.com/">
-Zinux Linux</a> (as default init scheme)
-<li><a href="http://www.gobolinux.org/">
-GoboLinux</a>
-</ul>
-If you know of more distributions, please
-<a href="mailto:supervision@list.skarnet.org">let me know</a>.
-<hr>
 Related links:
 <ul>
 <li><a href="http://www.fefe.de/minit/">
diff --git a/doc/upgrade.html b/doc/upgrade.html
index f2205a3..f132d84 100644
--- a/doc/upgrade.html
+++ b/doc/upgrade.html
@@ -9,7 +9,7 @@
 <hr>
 <h1>runit - upgrading from previous versions</h1>
 <hr>
-<h3>1.6.0 to 1.7.0 or 1.7.1</h3>
+<h3>1.6.0 to 1.7.x</h3>
 With this version the <a href="runsv.8.html">runsv</a> program starts to
 run the ./finish script with two arguments, the exit code and the exit
 status of the just finished ./run script.
diff --git a/man/runsv.8 b/man/runsv.8
index 824de2f..53f1b1b 100644
--- a/man/runsv.8
+++ b/man/runsv.8
@@ -159,14 +159,9 @@ This command is ignored if it is given to
 Example: to send a TERM signal to the socklog-unix service, either do
   # sv term /var/service/socklog-unix
  or
-  # echo \-n t >/var/service/socklog-unix/supervise/control
+  # printf t >/var/service/socklog-unix/supervise/control
 .P
-If
-.BR echo (1)
-on your systems does not provide the \-n option, leave it out,
-.B runsv
-ignores unknown characters written to the control pipe.
-.BR echo (1)
+.BR printf (1)
 usually blocks if no
 .B runsv
 process is running in the service directory.
diff --git a/package/CHANGES b/package/CHANGES
index 8b90493..2c572f1 100644
--- a/package/CHANGES
+++ b/package/CHANGES
@@ -1,8 +1,15 @@
-  * doc/index.html: add list of distributions
+1.7.2
+
+  * doc/index.html: add list of distributions that are known to include
+    or package runit; some reordering.
   * doc/replaceinit.html: point to faq.html#create, faq.html#tell (thx
     David Kaufman).
   * doc/runscripts.html: point to faq.html#createlog.
-  
+  * runit.c: fix arguments to wait_pid() after fork for reboot_system()
+    (thx Jan Kampe).
+  * man/runsv.8: suggest printf t instead of echo -n t.
+  * runsv.c: really don't act on commands in state finish; minor.
+
 1.7.1
 Sat, 04 Nov 2006 19:23:29 +0000
   * chpst.c, uidgid.c, uidgid.h: support numerical uid gid through
diff --git a/src/runit.c b/src/runit.c
index 46e10b7..3d244ab 100644
--- a/src/runit.c
+++ b/src/runit.c
@@ -90,14 +90,14 @@ int main (int argc, const char * const *argv, char * const *envp) {
 #endif
 
   strerr_warn3(INFO, "$Id$",
-	       ": booting.", 0);
+               ": 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);
+                   &strerr_sys);
       sleep(5);
     }
     if (!pid) {
@@ -107,18 +107,18 @@ int main (int argc, const char * const *argv, char * const *envp) {
 
       /* stage 1 gets full control of console */
       if (st == 0) {
-	if ((ttyfd =open("/dev/console", O_RDWR)) != -1) {
+        if ((ttyfd =open("/dev/console", O_RDWR)) != -1) {
 #ifdef TIOCSCTTY 
           ioctl(ttyfd, TIOCSCTTY, (char *)0);
 #endif
-	  dup2(ttyfd, 0);
-	  if (ttyfd > 2) close(ttyfd);
-	}
-	else
-	  strerr_warn2(WARNING, "unable to open /dev/console: ", &strerr_sys);
+          dup2(ttyfd, 0);
+          if (ttyfd > 2) close(ttyfd);
+        }
+        else
+          strerr_warn2(WARNING, "unable to open /dev/console: ", &strerr_sys);
       }
       else
-	setsid();
+        setsid();
 
       sig_unblock(sig_alarm);
       sig_unblock(sig_child);
@@ -162,119 +162,119 @@ int main (int argc, const char * const *argv, char * const *envp) {
 
       /* reget stderr */
       if ((ttyfd =open_write("/dev/console")) != -1) {
-	dup2(ttyfd, 2);
-	if (ttyfd > 2) close(ttyfd);
+        dup2(ttyfd, 2);
+        if (ttyfd > 2) close(ttyfd);
       }
 
       if (child == pid) {
-	if (wait_exitcode(wstat) != 0) {
-	  if (wait_crashed(wstat))
-	    strerr_warn3(WARNING, "child crashed: ", stage[st], 0);
-	  else
-	    strerr_warn3(WARNING, "child failed: ", stage[st], 0);
-	  if (st == 0)
-	    /* this is stage 1 */
-	    if (wait_crashed(wstat) || (wait_exitcode(wstat) == 100)) {
-	      strerr_warn3(INFO, "leave stage: ", stage[st], 0);
-	      strerr_warn2(WARNING, "skipping stage 2...", 0);
-	      st++;
-	      break;
-	    }
-	  if (st == 1)
-	    /* this is stage 2 */
-	    if (wait_crashed(wstat) || (wait_exitcode(wstat) == 111)) {
-	      strerr_warn2(WARNING, "killing all processes in stage 2...", 0);
-	      kill(-pid, 9);
-	      sleep(5);
-	      strerr_warn2(WARNING, "restarting.", 0);
-	      st--;
-	      break;
-	    }
-	}
-	strerr_warn3(INFO, "leave stage: ", stage[st], 0);
-	break;
+        if (wait_exitcode(wstat) != 0) {
+          if (wait_crashed(wstat))
+            strerr_warn3(WARNING, "child crashed: ", stage[st], 0);
+          else
+            strerr_warn3(WARNING, "child failed: ", stage[st], 0);
+          if (st == 0)
+            /* this is stage 1 */
+            if (wait_crashed(wstat) || (wait_exitcode(wstat) == 100)) {
+              strerr_warn3(INFO, "leave stage: ", stage[st], 0);
+              strerr_warn2(WARNING, "skipping stage 2...", 0);
+              st++;
+              break;
+            }
+          if (st == 1)
+            /* this is stage 2 */
+            if (wait_crashed(wstat) || (wait_exitcode(wstat) == 111)) {
+              strerr_warn2(WARNING, "killing all processes in stage 2...", 0);
+              kill(-pid, 9);
+              sleep(5);
+              strerr_warn2(WARNING, "restarting.", 0);
+              st--;
+              break;
+            }
+        }
+        strerr_warn3(INFO, "leave stage: ", stage[st], 0);
+        break;
       }
       if (child > 0) {
-	/* collect terminated children */
-	write(selfpipe[1], "", 1);
-	continue;
+        /* collect terminated children */
+        write(selfpipe[1], "", 1);
+        continue;
       }
 
       /* sig? */
       if (!sigc  && !sigi) {
 #ifdef DEBUG
-	strerr_warn2(WARNING, "poll: ", &strerr_sys);
+        strerr_warn2(WARNING, "poll: ", &strerr_sys);
 #endif
-	continue;
+        continue;
       }
       if (st != 1) {
-	strerr_warn2(WARNING, "signals only work in stage 2.", 0);
-	sigc =sigi =0;
-	continue;
+        strerr_warn2(WARNING, "signals only work in stage 2.", 0);
+        sigc =sigi =0;
+        continue;
       }
       if (sigi && (stat(CTRLALTDEL, &s) != -1) && (s.st_mode & S_IXUSR)) {
-	strerr_warn2(INFO, "ctrl-alt-del request...", 0);
-	prog[0] =CTRLALTDEL; prog[1] =0;
-	while ((pid2 =fork()) == -1) {
-	  strerr_warn4(FATAL, "unable to fork for \"", CTRLALTDEL,
-		       "\" pausing: ", &strerr_sys);
-	  sleep(5);
-	}
-	if (!pid2) {
-	  /* child */
-	  strerr_warn3(INFO, "enter stage: ", prog[0], 0);
-	  execve(*prog, (char *const *) prog, envp);
-	  strerr_die3sys(0, FATAL, "could not start child: ", prog[0]);
-	}
-	if (wait_pid(&wstat, pid2) == -1)
-	  strerr_warn2(FATAL, "wait_pid: ", &strerr_sys);
-	if (wait_crashed(wstat))
-	  strerr_warn3(WARNING, "child crashed: ", CTRLALTDEL, 0);
-	strerr_warn3(INFO, "leave stage: ", prog[0], 0);
-	sigi =0;
-	sigc++;
+        strerr_warn2(INFO, "ctrl-alt-del request...", 0);
+        prog[0] =CTRLALTDEL; prog[1] =0;
+        while ((pid2 =fork()) == -1) {
+          strerr_warn4(FATAL, "unable to fork for \"", CTRLALTDEL,
+                       "\" pausing: ", &strerr_sys);
+          sleep(5);
+        }
+        if (!pid2) {
+          /* child */
+          strerr_warn3(INFO, "enter stage: ", prog[0], 0);
+          execve(*prog, (char *const *) prog, envp);
+          strerr_die3sys(0, FATAL, "could not start child: ", prog[0]);
+        }
+        if (wait_pid(&wstat, pid2) == -1)
+          strerr_warn2(FATAL, "wait_pid: ", &strerr_sys);
+        if (wait_crashed(wstat))
+          strerr_warn3(WARNING, "child crashed: ", CTRLALTDEL, 0);
+        strerr_warn3(INFO, "leave stage: ", prog[0], 0);
+        sigi =0;
+        sigc++;
       }
       if (sigc && (stat(STOPIT, &s) != -1) && (s.st_mode & S_IXUSR)) {
-	int i;
-	/* unlink(STOPIT); */
-	chmod(STOPIT, 0);
+        int i;
+        /* unlink(STOPIT); */
+        chmod(STOPIT, 0);
 
-	/* kill stage 2 */
+        /* kill stage 2 */
 #ifdef DEBUG
-	strerr_warn2(WARNING, "sending sigterm...", 0);
+        strerr_warn2(WARNING, "sending sigterm...", 0);
 #endif
-	kill(pid, sig_term);
-	i =0;
-	while (i < 5) {
-	  if ((child =wait_nohang(&wstat)) == pid) {
+        kill(pid, sig_term);
+        i =0;
+        while (i < 5) {
+          if ((child =wait_nohang(&wstat)) == pid) {
 #ifdef DEBUG
-	    strerr_warn2(WARNING, "stage 2 terminated.", 0);
+            strerr_warn2(WARNING, "stage 2 terminated.", 0);
 #endif
-	    pid =0;
-	    break;
-	  }
-	  if (child) continue;
-	  if (child == -1) 
-	    strerr_warn2(WARNING, "wait_nohang: ", &strerr_sys);
+            pid =0;
+            break;
+          }
+          if (child) continue;
+          if (child == -1) 
+            strerr_warn2(WARNING, "wait_nohang: ", &strerr_sys);
 #ifdef DEBUG
-	  strerr_warn2(WARNING, "waiting...", 0);
+          strerr_warn2(WARNING, "waiting...", 0);
 #endif
-	  sleep(1);
-	  i++;
-	}
-	if (pid) {
-	  /* still there */
-	  strerr_warn2(WARNING,
-		       "stage 2 not terminated, sending sigkill...", 0);
-	  kill(pid, 9);
-	  if (wait_pid(&wstat, pid) == -1)
-	    strerr_warn2(WARNING, "wait_pid: ", &strerr_sys);
-	}
-	sigc =0;
-	strerr_warn3(INFO, "leave stage: ", stage[st], 0);
+          sleep(1);
+          i++;
+        }
+        if (pid) {
+          /* still there */
+          strerr_warn2(WARNING,
+                       "stage 2 not terminated, sending sigkill...", 0);
+          kill(pid, 9);
+          if (wait_pid(&wstat, pid) == -1)
+            strerr_warn2(WARNING, "wait_pid: ", &strerr_sys);
+        }
+        sigc =0;
+        strerr_warn3(INFO, "leave stage: ", stage[st], 0);
 
-	/* enter stage 3 */
-	break;
+        /* enter stage 3 */
+        break;
       }
       sigc =sigi =0;
 #ifdef DEBUG
@@ -330,7 +330,7 @@ int main (int argc, const char * const *argv, char * const *envp) {
   break;
   default:
   sig_unblock(sig_child);
-  while (wait_pid(pid, 0, 0) == -1);
+  while (wait_pid(0, pid) == -1);
   }
 #endif
 
diff --git a/src/runsv.c b/src/runsv.c
index db36422..8e60417 100644
--- a/src/runsv.c
+++ b/src/runsv.c
@@ -324,58 +324,58 @@ int ctrl(struct svdir *s, char c) {
   case 'd': /* down */
     s->want =W_DOWN;
     update_status(s);
-    if (s->pid && s->state != S_FINISH) stopservice(s);
+    if (s->state == S_RUN) stopservice(s);
     break;
   case 'u': /* up */
     s->want =W_UP;
     update_status(s);
-    if (s->pid == 0) startservice(s);
+    if (s->state == S_DOWN) startservice(s);
     break;
   case 'x': /* exit */
     if (s->islog) break;
     s->want =W_EXIT;
     update_status(s);
-    if (s->pid && s->state != S_FINISH) stopservice(s);
+    if (s->state == S_RUN) stopservice(s);
     break;
   case 't': /* sig term */
-    if (s->pid && s->state != S_FINISH) stopservice(s);
+    if (s->state == S_RUN) stopservice(s);
     break;
   case 'k': /* sig kill */
-    if (s->pid && ! custom(s, c)) kill(s->pid, SIGKILL);
+    if ((s->state == S_RUN) && ! custom(s, c)) kill(s->pid, SIGKILL);
     s->state =S_DOWN;
     break;
   case 'p': /* sig pause */
-    if (s->pid && ! custom(s, c)) kill(s->pid, SIGSTOP);
+    if ((s->state == S_RUN) && ! custom(s, c)) kill(s->pid, SIGSTOP);
     s->ctrl |=C_PAUSE;
     update_status(s);
     break;
   case 'c': /* sig cont */
-    if (s->pid && ! custom(s, c)) kill(s->pid, SIGCONT);
+    if ((s->state == S_RUN) && ! custom(s, c)) kill(s->pid, SIGCONT);
     if (s->ctrl & C_PAUSE) s->ctrl &=~C_PAUSE;
     update_status(s);
     break;
   case 'o': /* once */
     s->want =W_DOWN;
     update_status(s);
-    if (! s->pid) startservice(s);
+    if (s->state == S_DOWN) startservice(s);
     break;
   case 'a': /* sig alarm */
-    if (s->pid && ! custom(s, c)) kill(s->pid, SIGALRM);
+    if ((s->state == S_RUN) && ! custom(s, c)) kill(s->pid, SIGALRM);
     break;
   case 'h': /* sig hup */
-    if (s->pid && ! custom(s, c)) kill(s->pid, SIGHUP);
+    if ((s->state == S_RUN) && ! custom(s, c)) kill(s->pid, SIGHUP);
     break;
   case 'i': /* sig int */
-    if (s->pid && ! custom(s, c)) kill(s->pid, SIGINT);
+    if ((s->state == S_RUN) && ! custom(s, c)) kill(s->pid, SIGINT);
     break;
   case 'q': /* sig quit */
-    if (s->pid && ! custom(s, c)) kill(s->pid, SIGQUIT);
+    if ((s->state == S_RUN) && ! custom(s, c)) kill(s->pid, SIGQUIT);
     break;
   case '1': /* sig usr1 */
-    if (s->pid && ! custom(s, c)) kill(s->pid, SIGUSR1);
+    if ((s->state == S_RUN) && ! custom(s, c)) kill(s->pid, SIGUSR1);
     break;
   case '2': /* sig usr2 */
-    if (s->pid && ! custom(s, c)) kill(s->pid, SIGUSR2);
+    if ((s->state == S_RUN) && ! custom(s, c)) kill(s->pid, SIGUSR2);
     break;
   }
   return(1);
@@ -584,7 +584,7 @@ int main(int argc, char **argv) {
 
     if (sigterm) { ctrl(&svd[0], 'x'); sigterm =0; }
 
-    if (svd[0].want == W_EXIT && svd[0].state == S_DOWN) {
+    if ((svd[0].want == W_EXIT) && (svd[0].state == S_DOWN)) {
       if (svd[1].pid == 0) _exit(0);
       if (svd[1].want != W_EXIT) {
         svd[1].want =W_EXIT;