runit

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit b9a4bcd03846e0b97901bae12e9440a23f43dc30
parent 4cd0d32d85bcd8fe76d71f06665f1b1c97a4f4ee
Author: Gerrit Pape <pape@smarden.org>
Date:   Fri,  4 Oct 2002 09:05:26 +0000

  * runsv.c: sleep 1 second before exiting on fatal error.
  * runsvdir.c: check service directory's inode and device in addition
    to mtime; sleep 1 second if stat(service directory) fails.
  * runsvstat.c: new option -l: only show log service if -l is set.
  * runsvchdir: new; change service directory runsvdir is running in.
0.6.3.

Diffstat:
MMakefile | 4++--
Mdebian/changelog | 6++++++
Mdebian/postinst | 2+-
Mdebian/rules | 38+++++++++++++++++++-------------------
Mdoc/index.html | 24++++++++++++++----------
Mdoc/install.html | 10+++++-----
Mdoc/replaceinit.html | 4++--
Adoc/runlevels.html | 81+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Adoc/runsvchdir.8.html | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
Aman/runsvchdir.8 | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mpackage/CHANGES | 10+++++++++-
Mpackage/upgrade | 4++--
Msrc/Makefile | 12+++++++++---
Msrc/TARGETS | 2++
Msrc/runsv.c | 8++++++--
Asrc/runsvchdir.c | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/runsvdir.c | 12+++++++++---
Msrc/runsvstat.c | 46++++++++++++++++++++++++++++++++--------------
18 files changed, 372 insertions(+), 64 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,9 +1,9 @@ DESTDIR= -PACKAGE=runit-0.6.0 +PACKAGE=runit-0.6.3 DIRS=doc man etc package src MANPAGES=runit.8 runit-init.8 runsvdir.8 runsv.8 svwaitdown.8 svwaitup.8 \ -utmpset.8 +utmpset.8 runsvchdir.8 all: clean .manpages $(PACKAGE).tar.gz diff --git a/debian/changelog b/debian/changelog @@ -1,3 +1,9 @@ +runit (0.6.3-1) sarge; urgency=low + + * See /package/admin/runit/package/CHANGES. + + -- Gerrit Pape <pape@smarden.org> Fri, 4 Oct 2002 11:04:05 +0200 + runit (0.6.0-1) sarge; urgency=low * See /package/admin/runit/package/CHANGES. diff --git a/debian/postinst b/debian/postinst @@ -25,7 +25,7 @@ set -e case "$1" in configure) ( \ - cd /package/admin/runit-0.6.0 + cd /package/admin/runit-0.6.3 package/upgrade ) ;; diff --git a/debian/rules b/debian/rules @@ -23,15 +23,15 @@ build-stamp: # $(MAKE) #/usr/bin/docbook-to-man debian/runit.sgml > runit.1 - tar xfzvp runit-0.6.0.tar.gz + tar xfzvp runit-0.6.3.tar.gz ( \ - cd admin/runit-0.6.0 ; \ + cd admin/runit-0.6.3 ; \ echo 'diet gcc -O2 -Wall' > src/conf-cc ; \ echo 'diet gcc -s -Os -pipe' > src/conf-ld ; \ package/compile ; \ - echo "/package/admin/runit-0.6.0" > compile/home ; \ + echo "/package/admin/runit-0.6.3" > compile/home ; \ rm -f compile/src ; \ - ln -s /package/admin/runit-0.6.0/src compile/src ; \ + ln -s /package/admin/runit-0.6.3/src compile/src ; \ ) touch build-stamp @@ -58,40 +58,40 @@ install: build chmod 1755 debian/runit/package cp -a admin debian/runit/package/ - rm -rf debian/runit/package/admin/runit-0.6.0/compile - cp -a debian/runit/package/admin/runit-0.6.0/man . - rm -rf debian/runit/package/admin/runit-0.6.0/man - cp -a debian/runit/package/admin/runit-0.6.0/doc . - rm -rf debian/runit/package/admin/runit-0.6.0/doc - cp -a debian/runit/package/admin/runit-0.6.0/etc . - rm -rf debian/runit/package/admin/runit-0.6.0/etc - cp -a debian/runit/package/admin/runit-0.6.0/package . + rm -rf debian/runit/package/admin/runit-0.6.3/compile + cp -a debian/runit/package/admin/runit-0.6.3/man . + rm -rf debian/runit/package/admin/runit-0.6.3/man + cp -a debian/runit/package/admin/runit-0.6.3/doc . + rm -rf debian/runit/package/admin/runit-0.6.3/doc + cp -a debian/runit/package/admin/runit-0.6.3/etc . + rm -rf debian/runit/package/admin/runit-0.6.3/etc + cp -a debian/runit/package/admin/runit-0.6.3/package . # /etc/runit - cp -p admin/runit-0.6.0/etc/debian/[123] \ + cp -p admin/runit-0.6.3/etc/debian/[123] \ debian/runit/etc/runit/ - cp -p admin/runit-0.6.0/etc/debian/ctrlaltdel \ + cp -p admin/runit-0.6.3/etc/debian/ctrlaltdel \ debian/runit/etc/runit/ - cp -p admin/runit-0.6.0/etc/debian/getty-tty5/run \ + cp -p admin/runit-0.6.3/etc/debian/getty-tty5/run \ debian/runit/etc/runit/getty-5/run # runit programs - cp -p debian/runit/package/admin/runit-0.6.0/command/runit* \ + cp -p debian/runit/package/admin/runit-0.6.3/command/runit* \ debian/runit/sbin/ # cleanup - rm -rf debian/runit/package/admin/runit-0.6.0/compile + rm -rf debian/runit/package/admin/runit-0.6.3/compile # create debian/links rm -f debian/links for i in \ - `cat debian/runit/package/admin/runit-0.6.0/package/commands` ; \ + `cat debian/runit/package/admin/runit-0.6.3/package/commands` ; \ do \ echo "/package/admin/runit/command/$$i /command/$$i" \ >> debian/links ; \ done for i in \ - `cat debian/runit/package/admin/runit-0.6.0/package/commands` ; \ + `cat debian/runit/package/admin/runit-0.6.3/package/commands` ; \ do \ echo "/command/$$i /usr/local/bin/$$i" \ >> debian/links ; \ diff --git a/doc/index.html b/doc/index.html @@ -1,26 +1,30 @@ <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> <html> <head> -<title>runit - minimal replacement for sysvinit</title> +<title>runit - a UNIX init scheme</title> </head> <body> <a href="http://smarden.org/pape/">G. Pape</a> <hr> -<h1>runit - minimal replacement for <i>sysvinit</i></h1> +<h1>runit - a UNIX init scheme</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="replaceinit.html">How to replace init</a><br> <a href="usedietlibc.html">How to use dietlibc</a> <p> -<a href="runscripts.html">A collection of run scripts</a><br> +<a href="runlevels.html">Runlevels</a><br> <a href="http://smarden.org/pape/djb/daemontools/noinit.html"> -Dependencies and runlevels</a> +Dependencies</a><br> +<a href="runscripts.html">A collection of run scripts</a><br> <p> <a href="runit.8.html">The <tt>runit</tt> program</a><br> <a href="runit-init.8.html">The <tt>runit-init</tt> program</a><br> +<br> <a href="runsvdir.8.html">The <tt>runsvdir</tt> program</a><br> <a href="runsv.8.html">The <tt>runsv</tt> program</a><br> +<a href="runsvchdir.8.html">The <tt>runsvchdir</tt> program</a><br> +<br> <a href="utmpset.8.html">The <tt>utmpset</tt> program</a><br> <a href="svwaitdown.8.html">The <tt>svwaitdown</tt> program</a><br> <a href="svwaitup.8.html">The <tt>svwaitup</tt> program</a> @@ -28,12 +32,12 @@ Dependencies and runlevels</a> <i>runit</i> is a <a href="http://cr.yp.to/daemontools.html">daemontools</a> alike replacement for -<a href="ftp://ftp.cistron.nl/pub/people/miquels/sysvinit/">sysvinit</a>. -<i>runit</i> runs on <b>Debian GNU/Linux</b>, <b>OpenBSD 2.9</b>, -<b>FreeBSD 4.4</b>. <i>runit</i> reportedly runs on <b>FreeBSD 4.3</b>, -and can easily be adapted to other unix operating systems. If <i>runit</i> -runs for you on any other operating system or linux distribution, please -let me know. +<a href="ftp://ftp.cistron.nl/pub/people/miquels/sysvinit/">sysvinit</a> +and other init schemes. <i>runit</i> runs on <b>Debian GNU/Linux</b>, +<b>OpenBSD 2.9</b>, <b>FreeBSD 4.4</b>. <i>runit</i> reportedly runs on +<b>FreeBSD 4.3</b>, and can easily be adapted to other unix operating +systems. If <i>runit</i> runs for you on any other operating system or +linux distribution, please let me know. <p> <b>Warning:</b> Replacing <i>sysvinit</i> or <i>init</i> can cause the system's boot to fail. Make sure you are able to recover and repair your 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.6.0.tar.gz">runit-0.6.0.tar.gz</a> into <tt>/package</tt> +<a href="runit-0.6.3.tar.gz">runit-0.6.3.tar.gz</a> into <tt>/package</tt> and unpack the archive <pre> # cd /package - # gunzip runit-0.6.0.tar - # tar -xpf runit-0.6.0.tar - # rm runit-0.6.0.tar - # cd admin/runit-0.6.0 + # gunzip runit-0.6.3.tar + # tar -xpf runit-0.6.3.tar + # rm runit-0.6.3.tar + # cd admin/runit-0.6.3 </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.6.0@smarden.org + # ( uname -a ; cat /etc/runit/[123] ) | mail pape-runit-0.6.3@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.6.0@smarden.org + # ( uname -a ; cat /etc/runit/[123] ) | mail pape-runit-0.6.3@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/runlevels.html b/doc/runlevels.html @@ -0,0 +1,81 @@ +<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> +<html> +<head> +<title>runit - runlevels</title> +</head> +<body> +<a href="http://smarden.org/pape/">G. Pape</a><br> +<a href="index.html">runit</a><br> +<hr> +<h1>runit - runlevels</h1> +<hr> +<a href="#prepare">Prepare runit for using runlevels</a><br> +<a href="#switch">Switching runlevels</a><br> +<a href="#create">Creating runlevels</a> +<hr> +<a name="prepare"><h3>Prepare runit</h3></a> +If not yet done, configure your system to use <a href="runit.8.html">runit</a> +as process no 1 by following the <a href="replaceinit.html">instructions</a>. +<p> +Create the following direcotories and symlinks: +<pre> + # mkdir -p /etc/runit/runsvdir/default + # mkdir -p /etc/runit/runsvdir/single + # ln -s /etc/runit/getty-5 /etc/runit/runsvdir/single/getty-5 + # ln -s default /etc/runit/runsvdir/current +</pre> +Copy the content of <tt>/service/</tt> to <tt>/etc/runit/runsvdir/current</tt> +and replace <tt>/service</tt> with a symlink: +<pre> + # cp -pr /service/* /etc/runit/runsvdir/current/ + # mv -f /service /service.old && ln -s /etc/runit/runsvdir/current /service +</pre> +You have now created two runlevels: <tt>default</tt> and <tt>single</tt>. +The <tt>current</tt> runlevel is <tt>default</tt>. It is save to remove +<tt>/service.old</tt> if you don't need it anymore. +<hr> +<a name="switch"><h3>Switching runlevels</h3></a> +Switching runlevels with <i>runit</i> is done by +switching the directory the <a href="runsvdir.8.html">runsvdir</a> program +is running in. This is done by the <a href="runsvchdir.8.html">runsvchdir</a> +program, e.g. to switch to the <tt>single</tt> user runlevel, do: +<pre> + # runsvchdir single +</pre> +To switch back to the <tt>default</tt> runlevel, do: +<pre> + # runsvchdir default +</pre> +See <a href="runsvdir.8.html">the runsvdir program</a> for a description of +what happens when <i>runsvdir</i> sees the directory changed. Note that +there is no guarantee that all services from the <tt>previous</tt> runlevel +will stop, the <a href="runsv.8.html">runsv</a> processes have sent the +services a SIGTERM and wait for them to terminate. You can check the status +of the <tt>previous</tt> runlevel in <tt>/etc/runit/runsvdir/previous/</tt>. +<hr> +<a name="create"><h3>Creating new runlevels</h3></a> +To create a new runlevel, simply create a new service directory in +<tt>/etc/runit/runsvdir</tt>. The name of the runlevel must not start with +a dot and must not be <tt>current</tt>, <tt>current.new</tt> or +<tt>previous</tt>. E.g.: +<pre> + # mkdir /etc/runit/runsvdir/maintenance +</pre> +Add the services you want to run in the runlevel <tt>maintenance</tt> to the +newly created directory, e.g.: +<pre> + # ln -s /etc/runit/getty-5 /etc/runit/runsvdir/maintenance/ + # ln -s /etc/runit/runsv/ssh /etc/runit/runsvdir/maintenance/ + # ln -s /etc/runit/runsv/dnscache /etc/runit/runsvdir/maintenance/ +</pre> +If you want to switch to the runlevel <tt>mainenance</tt>, do: +<pre> + # runsvchdir maintenance +</pre> +<hr> +<address><a href="mailto:pape@smarden.org"> +Gerrit Pape &lt;pape@smarden.org&gt; +</a></address> +<small>$Id$</small> +</body> +</html> diff --git a/doc/runsvchdir.8.html b/doc/runsvchdir.8.html @@ -0,0 +1,51 @@ + + + +<HTML> +<HEAD> +<TITLE>runsvchdir(8) manual page</TITLE> +</HEAD> +<BODY bgcolor=white> +<a href="http://smarden.org/pape/">G. Pape</a><br><A HREF="index.html">runit</A><hr><P> + +<H2><A NAME="sect0">Name</A></H2> +runsvchdir - change service directory of <I>runsvdir(8)</I> +<H2><A NAME="sect1">Synopsis</A></H2> +<B>runsvchdir</B> +<I>dir</I> +<H2><A NAME="sect2">Description</A></H2> +<I>dir</I> is a directory for the use with <B><I>runsvdir</B>(8)</I>. If <I>dir</I> does +not start with a slash, it is searched in /etc/runit/runsvdir/. <I>dir</I> must +not start with a dot. <P> +<B>runsvchdir</B> switches to the directory <I>/etc/runit/runsvdir</I>, +copies <I>current</I> to <I>previous</I>, and replaces <I>current</I> with a symlink pointing +to <I>dir</I>. <P> +Normally <I>/service</I> is a symlink to <I>current</I>, and <B><I>runsvdir</B>(8)</I> is running +<I>/service</I>. +<H2><A NAME="sect3">Exit Codes</A></H2> +<B>runsvchdir</B> prints an error message and exits 111 on +error. <B>runsvchdir</B> exits 0 on success. +<H2><A NAME="sect4">Files</A></H2> + /etc/runit/runsvdir/previous<BR> + /etc/runit/runsvdir/current<BR> + /etc/runit/runsvdir/current.new<BR> + +<H2><A NAME="sect5">See Also</A></H2> +<I>runsvdir(8)</I>, <I>runsv(8)</I>, <I>runit(8)</I>, <I>runit-init(8)</I> <P> +<I>http://smarden.org/runit/</I> + +<H2><A NAME="sect6">Author</A></H2> +Gerrit Pape &lt;pape@smarden.org&gt; <P> + +<HR><P> +<A NAME="toc"><B>Table of Contents</B></A><P> +<UL> +<LI><A NAME="toc0" HREF="#sect0">Name</A></LI> +<LI><A NAME="toc1" HREF="#sect1">Synopsis</A></LI> +<LI><A NAME="toc2" HREF="#sect2">Description</A></LI> +<LI><A NAME="toc3" HREF="#sect3">Exit Codes</A></LI> +<LI><A NAME="toc4" HREF="#sect4">Files</A></LI> +<LI><A NAME="toc5" HREF="#sect5">See Also</A></LI> +<LI><A NAME="toc6" HREF="#sect6">Author</A></LI> +</UL> +</BODY></HTML> diff --git a/man/runsvchdir.8 b/man/runsvchdir.8 @@ -0,0 +1,54 @@ +.TH runsvchdir 8 +.SH NAME +runsvchdir \- change service directory of runsvdir(8) +.SH SYNOPSIS +.B runsvchdir +.I dir +.SH DESCRIPTION +.I dir +is a directory for the use with +.BR runsvdir (8). +If +.I dir +does not start with a slash, it is searched in /etc/runit/runsvdir/. +.I dir +must not start with a dot. +.P +.B runsvchdir +switches to the directory +.IR /etc/runit/runsvdir , +copies +.I current +to +.IR previous , +and replaces +.I current +with a symlink pointing to +.IR dir . +.P +Normally +.I /service +is a symlink to +.IR current , +and +.BR runsvdir (8) +is running +.IR /service . +.SH EXIT CODES +.B runsvchdir +prints an error message and exits 111 on error. +.B runsvchdir +exits 0 on success. +.SH FILES + /etc/runit/runsvdir/previous + /etc/runit/runsvdir/current + /etc/runit/runsvdir/current.new +.SH SEE ALSO +runsvdir(8), +runsv(8), +runit(8), +runit-init(8) +.P +http://smarden.org/runit/ +.SH AUTHOR +Gerrit Pape <pape@smarden.org> diff --git a/package/CHANGES b/package/CHANGES @@ -1,3 +1,11 @@ +runit 0.6.3 +Fri, 04 Oct 2002 10:57:02 +0200 + * runsv.c: sleep 1 second before exiting on fatal error. + * runsvdir.c: check service directory's inode and device in addition + to mtime; sleep 1 second if stat(service directory) fails. + * runsvstat.c: new option -l: only show log service if -l is set. + * runsvchdir: new; change service directory runsvdir is running in. + runit 0.6.0 Fri, 27 Sep 2002 16:34:57 +0200 * man/runsv.8, man/runsvdir.8: new. @@ -12,7 +20,7 @@ Fri, 27 Sep 2002 16:34:57 +0200 runit 0.5.3 Mon, 23 Sep 2002 16:25:07 +0200 * runsv, runsvdir: new; svscan/supervise replacement. - * etc/runit/2: use runsvlog instead of svscanboot. + * etc/runit/2: use runsvdir instead of svscanboot. * runsvstat.c: new; svstat for runsv. * runsvctrl.c: new; svc for runsv. * runsvdir.c, runsv.c: code cleanup. 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.6.0...' +echo 'Creating symlink runit -> runit-0.6.3...' rm -f runit -ln -s runit-0.6.0 runit +ln -s runit-0.6.3 runit mv -f runit .. echo 'Making command links in /command...' diff --git a/src/Makefile b/src/Makefile @@ -26,6 +26,12 @@ svwaitup: load svwaitup.o unix.a byte.a time.a svwaitdown: load svwaitdown.o unix.a byte.a time.a ./load svwaitdown unix.a byte.a time.a +utmpset: load utmpset.o unix.a byte.a + ./load utmpset unix.a byte.a + +runsvchdir: load runsvchdir.o unix.a byte.a + ./load runsvchdir unix.a byte.a + runit.o: compile sysdeps runit.c ./compile runit.c @@ -50,12 +56,12 @@ svwaitup.o: compile sysdeps svwaitup.c svwaitdown.o: compile sysdeps svwaitdown.c ./compile svwaitdown.c -utmpset: load utmpset.o unix.a byte.a - ./load utmpset unix.a byte.a - utmpset.o: compile utmpset.c ./compile utmpset.c +runsvchdir.o: compile runsvchdir.c + ./compile runsvchdir.c + clean: find . -name \*~ -exec rm -f {} \; find . -name .??*~ -exec rm -f {} \; diff --git a/src/TARGETS b/src/TARGETS @@ -16,6 +16,8 @@ svwaitup svwaitup.o utmpset utmpset.o +runsvchdir +runsvchdir.o alloc.o alloc_re.o buffer.o diff --git a/src/runsv.c b/src/runsv.c @@ -61,10 +61,14 @@ void usage () { strerr_die4x(1, "usage: ", progname, USAGE, "\n"); } void fatal(char *m) { - strerr_die5sys(111, "runsv ", dir, ": fatal: ", m, ": "); + strerr_warn5("runsv ", dir, ": fatal: ", m, ": ", &strerr_sys); + sleep(1); + exit(111); } void fatal2(char *m1, char *m2) { - strerr_die6sys(111, "runsv ", dir, ": fatal: ", m1, m2, ": "); + strerr_warn6("runsv ", dir, ": fatal: ", m1, m2, ": ", &strerr_sys); + sleep(1); + exit(111); } void warn(char *m) { strerr_warn5("runsv ", dir, ": warning: ", m, ": ", &strerr_sys); diff --git a/src/runsvchdir.c b/src/runsvchdir.c @@ -0,0 +1,68 @@ +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> +#include <stdio.h> +#include "strerr.h" +#include "error.h" + +#define USAGE " dir" + +#define SVDIR "/etc/runit/runsvdir" + +char *progname; +char *new; + +void usage () { + strerr_die4x(1, "usage: ", progname, USAGE, "\n"); +} +void fatal(char *m1, char *m2) { + strerr_die5sys(111, progname, ": fatal: ", m1, m2, ": "); +} +void fatalx(char *m1, char *m2) { + strerr_die4x(111, progname, ": fatal: ", m1, m2); +} + +int main (int argc, char **argv) { + struct stat s; + int dev; + int ino; + + progname =*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 (stat(new, &s) == -1) { + if (errno == error_noent) + fatal(new, 0); + fatal("unable to stat: ", new); + } + 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 ((s.st_ino == ino) && (s.st_dev == dev)) + strerr_die2x(0, new, ": already current."); + + if (unlink("current.new") == -1) + 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 (link("current", "previous") == -1) + fatal("unable to copy: current to ", "previous"); + if (rename("current.new", "current") == -1) + fatal("unabled to move: current.new to ", "current"); + + strerr_die2x(0, new, ": now current."); + exit(0); +} diff --git a/src/runsvdir.c b/src/runsvdir.c @@ -23,6 +23,8 @@ char *progname; char *svdir; +unsigned long dev =0; +unsigned long ino =0; struct { unsigned long dev; unsigned long ino; @@ -203,11 +205,13 @@ int main(int argc, char **argv) { } } if (stat(svdir, &s) != -1) { - if (check || s.st_mtime > mtime) { + if (check || s.st_mtime > mtime || s.st_ino != ino || s.st_dev != dev) { /* svdir modified */ mtime =s.st_mtime; + dev =s.st_dev; + ino =s.st_ino; check =0; - if (chdir(svdir) == -1) + if (chdir(svdir) == -1) warn("unable to change directory to", svdir); else { runsvdir(); @@ -216,8 +220,10 @@ int main(int argc, char **argv) { } } } - else + else { warn("unable to stat ", svdir); + sleep(1); + } taia_now(&now); if (log) diff --git a/src/runsvstat.c b/src/runsvstat.c @@ -3,21 +3,23 @@ #include <unistd.h> #include "strerr.h" #include "error.h" +#include "sgetopt.h" #include "open.h" #include "buffer.h" #include "tai.h" #include "fmt.h" -#define USAGE " service ..." +#define USAGE " [ -l ] service ..." #define VERSION "$Id$" #define FATAL "runsvstat: fatal: " #define WARNING "runsvstat: warning: " -char *progname; +const char *progname; unsigned int rc =0; struct stat s; +int showlog =0; void usage() { strerr_die4x(1, "usage: ", progname, USAGE, "\n"); @@ -110,10 +112,24 @@ int show_status(char *name) { } int main(int argc, char **argv) { + int opt; int curdir; char **dir; - progname =*argv++; + progname =*argv; + + while ((opt =getopt(argc, (const char * const *)argv, "lV")) != opteof) { + switch(opt) { + case 'l': + showlog =1; + break; + case 'V': + strerr_warn1(VERSION, 0); + case '?': + usage(); + } + } + argv +=optind; dir =argv; if (! dir || ! *dir) usage(); @@ -128,19 +144,21 @@ int main(int argc, char **argv) { continue; } if (show_status(*dir) == 1) { - if (stat("log", &s) == -1) { - if (errno != error_noent) - warn("unable to stat()", "./log"); - } - else { - if (! S_ISDIR(s.st_mode)) - warnx("./log", "not a directory."); + if (showlog) { + if (stat("log", &s) == -1) { + if (errno != error_noent) + warn("unable to stat()", "./log"); + } else { - if (chdir("log") == -1) { - warn(*dir, "unable to change directory"); - continue; + if (! S_ISDIR(s.st_mode)) + warnx("./log", "not a directory."); + else { + if (chdir("log") == -1) { + warn(*dir, "unable to change directory"); + continue; + } + show_status("\n log"); } - show_status("\n log"); } } buffer_putsflush(buffer_1, "\n");