admin 1755 0 0 0 7323352455 6166 5ustar00admin/daemontools-0.76 755 0 0 0 7323352455 11061 5ustar00admin/daemontools-0.76/package 755 0 0 0 7323352455 12454 5ustar00admin/daemontools-0.76/package/README 644 0 0 100 7323352455 13442 0ustar00Copyright 2001 D. J. Bernstein http://cr.yp.to/daemontools.html admin/daemontools-0.76/package/files 644 0 0 5350 7323352455 13643 0ustar00package package/README package/files package/sharing package/commands package/install package/compile package/upgrade package/run package/run.inittab package/boot.inittab package/run.rclocal package/boot.rclocal src src/CHANGES src/TODO src/Makefile src/svscanboot.sh src/svscan.c src/supervise.c src/svc.c src/svok.c src/svstat.c src/fghack.c src/pgrphack.c src/readproctitle.c src/multilog.c src/tai64n.c src/tai64nlocal.c src/softlimit.c src/setuidgid.c src/envuidgid.c src/envdir.c src/setlock.c src/match.c src/match.h src/matchtest.c src/timestamp.c src/timestamp.h src/deepsleep.c src/deepsleep.h src/conf-cc src/conf-ld src/print-cc.sh src/print-ld.sh src/print-ar.sh src/choose.sh src/warn-auto.sh src/find-systype.sh src/trycpp.c src/x86cpuid.c src/rts.tests src/buffer.h src/buffer.c src/byte.h src/str.h src/str_len.c src/byte_copy.c src/byte_cr.c src/error.h src/error.c src/buffer_put.c src/buffer_read.c src/buffer_write.c src/buffer_1.c src/direntry.h1 src/direntry.h2 src/trydrent.c src/strerr.h src/error_str.c src/strerr_sys.c src/buffer_2.c src/strerr_die.c src/wait.h src/trywaitp.c src/haswaitp.h1 src/haswaitp.h2 src/wait_pid.c src/coe.h src/coe.c src/fd.h src/fd_copy.c src/fd_move.c src/str_start.c src/env.h src/env.c src/alloc.h src/alloc.c src/alloc_re.c src/gen_alloc.h src/gen_allocdefs.h src/stralloc.h src/stralloc_eady.c src/stralloc_opyb.c src/stralloc_catb.c src/stralloc_cats.c src/stralloc_pend.c src/str_chr.c src/pathexec.h src/pathexec_run.c src/stralloc_opys.c src/stralloc_cat.c src/byte_diff.c src/pathexec_env.c src/wait_nohang.c src/sig.h src/sig.c src/sig_block.c src/sig_catch.c src/sig_pause.c src/hassgact.h1 src/hassgact.h2 src/hassgprm.h1 src/hassgprm.h2 src/trysgact.c src/trysgprm.c src/select.h1 src/select.h2 src/trysysel.c src/uint64.h1 src/uint64.h2 src/tryulong64.c src/tai.h src/taia.h src/taia_now.c src/taia_sub.c src/taia_less.c src/taia_frac.c src/taia_approx.c src/iopause.h1 src/iopause.h2 src/iopause.c src/trypoll.c src/fifo.h src/fifo.c src/hasmkffo.h1 src/hasmkffo.h2 src/trymkffo.c src/open.h src/open_read.c src/open_write.c src/open_append.c src/lock.h src/hasflock.h1 src/hasflock.h2 src/tryflock.c src/lock_exnb.c src/lock_ex.c src/ndelay.h src/ndelay_on.c src/ndelay_off.c src/tai_pack.c src/taia_pack.c src/taia_add.c src/open_trunc.c src/taia_uint.c src/subgetopt.h src/subgetopt.c src/sgetopt.h src/sgetopt.c src/byte_chr.c src/fmt.h src/scan.h src/fmt_ulong.c src/fmt_uint.c src/fmt_uint0.c src/tai_unpack.c src/tai_now.c src/tai_sub.c src/seek.h src/seek_set.c src/str_diff.c src/byte_rchr.c src/scan_ulong.c src/buffer_get.c src/buffer_0.c src/prot.h src/prot.c src/hasshsgr.h1 src/hasshsgr.h2 src/chkshsgr.c src/warn-shsgr src/tryshsgr.c src/readclose.h src/readclose.c src/openreadclose.h src/openreadclose.c admin/daemontools-0.76/package/sharing 644 0 0 60 7323352455 14125 0ustar00command:syst compile:syst package:dist src:dist admin/daemontools-0.76/package/commands 644 0 0 223 7323352455 14314 0ustar00svscan svscanboot supervise svc svok svstat fghack pgrphack readproctitle multilog tai64n tai64nlocal softlimit setuidgid envuidgid envdir setlock admin/daemontools-0.76/package/install 755 0 0 71 7323352455 14145 0ustar00#!/bin/sh -e package/compile package/upgrade package/run admin/daemontools-0.76/package/compile 755 0 0 1240 7323352455 14166 0ustar00#!/bin/sh -e umask 022 test -d package || ( echo 'Wrong working directory.'; exit 1 ) test -d src || ( echo 'Wrong working directory.'; exit 1 ) here=`env - PATH=$PATH pwd` mkdir -p compile command test -r compile/home || echo $here > compile/home test -h compile/src || ln -s $here/src compile/src echo 'Linking ./src/* into ./compile...' for i in `ls src` do test -h compile/$i || ln -s src/$i compile/$i done echo 'Compiling everything in ./compile...' ( cd compile; exec make ) echo 'Copying commands into ./command...' for i in `cat package/commands` do rm -f command/$i'{new}' cp -p compile/$i command/$i'{new}' mv -f command/$i'{new}' command/$i done admin/daemontools-0.76/package/upgrade 755 0 0 1446 7323352455 14175 0ustar00#!/bin/sh -e umask 022 test -d package || ( echo 'Wrong working directory.'; exit 1 ) test -d src || ( echo 'Wrong working directory.'; exit 1 ) here=`env - PATH=$PATH pwd` parent=`dirname $here` echo 'Creating symlink daemontools -> daemontools-0.76...' rm -f daemontools ln -s daemontools-0.76 daemontools mv -f daemontools .. echo 'Making command links in /command...' mkdir -p /command for i in `cat package/commands` do rm -f /command/$i'{new}' ln -s $parent/daemontools/command/$i /command/$i'{new}' mv -f /command/$i'{new}' /command/$i done echo 'Making compatibility links in /usr/local/bin...' mkdir -p /usr/local/bin for i in `cat package/commands` do rm -f /usr/local/bin/$i'{new}' ln -s /command/$i /usr/local/bin/$i'{new}' mv -f /usr/local/bin/$i'{new}' /usr/local/bin/$i done admin/daemontools-0.76/package/run 755 0 0 666 7323352455 13335 0ustar00#!/bin/sh -e umask 022 test -d package || ( echo 'Wrong working directory.'; exit 1 ) test -d src || ( echo 'Wrong working directory.'; exit 1 ) if test -d /service then echo '/service exists. I assume that svscan is already running.' exit 0 fi echo 'Creating /service...' mkdir /service if test -r /etc/inittab then /command/setlock /etc/inittab package/run.inittab else /command/setlock /etc/rc.local package/run.rclocal fi admin/daemontools-0.76/package/run.inittab 755 0 0 576 7323352455 14766 0ustar00#!/bin/sh -e if grep svscanboot /etc/inittab >/dev/null then echo 'inittab contains an svscanboot line. I assume that svscan is already running.' else echo 'Adding svscanboot to inittab...' rm -f /etc/inittab'{new}' cat /etc/inittab package/boot.inittab > /etc/inittab'{new}' mv -f /etc/inittab'{new}' /etc/inittab kill -HUP 1 echo 'init should start svscan now.' fi admin/daemontools-0.76/package/boot.inittab 644 0 0 47 7323352455 15073 0ustar00 SV:123456:respawn:/command/svscanboot admin/daemontools-0.76/package/run.rclocal 755 0 0 573 7323352455 14750 0ustar00#!/bin/sh -e if grep svscanboot /etc/rc.local >/dev/null then echo 'rc.local contains an svscanboot line. I assume that svscan is already running.' else echo 'Adding svscanboot to /etc/rc.local...' rm -f /etc/rc.local'{new}' cat /etc/rc.local package/boot.rclocal > /etc/rc.local'{new}' mv -f /etc/rc.local'{new}' /etc/rc.local echo 'Reboot now to start svscan.' fi admin/daemontools-0.76/package/boot.rclocal 644 0 0 41 7323352455 15052 0ustar00 csh -cf '/command/svscanboot &' admin/daemontools-0.76/src 755 0 0 0 7323352455 11650 5ustar00admin/daemontools-0.76/src/CHANGES 644 0 0 6441 7323352455 13007 0ustar0019990824 version: daemontools 0.60, alpha. 19990825 portability problem: some systems need sys/time.h, not just time.h, before sys/resource.h. impact: couldn't compile. fix: change time.h to sys/time.h in softlimit.c. tnx Jos Backus and Chris Johnson. portability problem: echo -n echoes literal -n under traditional System V. tnx Tim Goodwin. impact: rts mismatch. fix: echo | tr -d. doc: removed note on man pages in conf-home. tnx Mate Wierdl. ui: do pidchange() and announce() before opening supervise/ok in supervise.c. 19990826 version: daemontools 0.61, alpha. 20000304 internal: upgraded to latest installation system. internal: switched from substdio to buffer. internal: switched from execvp to pathexec. internal: miscellaneous cleanups. internal: sped up tai64n. ui: svscan sleeps only 5 seconds. ui: svscan chdirs to argv[1] if argv[1] is supplied. ui: supervise does exec without waiting 1 second in child; but it waits 1 second before continuing in parent. ui: svstat reports time since last supervise pid change. ui: added envdir. ui: incorporated setlock from serialmail. 20000305 internal: switched to new sig library. internal: switched to iopause. internal: more cleanups. internal: sped up multilog. ui: multilog sets current to mode 644 on restart. version: daemontools 0.70, beta. 20000315 internal: new iopause. 20000316 internal: supervise does announce() only after changing state. avoids disk writes when supervise is idle. 20010707 internal: added const at various places. internal: miscellaneous cleanups. portability problem: with recent versions of glibc, and on AIX, including sys/time.h doesn't define struct tm. impact: couldn't compile. fix: also include time.h. tnx many people. portability problem: although sleep() isn't interrupted by signals on my old BSD/OS development machine, it is interrupted by signals on all new systems. impact: if a supervised process dies quickly (but not too quickly), supervise's 1-second sleep is interrupted, and the process is restarted immediately. fix: new deepsleep(). internal: switched signal handling in supervise and multilog to blocked-by-default. ui: multilog accepts ALRM to immediately rotate all cyclic logs for which current is nonempty. tnx Peter Samuel and William E. Baxter. 20010708 portability problem: under System V, one process can hold many exclusive locks on one file. impact: no impact on normal use, but some of the setlock regression tests fail. fix: change the tests to invoke an intermediate sh. tnx Mads Eilertsen. internal: fitfiles() in multilog. ui: added readproctitle. ui: added svscanboot. tnx Matthias Andree. ui: svscan checks for log directory instead of sticky bit. tnx many people. 20010709 ui: added pgrphack. 20010710 internal: upgraded to latest installation system. 20010711 version: daemontools 0.75, beta. 20010712 internal: ./package/compile creates ./compile/home. internal: ./package/compile creates absolute ./compile/src symlink instead of using .., so ./compile can itself be a symlink. tnx Paul Jarc. portability problem: Solaris sh has a built-in test that doesn't support -e, even though the test program supports -e. impact: package/{compile,run,upgrade} fail. tnx Mate Wierdl. fix: use -d, -h, -r. version: daemontools 0.76, beta. admin/daemontools-0.76/src/TODO 644 0 0 162 7323352455 12456 0ustar00expand rts document disk state diagram for a cyclic log in multilog use libtai local-time routines in tai64nlocal admin/daemontools-0.76/src/Makefile 644 0 0 35660 7323352455 13501 0ustar00default: it clean: rm -f alloc.o alloc_re.o buffer.o buffer_0.o buffer_1.o buffer_2.o \ buffer_get.o buffer_put.o buffer_read.o buffer_write.o byte.a \ byte_chr.o byte_copy.o byte_cr.o byte_diff.o byte_rchr.o chkshsgr \ chkshsgr.o choose coe.o compile deepsleep.o direntry.h env.o envdir \ envdir.o envuidgid envuidgid.o error.o error_str.o fd_copy.o \ fd_move.o fghack fghack.o fifo.o fmt_uint.o fmt_uint0.o fmt_ulong.o \ hasflock.h hasmkffo.h hassgact.h hassgprm.h hasshsgr.h haswaitp.h \ iopause.h iopause.o it load lock_ex.o lock_exnb.o makelib match.o \ matchtest matchtest.o multilog multilog.o ndelay_off.o ndelay_on.o \ open_append.o open_read.o open_trunc.o open_write.o openreadclose.o \ pathexec_env.o pathexec_run.o pgrphack pgrphack.o prot.o readclose.o \ readproctitle readproctitle.o rts scan_ulong.o seek_set.o select.h \ setlock setlock.o setuidgid setuidgid.o sgetopt.o sig.o sig_block.o \ sig_catch.o sig_pause.o softlimit softlimit.o str_chr.o str_diff.o \ str_len.o str_start.o stralloc_cat.o stralloc_catb.o stralloc_cats.o \ stralloc_eady.o stralloc_opyb.o stralloc_opys.o stralloc_pend.o \ strerr_die.o strerr_sys.o subgetopt.o supervise supervise.o svc svc.o \ svok svok.o svscan svscan.o svscanboot svstat svstat.o sysdeps \ systype tai64n tai64n.o tai64nlocal tai64nlocal.o tai_now.o \ tai_pack.o tai_sub.o tai_unpack.o taia_add.o taia_approx.o \ taia_frac.o taia_less.o taia_now.o taia_pack.o taia_sub.o taia_uint.o \ time.a timestamp.o uint64.h unix.a wait_nohang.o wait_pid.o alloc.o: alloc.c alloc.h compile error.h ./compile alloc.c alloc_re.o: alloc.h alloc_re.c byte.h compile ./compile alloc_re.c buffer.o: buffer.c buffer.h compile ./compile buffer.c buffer_0.o: buffer.h buffer_0.c compile ./compile buffer_0.c buffer_1.o: buffer.h buffer_1.c compile ./compile buffer_1.c buffer_2.o: buffer.h buffer_2.c compile ./compile buffer_2.c buffer_get.o: buffer.h buffer_get.c byte.h compile error.h ./compile buffer_get.c buffer_put.o: buffer.h buffer_put.c byte.h compile error.h str.h ./compile buffer_put.c buffer_read.o: buffer.h buffer_read.c compile ./compile buffer_read.c buffer_write.o: buffer.h buffer_write.c compile ./compile buffer_write.c byte.a: byte_chr.o byte_copy.o byte_cr.o byte_diff.o byte_rchr.o \ fmt_uint.o fmt_uint0.o fmt_ulong.o makelib scan_ulong.o str_chr.o \ str_diff.o str_len.o str_start.o ./makelib byte.a byte_chr.o byte_copy.o byte_cr.o byte_diff.o \ byte_rchr.o fmt_uint.o fmt_uint0.o fmt_ulong.o scan_ulong.o str_chr.o \ str_diff.o str_len.o str_start.o byte_chr.o: byte.h byte_chr.c compile ./compile byte_chr.c byte_copy.o: byte.h byte_copy.c compile ./compile byte_copy.c byte_cr.o: byte.h byte_cr.c compile ./compile byte_cr.c byte_diff.o: byte.h byte_diff.c compile ./compile byte_diff.c byte_rchr.o: byte.h byte_rchr.c compile ./compile byte_rchr.c chkshsgr: chkshsgr.o load ./load chkshsgr chkshsgr.o: chkshsgr.c compile ./compile chkshsgr.c choose: choose.sh home warn-auto.sh rm -f choose cat warn-auto.sh choose.sh \ | sed s}HOME}"`head -1 home`"}g \ > choose chmod 555 choose coe.o: coe.c coe.h compile ./compile coe.c compile: conf-cc print-cc.sh systype warn-auto.sh rm -f compile sh print-cc.sh > compile chmod 555 compile deepsleep.o: compile deepsleep.c deepsleep.h iopause.h tai.h taia.h \ uint64.h ./compile deepsleep.c direntry.h: choose compile direntry.h1 direntry.h2 trydrent.c ./choose c trydrent direntry.h1 direntry.h2 > direntry.h env.o: compile env.c env.h str.h ./compile env.c envdir: byte.a envdir.o load unix.a ./load envdir unix.a byte.a envdir.o: byte.h compile direntry.h envdir.c error.h gen_alloc.h \ open.h openreadclose.h pathexec.h stralloc.h strerr.h ./compile envdir.c envuidgid: byte.a envuidgid.o load unix.a ./load envuidgid unix.a byte.a envuidgid.o: compile envuidgid.c fmt.h pathexec.h strerr.h ./compile envuidgid.c error.o: compile error.c error.h ./compile error.c error_str.o: compile error.h error_str.c ./compile error_str.c fd_copy.o: compile fd.h fd_copy.c ./compile fd_copy.c fd_move.o: compile fd.h fd_move.c ./compile fd_move.c fghack: byte.a fghack.o load unix.a ./load fghack unix.a byte.a fghack.o: buffer.h compile error.h fghack.c pathexec.h strerr.h \ wait.h ./compile fghack.c fifo.o: compile fifo.c fifo.h hasmkffo.h ./compile fifo.c fmt_uint.o: compile fmt.h fmt_uint.c ./compile fmt_uint.c fmt_uint0.o: compile fmt.h fmt_uint0.c ./compile fmt_uint0.c fmt_ulong.o: compile fmt.h fmt_ulong.c ./compile fmt_ulong.c hasflock.h: choose compile hasflock.h1 hasflock.h2 load tryflock.c ./choose cl tryflock hasflock.h1 hasflock.h2 > hasflock.h hasmkffo.h: choose compile hasmkffo.h1 hasmkffo.h2 load trymkffo.c ./choose cl trymkffo hasmkffo.h1 hasmkffo.h2 > hasmkffo.h hassgact.h: choose compile hassgact.h1 hassgact.h2 load trysgact.c ./choose cl trysgact hassgact.h1 hassgact.h2 > hassgact.h hassgprm.h: choose compile hassgprm.h1 hassgprm.h2 load trysgprm.c ./choose cl trysgprm hassgprm.h1 hassgprm.h2 > hassgprm.h hasshsgr.h: chkshsgr choose compile hasshsgr.h1 hasshsgr.h2 load \ tryshsgr.c warn-shsgr ./chkshsgr || ( cat warn-shsgr; exit 1 ) ./choose clr tryshsgr hasshsgr.h1 hasshsgr.h2 > hasshsgr.h haswaitp.h: choose compile haswaitp.h1 haswaitp.h2 load trywaitp.c ./choose cl trywaitp haswaitp.h1 haswaitp.h2 > haswaitp.h iopause.h: choose compile iopause.h1 iopause.h2 load trypoll.c ./choose clr trypoll iopause.h1 iopause.h2 > iopause.h iopause.o: compile iopause.c iopause.h select.h tai.h taia.h uint64.h ./compile iopause.c it: rts sysdeps load: conf-ld print-ld.sh systype warn-auto.sh rm -f load sh print-ld.sh > load chmod 555 load lock_ex.o: compile hasflock.h lock.h lock_ex.c ./compile lock_ex.c lock_exnb.o: compile hasflock.h lock.h lock_exnb.c ./compile lock_exnb.c makelib: print-ar.sh systype warn-auto.sh rm -f makelib sh print-ar.sh > makelib chmod 555 makelib match.o: compile match.c match.h ./compile match.c matchtest: byte.a load match.o matchtest.o unix.a ./load matchtest match.o unix.a byte.a matchtest.o: buffer.h compile match.h matchtest.c str.h ./compile matchtest.c multilog: byte.a deepsleep.o load match.o multilog.o time.a \ timestamp.o unix.a ./load multilog deepsleep.o timestamp.o match.o time.a unix.a byte.a multilog.o: alloc.h buffer.h byte.h coe.h compile deepsleep.h \ direntry.h env.h error.h fd.h lock.h match.h multilog.c open.h scan.h \ seek.h sig.h str.h strerr.h timestamp.h wait.h ./compile multilog.c ndelay_off.o: compile ndelay.h ndelay_off.c ./compile ndelay_off.c ndelay_on.o: compile ndelay.h ndelay_on.c ./compile ndelay_on.c open_append.o: compile open.h open_append.c ./compile open_append.c open_read.o: compile open.h open_read.c ./compile open_read.c open_trunc.o: compile open.h open_trunc.c ./compile open_trunc.c open_write.o: compile open.h open_write.c ./compile open_write.c openreadclose.o: compile error.h gen_alloc.h open.h openreadclose.c \ openreadclose.h readclose.h stralloc.h ./compile openreadclose.c pathexec_env.o: alloc.h byte.h compile env.h gen_alloc.h pathexec.h \ pathexec_env.c str.h stralloc.h ./compile pathexec_env.c pathexec_run.o: compile env.h error.h gen_alloc.h pathexec.h \ pathexec_run.c str.h stralloc.h ./compile pathexec_run.c pgrphack: byte.a load pgrphack.o unix.a ./load pgrphack unix.a byte.a pgrphack.o: compile pathexec.h pgrphack.c strerr.h ./compile pgrphack.c prot.o: compile hasshsgr.h prot.c prot.h ./compile prot.c readclose.o: compile error.h gen_alloc.h readclose.c readclose.h \ stralloc.h ./compile readclose.c readproctitle: byte.a load readproctitle.o unix.a ./load readproctitle unix.a byte.a readproctitle.o: compile error.h readproctitle.c ./compile readproctitle.c rts: envdir envuidgid fghack matchtest multilog pgrphack \ readproctitle rts.tests setlock setuidgid softlimit supervise svc \ svok svscan svscanboot svstat tai64n tai64nlocal env - /bin/sh rts.tests 2>&1 | cat -v > rts scan_ulong.o: compile scan.h scan_ulong.c ./compile scan_ulong.c seek_set.o: compile seek.h seek_set.c ./compile seek_set.c select.h: choose compile select.h1 select.h2 trysysel.c ./choose c trysysel select.h1 select.h2 > select.h setlock: byte.a load setlock.o unix.a ./load setlock unix.a byte.a setlock.o: compile lock.h open.h pathexec.h setlock.c sgetopt.h \ strerr.h subgetopt.h ./compile setlock.c setuidgid: byte.a load setuidgid.o unix.a ./load setuidgid unix.a byte.a setuidgid.o: compile pathexec.h prot.h setuidgid.c strerr.h ./compile setuidgid.c sgetopt.o: buffer.h compile sgetopt.c sgetopt.h subgetopt.h ./compile sgetopt.c sig.o: compile sig.c sig.h ./compile sig.c sig_block.o: compile hassgprm.h sig.h sig_block.c ./compile sig_block.c sig_catch.o: compile hassgact.h sig.h sig_catch.c ./compile sig_catch.c sig_pause.o: compile hassgprm.h sig.h sig_pause.c ./compile sig_pause.c softlimit: byte.a load softlimit.o unix.a ./load softlimit unix.a byte.a softlimit.o: compile pathexec.h scan.h sgetopt.h softlimit.c str.h \ strerr.h subgetopt.h ./compile softlimit.c str_chr.o: compile str.h str_chr.c ./compile str_chr.c str_diff.o: compile str.h str_diff.c ./compile str_diff.c str_len.o: compile str.h str_len.c ./compile str_len.c str_start.o: compile str.h str_start.c ./compile str_start.c stralloc_cat.o: byte.h compile gen_alloc.h stralloc.h stralloc_cat.c ./compile stralloc_cat.c stralloc_catb.o: byte.h compile gen_alloc.h stralloc.h \ stralloc_catb.c ./compile stralloc_catb.c stralloc_cats.o: byte.h compile gen_alloc.h str.h stralloc.h \ stralloc_cats.c ./compile stralloc_cats.c stralloc_eady.o: alloc.h compile gen_alloc.h gen_allocdefs.h \ stralloc.h stralloc_eady.c ./compile stralloc_eady.c stralloc_opyb.o: byte.h compile gen_alloc.h stralloc.h \ stralloc_opyb.c ./compile stralloc_opyb.c stralloc_opys.o: byte.h compile gen_alloc.h str.h stralloc.h \ stralloc_opys.c ./compile stralloc_opys.c stralloc_pend.o: alloc.h compile gen_alloc.h gen_allocdefs.h \ stralloc.h stralloc_pend.c ./compile stralloc_pend.c strerr_die.o: buffer.h compile strerr.h strerr_die.c ./compile strerr_die.c strerr_sys.o: compile error.h strerr.h strerr_sys.c ./compile strerr_sys.c subgetopt.o: compile subgetopt.c subgetopt.h ./compile subgetopt.c supervise: byte.a deepsleep.o load supervise.o time.a unix.a ./load supervise deepsleep.o time.a unix.a byte.a supervise.o: coe.h compile deepsleep.h env.h error.h fifo.h iopause.h \ lock.h ndelay.h open.h sig.h strerr.h supervise.c tai.h taia.h \ uint64.h wait.h ./compile supervise.c svc: byte.a load svc.o unix.a ./load svc unix.a byte.a svc.o: buffer.h byte.h compile error.h ndelay.h open.h sgetopt.h \ sig.h strerr.h subgetopt.h svc.c ./compile svc.c svok: byte.a load svok.o unix.a ./load svok unix.a byte.a svok.o: compile error.h open.h strerr.h svok.c ./compile svok.c svscan: byte.a load svscan.o unix.a ./load svscan unix.a byte.a svscan.o: byte.h coe.h compile direntry.h env.h error.h fd.h \ pathexec.h str.h strerr.h svscan.c wait.h ./compile svscan.c svscanboot: home svscanboot.sh warn-auto.sh rm -f svscanboot cat warn-auto.sh svscanboot.sh \ | sed s}HOME}"`head -1 home`"}g \ > svscanboot chmod 555 svscanboot svstat: byte.a load svstat.o time.a unix.a ./load svstat time.a unix.a byte.a svstat.o: buffer.h compile error.h fmt.h open.h strerr.h svstat.c \ tai.h uint64.h ./compile svstat.c sysdeps: compile direntry.h hasflock.h hasmkffo.h hassgact.h \ hassgprm.h hasshsgr.h haswaitp.h iopause.h load select.h systype \ uint64.h rm -f sysdeps cat systype compile load >> sysdeps grep sysdep direntry.h >> sysdeps grep sysdep haswaitp.h >> sysdeps grep sysdep hassgact.h >> sysdeps grep sysdep hassgprm.h >> sysdeps grep sysdep select.h >> sysdeps grep sysdep uint64.h >> sysdeps grep sysdep iopause.h >> sysdeps grep sysdep hasmkffo.h >> sysdeps grep sysdep hasflock.h >> sysdeps grep sysdep hasshsgr.h >> sysdeps systype: find-systype.sh trycpp.c x86cpuid.c sh find-systype.sh > systype tai64n: byte.a load tai64n.o time.a timestamp.o unix.a ./load tai64n timestamp.o time.a unix.a byte.a tai64n.o: buffer.h compile tai64n.c timestamp.h ./compile tai64n.c tai64nlocal: byte.a load tai64nlocal.o unix.a ./load tai64nlocal unix.a byte.a tai64nlocal.o: buffer.h compile fmt.h tai64nlocal.c ./compile tai64nlocal.c tai_now.o: compile tai.h tai_now.c uint64.h ./compile tai_now.c tai_pack.o: compile tai.h tai_pack.c uint64.h ./compile tai_pack.c tai_sub.o: compile tai.h tai_sub.c uint64.h ./compile tai_sub.c tai_unpack.o: compile tai.h tai_unpack.c uint64.h ./compile tai_unpack.c taia_add.o: compile tai.h taia.h taia_add.c uint64.h ./compile taia_add.c taia_approx.o: compile tai.h taia.h taia_approx.c uint64.h ./compile taia_approx.c taia_frac.o: compile tai.h taia.h taia_frac.c uint64.h ./compile taia_frac.c taia_less.o: compile tai.h taia.h taia_less.c uint64.h ./compile taia_less.c taia_now.o: compile tai.h taia.h taia_now.c uint64.h ./compile taia_now.c taia_pack.o: compile tai.h taia.h taia_pack.c uint64.h ./compile taia_pack.c taia_sub.o: compile tai.h taia.h taia_sub.c uint64.h ./compile taia_sub.c taia_uint.o: compile tai.h taia.h taia_uint.c uint64.h ./compile taia_uint.c time.a: iopause.o makelib tai_now.o tai_pack.o tai_sub.o tai_unpack.o \ taia_add.o taia_approx.o taia_frac.o taia_less.o taia_now.o \ taia_pack.o taia_sub.o taia_uint.o ./makelib time.a iopause.o tai_now.o tai_pack.o tai_sub.o \ tai_unpack.o taia_add.o taia_approx.o taia_frac.o taia_less.o \ taia_now.o taia_pack.o taia_sub.o taia_uint.o timestamp.o: compile tai.h taia.h timestamp.c timestamp.h uint64.h ./compile timestamp.c uint64.h: choose compile load tryulong64.c uint64.h1 uint64.h2 ./choose clr tryulong64 uint64.h1 uint64.h2 > uint64.h unix.a: alloc.o alloc_re.o buffer.o buffer_0.o buffer_1.o buffer_2.o \ buffer_get.o buffer_put.o buffer_read.o buffer_write.o coe.o env.o \ error.o error_str.o fd_copy.o fd_move.o fifo.o lock_ex.o lock_exnb.o \ makelib ndelay_off.o ndelay_on.o open_append.o open_read.o \ open_trunc.o open_write.o openreadclose.o pathexec_env.o \ pathexec_run.o prot.o readclose.o seek_set.o sgetopt.o sig.o \ sig_block.o sig_catch.o sig_pause.o stralloc_cat.o stralloc_catb.o \ stralloc_cats.o stralloc_eady.o stralloc_opyb.o stralloc_opys.o \ stralloc_pend.o strerr_die.o strerr_sys.o subgetopt.o wait_nohang.o \ wait_pid.o ./makelib unix.a alloc.o alloc_re.o buffer.o buffer_0.o buffer_1.o \ buffer_2.o buffer_get.o buffer_put.o buffer_read.o buffer_write.o \ coe.o env.o error.o error_str.o fd_copy.o fd_move.o fifo.o lock_ex.o \ lock_exnb.o ndelay_off.o ndelay_on.o open_append.o open_read.o \ open_trunc.o open_write.o openreadclose.o pathexec_env.o \ pathexec_run.o prot.o readclose.o seek_set.o sgetopt.o sig.o \ sig_block.o sig_catch.o sig_pause.o stralloc_cat.o stralloc_catb.o \ stralloc_cats.o stralloc_eady.o stralloc_opyb.o stralloc_opys.o \ stralloc_pend.o strerr_die.o strerr_sys.o subgetopt.o wait_nohang.o \ wait_pid.o wait_nohang.o: compile haswaitp.h wait_nohang.c ./compile wait_nohang.c wait_pid.o: compile error.h haswaitp.h wait_pid.c ./compile wait_pid.c admin/daemontools-0.76/src/svscanboot.sh 644 0 0 1244 7323352455 14525 0ustar00 PATH=/command:/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin exec /dev/null exec 2>/dev/null /command/svc -dx /service/* /service/*/log env - PATH=$PATH svscan /service 2>&1 | \ env - PATH=$PATH readproctitle service errors: ................................................................................................................................................................................................................................................................................................................................................................................................................ admin/daemontools-0.76/src/svscan.c 644 0 0 10213 7323352455 13465 0ustar00#include #include #include #include "direntry.h" #include "strerr.h" #include "error.h" #include "wait.h" #include "coe.h" #include "fd.h" #include "env.h" #include "str.h" #include "byte.h" #include "pathexec.h" #define SERVICES 1000 #define WARNING "svscan: warning: " #define FATAL "svscan: fatal: " struct { unsigned long dev; unsigned long ino; int flagactive; int flaglog; int pid; /* 0 if not running */ int pidlog; /* 0 if not running */ int pi[2]; /* defined if flaglog */ } x[SERVICES]; int numx = 0; char fnlog[260]; void start(char *fn) { unsigned int fnlen; struct stat st; int child; int i; const char *args[3]; if (fn[0] == '.') return; if (stat(fn,&st) == -1) { strerr_warn4(WARNING,"unable to stat ",fn,": ",&strerr_sys); return; } if ((st.st_mode & S_IFMT) != S_IFDIR) return; for (i = 0;i < numx;++i) if (x[i].ino == st.st_ino) if (x[i].dev == st.st_dev) break; if (i == numx) { if (numx >= SERVICES) { strerr_warn4(WARNING,"unable to start ",fn,": running too many services",0); return; } x[i].ino = st.st_ino; x[i].dev = st.st_dev; x[i].pid = 0; x[i].pidlog = 0; x[i].flaglog = 0; fnlen = str_len(fn); if (fnlen <= 255) { byte_copy(fnlog,fnlen,fn); byte_copy(fnlog + fnlen,5,"/log"); if (stat(fnlog,&st) == 0) x[i].flaglog = 1; else if (errno != error_noent) { strerr_warn4(WARNING,"unable to stat ",fn,"/log: ",&strerr_sys); return; } } if (x[i].flaglog) { if (pipe(x[i].pi) == -1) { strerr_warn4(WARNING,"unable to create pipe for ",fn,": ",&strerr_sys); return; } coe(x[i].pi[0]); coe(x[i].pi[1]); } ++numx; } x[i].flagactive = 1; if (!x[i].pid) switch(child = fork()) { case -1: strerr_warn4(WARNING,"unable to fork for ",fn,": ",&strerr_sys); return; case 0: if (x[i].flaglog) if (fd_move(1,x[i].pi[1]) == -1) strerr_die4sys(111,WARNING,"unable to set up descriptors for ",fn,": "); args[0] = "supervise"; args[1] = fn; args[2] = 0; pathexec_run(*args,args,environ); strerr_die4sys(111,WARNING,"unable to start supervise ",fn,": "); default: x[i].pid = child; } if (x[i].flaglog && !x[i].pidlog) switch(child = fork()) { case -1: strerr_warn4(WARNING,"unable to fork for ",fn,"/log: ",&strerr_sys); return; case 0: if (fd_move(0,x[i].pi[0]) == -1) strerr_die4sys(111,WARNING,"unable to set up descriptors for ",fn,"/log: "); if (chdir(fn) == -1) strerr_die4sys(111,WARNING,"unable to switch to ",fn,": "); args[0] = "supervise"; args[1] = "log"; args[2] = 0; pathexec_run(*args,args,environ); strerr_die4sys(111,WARNING,"unable to start supervise ",fn,"/log: "); default: x[i].pidlog = child; } } void direrror(void) { strerr_warn2(WARNING,"unable to read directory: ",&strerr_sys); } void doit(void) { DIR *dir; direntry *d; int i; int r; int wstat; for (;;) { r = wait_nohang(&wstat); if (!r) break; if (r == -1) { if (errno == error_intr) continue; /* impossible */ break; } for (i = 0;i < numx;++i) { if (x[i].pid == r) { x[i].pid = 0; break; } if (x[i].pidlog == r) { x[i].pidlog = 0; break; } } } for (i = 0;i < numx;++i) x[i].flagactive = 0; dir = opendir("."); if (!dir) { direrror(); return; } for (;;) { errno = 0; d = readdir(dir); if (!d) break; start(d->d_name); } if (errno) { direrror(); closedir(dir); return; } closedir(dir); i = 0; while (i < numx) { if (!x[i].flagactive && !x[i].pid && !x[i].pidlog) { if (x[i].flaglog) { close(x[i].pi[0]); close(x[i].pi[1]); x[i].flaglog = 0; } x[i] = x[--numx]; continue; } ++i; } } int main(int argc,char **argv) { if (argv[0] && argv[1]) if (chdir(argv[1]) == -1) strerr_die4sys(111,FATAL,"unable to chdir to ",argv[1],": "); for (;;) { doit(); sleep(5); } } admin/daemontools-0.76/src/supervise.c 644 0 0 12516 7323352455 14225 0ustar00#include #include #include #include #include "sig.h" #include "strerr.h" #include "error.h" #include "fifo.h" #include "open.h" #include "lock.h" #include "wait.h" #include "coe.h" #include "ndelay.h" #include "env.h" #include "iopause.h" #include "taia.h" #include "deepsleep.h" #define FATAL "supervise: fatal: " #define WARNING "supervise: warning: " char *dir; int selfpipe[2]; int fdlock; int fdcontrolwrite; int fdcontrol; int fdok; int flagexit = 0; int flagwant = 1; int flagwantup = 1; int pid = 0; /* 0 means down */ int flagpaused; /* defined if(pid) */ char status[18]; void pidchange(void) { struct taia now; unsigned long u; taia_now(&now); taia_pack(status,&now); u = (unsigned long) pid; status[12] = u; u >>= 8; status[13] = u; u >>= 8; status[14] = u; u >>= 8; status[15] = u; } void announce(void) { int fd; int r; status[16] = (pid ? flagpaused : 0); status[17] = (flagwant ? (flagwantup ? 'u' : 'd') : 0); fd = open_trunc("supervise/status.new"); if (fd == -1) { strerr_warn4(WARNING,"unable to open ",dir,"/supervise/status.new: ",&strerr_sys); return; } r = write(fd,status,sizeof status); if (r == -1) { strerr_warn4(WARNING,"unable to write ",dir,"/supervise/status.new: ",&strerr_sys); close(fd); return; } close(fd); if (r < sizeof status) { strerr_warn4(WARNING,"unable to write ",dir,"/supervise/status.new: partial write",0); return; } if (rename("supervise/status.new","supervise/status") == -1) strerr_warn4(WARNING,"unable to rename ",dir,"/supervise/status.new to status: ",&strerr_sys); } void trigger(void) { write(selfpipe[1],"",1); } const char *run[2] = { "./run", 0 }; void trystart(void) { int f; switch(f = fork()) { case -1: strerr_warn4(WARNING,"unable to fork for ",dir,", sleeping 60 seconds: ",&strerr_sys); deepsleep(60); trigger(); return; case 0: sig_uncatch(sig_child); sig_unblock(sig_child); execve(*run,run,environ); strerr_die4sys(111,FATAL,"unable to start ",dir,"/run: "); } flagpaused = 0; pid = f; pidchange(); announce(); deepsleep(1); } void doit(void) { iopause_fd x[2]; struct taia deadline; struct taia stamp; int wstat; int r; char ch; announce(); for (;;) { if (flagexit && !pid) return; sig_unblock(sig_child); x[0].fd = selfpipe[0]; x[0].events = IOPAUSE_READ; x[1].fd = fdcontrol; x[1].events = IOPAUSE_READ; taia_now(&stamp); taia_uint(&deadline,3600); taia_add(&deadline,&stamp,&deadline); iopause(x,2,&deadline,&stamp); sig_block(sig_child); while (read(selfpipe[0],&ch,1) == 1) ; for (;;) { r = wait_nohang(&wstat); if (!r) break; if ((r == -1) && (errno != error_intr)) break; if (r == pid) { pid = 0; pidchange(); announce(); if (flagexit) return; if (flagwant && flagwantup) trystart(); break; } } if (read(fdcontrol,&ch,1) == 1) switch(ch) { case 'd': flagwant = 1; flagwantup = 0; if (pid) { kill(pid,SIGTERM); kill(pid,SIGCONT); flagpaused = 0; } announce(); break; case 'u': flagwant = 1; flagwantup = 1; announce(); if (!pid) trystart(); break; case 'o': flagwant = 0; announce(); if (!pid) trystart(); break; case 'a': if (pid) kill(pid,SIGALRM); break; case 'h': if (pid) kill(pid,SIGHUP); break; case 'k': if (pid) kill(pid,SIGKILL); break; case 't': if (pid) kill(pid,SIGTERM); break; case 'i': if (pid) kill(pid,SIGINT); break; case 'p': flagpaused = 1; announce(); if (pid) kill(pid,SIGSTOP); break; case 'c': flagpaused = 0; announce(); if (pid) kill(pid,SIGCONT); break; case 'x': flagexit = 1; announce(); break; } } } int main(int argc,char **argv) { struct stat st; dir = argv[1]; if (!dir || argv[2]) strerr_die1x(100,"supervise: usage: supervise dir"); if (pipe(selfpipe) == -1) strerr_die4sys(111,FATAL,"unable to create pipe for ",dir,": "); coe(selfpipe[0]); coe(selfpipe[1]); ndelay_on(selfpipe[0]); ndelay_on(selfpipe[1]); sig_block(sig_child); sig_catch(sig_child,trigger); if (chdir(dir) == -1) strerr_die4sys(111,FATAL,"unable to chdir to ",dir,": "); if (stat("down",&st) != -1) flagwantup = 0; else if (errno != error_noent) strerr_die4sys(111,FATAL,"unable to stat ",dir,"/down: "); mkdir("supervise",0700); fdlock = open_append("supervise/lock"); if ((fdlock == -1) || (lock_exnb(fdlock) == -1)) strerr_die4sys(111,FATAL,"unable to acquire ",dir,"/supervise/lock: "); coe(fdlock); fifo_make("supervise/control",0600); fdcontrol = open_read("supervise/control"); if (fdcontrol == -1) strerr_die4sys(111,FATAL,"unable to read ",dir,"/supervise/control: "); coe(fdcontrol); ndelay_on(fdcontrol); /* shouldn't be necessary */ fdcontrolwrite = open_write("supervise/control"); if (fdcontrolwrite == -1) strerr_die4sys(111,FATAL,"unable to write ",dir,"/supervise/control: "); coe(fdcontrolwrite); pidchange(); announce(); fifo_make("supervise/ok",0600); fdok = open_read("supervise/ok"); if (fdok == -1) strerr_die4sys(111,FATAL,"unable to read ",dir,"/supervise/ok: "); coe(fdok); if (!flagwant || flagwantup) trystart(); doit(); announce(); _exit(0); } admin/daemontools-0.76/src/svc.c 644 0 0 3244 7323352455 12751 0ustar00#include #include "ndelay.h" #include "strerr.h" #include "error.h" #include "open.h" #include "sgetopt.h" #include "buffer.h" #include "byte.h" #include "sig.h" #define FATAL "svc: fatal: " #define WARNING "svc: warning: " int datalen = 0; char data[20]; buffer b; char bspace[1]; int fdorigdir; int main(int argc,const char *const *argv) { int opt; int fd; const char *dir; sig_ignore(sig_pipe); while ((opt = getopt(argc,argv,"udopchaitkx")) != opteof) if (opt == '?') strerr_die1x(100,"svc options: u up, d down, o once, x exit, p pause, c continue, h hup, a alarm, i interrupt, t term, k kill"); else if (datalen < sizeof data) if (byte_chr(data,datalen,opt) == datalen) data[datalen++] = opt; argv += optind; fdorigdir = open_read("."); if (fdorigdir == -1) strerr_die2sys(111,FATAL,"unable to open current directory: "); while (dir = *argv++) { if (chdir(dir) == -1) strerr_warn4(WARNING,"unable to chdir to ",dir,": ",&strerr_sys); else { fd = open_write("supervise/control"); if (fd == -1) if (errno == error_nodevice) strerr_warn4(WARNING,"unable to control ",dir,": supervise not running",0); else strerr_warn4(WARNING,"unable to control ",dir,": ",&strerr_sys); else { ndelay_off(fd); buffer_init(&b,buffer_unixwrite,fd,bspace,sizeof bspace); if (buffer_putflush(&b,data,datalen) == -1) strerr_warn4(WARNING,"error writing commands to ",dir,": ",&strerr_sys); close(fd); } } if (fchdir(fdorigdir) == -1) strerr_die2sys(111,FATAL,"unable to set directory: "); } _exit(0); } admin/daemontools-0.76/src/svok.c 644 0 0 1042 7323352455 13132 0ustar00#include #include "strerr.h" #include "error.h" #include "open.h" #define FATAL "svok: fatal: " int main(int argc,char **argv) { int fd; if (!argv[1]) strerr_die1x(100,"svok: usage: svok dir"); if (chdir(argv[1]) == -1) strerr_die4sys(111,FATAL,"unable to chdir to ",argv[1],": "); fd = open_write("supervise/ok"); if (fd == -1) { if (errno == error_noent) _exit(100); if (errno == error_nodevice) _exit(100); strerr_die4sys(111,FATAL,"unable to open ",argv[1],"/supervise/ok: "); } _exit(0); } admin/daemontools-0.76/src/svstat.c 644 0 0 5705 7323352455 13506 0ustar00#include #include #include #include "strerr.h" #include "error.h" #include "open.h" #include "fmt.h" #include "tai.h" #include "buffer.h" #define FATAL "svstat: fatal: " #define WARNING "svstat: warning: " char bspace[1024]; buffer b = BUFFER_INIT(buffer_unixwrite,1,bspace,sizeof bspace); char status[18]; char strnum[FMT_ULONG]; unsigned long pid; unsigned char normallyup; unsigned char want; unsigned char paused; void doit(char *dir) { struct stat st; int r; int fd; const char *x; struct tai when; struct tai now; buffer_puts(&b,dir); buffer_puts(&b,": "); if (chdir(dir) == -1) { x = error_str(errno); buffer_puts(&b,"unable to chdir: "); buffer_puts(&b,x); return; } normallyup = 0; if (stat("down",&st) == -1) { if (errno != error_noent) { x = error_str(errno); buffer_puts(&b,"unable to stat down: "); buffer_puts(&b,x); return; } normallyup = 1; } fd = open_write("supervise/ok"); if (fd == -1) { if (errno == error_nodevice) { buffer_puts(&b,"supervise not running"); return; } x = error_str(errno); buffer_puts(&b,"unable to open supervise/ok: "); buffer_puts(&b,x); return; } close(fd); fd = open_read("supervise/status"); if (fd == -1) { x = error_str(errno); buffer_puts(&b,"unable to open supervise/status: "); buffer_puts(&b,x); return; } r = buffer_unixread(fd,status,sizeof status); close(fd); if (r < sizeof status) { if (r == -1) x = error_str(errno); else x = "bad format"; buffer_puts(&b,"unable to read supervise/status: "); buffer_puts(&b,x); return; } 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]; paused = status[16]; want = status[17]; tai_unpack(status,&when); tai_now(&now); if (tai_less(&now,&when)) when = now; tai_sub(&when,&now,&when); if (pid) { buffer_puts(&b,"up (pid "); buffer_put(&b,strnum,fmt_ulong(strnum,pid)); buffer_puts(&b,") "); } else buffer_puts(&b,"down "); buffer_put(&b,strnum,fmt_ulong(strnum,tai_approx(&when))); buffer_puts(&b," seconds"); if (pid && !normallyup) buffer_puts(&b,", normally down"); if (!pid && normallyup) buffer_puts(&b,", normally up"); if (pid && paused) buffer_puts(&b,", paused"); if (!pid && (want == 'u')) buffer_puts(&b,", want up"); if (pid && (want == 'd')) buffer_puts(&b,", want down"); } int main(int argc,char **argv) { int fdorigdir; char *dir; ++argv; fdorigdir = open_read("."); if (fdorigdir == -1) strerr_die2sys(111,FATAL,"unable to open current directory: "); while (dir = *argv++) { doit(dir); buffer_puts(&b,"\n"); if (fchdir(fdorigdir) == -1) strerr_die2sys(111,FATAL,"unable to set directory: "); } buffer_flush(&b); _exit(0); } admin/daemontools-0.76/src/fghack.c 644 0 0 2047 7323352455 13401 0ustar00#include #include "wait.h" #include "error.h" #include "strerr.h" #include "buffer.h" #include "pathexec.h" #define FATAL "fghack: fatal: " int pid; int main(int argc,const char * const *argv,const char * const *envp) { char ch; int wstat; int pi[2]; int i; if (!argv[1]) strerr_die1x(100,"fghack: usage: fghack child"); if (pipe(pi) == -1) strerr_die2sys(111,FATAL,"unable to create pipe: "); switch(pid = fork()) { case -1: strerr_die2sys(111,FATAL,"unable to fork: "); case 0: close(pi[0]); for (i = 0;i < 30;++i) dup(pi[1]); pathexec_run(argv[1],argv + 1,envp); strerr_die4sys(111,FATAL,"unable to run ",argv[1],": "); } close(pi[1]); for (;;) { i = buffer_unixread(pi[0],&ch,1); if ((i == -1) && (errno == error_intr)) continue; if (i == 1) continue; break; } if (wait_pid(&wstat,pid) == -1) strerr_die2sys(111,FATAL,"wait failed: "); if (wait_crashed(wstat)) strerr_die2x(111,FATAL,"child crashed"); _exit(wait_exitcode(wstat)); } admin/daemontools-0.76/src/pgrphack.c 644 0 0 626 7323352455 13736 0ustar00#include #include "strerr.h" #include "pathexec.h" #define FATAL "pgrphack: fatal: " int main(int argc,const char * const *argv,const char * const *envp) { if (!argv[1]) strerr_die1x(100,"pgrphack: usage: pgrphack child"); setsid(); /* shouldn't fail; if it does, too bad */ pathexec_run(argv[1],argv + 1,envp); strerr_die4sys(111,"pgrphack: fatal: ","unable to run ",argv[1],": "); } admin/daemontools-0.76/src/readproctitle.c 644 0 0 746 7323352455 15003 0ustar00#include #include "error.h" int main(int argc,char **argv) { char *buf; unsigned int len; int i; char ch; if (argc < 2) _exit(100); buf = argv[argc - 1]; len = 0; while (buf[len]) buf[len++] = '.'; if (len < 5) _exit(100); for (;;) switch(read(0,&ch,1)) { case 1: if (ch) { for (i = 4;i < len;++i) buf[i - 1] = buf[i]; buf[len - 1] = ch; } break; case 0: _exit(0); case -1: if (errno != error_intr) _exit(111); } } admin/daemontools-0.76/src/multilog.c 644 0 0 33112 7323352455 14027 0ustar00#include #include #include #include "direntry.h" #include "alloc.h" #include "buffer.h" #include "strerr.h" #include "error.h" #include "open.h" #include "lock.h" #include "scan.h" #include "str.h" #include "byte.h" #include "seek.h" #include "timestamp.h" #include "wait.h" #include "coe.h" #include "env.h" #include "fd.h" #include "sig.h" #include "match.h" #include "deepsleep.h" #define FATAL "multilog: fatal: " #define WARNING "multilog: warning: " void pause3(const char *s1,const char *s2,const char *s3) { strerr_warn4(WARNING,s1,s2,s3,&strerr_sys); deepsleep(5); } void pause5(const char *s1,const char *s2,const char *s3,const char *s4,const char *s5) { strerr_warn6(WARNING,s1,s2,s3,s4,s5,&strerr_sys); deepsleep(5); } int fdstartdir; int *f; void f_init(char **script) { int i; int fd; for (i = 0;script[i];++i) ; f = (int *) alloc(i * sizeof(*f)); if (!f) strerr_die2x(111,FATAL,"out of memory"); for (i = 0;script[i];++i) { fd = -1; if (script[i][0] == '=') { if (fchdir(fdstartdir) == -1) strerr_die2sys(111,FATAL,"unable to switch to starting directory: "); fd = open_append(script[i] + 1); if (fd == -1) strerr_die4sys(111,FATAL,"unable to create ",script[i] + 1,": "); close(fd); fd = open_write(script[i] + 1); if (fd == -1) strerr_die4sys(111,FATAL,"unable to write ",script[i] + 1,": "); coe(fd); } f[i] = fd; } } struct cyclog { char buf[512]; buffer ss; int fdcurrent; unsigned long bytes; unsigned long num; unsigned long size; char *processor; char *dir; int fddir; int fdlock; int flagselected; } *c; int cnum; char fn[40]; int filesfit(struct cyclog *d) { DIR *dir; direntry *x; int count; int i; dir = opendir("."); if (!dir) return -1; fn[0] = '@'; fn[1] = 'z'; fn[2] = 0; count = 0; for (;;) { errno = 0; x = readdir(dir); if (!x) break; if (x->d_name[0] == '@') if (str_len(x->d_name) >= 25) { ++count; if (str_diff(x->d_name,fn) < 0) { for (i = 0;i < 25;++i) fn[i] = x->d_name[i]; fn[25] = 0; } } } if (errno) { closedir(dir); return -1; } closedir(dir); if (count < d->num) return 1; dir = opendir("."); if (!dir) return -1; for (;;) { errno = 0; x = readdir(dir); if (!x) break; if (x->d_name[0] == '@') if (str_len(x->d_name) >= 25) if (str_start(x->d_name,fn)) { unlink(x->d_name); break; } } if (errno) { closedir(dir); return -1; } closedir(dir); return 0; } void finish(struct cyclog *d,const char *file,const char *code) { struct stat st; for (;;) { if (stat(file,&st) == 0) break; if (errno == error_noent) return; pause5("unable to stat ",d->dir,"/",file,", pausing: "); } if (st.st_nlink == 1) for (;;) { timestamp(fn); fn[25] = '.'; fn[26] = code[0]; fn[27] = 0; if (link(file,fn) == 0) break; pause5("unable to link to ",d->dir,"/",fn,", pausing: "); } while (unlink(file) == -1) pause5("unable to remove ",d->dir,"/",file,", pausing: "); for (;;) switch(filesfit(d)) { case 1: return; case -1: pause3("unable to read ",d->dir,", pausing: "); } } void startprocessor(struct cyclog *d) { const char *args[4]; int fd; sig_uncatch(sig_term); sig_uncatch(sig_alarm); sig_unblock(sig_term); sig_unblock(sig_alarm); fd = open_read("previous"); if (fd == -1) return; if (fd_move(0,fd) == -1) return; fd = open_trunc("processed"); if (fd == -1) return; if (fd_move(1,fd) == -1) return; fd = open_read("state"); if (fd == -1) return; if (fd_move(4,fd) == -1) return; fd = open_trunc("newstate"); if (fd == -1) return; if (fd_move(5,fd) == -1) return; args[0] = "sh"; args[1] = "-c"; args[2] = d->processor; args[3] = 0; execve("/bin/sh",args,environ); } void fullcurrent(struct cyclog *d) { int fd; int pid; int wstat; while (fchdir(d->fddir) == -1) pause3("unable to switch to ",d->dir,", pausing: "); while (fsync(d->fdcurrent) == -1) pause3("unable to write ",d->dir,"/current to disk, pausing: "); close(d->fdcurrent); while (rename("current","previous") == -1) pause3("unable to rename current to previous in directory ",d->dir,", pausing: "); while ((d->fdcurrent = open_append("current")) == -1) pause3("unable to create ",d->dir,"/current, pausing: "); coe(d->fdcurrent); d->bytes = 0; while (fchmod(d->fdcurrent,0644) == -1) pause3("unable to set mode of ",d->dir,"/current, pausing: "); while (chmod("previous",0744) == -1) pause3("unable to set mode of ",d->dir,"/previous, pausing: "); if (!d->processor) finish(d,"previous","s"); else { for (;;) { while ((pid = fork()) == -1) pause3("unable to fork for processor in ",d->dir,", pausing: "); if (!pid) { startprocessor(d); strerr_die4sys(111,FATAL,"unable to run ",d->processor,": "); } if (wait_pid(&wstat,pid) == -1) pause3("wait failed for processor in ",d->dir,", pausing: "); else if (wait_crashed(wstat)) pause3("processor crashed in ",d->dir,", pausing: "); else if (!wait_exitcode(wstat)) break; strerr_warn4(WARNING,"processor failed in ",d->dir,", pausing",0); deepsleep(5); } while ((fd = open_append("processed")) == -1) pause3("unable to create ",d->dir,"/processed, pausing: "); while (fsync(fd) == -1) pause3("unable to write ",d->dir,"/processed to disk, pausing: "); while (fchmod(fd,0744) == -1) pause3("unable to set mode of ",d->dir,"/processed, pausing: "); close(fd); while ((fd = open_append("newstate")) == -1) pause3("unable to create ",d->dir,"/newstate, pausing: "); while (fsync(fd) == -1) pause3("unable to write ",d->dir,"/newstate to disk, pausing: "); close(fd); while (unlink("previous") == -1) pause3("unable to remove ",d->dir,"/previous, pausing: "); while (rename("newstate","state") == -1) pause3("unable to rename newstate to state in directory ",d->dir,", pausing: "); finish(d,"processed","s"); } } int c_write(int pos,char *buf,int len) { struct cyclog *d; int w; d = c + pos; if (d->bytes >= d->size) fullcurrent(d); if (len >= d->size - d->bytes) len = d->size - d->bytes; if (d->bytes + len >= d->size - 2000) { w = byte_rchr(buf,len,'\n'); if (w < len) len = w + 1; } for (;;) { w = write(d->fdcurrent,buf,len); if (w > 0) break; pause3("unable to write to ",d->dir,"/current, pausing: "); } d->bytes += w; if (d->bytes >= d->size - 2000) if (buf[w - 1] == '\n') fullcurrent(d); return w; } void restart(struct cyclog *d) { struct stat st; int fd; int flagprocessed; if (fchdir(fdstartdir) == -1) strerr_die2sys(111,FATAL,"unable to switch to starting directory: "); mkdir(d->dir,0700); d->fddir = open_read(d->dir); if ((d->fddir == -1) || (fchdir(d->fddir) == -1)) strerr_die4sys(111,FATAL,"unable to open directory ",d->dir,": "); coe(d->fddir); d->fdlock = open_append("lock"); if ((d->fdlock == -1) || (lock_exnb(d->fdlock) == -1)) strerr_die4sys(111,FATAL,"unable to lock directory ",d->dir,": "); coe(d->fdlock); if (stat("current",&st) == -1) { if (errno != error_noent) strerr_die4sys(111,FATAL,"unable to stat ",d->dir,"/current: "); } else if (st.st_mode & 0100) { fd = open_append("current"); if (fd == -1) strerr_die4sys(111,FATAL,"unable to append to ",d->dir,"/current: "); if (fchmod(fd,0644) == -1) strerr_die4sys(111,FATAL,"unable to set mode of ",d->dir,"/current: "); coe(fd); d->fdcurrent = fd; d->bytes = st.st_size; return; } unlink("state"); unlink("newstate"); flagprocessed = 0; if (stat("processed",&st) == -1) { if (errno != error_noent) strerr_die4sys(111,FATAL,"unable to stat ",d->dir,"/processed: "); } else if (st.st_mode & 0100) flagprocessed = 1; if (flagprocessed) { unlink("previous"); finish(d,"processed","s"); } else { unlink("processed"); finish(d,"previous","u"); } finish(d,"current","u"); fd = open_trunc("state"); if (fd == -1) strerr_die4sys(111,FATAL,"unable to write to ",d->dir,"/state: "); close(fd); fd = open_append("current"); if (fd == -1) strerr_die4sys(111,FATAL,"unable to write to ",d->dir,"/current: "); if (fchmod(fd,0644) == -1) strerr_die4sys(111,FATAL,"unable to set mode of ",d->dir,"/current: "); coe(fd); d->fdcurrent = fd; d->bytes = 0; } void c_init(char **script) { int i; struct cyclog *d; char *processor; unsigned long num; unsigned long size; cnum = 0; for (i = 0;script[i];++i) if ((script[i][0] == '.') || (script[i][0] == '/')) ++cnum; c = (struct cyclog *) alloc(cnum * sizeof(*c)); if (!c) strerr_die2x(111,FATAL,"out of memory"); d = c; processor = 0; num = 10; size = 99999; for (i = 0;script[i];++i) if (script[i][0] == 's') { scan_ulong(script[i] + 1,&size); if (size < 4096) size = 4096; if (size > 16777215) size = 16777215; } else if (script[i][0] == 'n') { scan_ulong(script[i] + 1,&num); if (num < 2) num = 2; } else if (script[i][0] == '!') { processor = script[i] + 1; } else if ((script[i][0] == '.') || (script[i][0] == '/')) { d->num = num; d->size = size; d->processor = processor; d->dir = script[i]; buffer_init(&d->ss,c_write,d - c,d->buf,sizeof d->buf); restart(d); ++d; } } void c_quit(void) { int j; for (j = 0;j < cnum;++j) { buffer_flush(&c[j].ss); while (fsync(c[j].fdcurrent) == -1) pause3("unable to write ",c[j].dir,"/current to disk, pausing: "); while (fchmod(c[j].fdcurrent,0744) == -1) pause3("unable to set mode of ",c[j].dir,"/current, pausing: "); } } int flagexitasap = 0; int flagforcerotate = 0; int flagnewline = 1; void exitasap(void) { flagexitasap = 1; } void forcerotate(void) { flagforcerotate = 1; } int flushread(int fd,char *buf,int len) { int j; for (j = 0;j < cnum;++j) buffer_flush(&c[j].ss); if (flagforcerotate) { for (j = 0;j < cnum;++j) if (c[j].bytes > 0) fullcurrent(&c[j]); flagforcerotate = 0; } if (!len) return 0; if (flagexitasap) { if (flagnewline) return 0; len = 1; } sig_unblock(sig_term); sig_unblock(sig_alarm); len = read(fd,buf,len); sig_block(sig_term); sig_block(sig_alarm); if (len <= 0) return len; flagnewline = (buf[len - 1] == '\n'); return len; } char inbuf[1024]; buffer ssin = BUFFER_INIT(flushread,0,inbuf,sizeof inbuf); char line[1001]; int linelen; /* 0 <= linelen <= 1000 */ void doit(char **script) { int flageof; char ch; int j; int i; char *action; int flagselected; int flagtimestamp; flagtimestamp = 0; if (script[0]) if (script[0][0] == 't') flagtimestamp = 1; for (i = 0;i <= 1000;++i) line[i] = '\n'; linelen = 0; flageof = 0; for (;;) { for (i = 0;i < linelen;++i) line[i] = '\n'; linelen = 0; while (linelen < 1000) { if (buffer_GETC(&ssin,&ch) <= 0) { if (!linelen) return; flageof = 1; break; } if (!linelen) if (flagtimestamp) { timestamp(line); line[25] = ' '; linelen = 26; } if (ch == '\n') break; line[linelen++] = ch; } flagselected = 1; j = 0; for (i = 0;action = script[i];++i) switch(*action) { case '+': if (!flagselected) if (match(action + 1,line,linelen)) flagselected = 1; break; case '-': if (flagselected) if (match(action + 1,line,linelen)) flagselected = 0; break; case 'e': if (flagselected) { if (linelen > 200) { buffer_put(buffer_2,line,200); buffer_puts(buffer_2,"...\n"); } else { buffer_put(buffer_2,line,linelen); buffer_puts(buffer_2,"\n"); } buffer_flush(buffer_2); } break; case '=': if (flagselected) for (;;) { while (seek_begin(f[i]) == -1) pause3("unable to move to beginning of ",action + 1,", pausing: "); if (write(f[i],line,1001) == 1001) break; pause3("unable to write ",action + 1,", pausing: "); } break; case '.': case '/': c[j].flagselected = flagselected; ++j; break; } for (j = 0;j < cnum;++j) if (c[j].flagselected) buffer_put(&c[j].ss,line,linelen); if (linelen == 1000) for (;;) { if (buffer_GETC(&ssin,&ch) <= 0) { flageof = 1; break; } if (ch == '\n') break; for (j = 0;j < cnum;++j) if (c[j].flagselected) buffer_PUTC(&c[j].ss,ch); } for (j = 0;j < cnum;++j) if (c[j].flagselected) { ch = '\n'; buffer_PUTC(&c[j].ss,ch); } if (flageof) return; } } int main(int argc,char **argv) { umask(022); fdstartdir = open_read("."); if (fdstartdir == -1) strerr_die2sys(111,FATAL,"unable to switch to current directory: "); coe(fdstartdir); sig_block(sig_term); sig_block(sig_alarm); sig_catch(sig_term,exitasap); sig_catch(sig_alarm,forcerotate); ++argv; f_init(argv); c_init(argv); doit(argv); c_quit(); _exit(0); } admin/daemontools-0.76/src/tai64n.c 644 0 0 1471 7323352455 13263 0ustar00#include #include "timestamp.h" #include "buffer.h" int mywrite(int fd,char *buf,int len) { int w; w = buffer_unixwrite(fd,buf,len); if (w == -1) _exit(111); return w; } char outbuf[2048]; buffer out = BUFFER_INIT(mywrite,1,outbuf,sizeof outbuf); int myread(int fd,char *buf,int len) { int r; buffer_flush(&out); r = buffer_unixread(fd,buf,len); if (r == -1) _exit(111); return r; } char inbuf[1024]; buffer in = BUFFER_INIT(myread,0,inbuf,sizeof inbuf); char stamp[TIMESTAMP + 1]; int main() { char ch; for (;;) { if (buffer_GETC(&in,&ch) != 1) _exit(0); timestamp(stamp); stamp[TIMESTAMP] = ' '; buffer_put(&out,stamp,TIMESTAMP + 1); for (;;) { buffer_PUTC(&out,ch); if (ch == '\n') break; if (buffer_GETC(&in,&ch) != 1) _exit(0); } } } admin/daemontools-0.76/src/tai64nlocal.c 644 0 0 2556 7323352455 14303 0ustar00#include #include #include #include #include "buffer.h" #include "fmt.h" char num[FMT_ULONG]; void get(char *ch) { int r; r = buffer_GETC(buffer_0,ch); if (r == 1) return; if (r == 0) _exit(0); _exit(111); } void out(const char *buf,int len) { if (buffer_put(buffer_1,buf,len) == -1) _exit(111); } time_t secs; unsigned long nanosecs; unsigned long u; struct tm *t; int main() { char ch; for (;;) { get(&ch); if (ch == '@') { secs = 0; nanosecs = 0; for (;;) { get(&ch); u = ch - '0'; if (u >= 10) { u = ch - 'a'; if (u >= 6) break; u += 10; } secs <<= 4; secs += nanosecs >> 28; nanosecs &= 0xfffffff; nanosecs <<= 4; nanosecs += u; } secs -= 4611686018427387914ULL; t = localtime(&secs); out(num,fmt_ulong(num,1900 + t->tm_year)); out("-",1); out(num,fmt_uint0(num,1 + t->tm_mon,2)); out("-",1); out(num,fmt_uint0(num,t->tm_mday,2)); out(" ",1); out(num,fmt_uint0(num,t->tm_hour,2)); out(":",1); out(num,fmt_uint0(num,t->tm_min,2)); out(":",1); out(num,fmt_uint0(num,t->tm_sec,2)); out(".",1); out(num,fmt_uint0(num,nanosecs,9)); } for (;;) { out(&ch,1); if (ch == '\n') break; get(&ch); } } } admin/daemontools-0.76/src/softlimit.c 644 0 0 5126 7323352455 14171 0ustar00#include #include #include #include #include "pathexec.h" #include "sgetopt.h" #include "strerr.h" #include "scan.h" #include "str.h" #define FATAL "softlimit: fatal: " void die_usage(void) { strerr_die1x(100,"softlimit: usage: softlimit [-a allbytes] [-c corebytes] [-d databytes] [-f filebytes] [-l lockbytes] [-m membytes] [-o openfiles] [-p processes] [-r residentbytes] [-s stackbytes] [-t cpusecs] child"); } void doit(int resource,const char *arg) { unsigned long u; struct rlimit r; if (getrlimit(resource,&r) == -1) strerr_die2sys(111,FATAL,"getrlimit failed: "); if (str_equal(arg,"=")) r.rlim_cur = r.rlim_max; else { if (arg[scan_ulong(arg,&u)]) die_usage(); r.rlim_cur = u; if (r.rlim_cur > r.rlim_max) r.rlim_cur = r.rlim_max; } if (setrlimit(resource,&r) == -1) strerr_die2sys(111,FATAL,"setrlimit failed: "); } int main(int argc,const char *const *argv,const char *const *envp) { int opt; while ((opt = getopt(argc,argv,"a:c:d:f:l:m:o:p:r:s:t:")) != opteof) switch(opt) { case '?': die_usage(); case 'a': #ifdef RLIMIT_AS doit(RLIMIT_AS,optarg); #endif #ifdef RLIMIT_VMEM doit(RLIMIT_VMEM,optarg); #endif break; case 'c': #ifdef RLIMIT_CORE doit(RLIMIT_CORE,optarg); #endif break; case 'd': #ifdef RLIMIT_DATA doit(RLIMIT_DATA,optarg); #endif break; case 'f': #ifdef RLIMIT_FSIZE doit(RLIMIT_FSIZE,optarg); #endif break; case 'l': #ifdef RLIMIT_MEMLOCK doit(RLIMIT_MEMLOCK,optarg); #endif break; case 'm': #ifdef RLIMIT_DATA doit(RLIMIT_DATA,optarg); #endif #ifdef RLIMIT_STACK doit(RLIMIT_STACK,optarg); #endif #ifdef RLIMIT_MEMLOCK doit(RLIMIT_MEMLOCK,optarg); #endif #ifdef RLIMIT_VMEM doit(RLIMIT_VMEM,optarg); #endif #ifdef RLIMIT_AS doit(RLIMIT_AS,optarg); #endif break; case 'o': #ifdef RLIMIT_NOFILE doit(RLIMIT_NOFILE,optarg); #endif #ifdef RLIMIT_OFILE doit(RLIMIT_OFILE,optarg); #endif break; case 'p': #ifdef RLIMIT_NPROC doit(RLIMIT_NPROC,optarg); #endif break; case 'r': #ifdef RLIMIT_RSS doit(RLIMIT_RSS,optarg); #endif break; case 's': #ifdef RLIMIT_STACK doit(RLIMIT_STACK,optarg); #endif break; case 't': #ifdef RLIMIT_CPU doit(RLIMIT_CPU,optarg); #endif break; } argv += optind; if (!*argv) die_usage(); pathexec_run(*argv,argv,envp); strerr_die4sys(111,FATAL,"unable to run ",*argv,": "); } admin/daemontools-0.76/src/setuidgid.c 644 0 0 1323 7323352455 14133 0ustar00#include #include #include "prot.h" #include "strerr.h" #include "pathexec.h" #define FATAL "setuidgid: fatal: " const char *account; struct passwd *pw; int main(int argc,const char *const *argv,const char *const *envp) { account = *++argv; if (!account || !*++argv) strerr_die1x(100,"setuidgid: usage: setuidgid account child"); pw = getpwnam(account); if (!pw) strerr_die3x(111,FATAL,"unknown account ",account); if (prot_gid(pw->pw_gid) == -1) strerr_die2sys(111,FATAL,"unable to setgid: "); if (prot_uid(pw->pw_uid) == -1) strerr_die2sys(111,FATAL,"unable to setuid: "); pathexec_run(*argv,argv,envp); strerr_die4sys(111,FATAL,"unable to run ",*argv,": "); } admin/daemontools-0.76/src/envuidgid.c 644 0 0 1410 7323352455 14125 0ustar00#include #include #include "fmt.h" #include "strerr.h" #include "pathexec.h" #define FATAL "envuidgid: fatal: " void nomem(void) { strerr_die2x(111,FATAL,"out of memory"); } char strnum[FMT_ULONG]; const char *account; struct passwd *pw; int main(int argc,const char *const *argv) { account = *++argv; if (!account || !*++argv) strerr_die1x(100,"envuidgid: usage: envuidgid account child"); pw = getpwnam(account); if (!pw) strerr_die3x(111,FATAL,"unknown account ",account); strnum[fmt_ulong(strnum,pw->pw_gid)] = 0; if (!pathexec_env("GID",strnum)) nomem(); strnum[fmt_ulong(strnum,pw->pw_uid)] = 0; if (!pathexec_env("UID",strnum)) nomem(); pathexec(argv); strerr_die4sys(111,FATAL,"unable to run ",*argv,": "); } admin/daemontools-0.76/src/envdir.c 644 0 0 3604 7323352455 13445 0ustar00#include #include "byte.h" #include "open.h" #include "error.h" #include "direntry.h" #include "stralloc.h" #include "openreadclose.h" #include "strerr.h" #include "pathexec.h" #define FATAL "envdir: fatal: " void die_usage(void) { strerr_die1x(111,"envdir: usage: envdir dir child"); } void nomem(void) { strerr_die2x(111,FATAL,"out of memory"); } static stralloc sa; int main(int argc,const char *const *argv) { int fdorigdir; const char *fn; DIR *dir; direntry *d; int i; if (!*argv) die_usage(); if (!*++argv) die_usage(); fn = *argv; if (!*++argv) die_usage(); fdorigdir = open_read("."); if (fdorigdir == -1) strerr_die2sys(111,FATAL,"unable to switch to current directory: "); if (chdir(fn) == -1) strerr_die4sys(111,FATAL,"unable to switch to directory ",fn,": "); dir = opendir("."); if (!dir) strerr_die4sys(111,FATAL,"unable to read directory ",fn,": "); for (;;) { errno = 0; d = readdir(dir); if (!d) { if (errno) strerr_die4sys(111,FATAL,"unable to read directory ",fn,": "); break; } if (d->d_name[0] != '.') { if (openreadclose(d->d_name,&sa,256) == -1) strerr_die6sys(111,FATAL,"unable to read ",fn,"/",d->d_name,": "); if (sa.len) { sa.len = byte_chr(sa.s,sa.len,'\n'); while (sa.len) { if (sa.s[sa.len - 1] != ' ') if (sa.s[sa.len - 1] != '\t') break; --sa.len; } for (i = 0;i < sa.len;++i) if (!sa.s[i]) sa.s[i] = '\n'; if (!stralloc_0(&sa)) nomem(); if (!pathexec_env(d->d_name,sa.s)) nomem(); } else { if (!pathexec_env(d->d_name,0)) nomem(); } } } closedir(dir); if (fchdir(fdorigdir) == -1) strerr_die2sys(111,FATAL,"unable to switch to starting directory: "); close(fdorigdir); pathexec(argv); strerr_die4sys(111,FATAL,"unable to run ",*argv,": "); } admin/daemontools-0.76/src/setlock.c 644 0 0 2114 7323352455 13615 0ustar00#include #include "lock.h" #include "open.h" #include "strerr.h" #include "pathexec.h" #include "sgetopt.h" #define FATAL "setlock: fatal: " void usage() { strerr_die1x(100,"setlock: usage: setlock [ -nNxX ] file program [ arg ... ]"); } int flagndelay = 0; int flagx = 0; int main(int argc,const char *const *argv,const char *const *envp) { int opt; int fd; const char *file; while ((opt = getopt(argc,argv,"nNxX")) != opteof) switch(opt) { case 'n': flagndelay = 1; break; case 'N': flagndelay = 0; break; case 'x': flagx = 1; break; case 'X': flagx = 0; break; default: usage(); } argv += optind; if (!*argv) usage(); file = *argv++; if (!*argv) usage(); fd = open_append(file); if (fd == -1) { if (flagx) _exit(0); strerr_die4sys(111,FATAL,"unable to open ",file,": "); } if ((flagndelay ? lock_exnb : lock_ex)(fd) == -1) { if (flagx) _exit(0); strerr_die4sys(111,FATAL,"unable to lock ",file,": "); } pathexec_run(*argv,argv,envp); strerr_die4sys(111,FATAL,"unable to run ",*argv,": "); } admin/daemontools-0.76/src/match.c 644 0 0 657 7323352455 13237 0ustar00#include "match.h" int match(const char *pattern,const char *buf,unsigned int len) { char ch; for (;;) { ch = *pattern++; if (!ch) return !len; if (ch == '*') { ch = *pattern; if (!ch) return 1; for (;;) { if (!len) return 0; if (*buf == ch) break; ++buf; --len; } continue; } if (!len) return 0; if (*buf != ch) return 0; ++buf; --len; } } admin/daemontools-0.76/src/match.h 644 0 0 143 7323352455 13232 0ustar00#ifndef MATCH_H #define MATCH_H extern int match(const char *,const char *,unsigned int); #endif admin/daemontools-0.76/src/matchtest.c 644 0 0 712 7323352455 14127 0ustar00#include "match.h" #include "buffer.h" #include "str.h" int main(int argc,char **argv) { const char *pattern = ""; const char *buf = ""; if (argv[1]) { pattern = argv[1]; if (argv[2]) buf = argv[2]; } buffer_puts(buffer_1,match(pattern,buf,str_len(buf)) ? "+" : "-"); buffer_puts(buffer_1,pattern); buffer_puts(buffer_1," ("); buffer_puts(buffer_1,buf); buffer_puts(buffer_1,")\n"); buffer_flush(buffer_1); _exit(0); } admin/daemontools-0.76/src/timestamp.c 644 0 0 547 7323352455 14144 0ustar00#include "taia.h" #include "timestamp.h" static char hex[16] = "0123456789abcdef"; void timestamp(char s[TIMESTAMP]) { struct taia now; char nowpack[TAIA_PACK]; int i; taia_now(&now); taia_pack(nowpack,&now); s[0] = '@'; for (i = 0;i < 12;++i) { s[i * 2 + 1] = hex[(nowpack[i] >> 4) & 15]; s[i * 2 + 2] = hex[nowpack[i] & 15]; } } admin/daemontools-0.76/src/timestamp.h 644 0 0 146 7323352455 14144 0ustar00#ifndef TIMESTAMP_H #define TIMESTAMP_H #define TIMESTAMP 25 extern void timestamp(char *); #endif admin/daemontools-0.76/src/deepsleep.c 644 0 0 530 7323352455 14077 0ustar00#include "iopause.h" #include "deepsleep.h" extern void deepsleep(unsigned int s) { struct taia now; struct taia deadline; iopause_fd x; taia_now(&now); taia_uint(&deadline,s); taia_add(&deadline,&now,&deadline); for (;;) { taia_now(&now); if (taia_less(&deadline,&now)) return; iopause(&x,0,&deadline,&now); } } admin/daemontools-0.76/src/deepsleep.h 644 0 0 126 7323352455 14105 0ustar00#ifndef DEEPSLEEP_H #define DEEPSLEEP_H extern void deepsleep(unsigned int); #endif admin/daemontools-0.76/src/conf-cc 644 0 0 242 7323352455 13220 0ustar00gcc -O2 -Wimplicit -Wunused -Wcomment -Wchar-subscripts -Wuninitialized -Wshadow -Wcast-qual -Wcast-align -Wwrite-strings This will be used to compile .c files. admin/daemontools-0.76/src/conf-ld 644 0 0 77 7323352455 13220 0ustar00gcc -s This will be used to link .o files into an executable. admin/daemontools-0.76/src/print-cc.sh 644 0 0 140 7323352455 14035 0ustar00cc="`head -1 conf-cc`" systype="`cat systype`" cat warn-auto.sh echo exec "$cc" '-c ${1+"$@"}' admin/daemontools-0.76/src/print-ld.sh 644 0 0 212 7323352455 14047 0ustar00ld="`head -1 conf-ld`" systype="`cat systype`" cat warn-auto.sh echo 'main="$1"; shift' echo exec "$ld" '-o "$main" "$main".o ${1+"$@"}' admin/daemontools-0.76/src/print-ar.sh 644 0 0 371 7323352455 14060 0ustar00cat warn-auto.sh echo 'main="$1"; shift' echo 'rm -f "$main"' echo 'ar cr "$main" ${1+"$@"}' case "`cat systype`" in sunos-5.*) ;; unix_sv*) ;; irix64-*) ;; irix-*) ;; dgux-*) ;; hp-ux-*) ;; sco*) ;; *) echo 'ranlib "$main"' ;; esac admin/daemontools-0.76/src/choose.sh 644 0 0 402 7323352455 13577 0ustar00 result="$4" case "$1" in *c*) ./compile $2.c >/dev/null 2>&1 || result="$3" ;; esac case "$1" in *l*) ./load $2 >/dev/null 2>&1 || result="$3" ;; esac case "$1" in *r*) ./$2 >/dev/null 2>&1 || result="$3" ;; esac rm -f $2.o $2 exec cat "$result" admin/daemontools-0.76/src/warn-auto.sh 644 0 0 100 7323352455 14227 0ustar00#!/bin/sh # WARNING: This file was auto-generated. Do not edit! admin/daemontools-0.76/src/find-systype.sh 644 0 0 6404 7323352455 15005 0ustar00# oper-:arch-:syst-:chip-:kern- # oper = operating system type; e.g., sunos-4.1.4 # arch = machine language; e.g., sparc # syst = which binaries can run; e.g., sun4 # chip = chip model; e.g., micro-2-80 # kern = kernel version; e.g., sun4m # dependence: arch --- chip # \ \ # oper --- syst --- kern # so, for example, syst is interpreted in light of oper, but chip is not. # anyway, no slashes, no extra colons, no uppercase letters. # the point of the extra -'s is to ease parsing: can add hierarchies later. # e.g., *:i386-*:*:pentium-*:* would handle pentium-100 as well as pentium, # and i386-486 (486s do have more instructions, you know) as well as i386. # the idea here is to include ALL useful available information. exec 2>/dev/null sys="`uname -s | tr '/:[A-Z]' '..[a-z]'`" if [ x"$sys" != x ] then unamer="`uname -r | tr /: ..`" unamem="`uname -m | tr /: ..`" unamev="`uname -v | tr /: ..`" case "$sys" in bsd.os|freebsd|netbsd|openbsd) # in bsd 4.4, uname -v does not have useful info. # in bsd 4.4, uname -m is arch, not chip. oper="$sys-$unamer" arch="$unamem" syst="" chip="`sysctl -n hw.model`" # hopefully kern="" ;; linux) # as in bsd 4.4, uname -v does not have useful info. oper="$sys-$unamer" syst="" chip="$unamem" kern="" case "$chip" in i386|i486|i586|i686) arch="i386" ;; alpha) arch="alpha" ;; esac ;; aix) # naturally IBM has to get uname -r and uname -v backwards. dorks. oper="$sys-$unamev-$unamer" arch="`arch | tr /: ..`" syst="" chip="$unamem" kern="" ;; sunos) oper="$sys-$unamer-$unamev" arch="`(uname -p || mach) | tr /: ..`" syst="`arch | tr /: ..`" chip="$unamem" # this is wrong; is there any way to get the real info? kern="`arch -k | tr /: ..`" ;; unix_sv) oper="$sys-$unamer-$unamev" arch="`uname -m`" syst="" chip="$unamem" kern="" ;; *) oper="$sys-$unamer-$unamev" arch="`arch | tr /: ..`" syst="" chip="$unamem" kern="" ;; esac else gcc -c trycpp.c gcc -o trycpp trycpp.o case `./trycpp` in nextstep) oper="nextstep-`hostinfo | sed -n 's/^[ ]*NeXT Mach \([^:]*\):.*$/\1/p'`" arch="`hostinfo | sed -n 's/^Processor type: \(.*\) (.*)$/\1/p' | tr /: ..`" syst="" chip="`hostinfo | sed -n 's/^Processor type: .* (\(.*\))$/\1/p' | tr ' /:' '...'`" kern="" ;; *) oper="unknown" arch="" syst="" chip="" kern="" ;; esac rm -f trycpp.o trycpp fi case "$chip" in 80486) # let's try to be consistent here. (BSD/OS) chip=i486 ;; i486DX) # respect the hyphen hierarchy. (FreeBSD) chip=i486-dx ;; i486.DX2) # respect the hyphen hierarchy. (FreeBSD) chip=i486-dx2 ;; Intel.586) # no, you nitwits, there is no such chip. (NeXTStep) chip=pentium ;; i586) # no, you nitwits, there is no such chip. (Linux) chip=pentium ;; i686) # STOP SAYING THAT! (Linux) chip=ppro esac if gcc -c x86cpuid.c then if gcc -o x86cpuid x86cpuid.o then x86cpuid="`./x86cpuid | tr /: ..`" case "$x86cpuid" in ?*) chip="$x86cpuid" ;; esac fi fi rm -f x86cpuid x86cpuid.o echo "$oper-:$arch-:$syst-:$chip-:$kern-" | tr ' [A-Z]' '.[a-z]' admin/daemontools-0.76/src/trycpp.c 644 0 0 171 7323352455 13453 0ustar00/* Public domain. */ int main() { #ifdef NeXT printf("nextstep\n"); exit(0); #endif printf("unknown\n"); exit(0); } admin/daemontools-0.76/src/x86cpuid.c 644 0 0 1213 7323352455 13622 0ustar00/* Public domain. */ #include void nope() { exit(1); } int main() { unsigned long x[4]; unsigned long y[4]; int i; int j; char c; signal(SIGILL,nope); x[0] = 0; x[1] = 0; x[2] = 0; x[3] = 0; asm volatile(".byte 15;.byte 162" : "=a"(x[0]),"=b"(x[1]),"=c"(x[3]),"=d"(x[2]) : "0"(0) ); if (!x[0]) return 0; asm volatile(".byte 15;.byte 162" : "=a"(y[0]),"=b"(y[1]),"=c"(y[2]),"=d"(y[3]) : "0"(1) ); for (i = 1;i < 4;++i) for (j = 0;j < 4;++j) { c = x[i] >> (8 * j); if (c < 32) c = 32; if (c > 126) c = 126; putchar(c); } printf("-%08x-%08x\n",y[0],y[3]); return 0; } admin/daemontools-0.76/src/rts.tests 644 0 0 16741 7323352455 13734 0ustar00# not tested: # multilog handles TERM # multilog handles ALRM # multilog handles out-of-memory # multilog handles log directories # multilog matches only first 1000 characters of long lines # multilog t produces the right time # multilog closes descriptors properly # tai64n produces the right time # tai64nlocal converts times correctly # supervise closes descriptors properly # svc -d # svc -p # svc -c # svc -a # svc -i # svc -t # svc -k # svscan # svscanboot # envuidgid sets GID # setuidgid # pgrphack works properly # readproctitle works properly # softlimit -m # softlimit -d # softlimit -s # softlimit -l # softlimit -a # softlimit -p0 preventing fork; need to run this as non-root # softlimit -o; shared libraries make tests difficult here # softlimit -c # softlimit -f # softlimit -r # softlimit -t PATH=`pwd`:/command:/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin export PATH umask 022 rm -rf rts-tmp mkdir rts-tmp cd rts-tmp mkdir test.sv echo '--- svstat handles new and nonexistent directories' ( echo '#!/bin/sh'; echo echo hi ) > test.sv/run chmod 755 test.sv/run touch test.sv/down svstat test.sv nonexistent; echo $? echo '--- svc handles new and nonexistent directories' svc test.sv nonexistent; echo $? echo '--- svok handles new and nonexistent directories' svok test.sv; echo $? svok nonexistent; echo $? echo '--- supervise handles nonexistent directories' supervise nonexistent; echo $? echo '--- supervise starts, svok works, svstat works, svc -x works' supervise test.sv & until svok test.sv do sleep 1 done svstat test.sv | sed 's/[0-9]* seconds/x seconds/'; echo $? svc -x test.sv; echo $? wait svstat test.sv; echo $? echo '--- svc -ox works' supervise test.sv & until svok test.sv do sleep 1 done svc -ox test.sv wait echo '--- svstat works for up services' ( echo '#!/bin/sh'; echo sleep 1; echo svstat . ) > test.sv/run chmod 755 test.sv/run supervise test.sv \ | sed -e 's/[0-9]* seconds/x seconds/' -e 's/pid [0-9]*/pid x/' & until svok test.sv do sleep 1 done svc -ox test.sv wait echo '--- svc -u works' ( echo '#!/bin/sh'; echo echo first; echo mv run2 run ) > test.sv/run chmod 755 test.sv/run ( echo '#!/bin/sh'; echo echo second; echo svc -x . ) > test.sv/run2 chmod 755 test.sv/run2 supervise test.sv & until svok test.sv do sleep 1 done svc -u test.sv wait echo '--- tai64n has the right format' ( echo ONE; echo TWO ) | tai64n | sed 's/[0-9a-f]/x/g' echo '--- tai64nlocal handles non-@ lines correctly' ( echo one; echo two ) | tai64nlocal; echo $? echo '--- softlimit insists on an argument' softlimit; echo $? echo '--- softlimit complains if it cannot run program' softlimit ./nonexistent; echo $? echo '--- softlimit -p0 still allows exec' softlimit -p0 echo ./nonexistent; echo $? echo '--- fghack insists on an argument' fghack; echo $? echo '--- fghack complains if it cannot run program' fghack ./nonexistent; echo $? echo '--- fghack runs a program' fghack sh -c 'echo hi &'; echo $? echo '--- pgrphack insists on an argument' pgrphack; echo $? echo '--- pgrphack complains if it cannot run program' pgrphack ./nonexistent; echo $? echo '--- pgrphack runs a program' pgrphack echo ok; echo $? echo '--- readproctitle insists on an argument' readproctitle < /dev/null; echo $? echo '--- readproctitle insists on last argument being at least five bytes' readproctitle .......... four < /dev/null; echo $? echo '--- multilog prints nothing with no actions' ( echo one; echo two ) | multilog; echo $? echo '--- multilog e prints to stderr' ( echo one; echo two ) | multilog e 2>&1; echo $? echo '--- multilog inserts newline after partial final line' ( echo one; echo two | tr -d '\012' ) | multilog e 2>&1; echo $? echo '--- multilog handles multiple actions' ( echo one; echo two ) | multilog e e 2>&1; echo $? echo '--- multilog handles wildcard -' ( echo one; echo two ) | multilog '-*' e 2>&1; echo $? echo '--- multilog handles literal +' ( echo one; echo two ) | multilog '-*' '+one' e 2>&1; echo $? echo '--- multilog handles long lines for stderr' echo 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678 \ | multilog e 2>&1; echo $? echo 01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 \ | multilog e 2>&1; echo $? echo 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 \ | multilog e 2>&1; echo $? echo '--- multilog handles status files' rm -f test.status ( echo one; echo two ) | multilog =test.status; echo $? uniq -c < test.status | sed 's/[ ]*[ ]/_/g' echo '--- multilog t has the right format' ( echo ONE; echo TWO ) | multilog t e 2>&1 | sed 's/[0-9a-f]/x/g' echo '--- match handles literal string' matchtest one one matchtest one '' matchtest one on matchtest one onf matchtest one 'one*' matchtest one onetwo echo '--- match handles empty string' matchtest '' '' matchtest '' x echo '--- match handles full-line wildcard' matchtest '*' '' matchtest '*' x matchtest '*' '*' matchtest '*' one echo '--- match handles ending wildcard' matchtest 'one*' one matchtest 'one*' 'one*' matchtest 'one*' onetwo matchtest 'one*' '' matchtest 'one*' x matchtest 'one*' on matchtest 'one*' onf echo '--- match handles wildcard termination' matchtest '* one' ' one' matchtest '* one' 'x one' matchtest '* one' '* one' matchtest '* one' 'xy one' matchtest '* one' 'one' matchtest '* one' ' two' matchtest '* one' ' one' matchtest '* one' 'xy one ' echo '--- match handles multiple wildcards' matchtest '* * one' ' one' matchtest '* * one' 'x one' matchtest '* * one' ' y one' matchtest '* * one' 'x y one' matchtest '* * one' 'one' matchtest '* * one' ' one' matchtest '* * one' ' one' echo '--- envuidgid insists on two arguments' envuidgid; echo $? envuidgid root; echo $? echo '--- envuidgid sets UID=0 for root' envuidgid root printenv UID; echo $? echo '--- envuidgid complains if it cannot run program' envuidgid root ./nonexistent; echo $? echo '--- envdir requires arguments' envdir whatever; echo $? echo '--- envdir complains if it cannot read directory' ln -s env1 env1 envdir env1 echo yes; echo $? echo '--- envdir complains if it cannot read file' rm env1 mkdir env1 ln -s Message env1/Message envdir env1 echo yes; echo $? echo '--- envdir adds variables' rm env1/Message echo This is a test. This is only a test. > env1/Message envdir env1 sh -c 'echo $Message'; echo $? echo '--- envdir removes variables' mkdir env2 touch env2/Message envdir env1 envdir env2 sh -c 'echo $Message'; echo $? echo '--- setlock requires arguments' setlock whatever; echo $? echo '--- setlock complains if it cannot create lock file' setlock nonexistent/lock echo wrong; echo $? echo '--- setlock -x exits quietly if it cannot create lock file' setlock -x nonexistent/lock echo wrong; echo $? echo '--- setlock creates lock file' setlock lock echo ok; echo $? echo '--- setlock does not truncate lock file' echo ok > lock setlock lock cat lock; echo $? rm -f lock echo '--- setlock -n complains if file is already locked' setlock lock sh -c 'setlock -n lock echo one && echo two'; echo $? echo '--- setlock -nx exits quietly if file is already locked' setlock lock sh -c 'setlock -nx lock echo one && echo two'; echo $? exit 0 admin/daemontools-0.76/src/buffer.h 644 0 0 3150 7323352455 13430 0ustar00/* Public domain. */ #ifndef BUFFER_H #define BUFFER_H typedef struct buffer { char *x; unsigned int p; unsigned int n; int fd; int (*op)(); } buffer; #define BUFFER_INIT(op,fd,buf,len) { (buf), 0, (len), (fd), (op) } #define BUFFER_INSIZE 8192 #define BUFFER_OUTSIZE 8192 extern void buffer_init(buffer *,int (*)(),int,char *,unsigned int); extern int buffer_flush(buffer *); extern int buffer_put(buffer *,const char *,unsigned int); extern int buffer_putalign(buffer *,const char *,unsigned int); extern int buffer_putflush(buffer *,const char *,unsigned int); extern int buffer_puts(buffer *,const char *); extern int buffer_putsalign(buffer *,const char *); extern int buffer_putsflush(buffer *,const char *); #define buffer_PUTC(s,c) \ ( ((s)->n != (s)->p) \ ? ( (s)->x[(s)->p++] = (c), 0 ) \ : buffer_put((s),&(c),1) \ ) extern int buffer_get(buffer *,char *,unsigned int); extern int buffer_bget(buffer *,char *,unsigned int); extern int buffer_feed(buffer *); extern char *buffer_peek(buffer *); extern void buffer_seek(buffer *,unsigned int); #define buffer_PEEK(s) ( (s)->x + (s)->n ) #define buffer_SEEK(s,len) ( ( (s)->p -= (len) ) , ( (s)->n += (len) ) ) #define buffer_GETC(s,c) \ ( ((s)->p > 0) \ ? ( *(c) = (s)->x[(s)->n], buffer_SEEK((s),1), 1 ) \ : buffer_get((s),(c),1) \ ) extern int buffer_copy(buffer *,buffer *); extern int buffer_unixread(int,char *,unsigned int); extern int buffer_unixwrite(int,const char *,unsigned int); extern buffer *buffer_0; extern buffer *buffer_0small; extern buffer *buffer_1; extern buffer *buffer_1small; extern buffer *buffer_2; #endif admin/daemontools-0.76/src/buffer.c 644 0 0 275 7323352455 13410 0ustar00/* Public domain. */ #include "buffer.h" void buffer_init(buffer *s,int (*op)(),int fd,char *buf,unsigned int len) { s->x = buf; s->fd = fd; s->op = op; s->p = 0; s->n = len; } admin/daemontools-0.76/src/byte.h 644 0 0 427 7323352455 13106 0ustar00/* Public domain. */ #ifndef BYTE_H #define BYTE_H extern unsigned int byte_chr(); extern unsigned int byte_rchr(); extern void byte_copy(); extern void byte_copyr(); extern int byte_diff(); extern void byte_zero(); #define byte_equal(s,n,t) (!byte_diff((s),(n),(t))) #endif admin/daemontools-0.76/src/str.h 644 0 0 704 7323352455 12751 0ustar00/* Public domain. */ #ifndef STR_H #define STR_H extern unsigned int str_copy(char *,const char *); extern int str_diff(const char *,const char *); extern int str_diffn(const char *,const char *,unsigned int); extern unsigned int str_len(const char *); extern unsigned int str_chr(const char *,int); extern unsigned int str_rchr(const char *,int); extern int str_start(const char *,const char *); #define str_equal(s,t) (!str_diff((s),(t))) #endif admin/daemontools-0.76/src/str_len.c 644 0 0 405 7323352455 13600 0ustar00/* Public domain. */ #include "str.h" unsigned int str_len(const char *s) { register const char *t; t = s; for (;;) { if (!*t) return t - s; ++t; if (!*t) return t - s; ++t; if (!*t) return t - s; ++t; if (!*t) return t - s; ++t; } } admin/daemontools-0.76/src/byte_copy.c 644 0 0 501 7323352455 14124 0ustar00/* Public domain. */ #include "byte.h" void byte_copy(to,n,from) register char *to; register unsigned int n; register char *from; { for (;;) { if (!n) return; *to++ = *from++; --n; if (!n) return; *to++ = *from++; --n; if (!n) return; *to++ = *from++; --n; if (!n) return; *to++ = *from++; --n; } } admin/daemontools-0.76/src/byte_cr.c 644 0 0 532 7323352455 13562 0ustar00/* Public domain. */ #include "byte.h" void byte_copyr(to,n,from) register char *to; register unsigned int n; register char *from; { to += n; from += n; for (;;) { if (!n) return; *--to = *--from; --n; if (!n) return; *--to = *--from; --n; if (!n) return; *--to = *--from; --n; if (!n) return; *--to = *--from; --n; } } admin/daemontools-0.76/src/error.h 644 0 0 1123 7323352455 13306 0ustar00/* Public domain. */ #ifndef ERROR_H #define ERROR_H extern int errno; extern int error_intr; extern int error_nomem; extern int error_noent; extern int error_txtbsy; extern int error_io; extern int error_exist; extern int error_timeout; extern int error_inprogress; extern int error_wouldblock; extern int error_again; extern int error_pipe; extern int error_perm; extern int error_acces; extern int error_nodevice; extern int error_proto; extern int error_isdir; extern int error_connrefused; extern int error_notdir; extern const char *error_str(int); extern int error_temp(int); #endif admin/daemontools-0.76/src/error.c 644 0 0 2321 7323352455 13302 0ustar00/* Public domain. */ #include #include "error.h" /* warning: as coverage improves here, should update error_{str,temp} */ int error_intr = #ifdef EINTR EINTR; #else -1; #endif int error_nomem = #ifdef ENOMEM ENOMEM; #else -2; #endif int error_noent = #ifdef ENOENT ENOENT; #else -3; #endif int error_txtbsy = #ifdef ETXTBSY ETXTBSY; #else -4; #endif int error_io = #ifdef EIO EIO; #else -5; #endif int error_exist = #ifdef EEXIST EEXIST; #else -6; #endif int error_timeout = #ifdef ETIMEDOUT ETIMEDOUT; #else -7; #endif int error_inprogress = #ifdef EINPROGRESS EINPROGRESS; #else -8; #endif int error_wouldblock = #ifdef EWOULDBLOCK EWOULDBLOCK; #else -9; #endif int error_again = #ifdef EAGAIN EAGAIN; #else -10; #endif int error_pipe = #ifdef EPIPE EPIPE; #else -11; #endif int error_perm = #ifdef EPERM EPERM; #else -12; #endif int error_acces = #ifdef EACCES EACCES; #else -13; #endif int error_nodevice = #ifdef ENXIO ENXIO; #else -14; #endif int error_proto = #ifdef EPROTO EPROTO; #else -15; #endif int error_isdir = #ifdef EISDIR EISDIR; #else -16; #endif int error_connrefused = #ifdef ECONNREFUSED ECONNREFUSED; #else -17; #endif int error_notdir = #ifdef ENOTDIR ENOTDIR; #else -18; #endif admin/daemontools-0.76/src/buffer_put.c 644 0 0 3415 7323352455 14317 0ustar00/* Public domain. */ #include "buffer.h" #include "str.h" #include "byte.h" #include "error.h" static int allwrite(int (*op)(),int fd,const char *buf,unsigned int len) { int w; while (len) { w = op(fd,buf,len); if (w == -1) { if (errno == error_intr) continue; return -1; /* note that some data may have been written */ } if (w == 0) ; /* luser's fault */ buf += w; len -= w; } return 0; } int buffer_flush(buffer *s) { int p; p = s->p; if (!p) return 0; s->p = 0; return allwrite(s->op,s->fd,s->x,p); } int buffer_putalign(buffer *s,const char *buf,unsigned int len) { unsigned int n; while (len > (n = s->n - s->p)) { byte_copy(s->x + s->p,n,buf); s->p += n; buf += n; len -= n; if (buffer_flush(s) == -1) return -1; } /* now len <= s->n - s->p */ byte_copy(s->x + s->p,len,buf); s->p += len; return 0; } int buffer_put(buffer *s,const char *buf,unsigned int len) { unsigned int n; n = s->n; if (len > n - s->p) { if (buffer_flush(s) == -1) return -1; /* now s->p == 0 */ if (n < BUFFER_OUTSIZE) n = BUFFER_OUTSIZE; while (len > s->n) { if (n > len) n = len; if (allwrite(s->op,s->fd,buf,n) == -1) return -1; buf += n; len -= n; } } /* now len <= s->n - s->p */ byte_copy(s->x + s->p,len,buf); s->p += len; return 0; } int buffer_putflush(buffer *s,const char *buf,unsigned int len) { if (buffer_flush(s) == -1) return -1; return allwrite(s->op,s->fd,buf,len); } int buffer_putsalign(buffer *s,const char *buf) { return buffer_putalign(s,buf,str_len(buf)); } int buffer_puts(buffer *s,const char *buf) { return buffer_put(s,buf,str_len(buf)); } int buffer_putsflush(buffer *s,const char *buf) { return buffer_putflush(s,buf,str_len(buf)); } admin/daemontools-0.76/src/buffer_read.c 644 0 0 225 7323352455 14376 0ustar00/* Public domain. */ #include #include "buffer.h" int buffer_unixread(int fd,char *buf,unsigned int len) { return read(fd,buf,len); } admin/daemontools-0.76/src/buffer_write.c 644 0 0 235 7323352455 14616 0ustar00/* Public domain. */ #include #include "buffer.h" int buffer_unixwrite(int fd,const char *buf,unsigned int len) { return write(fd,buf,len); } admin/daemontools-0.76/src/buffer_1.c 644 0 0 301 7323352455 13616 0ustar00/* Public domain. */ #include "buffer.h" char buffer_1_space[BUFFER_OUTSIZE]; static buffer it = BUFFER_INIT(buffer_unixwrite,1,buffer_1_space,sizeof buffer_1_space); buffer *buffer_1 = ⁢ admin/daemontools-0.76/src/direntry.h1 644 0 0 247 7323352455 14064 0ustar00/* Public domain. */ #ifndef DIRENTRY_H #define DIRENTRY_H /* sysdep: -dirent */ #include #include #define direntry struct direct #endif admin/daemontools-0.76/src/direntry.h2 644 0 0 246 7323352455 14064 0ustar00/* Public domain. */ #ifndef DIRENTRY_H #define DIRENTRY_H /* sysdep: +dirent */ #include #include #define direntry struct dirent #endif admin/daemontools-0.76/src/trydrent.c 644 0 0 161 7323352455 14004 0ustar00/* Public domain. */ #include #include void foo() { DIR *dir; struct dirent *d; } admin/daemontools-0.76/src/strerr.h 644 0 0 5322 7323352455 13503 0ustar00/* Public domain. */ #ifndef STRERR_H #define STRERR_H struct strerr { struct strerr *who; const char *x; const char *y; const char *z; } ; extern struct strerr strerr_sys; extern void strerr_sysinit(void); extern const char *strerr(const struct strerr *); extern void strerr_warn(const char *,const char *,const char *,const char *,const char *,const char *,const struct strerr *); extern void strerr_die(int,const char *,const char *,const char *,const char *,const char *,const char *,const struct strerr *); #define STRERR(r,se,a) \ { se.who = 0; se.x = a; se.y = 0; se.z = 0; return r; } #define STRERR_SYS(r,se,a) \ { se.who = &strerr_sys; se.x = a; se.y = 0; se.z = 0; return r; } #define STRERR_SYS3(r,se,a,b,c) \ { se.who = &strerr_sys; se.x = a; se.y = b; se.z = c; return r; } #define strerr_warn6(x1,x2,x3,x4,x5,x6,se) \ strerr_warn((x1),(x2),(x3),(x4),(x5),(x6),(se)) #define strerr_warn5(x1,x2,x3,x4,x5,se) \ strerr_warn((x1),(x2),(x3),(x4),(x5),0,(se)) #define strerr_warn4(x1,x2,x3,x4,se) \ strerr_warn((x1),(x2),(x3),(x4),0,0,(se)) #define strerr_warn3(x1,x2,x3,se) \ strerr_warn((x1),(x2),(x3),0,0,0,(se)) #define strerr_warn2(x1,x2,se) \ strerr_warn((x1),(x2),0,0,0,0,(se)) #define strerr_warn1(x1,se) \ strerr_warn((x1),0,0,0,0,0,(se)) #define strerr_die6(e,x1,x2,x3,x4,x5,x6,se) \ strerr_die((e),(x1),(x2),(x3),(x4),(x5),(x6),(se)) #define strerr_die5(e,x1,x2,x3,x4,x5,se) \ strerr_die((e),(x1),(x2),(x3),(x4),(x5),0,(se)) #define strerr_die4(e,x1,x2,x3,x4,se) \ strerr_die((e),(x1),(x2),(x3),(x4),0,0,(se)) #define strerr_die3(e,x1,x2,x3,se) \ strerr_die((e),(x1),(x2),(x3),0,0,0,(se)) #define strerr_die2(e,x1,x2,se) \ strerr_die((e),(x1),(x2),0,0,0,0,(se)) #define strerr_die1(e,x1,se) \ strerr_die((e),(x1),0,0,0,0,0,(se)) #define strerr_die6sys(e,x1,x2,x3,x4,x5,x6) \ strerr_die((e),(x1),(x2),(x3),(x4),(x5),(x6),&strerr_sys) #define strerr_die5sys(e,x1,x2,x3,x4,x5) \ strerr_die((e),(x1),(x2),(x3),(x4),(x5),0,&strerr_sys) #define strerr_die4sys(e,x1,x2,x3,x4) \ strerr_die((e),(x1),(x2),(x3),(x4),0,0,&strerr_sys) #define strerr_die3sys(e,x1,x2,x3) \ strerr_die((e),(x1),(x2),(x3),0,0,0,&strerr_sys) #define strerr_die2sys(e,x1,x2) \ strerr_die((e),(x1),(x2),0,0,0,0,&strerr_sys) #define strerr_die1sys(e,x1) \ strerr_die((e),(x1),0,0,0,0,0,&strerr_sys) #define strerr_die6x(e,x1,x2,x3,x4,x5,x6) \ strerr_die((e),(x1),(x2),(x3),(x4),(x5),(x6),0) #define strerr_die5x(e,x1,x2,x3,x4,x5) \ strerr_die((e),(x1),(x2),(x3),(x4),(x5),0,0) #define strerr_die4x(e,x1,x2,x3,x4) \ strerr_die((e),(x1),(x2),(x3),(x4),0,0,0) #define strerr_die3x(e,x1,x2,x3) \ strerr_die((e),(x1),(x2),(x3),0,0,0,0) #define strerr_die2x(e,x1,x2) \ strerr_die((e),(x1),(x2),0,0,0,0,0) #define strerr_die1x(e,x1) \ strerr_die((e),(x1),0,0,0,0,0,0) #endif admin/daemontools-0.76/src/error_str.c 644 0 0 12576 7323352455 14227 0ustar00/* Public domain. */ #include #include "error.h" #define X(e,s) if (i == e) return s; const char *error_str(int i) { X(0,"no error") X(error_intr,"interrupted system call") X(error_nomem,"out of memory") X(error_noent,"file does not exist") X(error_txtbsy,"text busy") X(error_io,"input/output error") X(error_exist,"file already exists") X(error_timeout,"timed out") X(error_inprogress,"operation in progress") X(error_again,"temporary failure") X(error_wouldblock,"input/output would block") X(error_pipe,"broken pipe") X(error_perm,"permission denied") X(error_acces,"access denied") X(error_nodevice,"device not configured") X(error_proto,"protocol error") X(error_isdir,"is a directory") X(error_connrefused,"connection refused") X(error_notdir,"not a directory") #ifdef ESRCH X(ESRCH,"no such process") #endif #ifdef E2BIG X(E2BIG,"argument list too long") #endif #ifdef ENOEXEC X(ENOEXEC,"exec format error") #endif #ifdef EBADF X(EBADF,"file descriptor not open") #endif #ifdef ECHILD X(ECHILD,"no child processes") #endif #ifdef EDEADLK X(EDEADLK,"operation would cause deadlock") #endif #ifdef EFAULT X(EFAULT,"bad address") #endif #ifdef ENOTBLK X(ENOTBLK,"not a block device") #endif #ifdef EBUSY X(EBUSY,"device busy") #endif #ifdef EXDEV X(EXDEV,"cross-device link") #endif #ifdef ENODEV X(ENODEV,"device does not support operation") #endif #ifdef EINVAL X(EINVAL,"invalid argument") #endif #ifdef ENFILE X(ENFILE,"system cannot open more files") #endif #ifdef EMFILE X(EMFILE,"process cannot open more files") #endif #ifdef ENOTTY X(ENOTTY,"not a tty") #endif #ifdef EFBIG X(EFBIG,"file too big") #endif #ifdef ENOSPC X(ENOSPC,"out of disk space") #endif #ifdef ESPIPE X(ESPIPE,"unseekable descriptor") #endif #ifdef EROFS X(EROFS,"read-only file system") #endif #ifdef EMLINK X(EMLINK,"too many links") #endif #ifdef EDOM X(EDOM,"input out of range") #endif #ifdef ERANGE X(ERANGE,"output out of range") #endif #ifdef EALREADY X(EALREADY,"operation already in progress") #endif #ifdef ENOTSOCK X(ENOTSOCK,"not a socket") #endif #ifdef EDESTADDRREQ X(EDESTADDRREQ,"destination address required") #endif #ifdef EMSGSIZE X(EMSGSIZE,"message too long") #endif #ifdef EPROTOTYPE X(EPROTOTYPE,"incorrect protocol type") #endif #ifdef ENOPROTOOPT X(ENOPROTOOPT,"protocol not available") #endif #ifdef EPROTONOSUPPORT X(EPROTONOSUPPORT,"protocol not supported") #endif #ifdef ESOCKTNOSUPPORT X(ESOCKTNOSUPPORT,"socket type not supported") #endif #ifdef EOPNOTSUPP X(EOPNOTSUPP,"operation not supported") #endif #ifdef EPFNOSUPPORT X(EPFNOSUPPORT,"protocol family not supported") #endif #ifdef EAFNOSUPPORT X(EAFNOSUPPORT,"address family not supported") #endif #ifdef EADDRINUSE X(EADDRINUSE,"address already used") #endif #ifdef EADDRNOTAVAIL X(EADDRNOTAVAIL,"address not available") #endif #ifdef ENETDOWN X(ENETDOWN,"network down") #endif #ifdef ENETUNREACH X(ENETUNREACH,"network unreachable") #endif #ifdef ENETRESET X(ENETRESET,"network reset") #endif #ifdef ECONNABORTED X(ECONNABORTED,"connection aborted") #endif #ifdef ECONNRESET X(ECONNRESET,"connection reset") #endif #ifdef ENOBUFS X(ENOBUFS,"out of buffer space") #endif #ifdef EISCONN X(EISCONN,"already connected") #endif #ifdef ENOTCONN X(ENOTCONN,"not connected") #endif #ifdef ESHUTDOWN X(ESHUTDOWN,"socket shut down") #endif #ifdef ETOOMANYREFS X(ETOOMANYREFS,"too many references") #endif #ifdef ELOOP X(ELOOP,"symbolic link loop") #endif #ifdef ENAMETOOLONG X(ENAMETOOLONG,"file name too long") #endif #ifdef EHOSTDOWN X(EHOSTDOWN,"host down") #endif #ifdef EHOSTUNREACH X(EHOSTUNREACH,"host unreachable") #endif #ifdef ENOTEMPTY X(ENOTEMPTY,"directory not empty") #endif #ifdef EPROCLIM X(EPROCLIM,"too many processes") #endif #ifdef EUSERS X(EUSERS,"too many users") #endif #ifdef EDQUOT X(EDQUOT,"disk quota exceeded") #endif #ifdef ESTALE X(ESTALE,"stale NFS file handle") #endif #ifdef EREMOTE X(EREMOTE,"too many levels of remote in path") #endif #ifdef EBADRPC X(EBADRPC,"RPC structure is bad") #endif #ifdef ERPCMISMATCH X(ERPCMISMATCH,"RPC version mismatch") #endif #ifdef EPROGUNAVAIL X(EPROGUNAVAIL,"RPC program unavailable") #endif #ifdef EPROGMISMATCH X(EPROGMISMATCH,"program version mismatch") #endif #ifdef EPROCUNAVAIL X(EPROCUNAVAIL,"bad procedure for program") #endif #ifdef ENOLCK X(ENOLCK,"no locks available") #endif #ifdef ENOSYS X(ENOSYS,"system call not available") #endif #ifdef EFTYPE X(EFTYPE,"bad file type") #endif #ifdef EAUTH X(EAUTH,"authentication error") #endif #ifdef ENEEDAUTH X(ENEEDAUTH,"not authenticated") #endif #ifdef ENOSTR X(ENOSTR,"not a stream device") #endif #ifdef ETIME X(ETIME,"timer expired") #endif #ifdef ENOSR X(ENOSR,"out of stream resources") #endif #ifdef ENOMSG X(ENOMSG,"no message of desired type") #endif #ifdef EBADMSG X(EBADMSG,"bad message type") #endif #ifdef EIDRM X(EIDRM,"identifier removed") #endif #ifdef ENONET X(ENONET,"machine not on network") #endif #ifdef ERREMOTE X(ERREMOTE,"object not local") #endif #ifdef ENOLINK X(ENOLINK,"link severed") #endif #ifdef EADV X(EADV,"advertise error") #endif #ifdef ESRMNT X(ESRMNT,"srmount error") #endif #ifdef ECOMM X(ECOMM,"communication error") #endif #ifdef EMULTIHOP X(EMULTIHOP,"multihop attempted") #endif #ifdef EREMCHG X(EREMCHG,"remote address changed") #endif return "unknown error"; } admin/daemontools-0.76/src/strerr_sys.c 644 0 0 332 7323352455 14350 0ustar00/* Public domain. */ #include "error.h" #include "strerr.h" struct strerr strerr_sys; void strerr_sysinit(void) { strerr_sys.who = 0; strerr_sys.x = error_str(errno); strerr_sys.y = ""; strerr_sys.z = ""; } admin/daemontools-0.76/src/buffer_2.c 644 0 0 266 7323352455 13631 0ustar00/* Public domain. */ #include "buffer.h" char buffer_2_space[256]; static buffer it = BUFFER_INIT(buffer_unixwrite,2,buffer_2_space,sizeof buffer_2_space); buffer *buffer_2 = ⁢ admin/daemontools-0.76/src/strerr_die.c 644 0 0 1554 7323352455 14322 0ustar00/* Public domain. */ #include #include "buffer.h" #include "strerr.h" void strerr_warn(const char *x1,const char *x2,const char *x3,const char *x4,const char *x5,const char *x6,const struct strerr *se) { strerr_sysinit(); if (x1) buffer_puts(buffer_2,x1); if (x2) buffer_puts(buffer_2,x2); if (x3) buffer_puts(buffer_2,x3); if (x4) buffer_puts(buffer_2,x4); if (x5) buffer_puts(buffer_2,x5); if (x6) buffer_puts(buffer_2,x6); while(se) { if (se->x) buffer_puts(buffer_2,se->x); if (se->y) buffer_puts(buffer_2,se->y); if (se->z) buffer_puts(buffer_2,se->z); se = se->who; } buffer_puts(buffer_2,"\n"); buffer_flush(buffer_2); } void strerr_die(int e,const char *x1,const char *x2,const char *x3,const char *x4,const char *x5,const char *x6,const struct strerr *se) { strerr_warn(x1,x2,x3,x4,x5,x6,se); _exit(e); } admin/daemontools-0.76/src/wait.h 644 0 0 475 7323352455 13112 0ustar00/* Public domain. */ #ifndef WAIT_H #define WAIT_H extern int wait_pid(); extern int wait_nohang(); extern int wait_stop(); extern int wait_stopnohang(); #define wait_crashed(w) ((w) & 127) #define wait_exitcode(w) ((w) >> 8) #define wait_stopsig(w) ((w) >> 8) #define wait_stopped(w) (((w) & 127) == 127) #endif admin/daemontools-0.76/src/trywaitp.c 644 0 0 141 7323352455 14012 0ustar00/* Public domain. */ #include #include main() { waitpid(0,0,0); } admin/daemontools-0.76/src/haswaitp.h1 644 0 0 55 7323352455 14021 0ustar00/* Public domain. */ /* sysdep: -waitpid */ admin/daemontools-0.76/src/haswaitp.h2 644 0 0 102 7323352455 14033 0ustar00/* Public domain. */ /* sysdep: +waitpid */ #define HASWAITPID 1 admin/daemontools-0.76/src/wait_pid.c 644 0 0 1333 7323352455 13753 0ustar00/* Public domain. */ #include #include #include "error.h" #include "haswaitp.h" #ifdef HASWAITPID int wait_pid(wstat,pid) int *wstat; int pid; { int r; do r = waitpid(pid,wstat,0); while ((r == -1) && (errno == error_intr)); return r; } #else /* XXX untested */ /* XXX breaks down with more than two children */ static int oldpid = 0; static int oldwstat; /* defined if(oldpid) */ int wait_pid(wstat,pid) int *wstat; int pid; { int r; if (pid == oldpid) { *wstat = oldwstat; oldpid = 0; return pid; } do { r = wait(wstat); if ((r != pid) && (r != -1)) { oldwstat = *wstat; oldpid = r; continue; } } while ((r == -1) && (errno == error_intr)); return r; } #endif admin/daemontools-0.76/src/coe.h 644 0 0 120 7323352455 12677 0ustar00/* Public domain. */ #ifndef COE_H #define COE_H extern int coe(int); #endif admin/daemontools-0.76/src/coe.c 644 0 0 155 7323352455 12702 0ustar00/* Public domain. */ #include #include "coe.h" int coe(int fd) { return fcntl(fd,F_SETFD,1); } admin/daemontools-0.76/src/fd.h 644 0 0 163 7323352455 12531 0ustar00/* Public domain. */ #ifndef FD_H #define FD_H extern int fd_copy(int,int); extern int fd_move(int,int); #endif admin/daemontools-0.76/src/fd_copy.c 644 0 0 401 7323352455 13551 0ustar00/* Public domain. */ #include #include #include "fd.h" int fd_copy(int to,int from) { if (to == from) return 0; if (fcntl(from,F_GETFL,0) == -1) return -1; close(to); if (fcntl(from,F_DUPFD,to) == -1) return -1; return 0; } admin/daemontools-0.76/src/fd_move.c 644 0 0 274 7323352455 13555 0ustar00/* Public domain. */ #include #include "fd.h" int fd_move(int to,int from) { if (to == from) return 0; if (fd_copy(to,from) == -1) return -1; close(from); return 0; } admin/daemontools-0.76/src/str_start.c 644 0 0 562 7323352455 14163 0ustar00/* Public domain. */ #include "str.h" int str_start(register const char *s,register const char *t) { register char x; for (;;) { x = *t++; if (!x) return 1; if (x != *s++) return 0; x = *t++; if (!x) return 1; if (x != *s++) return 0; x = *t++; if (!x) return 1; if (x != *s++) return 0; x = *t++; if (!x) return 1; if (x != *s++) return 0; } } admin/daemontools-0.76/src/env.h 644 0 0 201 7323352455 12721 0ustar00/* Public domain. */ #ifndef ENV_H #define ENV_H extern char **environ; extern /*@null@*/char *env_get(const char *); #endif admin/daemontools-0.76/src/env.c 644 0 0 472 7323352455 12726 0ustar00/* Public domain. */ #include "str.h" #include "env.h" extern /*@null@*/char *env_get(const char *s) { int i; unsigned int len; if (!s) return 0; len = str_len(s); for (i = 0;environ[i];++i) if (str_start(environ[i],s) && (environ[i][len] == '=')) return environ[i] + len + 1; return 0; } admin/daemontools-0.76/src/alloc.h 644 0 0 231 7323352455 13226 0ustar00/* Public domain. */ #ifndef ALLOC_H #define ALLOC_H extern /*@null@*//*@out@*/char *alloc(); extern void alloc_free(); extern int alloc_re(); #endif admin/daemontools-0.76/src/alloc.c 644 0 0 1500 7323352455 13241 0ustar00/* Public domain. */ #include #include "alloc.h" #include "error.h" #define ALIGNMENT 16 /* XXX: assuming that this alignment is enough */ #define SPACE 2048 /* must be multiple of ALIGNMENT */ typedef union { char irrelevant[ALIGNMENT]; double d; } aligned; static aligned realspace[SPACE / ALIGNMENT]; #define space ((char *) realspace) static unsigned int avail = SPACE; /* multiple of ALIGNMENT; 0<=avail<=SPACE */ /*@null@*//*@out@*/char *alloc(n) unsigned int n; { char *x; n = ALIGNMENT + n - (n & (ALIGNMENT - 1)); /* XXX: could overflow */ if (n <= avail) { avail -= n; return space + avail; } x = malloc(n); if (!x) errno = error_nomem; return x; } void alloc_free(x) char *x; { if (x >= space) if (x < space + SPACE) return; /* XXX: assuming that pointers are flat */ free(x); } admin/daemontools-0.76/src/alloc_re.c 644 0 0 354 7323352455 13715 0ustar00/* Public domain. */ #include "alloc.h" #include "byte.h" int alloc_re(x,m,n) char **x; unsigned int m; unsigned int n; { char *y; y = alloc(n); if (!y) return 0; byte_copy(y,m,*x); alloc_free(*x); *x = y; return 1; } admin/daemontools-0.76/src/gen_alloc.h 644 0 0 303 7323352455 14057 0ustar00/* Public domain. */ #ifndef GEN_ALLOC_H #define GEN_ALLOC_H #define GEN_ALLOC_typedef(ta,type,field,len,a) \ typedef struct ta { type *field; unsigned int len; unsigned int a; } ta; #endif admin/daemontools-0.76/src/gen_allocdefs.h 644 0 0 2274 7323352455 14752 0ustar00/* Public domain. */ #ifndef GEN_ALLOC_DEFS_H #define GEN_ALLOC_DEFS_H #define GEN_ALLOC_ready(ta,type,field,len,a,i,n,x,base,ta_ready) \ int ta_ready(register ta *x,register unsigned int n) \ { register unsigned int i; \ if (x->field) { \ i = x->a; \ if (n > i) { \ x->a = base + n + (n >> 3); \ if (alloc_re(&x->field,i * sizeof(type),x->a * sizeof(type))) return 1; \ x->a = i; return 0; } \ return 1; } \ x->len = 0; \ return !!(x->field = (type *) alloc((x->a = n) * sizeof(type))); } #define GEN_ALLOC_readyplus(ta,type,field,len,a,i,n,x,base,ta_rplus) \ int ta_rplus(register ta *x,register unsigned int n) \ { register unsigned int i; \ if (x->field) { \ i = x->a; n += x->len; \ if (n > i) { \ x->a = base + n + (n >> 3); \ if (alloc_re(&x->field,i * sizeof(type),x->a * sizeof(type))) return 1; \ x->a = i; return 0; } \ return 1; } \ x->len = 0; \ return !!(x->field = (type *) alloc((x->a = n) * sizeof(type))); } #define GEN_ALLOC_append(ta,type,field,len,a,i,n,x,base,ta_rplus,ta_append) \ int ta_append(register ta *x,register const type *i) \ { if (!ta_rplus(x,1)) return 0; x->field[x->len++] = *i; return 1; } #endif admin/daemontools-0.76/src/stralloc.h 644 0 0 2227 7323352455 14006 0ustar00/* Public domain. */ #ifndef STRALLOC_H #define STRALLOC_H #include "gen_alloc.h" GEN_ALLOC_typedef(stralloc,char,s,len,a) extern int stralloc_ready(stralloc *,unsigned int); extern int stralloc_readyplus(stralloc *,unsigned int); extern int stralloc_copy(stralloc *,const stralloc *); extern int stralloc_cat(stralloc *,const stralloc *); extern int stralloc_copys(stralloc *,const char *); extern int stralloc_cats(stralloc *,const char *); extern int stralloc_copyb(stralloc *,const char *,unsigned int); extern int stralloc_catb(stralloc *,const char *,unsigned int); extern int stralloc_append(stralloc *,const char *); /* beware: this takes a pointer to 1 char */ extern int stralloc_starts(stralloc *,const char *); #define stralloc_0(sa) stralloc_append(sa,"") extern int stralloc_catulong0(stralloc *,unsigned long,unsigned int); extern int stralloc_catlong0(stralloc *,long,unsigned int); #define stralloc_catlong(sa,l) (stralloc_catlong0((sa),(l),0)) #define stralloc_catuint0(sa,i,n) (stralloc_catulong0((sa),(i),(n))) #define stralloc_catint0(sa,i,n) (stralloc_catlong0((sa),(i),(n))) #define stralloc_catint(sa,i) (stralloc_catlong0((sa),(i),0)) #endif admin/daemontools-0.76/src/stralloc_eady.c 644 0 0 341 7323352455 14756 0ustar00/* Public domain. */ #include "alloc.h" #include "stralloc.h" #include "gen_allocdefs.h" GEN_ALLOC_ready(stralloc,char,s,len,a,i,n,x,30,stralloc_ready) GEN_ALLOC_readyplus(stralloc,char,s,len,a,i,n,x,30,stralloc_readyplus) admin/daemontools-0.76/src/stralloc_opyb.c 644 0 0 421 7323352455 15004 0ustar00/* Public domain. */ #include "stralloc.h" #include "byte.h" int stralloc_copyb(stralloc *sa,const char *s,unsigned int n) { if (!stralloc_ready(sa,n + 1)) return 0; byte_copy(sa->s,n,s); sa->len = n; sa->s[n] = 'Z'; /* ``offensive programming'' */ return 1; } admin/daemontools-0.76/src/stralloc_catb.c 644 0 0 522 7323352455 14746 0ustar00/* Public domain. */ #include "stralloc.h" #include "byte.h" int stralloc_catb(stralloc *sa,const char *s,unsigned int n) { if (!sa->s) return stralloc_copyb(sa,s,n); if (!stralloc_readyplus(sa,n + 1)) return 0; byte_copy(sa->s + sa->len,n,s); sa->len += n; sa->s[sa->len] = 'Z'; /* ``offensive programming'' */ return 1; } admin/daemontools-0.76/src/stralloc_cats.c 644 0 0 253 7323352455 14770 0ustar00/* Public domain. */ #include "byte.h" #include "str.h" #include "stralloc.h" int stralloc_cats(stralloc *sa,const char *s) { return stralloc_catb(sa,s,str_len(s)); } admin/daemontools-0.76/src/stralloc_pend.c 644 0 0 257 7323352455 14770 0ustar00/* Public domain. */ #include "alloc.h" #include "stralloc.h" #include "gen_allocdefs.h" GEN_ALLOC_append(stralloc,char,s,len,a,i,n,x,30,stralloc_readyplus,stralloc_append) admin/daemontools-0.76/src/str_chr.c 644 0 0 572 7323352455 13603 0ustar00/* Public domain. */ #include "str.h" unsigned int str_chr(register const char *s,int c) { register char ch; register const char *t; ch = c; t = s; for (;;) { if (!*t) break; if (*t == ch) break; ++t; if (!*t) break; if (*t == ch) break; ++t; if (!*t) break; if (*t == ch) break; ++t; if (!*t) break; if (*t == ch) break; ++t; } return t - s; } admin/daemontools-0.76/src/pathexec.h 644 0 0 367 7323352455 13747 0ustar00/* Public domain. */ #ifndef PATHEXEC_H #define PATHEXEC_H extern void pathexec_run(const char *,const char * const *,const char * const *); extern int pathexec_env(const char *,const char *); extern void pathexec(const char * const *); #endif admin/daemontools-0.76/src/pathexec_run.c 644 0 0 2020 7323352455 14632 0ustar00/* Public domain. */ #include "error.h" #include "stralloc.h" #include "str.h" #include "env.h" #include "pathexec.h" static stralloc tmp; void pathexec_run(const char *file,const char * const *argv,const char * const *envp) { const char *path; unsigned int split; int savederrno; if (file[str_chr(file,'/')]) { execve(file,argv,envp); return; } path = env_get("PATH"); if (!path) path = "/bin:/usr/bin"; savederrno = 0; for (;;) { split = str_chr(path,':'); if (!stralloc_copyb(&tmp,path,split)) return; if (!split) if (!stralloc_cats(&tmp,".")) return; if (!stralloc_cats(&tmp,"/")) return; if (!stralloc_cats(&tmp,file)) return; if (!stralloc_0(&tmp)) return; execve(tmp.s,argv,envp); if (errno != error_noent) { savederrno = errno; if ((errno != error_acces) && (errno != error_perm) && (errno != error_isdir)) return; } if (!path[split]) { if (savederrno) errno = savederrno; return; } path += split; path += 1; } } admin/daemontools-0.76/src/stralloc_opys.c 644 0 0 255 7323352455 15032 0ustar00/* Public domain. */ #include "byte.h" #include "str.h" #include "stralloc.h" int stralloc_copys(stralloc *sa,const char *s) { return stralloc_copyb(sa,s,str_len(s)); } admin/daemontools-0.76/src/stralloc_cat.c 644 0 0 257 7323352455 14611 0ustar00/* Public domain. */ #include "byte.h" #include "stralloc.h" int stralloc_cat(stralloc *sato,const stralloc *safrom) { return stralloc_catb(sato,safrom->s,safrom->len); } admin/daemontools-0.76/src/byte_diff.c 644 0 0 733 7323352455 14071 0ustar00/* Public domain. */ #include "byte.h" int byte_diff(s,n,t) register char *s; register unsigned int n; register char *t; { for (;;) { if (!n) return 0; if (*s != *t) break; ++s; ++t; --n; if (!n) return 0; if (*s != *t) break; ++s; ++t; --n; if (!n) return 0; if (*s != *t) break; ++s; ++t; --n; if (!n) return 0; if (*s != *t) break; ++s; ++t; --n; } return ((int)(unsigned int)(unsigned char) *s) - ((int)(unsigned int)(unsigned char) *t); } admin/daemontools-0.76/src/pathexec_env.c 644 0 0 2453 7323352455 14630 0ustar00/* Public domain. */ #include "stralloc.h" #include "alloc.h" #include "str.h" #include "byte.h" #include "env.h" #include "pathexec.h" static stralloc plus; static stralloc tmp; int pathexec_env(const char *s,const char *t) { if (!s) return 1; if (!stralloc_copys(&tmp,s)) return 0; if (t) { if (!stralloc_cats(&tmp,"=")) return 0; if (!stralloc_cats(&tmp,t)) return 0; } if (!stralloc_0(&tmp)) return 0; return stralloc_cat(&plus,&tmp); } void pathexec(const char *const *argv) { const char **e; unsigned int elen; unsigned int i; unsigned int j; unsigned int split; unsigned int t; if (!stralloc_cats(&plus,"")) return; elen = 0; for (i = 0;environ[i];++i) ++elen; for (i = 0;i < plus.len;++i) if (!plus.s[i]) ++elen; e = (const char **) alloc((elen + 1) * sizeof(char *)); if (!e) return; elen = 0; for (i = 0;environ[i];++i) e[elen++] = environ[i]; j = 0; for (i = 0;i < plus.len;++i) if (!plus.s[i]) { split = str_chr(plus.s + j,'='); for (t = 0;t < elen;++t) if (byte_equal(plus.s + j,split,e[t])) if (e[t][split] == '=') { --elen; e[t] = e[elen]; break; } if (plus.s[j + split]) e[elen++] = plus.s + j; j = i + 1; } e[elen] = 0; pathexec_run(*argv,argv,e); alloc_free(e); } admin/daemontools-0.76/src/wait_nohang.c 644 0 0 367 7323352455 14437 0ustar00/* Public domain. */ #include #include #include "haswaitp.h" int wait_nohang(wstat) int *wstat; { #ifdef HASWAITPID return waitpid(-1,wstat,WNOHANG); #else return wait3(wstat,WNOHANG,(struct rusage *) 0); #endif } admin/daemontools-0.76/src/sig.h 644 0 0 1113 7323352455 12736 0ustar00/* Public domain. */ #ifndef SIG_H #define SIG_H extern int sig_alarm; extern int sig_child; extern int sig_cont; extern int sig_hangup; extern int sig_int; extern int sig_pipe; extern int sig_term; extern void (*sig_defaulthandler)(); extern void (*sig_ignorehandler)(); extern void sig_catch(int,void (*)()); #define sig_ignore(s) (sig_catch((s),sig_ignorehandler)) #define sig_uncatch(s) (sig_catch((s),sig_defaulthandler)) extern void sig_block(int); extern void sig_unblock(int); extern void sig_blocknone(void); extern void sig_pause(void); extern void sig_dfl(int); #endif admin/daemontools-0.76/src/sig.c 644 0 0 465 7323352455 12722 0ustar00/* Public domain. */ #include #include "sig.h" int sig_alarm = SIGALRM; int sig_child = SIGCHLD; int sig_cont = SIGCONT; int sig_hangup = SIGHUP; int sig_int = SIGINT; int sig_pipe = SIGPIPE; int sig_term = SIGTERM; void (*sig_defaulthandler)() = SIG_DFL; void (*sig_ignorehandler)() = SIG_IGN; admin/daemontools-0.76/src/sig_block.c 644 0 0 1223 7323352455 14105 0ustar00/* Public domain. */ #include #include "sig.h" #include "hassgprm.h" void sig_block(int sig) { #ifdef HASSIGPROCMASK sigset_t ss; sigemptyset(&ss); sigaddset(&ss,sig); sigprocmask(SIG_BLOCK,&ss,(sigset_t *) 0); #else sigblock(1 << (sig - 1)); #endif } void sig_unblock(int sig) { #ifdef HASSIGPROCMASK sigset_t ss; sigemptyset(&ss); sigaddset(&ss,sig); sigprocmask(SIG_UNBLOCK,&ss,(sigset_t *) 0); #else sigsetmask(sigsetmask(~0) & ~(1 << (sig - 1))); #endif } void sig_blocknone(void) { #ifdef HASSIGPROCMASK sigset_t ss; sigemptyset(&ss); sigprocmask(SIG_SETMASK,&ss,(sigset_t *) 0); #else sigsetmask(0); #endif } admin/daemontools-0.76/src/sig_catch.c 644 0 0 553 7323352455 14062 0ustar00/* Public domain. */ #include #include "sig.h" #include "hassgact.h" void sig_catch(int sig,void (*f)()) { #ifdef HASSIGACTION struct sigaction sa; sa.sa_handler = f; sa.sa_flags = 0; sigemptyset(&sa.sa_mask); sigaction(sig,&sa,(struct sigaction *) 0); #else signal(sig,f); /* won't work under System V, even nowadays---dorks */ #endif } admin/daemontools-0.76/src/sig_pause.c 644 0 0 323 7323352455 14110 0ustar00/* Public domain. */ #include #include "sig.h" #include "hassgprm.h" void sig_pause(void) { #ifdef HASSIGPROCMASK sigset_t ss; sigemptyset(&ss); sigsuspend(&ss); #else sigpause(0); #endif } admin/daemontools-0.76/src/hassgact.h1 644 0 0 57 7323352455 14000 0ustar00/* Public domain. */ /* sysdep: -sigaction */ admin/daemontools-0.76/src/hassgact.h2 644 0 0 106 7323352455 14014 0ustar00/* Public domain. */ /* sysdep: +sigaction */ #define HASSIGACTION 1 admin/daemontools-0.76/src/hassgprm.h1 644 0 0 61 7323352455 14022 0ustar00/* Public domain. */ /* sysdep: -sigprocmask */ admin/daemontools-0.76/src/hassgprm.h2 644 0 0 112 7323352455 14040 0ustar00/* Public domain. */ /* sysdep: +sigprocmask */ #define HASSIGPROCMASK 1 admin/daemontools-0.76/src/trysgact.c 644 0 0 274 7323352455 13776 0ustar00/* Public domain. */ #include main() { struct sigaction sa; sa.sa_handler = 0; sa.sa_flags = 0; sigemptyset(&sa.sa_mask); sigaction(0,&sa,(struct sigaction *) 0); } admin/daemontools-0.76/src/trysgprm.c 644 0 0 244 7323352455 14022 0ustar00/* Public domain. */ #include main() { sigset_t ss; sigemptyset(&ss); sigaddset(&ss,SIGCHLD); sigprocmask(SIG_SETMASK,&ss,(sigset_t *) 0); } admin/daemontools-0.76/src/select.h1 644 0 0 235 7323352455 13500 0ustar00/* Public domain. */ #ifndef SELECT_H #define SELECT_H /* sysdep: -sysselect */ #include #include extern int select(); #endif admin/daemontools-0.76/src/select.h2 644 0 0 265 7323352455 13504 0ustar00/* Public domain. */ #ifndef SELECT_H #define SELECT_H /* sysdep: +sysselect */ #include #include #include extern int select(); #endif admin/daemontools-0.76/src/trysysel.c 644 0 0 226 7323352455 14031 0ustar00/* Public domain. */ #include #include #include #include /* SVR4 silliness */ void foo() { ; } admin/daemontools-0.76/src/uint64.h1 644 0 0 174 7323352455 13354 0ustar00/* Public domain. */ #ifndef UINT64_H #define UINT64_H /* sysdep: -ulong64 */ typedef unsigned long long uint64; #endif admin/daemontools-0.76/src/uint64.h2 644 0 0 167 7323352455 13357 0ustar00/* Public domain. */ #ifndef UINT64_H #define UINT64_H /* sysdep: +ulong64 */ typedef unsigned long uint64; #endif admin/daemontools-0.76/src/tryulong64.c 644 0 0 551 7323352455 14171 0ustar00/* Public domain. */ int main() { unsigned long u; u = 1; u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u; if (!u) _exit(1); _exit(0); } admin/daemontools-0.76/src/tai.h 644 0 0 1162 7323352455 12735 0ustar00/* Public domain. */ #ifndef TAI_H #define TAI_H #include "uint64.h" struct tai { uint64 x; } ; #define tai_unix(t,u) ((void) ((t)->x = 4611686018427387914ULL + (uint64) (u))) extern void tai_now(struct tai *); #define tai_approx(t) ((double) ((t)->x)) extern void tai_add(struct tai *,const struct tai *,const struct tai *); extern void tai_sub(struct tai *,const struct tai *,const struct tai *); #define tai_less(t,u) ((t)->x < (u)->x) #define TAI_PACK 8 extern void tai_pack(char *,const struct tai *); extern void tai_unpack(const char *,struct tai *); extern void tai_uint(struct tai *,unsigned int); #endif admin/daemontools-0.76/src/taia.h 644 0 0 1742 7323352455 13102 0ustar00/* Public domain. */ #ifndef TAIA_H #define TAIA_H #include "tai.h" struct taia { struct tai sec; unsigned long nano; /* 0...999999999 */ unsigned long atto; /* 0...999999999 */ } ; extern void taia_tai(const struct taia *,struct tai *); extern void taia_now(struct taia *); extern double taia_approx(const struct taia *); extern double taia_frac(const struct taia *); extern void taia_add(struct taia *,const struct taia *,const struct taia *); extern void taia_addsec(struct taia *,const struct taia *,int); extern void taia_sub(struct taia *,const struct taia *,const struct taia *); extern void taia_half(struct taia *,const struct taia *); extern int taia_less(const struct taia *,const struct taia *); #define TAIA_PACK 16 extern void taia_pack(char *,const struct taia *); extern void taia_unpack(const char *,struct taia *); #define TAIA_FMTFRAC 19 extern unsigned int taia_fmtfrac(char *,const struct taia *); extern void taia_uint(struct taia *,unsigned int); #endif admin/daemontools-0.76/src/taia_now.c 644 0 0 441 7323352455 13733 0ustar00/* Public domain. */ #include #include #include #include "taia.h" void taia_now(struct taia *t) { struct timeval now; gettimeofday(&now,(struct timezone *) 0); tai_unix(&t->sec,now.tv_sec); t->nano = 1000 * now.tv_usec + 500; t->atto = 0; } admin/daemontools-0.76/src/taia_sub.c 644 0 0 716 7323352455 13726 0ustar00/* Public domain. */ #include "taia.h" /* XXX: breaks tai encapsulation */ void taia_sub(struct taia *t,const struct taia *u,const struct taia *v) { unsigned long unano = u->nano; unsigned long uatto = u->atto; t->sec.x = u->sec.x - v->sec.x; t->nano = unano - v->nano; t->atto = uatto - v->atto; if (t->atto > uatto) { t->atto += 1000000000UL; --t->nano; } if (t->nano > unano) { t->nano += 1000000000UL; --t->sec.x; } } admin/daemontools-0.76/src/taia_less.c 644 0 0 467 7323352455 14106 0ustar00/* Public domain. */ #include "taia.h" /* XXX: breaks tai encapsulation */ int taia_less(const struct taia *t,const struct taia *u) { if (t->sec.x < u->sec.x) return 1; if (t->sec.x > u->sec.x) return 0; if (t->nano < u->nano) return 1; if (t->nano > u->nano) return 0; return t->atto < u->atto; } admin/daemontools-0.76/src/taia_frac.c 644 0 0 216 7323352455 14043 0ustar00/* Public domain. */ #include "taia.h" double taia_frac(const struct taia *t) { return (t->atto * 0.000000001 + t->nano) * 0.000000001; } admin/daemontools-0.76/src/taia_approx.c 644 0 0 203 7323352455 14435 0ustar00/* Public domain. */ #include "taia.h" double taia_approx(const struct taia *t) { return tai_approx(&t->sec) + taia_frac(t); } admin/daemontools-0.76/src/iopause.h1 644 0 0 462 7323352455 13670 0ustar00/* Public domain. */ #ifndef IOPAUSE_H #define IOPAUSE_H /* sysdep: -poll */ typedef struct { int fd; short events; short revents; } iopause_fd; #define IOPAUSE_READ 1 #define IOPAUSE_WRITE 4 #include "taia.h" extern void iopause(iopause_fd *,unsigned int,struct taia *,struct taia *); #endif admin/daemontools-0.76/src/iopause.h2 644 0 0 523 7323352455 13667 0ustar00/* Public domain. */ #ifndef IOPAUSE_H #define IOPAUSE_H /* sysdep: +poll */ #define IOPAUSE_POLL #include #include typedef struct pollfd iopause_fd; #define IOPAUSE_READ POLLIN #define IOPAUSE_WRITE POLLOUT #include "taia.h" extern void iopause(iopause_fd *,unsigned int,struct taia *,struct taia *); #endif admin/daemontools-0.76/src/iopause.c 644 0 0 3214 7323352455 13620 0ustar00/* Public domain. */ #include "taia.h" #include "select.h" #include "iopause.h" void iopause(iopause_fd *x,unsigned int len,struct taia *deadline,struct taia *stamp) { struct taia t; int millisecs; double d; int i; if (taia_less(deadline,stamp)) millisecs = 0; else { t = *stamp; taia_sub(&t,deadline,&t); d = taia_approx(&t); if (d > 1000.0) d = 1000.0; millisecs = d * 1000.0 + 20.0; } for (i = 0;i < len;++i) x[i].revents = 0; #ifdef IOPAUSE_POLL poll(x,len,millisecs); /* XXX: some kernels apparently need x[0] even if len is 0 */ /* XXX: how to handle EAGAIN? are kernels really this dumb? */ /* XXX: how to handle EINVAL? when exactly can this happen? */ #else { struct timeval tv; fd_set rfds; fd_set wfds; int nfds; int fd; FD_ZERO(&rfds); FD_ZERO(&wfds); nfds = 1; for (i = 0;i < len;++i) { fd = x[i].fd; if (fd < 0) continue; if (fd >= 8 * sizeof(fd_set)) continue; /*XXX*/ if (fd >= nfds) nfds = fd + 1; if (x[i].events & IOPAUSE_READ) FD_SET(fd,&rfds); if (x[i].events & IOPAUSE_WRITE) FD_SET(fd,&wfds); } tv.tv_sec = millisecs / 1000; tv.tv_usec = 1000 * (millisecs % 1000); if (select(nfds,&rfds,&wfds,(fd_set *) 0,&tv) <= 0) return; /* XXX: for EBADF, could seek out and destroy the bad descriptor */ for (i = 0;i < len;++i) { fd = x[i].fd; if (fd < 0) continue; if (fd >= 8 * sizeof(fd_set)) continue; /*XXX*/ if (x[i].events & IOPAUSE_READ) if (FD_ISSET(fd,&rfds)) x[i].revents |= IOPAUSE_READ; if (x[i].events & IOPAUSE_WRITE) if (FD_ISSET(fd,&wfds)) x[i].revents |= IOPAUSE_WRITE; } } #endif } admin/daemontools-0.76/src/trypoll.c 644 0 0 546 7323352455 13645 0ustar00/* Public domain. */ #include #include #include int main() { struct pollfd x; x.fd = open("trypoll.c",O_RDONLY); if (x.fd == -1) _exit(111); x.events = POLLIN; if (poll(&x,1,10) == -1) _exit(1); if (x.revents != POLLIN) _exit(1); /* XXX: try to detect and avoid poll() imitation libraries */ _exit(0); } admin/daemontools-0.76/src/fifo.h 644 0 0 145 7323352455 13063 0ustar00/* Public domain. */ #ifndef FIFO_H #define FIFO_H extern int fifo_make(const char *,int); #endif admin/daemontools-0.76/src/fifo.c 644 0 0 433 7323352455 13056 0ustar00/* Public domain. */ #include #include #include "hasmkffo.h" #include "fifo.h" #ifdef HASMKFIFO int fifo_make(const char *fn,int mode) { return mkfifo(fn,mode); } #else int fifo_make(const char *fn,int mode) { return mknod(fn,S_IFIFO | mode,0); } #endif admin/daemontools-0.76/src/hasmkffo.h1 644 0 0 54 7323352455 13776 0ustar00/* Public domain. */ /* sysdep: -mkfifo */ admin/daemontools-0.76/src/hasmkffo.h2 644 0 0 100 7323352455 14007 0ustar00/* Public domain. */ /* sysdep: +mkfifo */ #define HASMKFIFO 1 admin/daemontools-0.76/src/trymkffo.c 644 0 0 161 7323352455 13772 0ustar00/* Public domain. */ #include #include void main() { mkfifo("temp-trymkffo",0); } admin/daemontools-0.76/src/open.h 644 0 0 365 7323352455 13105 0ustar00/* Public domain. */ #ifndef OPEN_H #define OPEN_H extern int open_read(const char *); extern int open_excl(const char *); extern int open_append(const char *); extern int open_trunc(const char *); extern int open_write(const char *); #endif admin/daemontools-0.76/src/open_read.c 644 0 0 232 7323352455 14064 0ustar00/* Public domain. */ #include #include #include "open.h" int open_read(const char *fn) { return open(fn,O_RDONLY | O_NDELAY); } admin/daemontools-0.76/src/open_write.c 644 0 0 233 7323352455 14304 0ustar00/* Public domain. */ #include #include #include "open.h" int open_write(const char *fn) { return open(fn,O_WRONLY | O_NDELAY); } admin/daemontools-0.76/src/open_append.c 644 0 0 266 7323352455 14427 0ustar00/* Public domain. */ #include #include #include "open.h" int open_append(const char *fn) { return open(fn,O_WRONLY | O_NDELAY | O_APPEND | O_CREAT,0600); } admin/daemontools-0.76/src/lock.h 644 0 0 212 7323352455 13063 0ustar00/* Public domain. */ #ifndef LOCK_H #define LOCK_H extern int lock_ex(int); extern int lock_un(int); extern int lock_exnb(int); #endif admin/daemontools-0.76/src/hasflock.h1 644 0 0 53 7323352455 13771 0ustar00/* Public domain. */ /* sysdep: -flock */ admin/daemontools-0.76/src/hasflock.h2 644 0 0 76 7323352455 13777 0ustar00/* Public domain. */ /* sysdep: +flock */ #define HASFLOCK 1 admin/daemontools-0.76/src/tryflock.c 644 0 0 212 7323352455 13763 0ustar00/* Public domain. */ #include #include #include main() { flock(0,LOCK_EX | LOCK_UN | LOCK_NB); } admin/daemontools-0.76/src/lock_exnb.c 644 0 0 412 7323352455 14074 0ustar00/* Public domain. */ #include #include #include #include "hasflock.h" #include "lock.h" #ifdef HASFLOCK int lock_exnb(int fd) { return flock(fd,LOCK_EX | LOCK_NB); } #else int lock_exnb(int fd) { return lockf(fd,2,0); } #endif admin/daemontools-0.76/src/lock_ex.c 644 0 0 374 7323352455 13563 0ustar00/* Public domain. */ #include #include #include #include "hasflock.h" #include "lock.h" #ifdef HASFLOCK int lock_ex(int fd) { return flock(fd,LOCK_EX); } #else int lock_ex(int fd) { return lockf(fd,1,0); } #endif admin/daemontools-0.76/src/ndelay.h 644 0 0 170 7323352455 13412 0ustar00/* Public domain. */ #ifndef NDELAY_H #define NDELAY_H extern int ndelay_on(int); extern int ndelay_off(int); #endif admin/daemontools-0.76/src/ndelay_on.c 644 0 0 343 7323352455 14103 0ustar00/* Public domain. */ #include #include #include "ndelay.h" #ifndef O_NONBLOCK #define O_NONBLOCK O_NDELAY #endif int ndelay_on(int fd) { return fcntl(fd,F_SETFL,fcntl(fd,F_GETFL,0) | O_NONBLOCK); } admin/daemontools-0.76/src/ndelay_off.c 644 0 0 345 7323352455 14243 0ustar00/* Public domain. */ #include #include #include "ndelay.h" #ifndef O_NONBLOCK #define O_NONBLOCK O_NDELAY #endif int ndelay_off(int fd) { return fcntl(fd,F_SETFL,fcntl(fd,F_GETFL,0) & ~O_NONBLOCK); } admin/daemontools-0.76/src/tai_pack.c 644 0 0 471 7323352455 13710 0ustar00/* Public domain. */ #include "tai.h" void tai_pack(char *s,const struct tai *t) { uint64 x; x = t->x; s[7] = x & 255; x >>= 8; s[6] = x & 255; x >>= 8; s[5] = x & 255; x >>= 8; s[4] = x & 255; x >>= 8; s[3] = x & 255; x >>= 8; s[2] = x & 255; x >>= 8; s[1] = x & 255; x >>= 8; s[0] = x; } admin/daemontools-0.76/src/taia_pack.c 644 0 0 550 7323352455 14047 0ustar00/* Public domain. */ #include "taia.h" void taia_pack(char *s,const struct taia *t) { unsigned long x; tai_pack(s,&t->sec); s += 8; x = t->atto; s[7] = x & 255; x >>= 8; s[6] = x & 255; x >>= 8; s[5] = x & 255; x >>= 8; s[4] = x; x = t->nano; s[3] = x & 255; x >>= 8; s[2] = x & 255; x >>= 8; s[1] = x & 255; x >>= 8; s[0] = x; } admin/daemontools-0.76/src/taia_add.c 644 0 0 631 7323352455 13661 0ustar00/* Public domain. */ #include "taia.h" /* XXX: breaks tai encapsulation */ void taia_add(struct taia *t,const struct taia *u,const struct taia *v) { t->sec.x = u->sec.x + v->sec.x; t->nano = u->nano + v->nano; t->atto = u->atto + v->atto; if (t->atto > 999999999UL) { t->atto -= 1000000000UL; ++t->nano; } if (t->nano > 999999999UL) { t->nano -= 1000000000UL; ++t->sec.x; } } admin/daemontools-0.76/src/open_trunc.c 644 0 0 264 7323352455 14311 0ustar00/* Public domain. */ #include #include #include "open.h" int open_trunc(const char *fn) { return open(fn,O_WRONLY | O_NDELAY | O_TRUNC | O_CREAT,0644); } admin/daemontools-0.76/src/taia_uint.c 644 0 0 256 7323352455 14113 0ustar00/* Public domain. */ #include "taia.h" /* XXX: breaks tai encapsulation */ void taia_uint(struct taia *t,unsigned int s) { t->sec.x = s; t->nano = 0; t->atto = 0; } admin/daemontools-0.76/src/subgetopt.h 644 0 0 1116 7323352455 14173 0ustar00/* Public domain. */ #ifndef SUBGETOPT_H #define SUBGETOPT_H #ifndef SUBGETOPTNOSHORT #define sgopt subgetopt #define sgoptarg subgetoptarg #define sgoptind subgetoptind #define sgoptpos subgetoptpos #define sgoptproblem subgetoptproblem #define sgoptprogname subgetoptprogname #define sgoptdone subgetoptdone #endif #define SUBGETOPTDONE -1 extern int subgetopt(int,const char *const *,const char *); extern const char *subgetoptarg; extern int subgetoptind; extern int subgetoptpos; extern int subgetoptproblem; extern const char *subgetoptprogname; extern int subgetoptdone; #endif admin/daemontools-0.76/src/subgetopt.c 644 0 0 2604 7323352455 14171 0ustar00/* Public domain. */ #define SUBGETOPTNOSHORT #include "subgetopt.h" #define sgopt subgetopt #define optind subgetoptind #define optpos subgetoptpos #define optarg subgetoptarg #define optproblem subgetoptproblem #define optdone subgetoptdone int optind = 1; int optpos = 0; const char *optarg = 0; int optproblem = 0; int optdone = SUBGETOPTDONE; int sgopt(int argc,const char *const *argv,const char *opts) { int c; const char *s; optarg = 0; if (!argv || (optind >= argc) || !argv[optind]) return optdone; if (optpos && !argv[optind][optpos]) { ++optind; optpos = 0; if ((optind >= argc) || !argv[optind]) return optdone; } if (!optpos) { if (argv[optind][0] != '-') return optdone; ++optpos; c = argv[optind][1]; if ((c == '-') || (c == 0)) { if (c) ++optind; optpos = 0; return optdone; } /* otherwise c is reassigned below */ } c = argv[optind][optpos]; ++optpos; s = opts; while (*s) { if (c == *s) { if (s[1] == ':') { optarg = argv[optind] + optpos; ++optind; optpos = 0; if (!*optarg) { optarg = argv[optind]; if ((optind >= argc) || !optarg) { /* argument past end */ optproblem = c; return '?'; } ++optind; } } return c; } ++s; if (*s == ':') ++s; } optproblem = c; return '?'; } admin/daemontools-0.76/src/sgetopt.h 644 0 0 741 7323352455 13627 0ustar00/* Public domain. */ #ifndef SGETOPT_H #define SGETOPT_H #ifndef SGETOPTNOSHORT #define getopt sgetoptmine #define optarg subgetoptarg #define optind subgetoptind #define optpos subgetoptpos #define opterr sgetopterr #define optproblem subgetoptproblem #define optprogname sgetoptprogname #define opteof subgetoptdone #endif #include "subgetopt.h" extern int sgetoptmine(int,const char *const *,const char *); extern int sgetopterr; extern const char *sgetoptprogname; #endif admin/daemontools-0.76/src/sgetopt.c 644 0 0 2425 7323352455 13643 0ustar00/* Public domain. */ /* sgetopt.c, sgetopt.h: (yet another) improved getopt clone, outer layer D. J. Bernstein, djb@pobox.com. Depends on subgetopt.h, buffer.h. No system requirements. 19991219: Switched to buffer.h. 19970208: Cleanups. 931201: Baseline. No known patent problems. Documentation in sgetopt.3. */ #include "buffer.h" #define SGETOPTNOSHORT #include "sgetopt.h" #define SUBGETOPTNOSHORT #include "subgetopt.h" #define getopt sgetoptmine #define optind subgetoptind #define opterr sgetopterr #define optproblem subgetoptproblem #define optprogname sgetoptprogname int opterr = 1; const char *optprogname = 0; int getopt(int argc,const char *const *argv,const char *opts) { int c; const char *s; if (!optprogname) { optprogname = *argv; if (!optprogname) optprogname = ""; for (s = optprogname;*s;++s) if (*s == '/') optprogname = s + 1; } c = subgetopt(argc,argv,opts); if (opterr) if (c == '?') { char chp[2]; chp[0] = optproblem; chp[1] = '\n'; buffer_puts(buffer_2,optprogname); if (argv[optind] && (optind < argc)) buffer_puts(buffer_2,": illegal option -- "); else buffer_puts(buffer_2,": option requires an argument -- "); buffer_put(buffer_2,chp,2); buffer_flush(buffer_2); } return c; } admin/daemontools-0.76/src/byte_chr.c 644 0 0 630 7323352455 13731 0ustar00/* Public domain. */ #include "byte.h" unsigned int byte_chr(s,n,c) char *s; register unsigned int n; int c; { register char ch; register char *t; ch = c; t = s; for (;;) { if (!n) break; if (*t == ch) break; ++t; --n; if (!n) break; if (*t == ch) break; ++t; --n; if (!n) break; if (*t == ch) break; ++t; --n; if (!n) break; if (*t == ch) break; ++t; --n; } return t - s; } admin/daemontools-0.76/src/fmt.h 644 0 0 2124 7323352455 12745 0ustar00/* Public domain. */ #ifndef FMT_H #define FMT_H #define FMT_ULONG 40 /* enough space to hold 2^128 - 1 in decimal, plus \0 */ #define FMT_LEN ((char *) 0) /* convenient abbreviation */ extern unsigned int fmt_uint(char *,unsigned int); extern unsigned int fmt_uint0(char *,unsigned int,unsigned int); extern unsigned int fmt_xint(char *,unsigned int); extern unsigned int fmt_nbbint(char *,unsigned int,unsigned int,unsigned int,unsigned int); extern unsigned int fmt_ushort(char *,unsigned short); extern unsigned int fmt_xshort(char *,unsigned short); extern unsigned int fmt_nbbshort(char *,unsigned int,unsigned int,unsigned int,unsigned short); extern unsigned int fmt_ulong(char *,unsigned long); extern unsigned int fmt_xlong(char *,unsigned long); extern unsigned int fmt_nbblong(char *,unsigned int,unsigned int,unsigned int,unsigned long); extern unsigned int fmt_plusminus(char *,int); extern unsigned int fmt_minus(char *,int); extern unsigned int fmt_0x(char *,int); extern unsigned int fmt_str(char *,const char *); extern unsigned int fmt_strn(char *,const char *,unsigned int); #endif admin/daemontools-0.76/src/scan.h 644 0 0 2605 7323352455 13107 0ustar00/* Public domain. */ #ifndef SCAN_H #define SCAN_H extern unsigned int scan_uint(const char *,unsigned int *); extern unsigned int scan_xint(const char *,unsigned int *); extern unsigned int scan_nbbint(const char *,unsigned int,unsigned int,unsigned int,unsigned int *); extern unsigned int scan_ushort(const char *,unsigned short *); extern unsigned int scan_xshort(const char *,unsigned short *); extern unsigned int scan_nbbshort(const char *,unsigned int,unsigned int,unsigned int,unsigned short *); extern unsigned int scan_ulong(const char *,unsigned long *); extern unsigned int scan_xlong(const char *,unsigned long *); extern unsigned int scan_nbblong(const char *,unsigned int,unsigned int,unsigned int,unsigned long *); extern unsigned int scan_plusminus(const char *,int *); extern unsigned int scan_0x(const char *,unsigned int *); extern unsigned int scan_whitenskip(const char *,unsigned int); extern unsigned int scan_nonwhitenskip(const char *,unsigned int); extern unsigned int scan_charsetnskip(const char *,const char *,unsigned int); extern unsigned int scan_noncharsetnskip(const char *,const char *,unsigned int); extern unsigned int scan_strncmp(const char *,const char *,unsigned int); extern unsigned int scan_memcmp(const char *,const char *,unsigned int); extern unsigned int scan_long(const char *,long *); extern unsigned int scan_8long(const char *,unsigned long *); #endif admin/daemontools-0.76/src/fmt_ulong.c 644 0 0 520 7323352455 14122 0ustar00/* Public domain. */ #include "fmt.h" unsigned int fmt_ulong(register char *s,register unsigned long u) { register unsigned int len; register unsigned long q; len = 1; q = u; while (q > 9) { ++len; q /= 10; } if (s) { s += len; do { *--s = '0' + (u % 10); u /= 10; } while(u); /* handles u == 0 */ } return len; } admin/daemontools-0.76/src/fmt_uint.c 644 0 0 205 7323352455 13755 0ustar00/* Public domain. */ #include "fmt.h" unsigned int fmt_uint(register char *s,register unsigned int u) { return fmt_ulong(s,u); } admin/daemontools-0.76/src/fmt_uint0.c 644 0 0 361 7323352455 14040 0ustar00/* Public domain. */ #include "fmt.h" unsigned int fmt_uint0(char *s,unsigned int u,unsigned int n) { unsigned int len; len = fmt_uint(FMT_LEN,u); while (len < n) { if (s) *s++ = '0'; ++len; } if (s) fmt_uint(s,u); return len; } admin/daemontools-0.76/src/tai_unpack.c 644 0 0 630 7323352455 14250 0ustar00/* Public domain. */ #include "tai.h" void tai_unpack(const char *s,struct tai *t) { uint64 x; x = (unsigned char) s[0]; x <<= 8; x += (unsigned char) s[1]; x <<= 8; x += (unsigned char) s[2]; x <<= 8; x += (unsigned char) s[3]; x <<= 8; x += (unsigned char) s[4]; x <<= 8; x += (unsigned char) s[5]; x <<= 8; x += (unsigned char) s[6]; x <<= 8; x += (unsigned char) s[7]; t->x = x; } admin/daemontools-0.76/src/tai_now.c 644 0 0 174 7323352455 13575 0ustar00/* Public domain. */ #include #include "tai.h" void tai_now(struct tai *t) { tai_unix(t,time((time_t *) 0)); } admin/daemontools-0.76/src/tai_sub.c 644 0 0 206 7323352455 13557 0ustar00/* Public domain. */ #include "tai.h" void tai_sub(struct tai *t,const struct tai *u,const struct tai *v) { t->x = u->x - v->x; } admin/daemontools-0.76/src/seek.h 644 0 0 427 7323352455 13072 0ustar00/* Public domain. */ #ifndef SEEK_H #define SEEK_H typedef unsigned long seek_pos; extern seek_pos seek_cur(int); extern int seek_set(int,seek_pos); extern int seek_end(int); extern int seek_trunc(int,seek_pos); #define seek_begin(fd) (seek_set((fd),(seek_pos) 0)) #endif admin/daemontools-0.76/src/seek_set.c 644 0 0 272 7323352455 13736 0ustar00/* Public domain. */ #include #include "seek.h" #define SET 0 /* sigh */ int seek_set(int fd,seek_pos pos) { if (lseek(fd,(off_t) pos,SET) == -1) return -1; return 0; } admin/daemontools-0.76/src/str_diff.c 644 0 0 723 7323352455 13735 0ustar00/* Public domain. */ #include "str.h" int str_diff(register const char *s,register const char *t) { register char x; for (;;) { x = *s; if (x != *t) break; if (!x) break; ++s; ++t; x = *s; if (x != *t) break; if (!x) break; ++s; ++t; x = *s; if (x != *t) break; if (!x) break; ++s; ++t; x = *s; if (x != *t) break; if (!x) break; ++s; ++t; } return ((int)(unsigned int)(unsigned char) x) - ((int)(unsigned int)(unsigned char) *t); } admin/daemontools-0.76/src/byte_rchr.c 644 0 0 707 7323352455 14120 0ustar00/* Public domain. */ #include "byte.h" unsigned int byte_rchr(s,n,c) char *s; register unsigned int n; int c; { register char ch; register char *t; register char *u; ch = c; t = s; u = 0; for (;;) { if (!n) break; if (*t == ch) u = t; ++t; --n; if (!n) break; if (*t == ch) u = t; ++t; --n; if (!n) break; if (*t == ch) u = t; ++t; --n; if (!n) break; if (*t == ch) u = t; ++t; --n; } if (!u) u = t; return u - s; } admin/daemontools-0.76/src/scan_ulong.c 644 0 0 551 7323352455 14264 0ustar00/* Public domain. */ #include "scan.h" unsigned int scan_ulong(register const char *s,register unsigned long *u) { register unsigned int pos = 0; register unsigned long result = 0; register unsigned long c; while ((c = (unsigned long) (unsigned char) (s[pos] - '0')) < 10) { result = result * 10 + c; ++pos; } *u = result; return pos; } admin/daemontools-0.76/src/buffer_get.c 644 0 0 2367 7323352455 14273 0ustar00/* Public domain. */ #include "buffer.h" #include "byte.h" #include "error.h" static int oneread(int (*op)(),int fd,char *buf,unsigned int len) { int r; for (;;) { r = op(fd,buf,len); if (r == -1) if (errno == error_intr) continue; return r; } } static int getthis(buffer *s,char *buf,unsigned int len) { if (len > s->p) len = s->p; s->p -= len; byte_copy(buf,len,s->x + s->n); s->n += len; return len; } int buffer_feed(buffer *s) { int r; if (s->p) return s->p; r = oneread(s->op,s->fd,s->x,s->n); if (r <= 0) return r; s->p = r; s->n -= r; if (s->n > 0) byte_copyr(s->x + s->n,r,s->x); return r; } int buffer_bget(buffer *s,char *buf,unsigned int len) { int r; if (s->p > 0) return getthis(s,buf,len); if (s->n <= len) return oneread(s->op,s->fd,buf,s->n); r = buffer_feed(s); if (r <= 0) return r; return getthis(s,buf,len); } int buffer_get(buffer *s,char *buf,unsigned int len) { int r; if (s->p > 0) return getthis(s,buf,len); if (s->n <= len) return oneread(s->op,s->fd,buf,len); r = buffer_feed(s); if (r <= 0) return r; return getthis(s,buf,len); } char *buffer_peek(buffer *s) { return s->x + s->n; } void buffer_seek(buffer *s,unsigned int len) { s->n += len; s->p -= len; } admin/daemontools-0.76/src/buffer_0.c 644 0 0 521 7323352455 13621 0ustar00/* Public domain. */ #include "buffer.h" int buffer_0_read(fd,buf,len) int fd; char *buf; int len; { if (buffer_flush(buffer_1) == -1) return -1; return buffer_unixread(fd,buf,len); } char buffer_0_space[BUFFER_INSIZE]; static buffer it = BUFFER_INIT(buffer_0_read,0,buffer_0_space,sizeof buffer_0_space); buffer *buffer_0 = ⁢ admin/daemontools-0.76/src/prot.h 644 0 0 161 7323352455 13122 0ustar00/* Public domain. */ #ifndef PROT_H #define PROT_H extern int prot_gid(int); extern int prot_uid(int); #endif admin/daemontools-0.76/src/prot.c 644 0 0 613 7323352455 13117 0ustar00/* Public domain. */ #include "hasshsgr.h" #include "prot.h" int prot_gid(int gid) { #ifdef HASSHORTSETGROUPS short x[2]; x[0] = gid; x[1] = 73; /* catch errors */ if (setgroups(1,x) == -1) return -1; #else if (setgroups(1,&gid) == -1) return -1; #endif return setgid(gid); /* _should_ be redundant, but on some systems it isn't */ } int prot_uid(int uid) { return setuid(uid); } admin/daemontools-0.76/src/hasshsgr.h1 644 0 0 64 7323352455 14023 0ustar00/* Public domain. */ /* sysdep: -shortsetgroups */ admin/daemontools-0.76/src/hasshsgr.h2 644 0 0 120 7323352455 14035 0ustar00/* Public domain. */ /* sysdep: +shortsetgroups */ #define HASSHORTSETGROUPS 1 admin/daemontools-0.76/src/chkshsgr.c 644 0 0 247 7323352455 13752 0ustar00/* Public domain. */ #include int main() { short x[4]; x[0] = x[1] = 0; if (getgroups(1,x) == 0) if (setgroups(1,x) == -1) _exit(1); _exit(0); } admin/daemontools-0.76/src/warn-shsgr 644 0 0 313 7323352455 14002 0ustar00Oops. Your getgroups() returned 0, and setgroups() failed; this means that I can't reliably do my shsgr test. Please either ``make'' as root or ``make'' while you're in one or more supplementary groups. admin/daemontools-0.76/src/tryshsgr.c 644 0 0 443 7323352455 14021 0ustar00/* Public domain. */ int main() { short x[4]; x[0] = x[1] = 1; if (getgroups(1,x) == 0) if (setgroups(1,x) == -1) _exit(1); if (getgroups(1,x) == -1) _exit(1); if (x[1] != 1) _exit(1); x[1] = 2; if (getgroups(1,x) == -1) _exit(1); if (x[1] != 2) _exit(1); _exit(0); } admin/daemontools-0.76/src/readclose.h 644 0 0 313 7323352455 14076 0ustar00/* Public domain. */ #ifndef READCLOSE_H #define READCLOSE_H #include "stralloc.h" extern int readclose_append(int,stralloc *,unsigned int); extern int readclose(int,stralloc *,unsigned int); #endif admin/daemontools-0.76/src/readclose.c 644 0 0 1055 7323352455 14115 0ustar00/* Public domain. */ #include #include "error.h" #include "readclose.h" int readclose_append(int fd,stralloc *sa,unsigned int bufsize) { int r; for (;;) { if (!stralloc_readyplus(sa,bufsize)) { close(fd); return -1; } r = read(fd,sa->s + sa->len,bufsize); if (r == -1) if (errno == error_intr) continue; if (r <= 0) { close(fd); return r; } sa->len += r; } } int readclose(int fd,stralloc *sa,unsigned int bufsize) { if (!stralloc_copys(sa,"")) { close(fd); return -1; } return readclose_append(fd,sa,bufsize); } admin/daemontools-0.76/src/openreadclose.h 644 0 0 246 7323352455 14765 0ustar00/* Public domain. */ #ifndef OPENREADCLOSE_H #define OPENREADCLOSE_H #include "stralloc.h" extern int openreadclose(const char *,stralloc *,unsigned int); #endif admin/daemontools-0.76/src/openreadclose.c 644 0 0 540 7323352455 14755 0ustar00/* Public domain. */ #include "error.h" #include "open.h" #include "readclose.h" #include "openreadclose.h" int openreadclose(const char *fn,stralloc *sa,unsigned int bufsize) { int fd; fd = open_read(fn); if (fd == -1) { if (errno == error_noent) return 0; return -1; } if (readclose(fd,sa,bufsize) == -1) return -1; return 1; }