commit 540ef73ee9c9ee3ebb046e6f86bec438bdd131d1
parent 833db9a26c5db5b1e4ddbf0cb330675754810416
Author: Gerrit Pape <pape@smarden.org>
Date: Tue, 25 Feb 2003 12:51:38 +0000
* doc/benefits.html: new.
* doc/index.html, doc/upgrade.html: adapt.
* etc/*/1, etc/*/3, etc/*/ctrlaltdel: set permissions on the magic files
instead of creating and removing them (can make them symbolic links
now); set PATH.
* runit.h: new; centralize runit's compiled in magic file names.
* runit.c: check permissions of magic files instead of sole existence;
conditionally call reboot(RB_AUTOBOOT), reboot(RB_POWER_OFF),
reboot(RB_HALT_SYSTEM) if possible; code cleanup.
* runit-init.c: set permissions on magic files instead of creating or
removing them; code cleanup.
* runsvdir.c: detect and tolerate system time warp; code cleanup.
* runsv.c, runsvchdir.c, runsvctrl.c, runsvstat.c, svwaitdown.c,
svwaitup.c, utmpset.c: code cleanup.
0.8.0.
Diffstat:
31 files changed, 487 insertions(+), 324 deletions(-)
diff --git a/Makefile b/Makefile
@@ -1,6 +1,6 @@
DESTDIR=
-PACKAGE=runit-0.7.2
+PACKAGE=runit-0.8.0
DIRS=doc man etc package src
MANPAGES=runit.8 runit-init.8 runsvdir.8 runsv.8 svwaitdown.8 svwaitup.8 \
utmpset.8 runsvchdir.8 runsvstat.8 runsvctrl.8
diff --git a/debian/changelog b/debian/changelog
@@ -1,3 +1,9 @@
+runit (0.8.0-1) unstable; urgency=low
+
+ * new upstream version.
+
+ -- Gerrit Pape <pape@smarden.org> Tue, 25 Feb 2003 13:50:04 +0100
+
runit (0.7.2-2) unstable; urgency=low
* debian/rules: resurrect copyright file.
diff --git a/debian/rules b/debian/rules
@@ -26,11 +26,11 @@ build-arch-stamp:
# Add here command to compile/build the package.
# $(MAKE)
- tar xfzvp runit-0.7.2.tar.gz
+ tar xfzvp runit-0.8.0.tar.gz
( \
set -e; \
- cd admin/runit-0.7.2/src; \
- ln -s runit-0.7.2 runit; mv runit ../..; \
+ cd admin/runit-0.8.0/src; \
+ ln -s runit-0.8.0 runit; mv runit ../..; \
echo 'diet -v -Os gcc -O2 -Wall' >conf-cc; \
echo 'diet -v -Os gcc -s -Os -pipe' >conf-ld; \
$(MAKE); \
@@ -74,26 +74,26 @@ install: build
# $(MAKE) install DESTDIR=$(CURDIR)/debian/runit
# runit
- install -m0500 admin/runit-0.7.2/src/runit \
+ install -m0500 admin/runit-0.8.0/src/runit \
$(CURDIR)/debian/runit/sbin/runit
- install -m0500 admin/runit-0.7.2/src/runit-init \
+ install -m0500 admin/runit-0.8.0/src/runit-init \
$(CURDIR)/debian/runit/sbin/runit-init
- install -m0755 admin/runit-0.7.2/src/runsvdir \
+ install -m0755 admin/runit-0.8.0/src/runsvdir \
$(CURDIR)/debian/runit/usr/bin/runsvdir
- install -m0755 admin/runit-0.7.2/src/runsv \
+ install -m0755 admin/runit-0.8.0/src/runsv \
$(CURDIR)/debian/runit/usr/bin/runsv
- install -m0755 admin/runit-0.7.2/src/runsvchdir \
+ install -m0755 admin/runit-0.8.0/src/runsvchdir \
$(CURDIR)/debian/runit/usr/sbin/runsvchdir
- install -m0755 admin/runit-0.7.2/src/svwaitdown \
+ install -m0755 admin/runit-0.8.0/src/svwaitdown \
$(CURDIR)/debian/runit/usr/bin/svwaitdown
- install -m0755 admin/runit-0.7.2/src/svwaitup \
+ install -m0755 admin/runit-0.8.0/src/svwaitup \
$(CURDIR)/debian/runit/usr/bin/svwaitup
- install -m0755 admin/runit-0.7.2/src/utmpset \
+ install -m0755 admin/runit-0.8.0/src/utmpset \
$(CURDIR)/debian/runit/usr/sbin/utmpset
- install -m0755 admin/runit-0.7.2/src/runsvstat \
+ install -m0755 admin/runit-0.8.0/src/runsvstat \
$(CURDIR)/debian/runit/usr/bin/runsvstat
- install -m0755 admin/runit-0.7.2/src/runsvctrl \
+ install -m0755 admin/runit-0.8.0/src/runsvctrl \
$(CURDIR)/debian/runit/usr/bin/runsvctrl
# install -m0700 debian/1 \
@@ -146,7 +146,7 @@ binary-arch: build install
# dh_installexamples -a
dh_installman -a admin/runit/man/*.8
# dh_undocumented -a
- dh_installchangelogs -a admin/runit-0.7.2/package/CHANGES
+ dh_installchangelogs -a admin/runit-0.8.0/package/CHANGES
dh_strip -a
# dh_link -a
dh_compress -a
diff --git a/doc/benefits.html b/doc/benefits.html
@@ -0,0 +1,191 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<title>runit - benefits</title>
+</head>
+<body>
+<a href="http://smarden.org/pape/">G. Pape</a><br>
+<a href="index.html">runit</a><br>
+<hr>
+<h1>runit - benefits</h1>
+<hr>
+<a href="#supervision">Service supervision</a><br>
+<a href="#state">Clean process state</a><br>
+<a href="#log">Reliable logging facility</a><br>
+<a href="#fast">Fast system boot up and shutdown</a><br>
+<a href="#portability">Portability</a><br>
+<a href="#packaging">Packaging friendly</a><br>
+<a href="#smallcode">Small code size</a>
+
+<hr>
+<i>runit</i>'s service concept is heavily based on the
+<a href="http://cr.yp.to/daemontools.html">daemontools</a>' one, and mostly
+compatible with it. The benefits described in the
+<a href="http://cr.yp.to/daemontools/faq/create.html#why">daemontools faq</a>
+also apply to <i>runit</i>'s service supervision.
+Many of the benefits described here also apply to the
+<a href="http://cr.yp.to/daemontools.html">daemontools</a> package.
+Some are described in both places.
+
+<hr>
+<a name="supervision"><h3>Service supervision</h3></a>
+Each service is associated with a <i>service directory</i>, and each
+service daemon runs as a child process of a supervising
+<a href="runsv.8.html">runsv</a> process running in this directory.
+The <a href="runsv.8.html">runsv</a> program provides a reliable interface
+for signalling the service daemon and controlling the service and supervisor.
+Normally the <a href="runsvctrl.8.html">runsvctrl</a> program is used to
+send commands through this interface.
+The <a href="runsvstat.8.html">runsvstat</a> program can be used to print
+status information about the service.
+<p>
+The <a href="runsv.8.html">runsv</a> program supervises the corresponding
+service daemon.
+By default a service is defined to be up, that means, if the service daemon
+dies, it will be restarted.
+Of course you can <a href="runsvctrl.8.html">tell runsv</a> otherwise.
+<p>
+You don't have such a control interface with sysv init for example.
+Using the control interface to send signals to the service daemon saves a lot
+of extra (non trivial) work to reliably find out the daemon's process id.
+
+<hr>
+<a name="state"><h3>Clean process state</h3></a>
+<i>runit</i> guarantees each service a clean process state, no matter if the
+service is activated for the first time, reactivated, or simply restarted.
+This means that the service always is started with the same environment,
+resource limits, open file descriptors, and controlling terminals.
+<p>
+You don't necessarily have that with sysv init scripts for example.
+It requires a carefully written init script that reliably cleans up and sets
+the initial process state before starting the service daemon.
+This adds even more complexity to the init script in comparison with a run
+script used by <i>runit</i>.
+Many of today's init scripts don't provide a clean process state, here is
+an example on what could happen:
+<pre>
+ # /etc/init.d/foo-daemon start
+ Starting foo daemon: food.
+ #
+</pre>
+Fine.
+Everything works, nothing to worry about.
+After rebooting the system this shows up on the screen:
+<pre>
+ ...
+ Starting foo daemon: food: command not found
+ failed.
+ ...
+</pre>
+The <tt>food</tt> program is installed in <tt>/opt/foo/bin/</tt>. When
+starting the service for the first time using the init script, the
+<tt>PATH</tt> environment variable contained <tt>/opt/foo/bin</tt>.
+After reboot init started the service using the init script, but with a
+different value for the <tt>PATH</tt> variable, not containing
+<tt>/opt/foo/bin</tt>.
+Of course the init script should have set <tt>PATH</tt> before starting the
+daemon; the problem is that it worked in the first place, and that the error
+didn't show up until system reboot.
+<p>
+With bad init scripts miraculous things could also happen when just doing
+<pre>
+ # /etc/init.d/foo-daemon restart
+</pre>
+at the command line.
+
+<hr>
+<a name="log"><h3>Reliable logging facility</h3></a>
+The <a href="runsv.8.html">runsv</a> program provides a reliable logging
+facility for the service daemon.
+If configured, <a href="runsv.8.html">runsv</a> creates a pipe, starts and
+supervises an additional log service, redirects the log daemon's standard
+input to read from the pipe, and redirects the service daemon's standard
+output to write to the pipe.
+Restarting the service does not require restarting the log service.
+A good choice for a log daemon is
+<a href="http://cr.yp.to/daemontools/multilog.html">multilog</a>.
+<p>
+The service daemon and the log daemon can run with different process states,
+and under different user ids.
+<i>runit</i> supports easy and reliable logging for service daemons running
+chroot'ed.
+<p>
+If <a href="runsv.8.html">runsv</a> is told to shutdown a service, e.g. at
+system shutdown, it ensures that the log service stays up as long as the
+corresponding service daemon is running and possibly writing to the log.
+
+<hr>
+<a name="fast"><h3>Fast system boot up and shutdown</h3></a>
+After the system's one time tasks (stage 1) are done, the system services
+are started up in parallel.
+The operating system's process scheduler takes care of having the services
+available as soon as possible.
+<p>
+On system shutdown, stage 3 uses <a href="runsv.8.html">runsv</a>'s control
+interface to wait until each service daemon is terminated and all logs are
+written.
+Again, services are taken down in parallel.
+As soon as all services are done, system halt or system reboot is initiated.
+
+<hr>
+<a name="portability"><h3>Portability</h3></a>
+<i>runit</i> comes ready-to-run for Debian GNU/Linux and BSD systems, and
+can easily be configured to run on other UNIX systems.
+The UNIX system's one time initialization tasks and tasks to shutdown the
+system must be identified and <i>runit</i>'s stages 1 and 3 configured
+accordingly.
+<p>
+Stages 1 and 3 handle one time tasks.
+They only run for short and exit soon.
+Stage 2 handles the system's uptime tasks (via the
+<a href="runsvdir.8.html">runsvdir</a> program) and is running the whole
+system's uptime.
+<p>
+<i>runit</i>'s stage 2 is portable across UNIX systems.
+<i>runit</i> is well suited for server systems and embedded systems, and
+also does its job well on desktop systems.
+
+<hr>
+<a name="packaging"><h3>Packaging friendly</h3></a>
+<i>runit</i>'s stages 1 and 3 are distribution specific.
+They are shell scripts, and an operating system distribution with software
+package management should adapt these scripts if they need support for their
+package management.
+The
+<a href="http://packages.debian.org/unstable/admin/runit-run.html">
+runit-run</a>
+Debian package is an attempt to integrate <i>runit</i> into
+<a href="http://www.debian.org/">Debian GNU/Linux</a> as an alternative to
+the default
+<a href="http://packages.debian.org/unstable/base/sysvinit.html">
+sysvinit</a>.
+<p>
+Stage 2 already is packaging friendly:
+all a software package that provides a service needs to do is to include
+a <i>service directory</i> in the package and to provide a symbolic link
+to this directory in <tt>/service/</tt>.
+The service will be started within five seconds.
+The package's install and update scripts can use the reliable control
+interface to stop, start, restart, or send signals to the service.
+On package removal, the symbolic link simply is removed.
+<hr>
+<a name="smallcode"><h3>Small code size</h3></a>
+One of the <i>runit</i> project's principles is to keep the code size
+small. As of version 0.8.0 of <i>runit</i>, the <tt>runit.c</tt>
+source contains only about 300 lines of code; the <tt>runsvdir.c</tt>
+source is also about 300 lines of code, the <tt>runsv.c</tt> source about
+500.
+This minimizes the possibility of bugs introduced by programmer's fault,
+and makes it more easy for security related people to proofread the source
+code.
+<p>
+The <i>runit</i> programs have a very small memory footprint and do not
+allocate memory dynamically.
+
+<hr>
+<address><a href="mailto:pape@smarden.org">
+Gerrit Pape <pape@smarden.org>
+</a></address>
+<small>$Id$</small>
+</body>
+</html>
diff --git a/doc/index.html b/doc/index.html
@@ -9,7 +9,9 @@
<h1>runit - a UNIX init scheme with service supervision</h1>
<hr>
<a href="install.html">How to install runit</a><br>
-<a href="upgrade.html">Upgrading from previous versions of runit</a><br>
+<a href="upgrade.html">Upgrading from previous versions of runit</a>
+<p>
+<a href="benefits.html">Benefits</a><br>
<a href="replaceinit.html">How to replace init</a><br>
<a href="usedietlibc.html">How to use dietlibc</a>
<p>
diff --git a/doc/install.html b/doc/install.html
@@ -13,14 +13,14 @@ Check that you have the recent version of
<a href="http://cr.yp.to/daemontools.html">daemontools</a> installed.
<p>
Download
-<a href="runit-0.7.2.tar.gz">runit-0.7.2.tar.gz</a> into <tt>/package</tt>
+<a href="runit-0.8.0.tar.gz">runit-0.8.0.tar.gz</a> into <tt>/package</tt>
and unpack the archive
<pre>
# cd /package
- # gunzip runit-0.7.2.tar
- # tar -xpf runit-0.7.2.tar
- # rm runit-0.7.2.tar
- # cd admin/runit-0.7.2
+ # gunzip runit-0.8.0.tar
+ # tar -xpf runit-0.8.0.tar
+ # rm runit-0.8.0.tar
+ # cd admin/runit-0.8.0
</pre>
Compile and install the <i>runit</i> programs
<pre>
diff --git a/doc/replaceinit.html b/doc/replaceinit.html
@@ -107,7 +107,7 @@ default Unix process no 1 <i>runit</i>.
</pre>
To report success:
<pre>
- # ( uname -a ; cat /etc/runit/[123] ) | mail pape-runit-0.7.2@smarden.org
+ # ( uname -a ; cat /etc/runit/[123] ) | mail pape-runit-0.8.0@smarden.org
</pre>
<hr>
@@ -188,7 +188,7 @@ Use <b>init 6</b> to reboot and <b>init 0</b> to halt a system that runs
<p>
To report success:
<pre>
- # ( uname -a ; cat /etc/runit/[123] ) | mail pape-runit-0.7.2@smarden.org
+ # ( uname -a ; cat /etc/runit/[123] ) | mail pape-runit-0.8.0@smarden.org
</pre>
<h3>Step 5: Service migration</h3>
The goal is to migrate all services from <i>/etc/rc.*</i> scheme to the
diff --git a/doc/upgrade.html b/doc/upgrade.html
@@ -10,6 +10,15 @@
<h1>runit - upgrading from previous versions</h1>
<hr>
+<h3>0.7.x to 0.8.0</h3>
+With this version <i>runit</i>'s handling of its magic files has changed
+slightly for better support of read-only root filesystems.
+You should adapt stages 1 and 3 and <tt>ctrlaltdel</tt> to set file
+permissions on the magic files instead of creating and removing them; please
+take a look at the examples in <tt>/package/admin/runit/etc/</tt>.
+<p>
+The <a href="runit.8.html">runit</a> program now calls the <tt>reboot()</tt>
+function if possible, and if stage 3 didn't take care of this.
<h3>0.6.0 to 0.7.0 or 0.7.1 or 0.7.2</h3>
This version introduces runlevel support with the new
<a href="runsvchdir.8.html">runsvchdir</a> program. See the
diff --git a/etc/debian/1 b/etc/debian/1
@@ -1,7 +1,10 @@
#!/bin/sh
# system one time tasks
-/etc/init.d/rcS
+PATH=/command:/sbin:/bin:/usr/sbin:/usr/bin
-rm -f /etc/runit/stopit
+/etc/init.d/rcS
/etc/init.d/rmnologin
+
+touch /etc/runit/stopit
+chmod 0 /etc/runit/stopit
diff --git a/etc/debian/3 b/etc/debian/3
@@ -1,7 +1,7 @@
#!/bin/sh
exec 2>&1
-PATH=/sbin:/bin:/command
+PATH=/command:/sbin:/bin:/usr/sbin:/usr/bin
LAST=0
test -r /etc/runit/reboot && LAST=6
diff --git a/etc/debian/ctrlaltdel b/etc/debian/ctrlaltdel
@@ -1,7 +1,9 @@
#!/bin/sh
+
+PATH=/bin:/usr/bin
MSG="System is going down in 14 seconds..."
-#echo 'disabled.' ; exit
-/bin/touch /etc/runit/stopit && \
- /bin/echo "$MSG" | /usr/bin/wall
+# echo 'disabled.' ; exit
+touch /etc/runit/stopit
+chmod 100 /etc/runit/stopit && echo "$MSG" | wall
/bin/sleep 14
diff --git a/etc/freebsd/1 b/etc/freebsd/1
@@ -1,12 +1,17 @@
#!/bin/sh
# system one time tasks
+
+PATH=/command:/sbin:/bin:/usr/sbin:/usr/bin
trap : 2
trap : 3
-/bin/sh /etc/rc autoboot && exit 0
-
-# /etc/rc crashed, start emergency shell.
-echo '/etc/rc failed. Press <enter> for emergency shell...'
-read input
-/bin/sh -p
-/sbin/reboot
+sh /etc/rc autoboot
+if test $? -ne 0; then
+ # /etc/rc crashed, start emergency shell.
+ echo '/etc/rc failed. Press <enter> for emergency shell...'
+ read input
+ sh -p
+ exec reboot
+fi
+touch /etc/runit/stopit
+chmod 0 /etc/runit/stopit
diff --git a/etc/freebsd/3 b/etc/freebsd/3
@@ -1,7 +1,7 @@
#!/bin/sh
exec 2>&1
-PATH=/bin:/sbin:/command
+PATH=/command:/sbin:/bin:/usr/sbin:/usr/bin
echo 'Waiting for services to stop...'
svwaitdown -xk -t350 /service/*
diff --git a/etc/freebsd/ctrlaltdel b/etc/freebsd/ctrlaltdel
@@ -1,8 +1,9 @@
#!/bin/sh
-MSG="System is going down in 14 seconds..."
-echo 'disabled.' ; exit
+PATH=/bin:/usr/bin
+MSG="System is going down in 14 seconds..."
-/bin/touch /etc/runit/stopit && \
- /bin/echo "$MSG" | /usr/bin/wall
+# echo 'disabled.' ; exit
+touch /etc/runit/stopit
+chmod 100 /etc/runit/stopit && echo "$MSG" | wall
/bin/sleep 14
diff --git a/etc/openbsd/1 b/etc/openbsd/1
@@ -1,12 +1,17 @@
#!/bin/sh
# system one time tasks
+
+PATH=/command:/sbin:/bin:/usr/sbin:/usr/bin
trap : 2
trap : 3
-/bin/sh /etc/rc autoboot && exit 0
-
-# /etc/rc crashed, start emergency shell.
-echo '/etc/rc failed. Press <enter> for emergency shell...'
-read input
-/bin/sh -l
-/sbin/reboot
+sh /etc/rc autoboot
+if test $? -ne 0; then
+ # /etc/rc crashed, start emergency shell.
+ echo '/etc/rc failed. Press <enter> for emergency shell...'
+ read input
+ sh -l
+ exec reboot
+fi
+touch /etc/runit/stopit
+chmod 0 /etc/runit/stopit
diff --git a/etc/openbsd/3 b/etc/openbsd/3
@@ -1,7 +1,7 @@
#!/bin/sh
exec 2>&1
-PATH=/bin:/sbin:/command
+PATH=/command:/sbin:/bin:/usr/sbin:/usr/bin
echo 'Waiting for getties to stop...'
svwaitdown -xk -t14 /service/getty-*
diff --git a/etc/openbsd/ctrlaltdel b/etc/openbsd/ctrlaltdel
@@ -1,8 +1,9 @@
#!/bin/sh
-MSG="System is going down in 14 seconds..."
-echo 'disabled.' ; exit
+PATH=/bin:/usr/bin
+MSG="System is going down in 14 seconds..."
-/bin/touch /etc/runit/stopit && \
- /bin/echo "$MSG" | /usr/bin/wall
+# echo 'disabled.' ; exit
+touch /etc/runit/stopit
+chmod 100 /etc/runit/stopit && echo "$MSG" | wall
/bin/sleep 14
diff --git a/package/CHANGES b/package/CHANGES
@@ -1,3 +1,20 @@
+runit 0.8.0
+Tue, 25 Feb 2003 13:31:21 +0100
+ * doc/benefits.html: new.
+ * doc/index.html, doc/upgrade.html: adapt.
+ * etc/*/1, etc/*/3, etc/*/ctrlaltdel: set permissions on the magic files
+ instead of creating and removing them (can make them symbolic links
+ now); set PATH.
+ * runit.h: new; centralize runit's compiled in magic file names.
+ * runit.c: check permissions of magic files instead of sole existence;
+ conditionally call reboot(RB_AUTOBOOT), reboot(RB_POWER_OFF),
+ reboot(RB_HALT_SYSTEM) if possible; code cleanup.
+ * runit-init.c: set permissions on magic files instead of creating or
+ removing them; code cleanup.
+ * runsvdir.c: detect and tolerate system time warp; code cleanup.
+ * runsv.c, runsvchdir.c, runsvctrl.c, runsvstat.c, svwaitdown.c,
+ svwaitup.c, utmpset.c: code cleanup.
+
runit 0.7.2
Fri, 10 Jan 2003 21:34:13 +0100
* runsv.c: close finish script file descriptor.
diff --git a/package/COPYING b/package/COPYING
@@ -1,4 +1,4 @@
-Copyright (c) 2001-2002, Gerrit Pape
+Copyright (c) 2001-2003, Gerrit Pape
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -12,7 +12,7 @@ modification, are permitted provided that the following conditions are met:
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
-THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR IMPLIED
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
diff --git a/package/upgrade b/package/upgrade
@@ -7,9 +7,9 @@ test -d src || ( echo 'Wrong working directory.'; exit 1 )
here=`env - PATH=$PATH pwd`
parent=`dirname $here`
-echo 'Creating symlink runit -> runit-0.7.2...'
+echo 'Creating symlink runit -> runit-0.8.0...'
rm -f runit
-ln -s runit-0.7.2 runit
+ln -s runit-0.8.0 runit
mv -f runit ..
echo 'Making command links in /command...'
diff --git a/src/runit-init.c b/src/runit-init.c
@@ -1,50 +1,47 @@
#include <sys/types.h>
+#include <sys/stat.h>
#include <signal.h>
#include <unistd.h>
+#include "runit.h"
#include "strerr.h"
-#include "pathexec.h"
#include "sig.h"
#include "open.h"
#include "error.h"
#define USAGE " 0|6"
-#define WARNING "init: warning: "
#define FATAL "init: fatal: "
-
-#define RUNIT "/sbin/runit"
-#define STOPIT "/etc/runit/stopit"
-#define REBOOT "/etc/runit/reboot"
+/* #define WARNING "init: warning: " */
const char *progname;
-void usage(void) {
- strerr_die4x(1, "usage: ", progname, USAGE, "\n");
-}
+void usage(void) { strerr_die4x(1, "usage: ", progname, USAGE, "\n"); }
void runit_halt () {
- if (open_trunc(STOPIT) == -1) {
+ if (open_trunc(STOPIT) == -1)
strerr_die4sys(111, FATAL, "unable to create ", STOPIT, ": ");
- }
- if (unlink(REBOOT) == -1) {
- if (errno != error_noent) {
- strerr_die4sys(111, FATAL, "unable to remove ", REBOOT, ": ");
- }
- }
+ if (chmod(STOPIT, 0100) == -1)
+ strerr_die4sys(111, FATAL, "unable to chmod ", STOPIT, ": ");
+ if (chmod(REBOOT, 0) == -1)
+ if (errno != error_noent)
+ strerr_die4sys(111, FATAL, "unable to chmod ", REBOOT, ": ");
kill(1, sig_cont);
- exit(0);
+ _exit(0);
}
+
void runit_reboot () {
- if (open_trunc(STOPIT) == -1) {
+ if (open_trunc(STOPIT) == -1)
strerr_die4sys(111, FATAL, "unable to create ", STOPIT, ": ");
- }
- if (open_trunc(REBOOT) == -1) {
+ if (chmod(STOPIT, 0100) == -1)
+ strerr_die4sys(111, FATAL, "unable to chmod ", STOPIT, ": ");
+ if (open_trunc(REBOOT) == -1)
strerr_die4sys(111, FATAL, "unable to create ", REBOOT, ": ");
- }
+ if (chmod(REBOOT, 0100) == -1)
+ strerr_die4sys(111, FATAL, "unable to chmod ", REBOOT, ": ");
kill(1, sig_cont);
- exit(0);
+ _exit(0);
}
-int main (int argc, const char * const *argv, const char * const *envp) {
+int main (int argc, const char * const *argv, char * const *envp) {
const char *prog[2];
progname =*argv++;
@@ -54,14 +51,13 @@ int main (int argc, const char * const *argv, const char * const *envp) {
prog[0] ="runit";
/* kernel is starting init, runit does the job. */
- pathexec_run(RUNIT, (const char * const *) prog, envp);
+ execve(RUNIT, (char *const *)prog, envp);
/* serious error */
strerr_die4sys(111, FATAL, "unable to start ", prog[0], ": ");
}
if (! *argv || ! **argv) usage();
-
switch (**argv) {
case '0':
runit_halt();
@@ -70,13 +66,11 @@ int main (int argc, const char * const *argv, const char * const *envp) {
runit_reboot();
break;
case '-':
- if ((*argv)[1] == 'V') {
+ if ((*argv)[1] == 'V')
strerr_warn1("$Id$\n", 0);
- }
default:
usage();
}
-
/* not reached */
- exit(0);
+ _exit(0);
}
diff --git a/src/runit.c b/src/runit.c
@@ -1,17 +1,16 @@
-/* this requires: */
#include <poll.h>
#include <sys/types.h>
#include <sys/reboot.h>
#include <sys/ioctl.h>
+#include <sys/stat.h>
#include <signal.h>
#include <unistd.h>
#include <fcntl.h>
-
+#include "runit.h"
#include "sig.h"
#include "strerr.h"
#include "error.h"
-#include "pathexec.h"
#include "iopause.h"
#include "coe.h"
#include "ndelay.h"
@@ -24,9 +23,6 @@
#define WARNING "- runit: warning: "
#define FATAL "- runit: fatal: "
-#define STOPIT "/etc/runit/stopit"
-#define CTRLALTDEL "/etc/runit/ctrlaltdel"
-
const char * const stage[3] ={
"/etc/runit/1",
"/etc/runit/2",
@@ -44,24 +40,19 @@ void sig_int_handler (void) {
sigi++;
write(selfpipe[1], "", 1);
}
-void sig_child_handler (void) {
- write(selfpipe[1], "", 1);
-}
+void sig_child_handler (void) { write(selfpipe[1], "", 1); }
-int main (int argc, const char * const *argv, const char * const *envp) {
+int main (int argc, const char * const *argv, char * const *envp) {
const char * prog[2];
int pid, pid2;
int wstat;
- int fd;
int st;
iopause_fd x;
char ch;
int ttyfd;
+ struct stat s;
- if (getpid() != 1) {
- strerr_die2x(111, FATAL, "must be run as process no 1.");
- }
-
+ if (getpid() != 1) strerr_die2x(111, FATAL, "must be run as process no 1.");
setsid();
sig_block(sig_alarm);
@@ -77,12 +68,10 @@ int main (int argc, const char * const *argv, const char * const *envp) {
/* console */
if ((ttyfd =open_write("/dev/console")) != -1) {
- if (ioctl(ttyfd, TIOCSCTTY, (char *)NULL) != -1) {
+ if (ioctl(ttyfd, TIOCSCTTY, (char *)NULL) != -1)
strerr_warn2(WARNING, "ioctl: ", &strerr_sys);
- }
dup2(ttyfd, 0); dup2(ttyfd, 1); dup2(ttyfd, 2);
- if (ttyfd > 2)
- close(ttyfd);
+ if (ttyfd > 2) close(ttyfd);
}
/* create selfpipe */
@@ -97,13 +86,7 @@ int main (int argc, const char * const *argv, const char * const *envp) {
#ifdef RB_DISABLE_CAD
/* activate ctrlaltdel handling, glibc */
- if (RB_DISABLE_CAD == 0)
- reboot(0);
-#endif
-#ifdef LINUX_REBOOT_CMD_CAD_OFF
- /* activate ctrlaltdel handling, dietlibc */
- if (LINUX_REBOOT_CMD_CAD_OFF == 0)
- reboot(0);
+ if (RB_DISABLE_CAD == 0) reboot(0);
#endif
strerr_warn3(INFO, "$Id$",
@@ -111,9 +94,7 @@ int main (int argc, const char * const *argv, const char * const *envp) {
/* runit */
for (st =0; st < 3; st++) {
- /*
- if (st == 2) logwtmp("~", "reboot", "");
- */
+ /* if (st == 2) logwtmp("~", "reboot", ""); */
while ((pid =fork()) == -1) {
strerr_warn4(FATAL, "unable to fork for \"", stage[st], "\" pausing: ",
&strerr_sys);
@@ -121,7 +102,6 @@ int main (int argc, const char * const *argv, const char * const *envp) {
}
if (!pid) {
/* child */
-
prog[0] =stage[st];
prog[1] =0;
@@ -129,15 +109,13 @@ int main (int argc, const char * const *argv, const char * const *envp) {
if (st == 0) {
if ((ttyfd =open("/dev/console", O_RDWR)) != -1) {
dup2(ttyfd, 0);
- if (ttyfd > 2)
- close(ttyfd);
+ if (ttyfd > 2) close(ttyfd);
}
else
strerr_warn2(WARNING, "unable to open /dev/console: ", &strerr_sys);
}
- else {
+ else
setsid();
- }
sig_unblock(sig_alarm);
sig_unblock(sig_child);
@@ -151,7 +129,7 @@ int main (int argc, const char * const *argv, const char * const *envp) {
sig_unblock(sig_term);
strerr_warn3(INFO, "enter stage: ", stage[st], 0);
- pathexec_run(*prog, (const char* const *) prog, envp);
+ execve(*prog, (char *const *)prog, envp);
strerr_die3sys(0, FATAL, "could not start child: ", stage[st]);
}
@@ -170,14 +148,12 @@ int main (int argc, const char * const *argv, const char * const *envp) {
sig_block(sig_int);
read(selfpipe[0], &ch, 1);
-
child =wait_nohang(&wstat);
/* reget stderr */
if ((ttyfd =open_write("/dev/console")) != -1) {
dup2(ttyfd, 2);
- if (ttyfd > 2)
- close(ttyfd);
+ if (ttyfd > 2) close(ttyfd);
}
if (child == pid) {
@@ -221,39 +197,32 @@ int main (int argc, const char * const *argv, const char * const *envp) {
sigc =sigi =0;
continue;
}
- if (sigi && ((fd =open_read(CTRLALTDEL)) != -1)) {
- close(fd);
+ 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;
-
+ prog[0] =CTRLALTDEL; prog[1] =0;
while ((pid2 =fork()) == -1) {
- strerr_warn4(FATAL,
- "unable to fork for \"", CTRLALTDEL, "\" pausing: ",
- &strerr_sys);
+ strerr_warn4(FATAL, "unable to fork for \"", CTRLALTDEL,
+ "\" pausing: ", &strerr_sys);
sleep(5);
}
if (!pid2) {
/* child */
strerr_warn3(INFO, "enter stage: ", prog[0], 0);
- pathexec_run(*prog, (const char * const *) prog, envp);
+ execve(*prog, (char *const *) prog, envp);
strerr_die3sys(0, FATAL, "could not start child: ", prog[0]);
}
- if (wait_pid(&wstat, pid2) == -1) {
+ if (wait_pid(&wstat, pid2) == -1)
strerr_warn2(FATAL, "wait_pid: ", &strerr_sys);
- }
- if (wait_crashed(wstat)) {
+ if (wait_crashed(wstat))
strerr_warn3(WARNING, "child crashed: ", CTRLALTDEL, 0);
- }
strerr_warn3(INFO, "leave stage: ", prog[0], 0);
sigi =0;
sigc++;
}
- if (sigc && ((fd =open_write(STOPIT)) != -1)) {
+ if (sigc && (stat(STOPIT, &s) != -1) && (s.st_mode & S_IXUSR)) {
int i;
- close(fd);
- unlink(STOPIT);
+ /* unlink(STOPIT); */
+ chmod(STOPIT, 0);
/* kill stage 2 */
#ifdef DEBUG
@@ -270,9 +239,8 @@ int main (int argc, const char * const *argv, const char * const *envp) {
break;
}
if (child) continue;
- if (child == -1) {
+ if (child == -1)
strerr_warn2(WARNING, "wait_nohang: ", &strerr_sys);
- }
#ifdef DEBUG
strerr_warn2(WARNING, "waiting...", 0);
#endif
@@ -284,9 +252,8 @@ int main (int argc, const char * const *argv, const char * const *envp) {
strerr_warn2(WARNING,
"stage 2 not terminated, sending sigkill...", 0);
kill(pid, 9);
- if (wait_pid(&wstat, pid) == -1) {
+ if (wait_pid(&wstat, pid) == -1)
strerr_warn2(WARNING, "wait_pid: ", &strerr_sys);
- }
}
sigc =0;
strerr_warn3(INFO, "leave stage: ", stage[st], 0);
@@ -295,16 +262,38 @@ int main (int argc, const char * const *argv, const char * const *envp) {
break;
}
sigc =sigi =0;
-
#ifdef DEBUG
strerr_warn2(WARNING, "no request.", 0);
#endif
}
}
- for (;;) {
- sig_pause();
+#ifdef RB_AUTOBOOT
+ /* fallthrough stage 3 */
+ strerr_warn2(INFO, "sending KILL signal to all processes...", 0);
+ kill(-1, SIGKILL);
+
+ if ((stat(REBOOT, &s) != -1) && (s.st_mode & S_IXUSR)) {
+ strerr_warn2(INFO, "system reboot.", 0);
+ reboot(RB_AUTOBOOT);
+ }
+ else {
+#ifdef RB_HALT_SYSTEM
+#ifdef RB_POWER_OFF
+ strerr_warn2(INFO, "power off...", 0);
+ reboot(RB_POWER_OFF);
+ sleep(2);
+#endif
+ strerr_warn2(INFO, "system halt.", 0);
+ reboot(RB_HALT_SYSTEM);
+#else
+ strerr_warn2(INFO, "system reboot.", 0);
+ reboot(RB_AUTOBOOT);
+#endif
}
+#endif
+
+ for (;;) sig_pause();
/* not reached */
strerr_die2x(0, INFO, "exit.");
return(0);
diff --git a/src/runit.h b/src/runit.h
@@ -0,0 +1,4 @@
+#define RUNIT "/sbin/runit"
+#define STOPIT "/etc/runit/stopit"
+#define REBOOT "/etc/runit/reboot"
+#define CTRLALTDEL "/etc/runit/ctrlaltdel"
diff --git a/src/runsv.c b/src/runsv.c
@@ -57,9 +57,8 @@ int pidchanged =1;
int logpipe[2];
char *dir;
-void usage () {
- strerr_die4x(1, "usage: ", progname, USAGE, "\n");
-}
+void usage () { strerr_die4x(1, "usage: ", progname, USAGE, "\n"); }
+
void fatal(char *m) {
strerr_die5sys(111, "runsv ", dir, ": fatal: ", m, ": ");
}
@@ -69,15 +68,11 @@ void fatal2(char *m1, char *m2) {
void warn(char *m) {
strerr_warn5("runsv ", dir, ": warning: ", m, ": ", &strerr_sys);
}
-void warnx(char *m) {
- strerr_warn4("runsv ", dir, ": warning: ", m, 0);
-}
+void warnx(char *m) { strerr_warn4("runsv ", dir, ": warning: ", m, 0); }
void stopservice(struct svdir *);
-void s_child() {
- write(selfpipe[1], "", 1);
-}
+void s_child() { write(selfpipe[1], "", 1); }
void s_term() {
svd[0].want =W_EXIT;
stopservice(&svd[0]);
@@ -137,10 +132,8 @@ void update_status(struct svdir *s) {
buffer_puts(&b, "finish");
break;
}
- if (s->ctrl & C_PAUSE)
- buffer_puts(&b, ", paused");
- if (s->ctrl & C_TERM)
- buffer_puts(&b, ", got TERM");
+ if (s->ctrl & C_PAUSE) buffer_puts(&b, ", paused");
+ if (s->ctrl & C_TERM) buffer_puts(&b, ", got TERM");
switch(s->want) {
case W_DOWN:
if (s->state != S_DOWN) buffer_puts(&b, ", want down");
@@ -279,8 +272,7 @@ int ctrl(struct svdir *s, char c) {
case 'x': /* exit */
if (s->islog) break;
s->want =W_EXIT;
- if (s->pid && s->state != S_FINISH)
- stopservice(s);
+ if (s->pid && s->state != S_FINISH) stopservice(s);
break;
case 't': /* sig term */
if (s->pid && s->state != S_FINISH) stopservice(s);
@@ -296,8 +288,7 @@ int ctrl(struct svdir *s, char c) {
break;
case 'c': /* sig cont */
kill(s->pid, SIGCONT);
- if (s->ctrl & C_PAUSE)
- s->ctrl &=~C_PAUSE;
+ if (s->ctrl & C_PAUSE) s->ctrl &=~C_PAUSE;
update_status(s);
break;
case 'o': /* once */
@@ -332,8 +323,7 @@ int main(int argc, char **argv) {
if (! argv[1] || argv[2]) usage();
dir =argv[1];
- if (pipe(selfpipe) == -1)
- fatal("unable to create selfpipe");
+ if (pipe(selfpipe) == -1) fatal("unable to create selfpipe");
coe(selfpipe[0]);
coe(selfpipe[1]);
ndelay_on(selfpipe[0]);
@@ -344,8 +334,7 @@ int main(int argc, char **argv) {
sig_block(sig_term);
sig_catch(sig_term, s_term);
- if (chdir(dir) == -1)
- fatal("unable to change to directory");
+ if (chdir(dir) == -1) fatal("unable to change to directory");
svd[0].pid =0;
svd[0].state =S_DOWN;
svd[0].ctrl =C_NOOP;
@@ -353,8 +342,7 @@ int main(int argc, char **argv) {
svd[0].islog =0;
svd[1].pid =0;
taia_now(&svd[0].start);
- if (stat("down", &s) != -1)
- svd[0].want =W_DOWN;
+ if (stat("down", &s) != -1) svd[0].want =W_DOWN;
if (stat("log", &s) == -1) {
if (errno != error_noent)
@@ -382,8 +370,7 @@ int main(int argc, char **argv) {
mkdir("supervise", 0700);
if ((svd[0].fdlock =open_append("supervise/lock")) == -1)
fatal("unable to open lock");
- if (lock_exnb(svd[0].fdlock) == -1)
- fatal("unable to lock");
+ if (lock_exnb(svd[0].fdlock) == -1) fatal("unable to lock");
if (haslog) {
mkdir("log/supervise", 0700);
if ((svd[1].fdlock =open_append("log/supervise/lock")) == -1)
@@ -454,7 +441,7 @@ int main(int argc, char **argv) {
int child;
int wstat;
- child = wait_nohang(&wstat);
+ child =wait_nohang(&wstat);
if (!child) break;
if ((child == -1) && (errno != error_intr)) break;
if (child == svd[0].pid) {
@@ -491,26 +478,20 @@ int main(int argc, char **argv) {
}
}
}
- if (read(svd[0].fdcontrol, &ch, 1) == 1)
- ctrl(&svd[0], ch);
- if (haslog) {
- if (read(svd[1].fdcontrol, &ch, 1) == 1)
- ctrl(&svd[1], ch);
- }
+ if (read(svd[0].fdcontrol, &ch, 1) == 1) ctrl(&svd[0], ch);
+ if (haslog)
+ if (read(svd[1].fdcontrol, &ch, 1) == 1) ctrl(&svd[1], ch);
if (svd[0].want == W_EXIT && svd[0].pid == 0) {
- if (svd[1].pid == 0)
- exit(0);
+ if (svd[1].pid == 0) _exit(0);
if (svd[1].want != W_EXIT) {
svd[1].want =W_EXIT;
- /*
- stopservice(&svd[1]);
- */
+ /* stopservice(&svd[1]); */
update_status(&svd[1]);
if (close(logpipe[1]) == -1) warn("unable to close logpipe[1]");
if (close(logpipe[0]) == -1) warn("unable to close logpipe[0]");
}
}
}
- exit(0);
+ _exit(0);
}
diff --git a/src/runsvchdir.c b/src/runsvchdir.c
@@ -14,9 +14,8 @@
char *progname;
char *new;
-void usage () {
- strerr_die4x(1, "usage: ", progname, USAGE, "\n");
-}
+void usage () { strerr_die4x(1, "usage: ", progname, USAGE, "\n"); }
+
void fatal(char *m1, char *m2) {
strerr_die5sys(111, progname, ": fatal: ", m1, m2, ": ");
}
@@ -36,47 +35,40 @@ int main (int argc, char **argv) {
if (! argv || ! *argv) usage();
new =*argv;
- if (new[0] == '.')
- fatalx(new, ": must not start with a dot.");
- if (chdir(SVDIR) == -1)
- fatal("unable to chdir: ", SVDIR);
+ if (new[0] == '.') fatalx(new, ": must not start with a dot.");
+ if (chdir(SVDIR) == -1) fatal("unable to chdir: ", SVDIR);
if (stat(new, &s) == -1) {
- if (errno == error_noent)
- fatal(new, 0);
+ if (errno == error_noent) fatal(new, 0);
fatal("unable to stat: ", new);
}
- if (! S_ISDIR(s.st_mode))
- fatalx(new, "not a directory.");
+ if (! S_ISDIR(s.st_mode)) fatalx(new, "not a directory.");
ino =s.st_ino;
dev =s.st_dev;
- if (stat("current", &s) == -1)
- fatal("unable to stat: ", "current");
+ if (stat("current", &s) == -1) fatal("unable to stat: ", "current");
if ((s.st_ino == ino) && (s.st_dev == dev)) {
buffer_puts(buffer_1, "runsvchdir: ");
buffer_puts(buffer_1, new);
buffer_putsflush(buffer_1, ": current.\n");
- exit(0);
+ _exit(0);
}
if (unlink("current.new") == -1)
- if (errno != error_noent)
- fatal("unable to unlink: ", "current.new");
+ if (errno != error_noent) fatal("unable to unlink: ", "current.new");
if (symlink(new, "current.new") == -1)
fatal("unable to create: current.new -> ", new);
if (unlink("previous") == -1)
- if (errno != error_noent)
- fatal("unable to unlink: ", "previous");
+ if (errno != error_noent) fatal("unable to unlink: ", "previous");
if (rename("current", "previous") == -1)
fatal("unable to copy: current to ", "previous");
if (rename("current.new", "current") == -1) {
warn("unable to move: current.new to ", "current");
if (rename("previous", "current") == -1)
fatal("unable to move previous back to ", "current");
- exit(111);
+ _exit(111);
}
buffer_puts(buffer_1, "runsvchdir: ");
buffer_puts(buffer_1, new);
buffer_putsflush(buffer_1, ": now current.\n");
- exit(0);
+ _exit(0);
}
diff --git a/src/runsvctrl.c b/src/runsvctrl.c
@@ -13,12 +13,9 @@
char *progname;
unsigned int rc =0;
-void usage() {
- strerr_die4x(1, "usage: ", progname, USAGE, "\n");
-}
-void fatal(char *m1) {
- strerr_die3sys(111, FATAL, m1, ": ");
-}
+void usage() { strerr_die4x(1, "usage: ", progname, USAGE, "\n"); }
+
+void fatal(char *m1) { strerr_die3sys(111, FATAL, m1, ": "); }
void warn(char *m1, char *m2) {
rc++;
strerr_warn5(WARNING, m1, ": ", m2, ": ", &strerr_sys);
diff --git a/src/runsvdir.c b/src/runsvdir.c
@@ -40,9 +40,7 @@ iopause_fd io[1];
struct taia stamplog;
int exitsoon =0;
-void usage () {
- strerr_die4x(1, "usage: ", progname, USAGE, "\n");
-}
+void usage () { strerr_die4x(1, "usage: ", progname, USAGE, "\n"); }
void fatal(char *m1, char *m2) {
strerr_die6sys(100, "runsvdir ", svdir, ": fatal: ", m1, m2, ": ");
}
@@ -52,9 +50,8 @@ void warn(char *m1, char *m2) {
void warn3x(char *m1, char *m2, char *m3) {
strerr_warn6("runsvdir ", svdir, ": warning: ", m1, m2, m3, 0);
}
-void s_term() {
- exitsoon =1;
-}
+void s_term() { exitsoon =1; }
+
void runsv(int no, char *name) {
int pid;
@@ -88,8 +85,7 @@ void runsvdir() {
warn("unable to open directory ", svdir);
return;
}
- for (i =0; i < svnum; i++)
- sv[i].isgone =1;
+ for (i =0; i < svnum; i++) sv[i].isgone =1;
errno =0;
while ((d =readdir(dir))) {
if (d->d_name[0] == '.') continue;
@@ -98,13 +94,11 @@ void runsvdir() {
errno =0;
continue;
}
- if (! S_ISDIR(s.st_mode))
- continue;
+ if (! S_ISDIR(s.st_mode)) continue;
for (i =0; i < svnum; i++) {
if ((sv[i].ino == s.st_ino) && (sv[i].dev == s.st_dev)) {
sv[i].isgone =0;
- if (! sv[i].pid)
- runsv(i, d->d_name);
+ if (! sv[i].pid) runsv(i, d->d_name);
break;
}
}
@@ -131,10 +125,8 @@ void runsvdir() {
/* SIGTERM removed runsv's */
for (i =0; i < svnum; i++) {
- if (! sv[i].isgone)
- continue;
- if (sv[i].pid)
- kill(sv[i].pid, SIGTERM);
+ if (! sv[i].isgone) continue;
+ if (sv[i].pid) kill(sv[i].pid, SIGTERM);
sv[i] =sv[--svnum];
check =1;
}
@@ -187,7 +179,7 @@ int main(int argc, char **argv) {
warn3x("log service disabled.", 0, 0);
}
}
- if ((curdir =open_read(".")) == -1)
+ if ((curdir =open_read(".")) == -1)
fatal("unable to open current directory", 0);
taia_now(&stampcheck);
@@ -207,6 +199,13 @@ int main(int argc, char **argv) {
}
taia_now(&now);
+ if (now.sec.x < (stampcheck.sec.x -3)) {
+ /* time warp */
+ warn3x("time warp: resetting time stamp.", 0, 0);
+ taia_now(&stampcheck);
+ taia_now(&now);
+ if (log) taia_now(&stamplog);
+ }
if (taia_less(&now, &stampcheck) == 0) {
/* wait at least a second */
taia_uint(&deadline, 1);
@@ -237,7 +236,7 @@ int main(int argc, char **argv) {
if (taia_less(&now, &stamplog) == 0) {
write(logpipe[1], ".", 1);
taia_uint(&deadline, 900);
- taia_add(&stamplog, &stamplog, &deadline);
+ taia_add(&stamplog, &now, &deadline);
}
taia_uint(&deadline, 5);
taia_add(&deadline, &now, &deadline);
@@ -249,23 +248,19 @@ int main(int argc, char **argv) {
iopause(0, 0, &deadline, &now);
sig_unblock(sig_child);
- if (log)
- if (io[0].revents | IOPAUSE_READ) {
- while (read(logpipe[0], &ch, 1) > 0) {
- if (ch) {
- for (i =6; i < loglen; i++)
- log[i -1] =log[i];
- log[loglen -1] =ch;
- }
+ if (log && (io[0].revents | IOPAUSE_READ))
+ while (read(logpipe[0], &ch, 1) > 0) {
+ if (ch) {
+ for (i =6; i < loglen; i++)
+ log[i -1] =log[i];
+ log[loglen -1] =ch;
}
}
if (exitsoon) {
- for (i =0; i < svnum; i++) {
- if (sv[i].pid) kill(sv[i].pid, SIGTERM);
- }
- exit(0);
+ for (i =0; i < svnum; i++) if (sv[i].pid) kill(sv[i].pid, SIGTERM);
+ _exit(0);
}
}
/* not reached */
- exit(0);
+ _exit(0);
}
diff --git a/src/runsvstat.c b/src/runsvstat.c
@@ -21,12 +21,9 @@ unsigned int rc =0;
struct stat s;
int showlog =0;
-void usage() {
- strerr_die4x(1, "usage: ", progname, USAGE, "\n");
-}
-void fatal(char *m1) {
- strerr_die3sys(111, FATAL, m1, ": ");
-}
+void usage() { strerr_die4x(1, "usage: ", progname, USAGE, "\n"); }
+
+void fatal(char *m1) { strerr_die3sys(111, FATAL, m1, ": "); }
void warn(char *m1, char *m2) {
rc++;
strerr_warn5(WARNING, m1, ": ", m2, ": ", &strerr_sys);
@@ -65,8 +62,7 @@ int show_status(char *name) {
return(-1);
}
switch(read(fd, status, 20)) {
- case 20:
- break;
+ case 20: break;
case -1:
warn(name, "unable to read supervise/status");
return(-1);
@@ -74,14 +70,14 @@ int show_status(char *name) {
warnx(name, "unable to read supervise/status: bad format.");
return(-1);
}
- pid = (unsigned char) status[15];
- pid <<= 8; pid += (unsigned char) status[14];
- pid <<= 8; pid += (unsigned char) status[13];
- pid <<= 8; pid += (unsigned char) status[12];
+ pid =(unsigned char) status[15];
+ pid <<=8; pid +=(unsigned char)status[14];
+ pid <<=8; pid +=(unsigned char)status[13];
+ pid <<=8; pid +=(unsigned char)status[12];
tai_unpack(status,&when);
tai_now(&now);
- if (tai_less(&now,&when)) when = now;
+ if (tai_less(&now,&when)) when =now;
tai_sub(&when,&now,&when);
buffer_puts(buffer_1, name);
@@ -99,19 +95,13 @@ int show_status(char *name) {
buffer_puts(buffer_1, "down ");
buffer_put(buffer_1, sulong, fmt_ulong(sulong, tai_approx(&when)));
buffer_puts(buffer_1, " seconds");
- if (pid && !normallyup)
- buffer_puts(buffer_1,", normally down");
- if (!pid && normallyup)
- buffer_puts(buffer_1,", normally up");
- if (pid && status[16])
- buffer_puts(buffer_1,", paused");
- if (!pid && (status[17] == 'u'))
- buffer_puts(buffer_1,", want up");
- if (pid && (status[17] == 'd'))
- buffer_puts(buffer_1,", want down");
- if (pid && status[18])
- buffer_puts(buffer_1, ", got TERM");
- // buffer_putsflush(buffer_1, "\n");
+ if (pid && !normallyup) buffer_puts(buffer_1,", normally down");
+ if (!pid && normallyup) buffer_puts(buffer_1,", normally up");
+ if (pid && status[16]) buffer_puts(buffer_1,", paused");
+ if (!pid && (status[17] == 'u')) buffer_puts(buffer_1,", want up");
+ if (pid && (status[17] == 'd')) buffer_puts(buffer_1,", want down");
+ if (pid && status[18]) buffer_puts(buffer_1, ", got TERM");
+ /* buffer_putsflush(buffer_1, "\n"); */
return(1);
}
@@ -151,7 +141,7 @@ int main(int argc, char **argv) {
if (showlog) {
if (stat("log", &s) == -1) {
if (errno != error_noent)
- warn("unable to stat()", "./log");
+ warn("unable to stat()", "./log");
}
else {
if (! S_ISDIR(s.st_mode))
diff --git a/src/svwaitdown.c b/src/svwaitdown.c
@@ -18,9 +18,7 @@ const char *progname;
const char * const *dir;
unsigned int rc =0;
-void usage () {
- strerr_die4x(1, "usage: ", progname, USAGE, "\n");
-}
+void usage () { strerr_die4x(1, "usage: ", progname, USAGE, "\n"); }
void warn (const char *s1, const char *s2, struct strerr *e) {
dir++;
@@ -47,9 +45,7 @@ int main (int argc, const char * const *argv) {
switch(opt) {
case 't':
scan_ulong(optarg, &sec);
- if ((sec < 2) || (sec > 6000)) {
- usage();
- }
+ if ((sec < 2) || (sec > 6000)) usage();
break;
case 'x':
doexit =1;
@@ -67,9 +63,7 @@ int main (int argc, const char * const *argv) {
}
}
argv +=optind;
- if (! argv || ! *argv) {
- usage();
- }
+ if (! argv || ! *argv) usage();
dir =argv;
tai_now(&start);
@@ -83,8 +77,7 @@ int main (int argc, const char * const *argv) {
continue;
}
- fd = open_write("supervise/ok");
- if (fd == -1) {
+ if ((fd =open_write("supervise/ok")) == -1) {
if (errno == error_nodevice) {
if (verbose) strerr_warn3(INFO, *dir, ": supervise not running.", 0);
dir++;
@@ -96,12 +89,11 @@ int main (int argc, const char * const *argv) {
close(fd);
if (! doexit) {
- fd = open_read("supervise/status");
- if (fd == -1) {
+ if ((fd =open_read("supervise/status")) == -1) {
warn(*dir, "unable to open supervise/status: ", &strerr_sys);
continue;
}
- r = buffer_unixread(fd, status, sizeof status);
+ r =buffer_unixread(fd, status, sizeof status);
close(fd);
if (r < sizeof status) {
if (r == -1)
@@ -110,10 +102,10 @@ int main (int argc, const char * const *argv) {
warn(*dir, ": unable to read supervise/status: bad format.", 0);
continue;
}
- pid = (unsigned char) status[15];
- pid <<= 8; pid += (unsigned char) status[14];
- pid <<= 8; pid += (unsigned char) status[13];
- pid <<= 8; pid += (unsigned char) status[12];
+ pid =(unsigned char)status[15];
+ pid <<=8; pid +=(unsigned char)status[14];
+ pid <<=8; pid +=(unsigned char)status[13];
+ pid <<=8; pid +=(unsigned char)status[12];
if (! pid) {
/* ok, service is down */
if (verbose) strerr_warn3(INFO, *dir, ": down.", 0);
@@ -147,13 +139,13 @@ int main (int argc, const char * const *argv) {
strerr_warn3(INFO, *dir, ": killed.", 0);
close(fd);
dir++;
- if (! *dir) exit(111);
+ if (! *dir) _exit(111);
continue;
}
- exit(111);
+ _exit(111);
}
sleep(1);
}
if (rc > 100) rc =100;
- exit(rc);
+ _exit(rc);
}
diff --git a/src/svwaitup.c b/src/svwaitup.c
@@ -17,9 +17,7 @@ unsigned long sec =2;
unsigned int rc =0;
const char * const *dir;
-void usage () {
- strerr_die4x(1, "usage: ", progname, USAGE, "\n");
-}
+void usage () { strerr_die4x(1, "usage: ", progname, USAGE, "\n"); }
void warn (const char *s1, const char *s2, struct strerr *e) {
dir++;
@@ -44,9 +42,7 @@ int main (int argc, const char * const *argv) {
switch(opt) {
case 's':
scan_ulong(optarg, &sec);
- if ((sec < 2) || (sec > 600)) {
- usage();
- }
+ if ((sec < 2) || (sec > 600)) usage();
break;
case 'v':
verbose =1;
@@ -58,12 +54,9 @@ int main (int argc, const char * const *argv) {
}
}
argv +=optind;
- if (! argv || ! *argv) {
- usage();
- }
-
- dir =argv;
+ if (! argv || ! *argv) usage();
+ dir =argv;
while (*dir) {
if (*dir[0] != '/') {
warn(*dir, ": service directory must start with a slash.", 0);
@@ -74,8 +67,7 @@ int main (int argc, const char * const *argv) {
continue;
}
- fd = open_write("supervise/ok");
- if (fd == -1) {
+ if ((fd =open_write("supervise/ok")) == -1) {
if (errno == error_nodevice)
warn(*dir, ": supervise not running.", 0);
else
@@ -84,12 +76,11 @@ int main (int argc, const char * const *argv) {
}
close(fd);
- fd = open_read("supervise/status");
- if (fd == -1) {
+ if ((fd =open_read("supervise/status")) == -1) {
warn(*dir, "unable to open supervise/status: ", &strerr_sys);
continue;
}
- r = buffer_unixread(fd, status, sizeof status);
+ r =buffer_unixread(fd, status, sizeof status);
close(fd);
if (r < sizeof status) {
if (r == -1)
@@ -99,10 +90,10 @@ int main (int argc, const char * const *argv) {
continue;
}
- pid = (unsigned char) status[15];
- pid <<= 8; pid += (unsigned char) status[14];
- pid <<= 8; pid += (unsigned char) status[13];
- pid <<= 8; pid += (unsigned char) status[12];
+ pid =(unsigned char)status[15];
+ pid <<=8; pid +=(unsigned char)status[14];
+ pid <<=8; pid +=(unsigned char)status[13];
+ pid <<=8; pid +=(unsigned char)status[12];
if (! pid) {
warn(*dir, ": is down.", 0);
continue;
@@ -123,5 +114,5 @@ int main (int argc, const char * const *argv) {
sleep(sec -is);
}
if (rc > 100) rc =100;
- exit(rc);
+ _exit(rc);
}
diff --git a/src/utmpset.c b/src/utmpset.c
@@ -4,6 +4,7 @@
#include <sys/stat.h>
#include <unistd.h>
#include <utmp.h>
+#include <string.h>
#include "strerr.h"
#include "sgetopt.h"
#include "seek.h"
@@ -18,9 +19,7 @@
const char *progname;
-void usage(void) {
- strerr_die4x(1, "usage: ", progname, USAGE, "\n");
-}
+void usage(void) { strerr_die4x(1, "usage: ", progname, USAGE, "\n"); }
int utmp_logout(const char *line) {
int fd;
@@ -33,8 +32,7 @@ int utmp_logout(const char *line) {
strerr_die4sys(111, FATAL, "unable to lock: ", _PATH_UTMP, ": ");
while (read(fd, &ut, sizeof(struct utmp)) == sizeof(struct utmp)) {
- if (!ut.ut_name[0] || (str_diff(ut.ut_line, line) != 0))
- continue;
+ if (!ut.ut_name[0] || (str_diff(ut.ut_line, line) != 0)) continue;
memset(ut.ut_name, 0, UT_NAMESIZE);
memset(ut.ut_host, 0, UT_HOSTSIZE);
if (time(&ut.ut_time) == -1) break;
@@ -62,8 +60,7 @@ int wtmp_logout(const char *line) {
return(-1);
}
memset(&ut, 0, sizeof(struct utmp));
- if ((len =str_len(line)) > UT_LINESIZE)
- len =UT_LINESIZE -1;
+ if ((len =str_len(line)) > UT_LINESIZE) len =UT_LINESIZE -1;
byte_copy(ut.ut_line, len, line);
if (time(&ut.ut_time) == -1) {
close(fd);
@@ -101,10 +98,9 @@ int main (int argc, const char * const *argv, const char * const *envp) {
if (utmp_logout(*argv) == -1)
strerr_die4x(111, WARNING, "unable to logout line ", *argv,
" in utmp: no such entry");
- if (wtmp) {
+ if (wtmp)
if (wtmp_logout(*argv) == -1)
- strerr_die4sys(111, WARNING, "unable to logout line ", *argv,
- " in wtmp: ");
- }
- exit(0);
+ strerr_die4sys(111, WARNING,
+ "unable to logout line ", *argv, " in wtmp: ");
+ _exit(0);
}