From cee18a4121903116c7b671c0a5f86398d4c5f788 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Arkadiusz=20Mi=C5=9Bkiewicz?= Date: Fri, 18 Jun 1999 19:23:52 +0000 Subject: [PATCH] pare zmian svn-id: @374 --- doc-devel/ogolnie | 17 + doc/initlog.1 | 48 +++ rc.d/init.d/functions | 44 ++- rc.d/init.d/netfs | 90 +++++ rc.d/init.d/network | 4 +- rc.d/init.d/shutdwn | 23 +- rc.d/init.d/single | 2 +- rc.d/rc.serial | 7 +- rc.d/rc.sysinit | 121 +++---- src/Makefile | 38 +++ src/initlog.1 | 48 +++ src/initlog.c | 316 ++++++++++++++++++ src/initlog.h | 20 ++ src/loglevel.c | 25 ++ src/minilogd.c | 161 +++++++++ src/process.c | 223 ++++++++++++ src/process.h | 9 + sysconfig/interfaces/ifcfg-sl0 | 12 + .../tnlcfg-icm | 0 sysconfig/system | 9 + 20 files changed, 1128 insertions(+), 89 deletions(-) create mode 100644 doc-devel/ogolnie create mode 100644 doc/initlog.1 create mode 100644 rc.d/init.d/netfs create mode 100644 src/Makefile create mode 100644 src/initlog.1 create mode 100644 src/initlog.c create mode 100644 src/initlog.h create mode 100644 src/loglevel.c create mode 100644 src/minilogd.c create mode 100644 src/process.c create mode 100644 src/process.h create mode 100644 sysconfig/interfaces/ifcfg-sl0 rename sysconfig/{network-scripts => interfaces}/tnlcfg-icm (100%) diff --git a/doc-devel/ogolnie b/doc-devel/ogolnie new file mode 100644 index 00000000..08e4f95b --- /dev/null +++ b/doc-devel/ogolnie @@ -0,0 +1,17 @@ +rc-scripts + +- pliki interfejsów l±duj± w /etc/sysconfig/interfaces +(zarówno interfejsów sieciowych - ifcfg-* jak i tuneli tnlcfg-*) +- konfiguracja dotycz±ca wy³±cznie IPv4 siedzi sobie w /etc/sysconfig/network-ipv4 +natomias konfiguracja dla IPv6 siedzi w /etc/sysconfig/network-ipv6 +- tunnels-ipv6 wypada z obiegu. Ka¿dy tunel bêdzie mia³ swój w³asny plik. +- network-ip6.conf te¿ wypada... +- IPV6_NETWORKING wypada z network a l±duje w network-ipv6 +- wszystkie chat-* nadal w /etc/sysconfig/network-scripts +- pliki z funkcjami w /etc/rc.d/init.d/ czyli + functions - podstawowe + functions.network.ipv4 - do ipv4 + functions.network.ipv6 - do ipv6 +- network-ip6.init wylatuje. startowanie ipv4 _i_ ipv6 musi zawieraæ siê w network +- to samo dotyczy tunnels-ip6.init + diff --git a/doc/initlog.1 b/doc/initlog.1 new file mode 100644 index 00000000..103ef3fd --- /dev/null +++ b/doc/initlog.1 @@ -0,0 +1,48 @@ +.TH initlog 8 "Sun Jan 24 1999" +.SH NAME +initlog \- log messages and events to the system logger +.SH SYNOPSIS +.B initlog +[\-cefnprs] [\-\-cmd=ARG] [\-\-event=ARG] [\-\-facility=ARG] +[\-\-name=ARG] [\-\-priority=ARG] [\-\-run=ARG] [\-\-string=ARG] +.SH DESCRIPTION +\fBinitlog\fR logs messages and events to the system logger. +It is mainly designed for use in init scripts. + +.SS OPTIONS +.TP +.I "\-c, \-\-cmd=[program]" +Execute the specified program, logging anything output to +stdout or stderr. +.TP +.I "\-e, \-\-event=[number]" +Logs that the specified event happened. Usually used in conjuction +with \fB\-\-name\fR. Currently specified events are: +.nf + \fB1\fR the action completed successfully + \fB2\fR the action failed + \fB3\fR the action was cancelled at user request + \fB4\fR the action failed due to the failure of a dependent action +.TP +.I "\-f, \-\-facility=[facility]" + +Log at the specified syslog facility. The default +is \fBdaemon\fR (see syslog(3)). +.TP +.I "\-n, \-\-name=[string]" +Log the event under the specified string, such as +"inetd". +.TP +.I "\-p, \-\-priority=[priority]" +Log at the specified syslog priority. The default +is \fBnotice\fR (see syslog(3)). +.TP +.I "\-r, \-\-run=[program]" +Execute the specified program, with an open file +descriptor so that the program can pass back +commands to initlog. +.TP +.I "\-s, \-\-string=[string] +Log the specified string to the logger. +.SH "SEE ALSO" +syslog(3), logger(1) diff --git a/rc.d/init.d/functions b/rc.d/init.d/functions index 2ead74cb..46d53a3e 100644 --- a/rc.d/init.d/functions +++ b/rc.d/init.d/functions @@ -1,7 +1,7 @@ # functions This file contains functions to be used by most or all # shell scripts in the /etc/init.d directory. # -# Version: @(#) /etc/init.d/functions $Revision: 1.7 $ $Date: 1999/06/14 21:17:10 $ +# Version: @(#) /etc/init.d/functions $Revision: 1.8 $ $Date: 1999/06/18 19:23:51 $ # # Author: Miquel van Smoorenburg, # Hacked by: Greg Galloway and Marc Ewing @@ -10,10 +10,31 @@ # Arkadiusz Mi¶kiewicz # First set up a default search path. -PATH="/sbin:/usr/sbin:/bin:/usr/bin"; export PATH +export PATH="/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin" [ -z "$COLUMNS" ] && COLUMNS=80 +# Colors workaround +unset tput || : +if [ "$COLOR_INIT" == "no" ]; then + tput() + { + : + } +elif [ ! -d /usr/share/terminfo ]; then + tput() + { + if [ "$2" == "1" ]; then echo -ne "\033[0;31m" + elif [ "$2" == "2" ]; then echo -ne "\033[0;32m" + elif [ "$2" == "5" ]; then echo -ne "\033[0;35m" + elif [ "$2" == "6" ]; then echo -ne "\033[0;36m" + elif [ "$2" == "7" ]; then echo -ne "\033[0;37m" + fi + } +else +unset tput || : +fi + # Some functions to handle PLD-style messages show() { @@ -51,6 +72,23 @@ deltext() echo -ne '\b\b\b\b\b\b\b\b' } +# Usage run_cmd Message command_to_run +run_cmd() +{ +_ERRORS="" +MESSAGE=$1 +show "$MESSAGE"; busy +shift +if _ERRORS="`initlog -c \"$*\"`"; then +deltext; ok +else +deltext; fail; echo $_ERRORS +fi +exit_code=$? +unset _ERRORS +return $exit_code +} + # A function to start a program (now it's usefull on read-only filesystem too) daemon() { @@ -71,7 +109,7 @@ daemon() # And start it up. busy - if _ERRORS="`nice -n ${SERVICE_RUN_NICE_LEVEL:-$DEFAULT_SERVICE_RUN_NICE_LEVEL} initlog -c \"$@\" 2>&1`"; then + if _ERRORS="`nice -n ${SERVICE_RUN_NICE_LEVEL:-$DEFAULT_SERVICE_RUN_NICE_LEVEL} initlog -c "$*" 2>&1`"; then deltext ok else diff --git a/rc.d/init.d/netfs b/rc.d/init.d/netfs new file mode 100644 index 00000000..bdc0fb70 --- /dev/null +++ b/rc.d/init.d/netfs @@ -0,0 +1,90 @@ +#!/bin/sh +# +# netfs Mount network filesystems. +# +# Authors: Bill Nottingham +# Miquel van Smoorenburg, +# +# chkconfig: 345 15 85 +# description: Mounts and unmounts all Network File System (NFS), \ +# SMB (Lan Manager/Windows), and NCP (NetWare) mount points. + +# Source networking configuration. +if [ ! -f /etc/sysconfig/network ]; then + exit 0 +fi + +# Source function library. +. /etc/rc.d/init.d/functions + +. /etc/sysconfig/network + +# Check that networking is up. +[ ${NETWORKING} = "no" ] && exit 0 + +NFSFSTAB=`grep -v '^#' /etc/fstab | awk '{ if ($3 ~ /^nfs$/ && $4 !~ /noauto/) print $2}'` +SMBFSTAB=`grep -v '^#' /etc/fstab | awk '{ if ($3 ~ /^smbfs$/ && $4 !~ /noauto/) print $2}'` +NCPFSTAB=`grep -v '^#' /etc/fstab | awk '{ if ($3 ~ /^ncpfs$/ && $4 !~ /noauto/) print $2}'` +NFSMTAB=`grep -v '^#' /proc/mounts | awk '{ if ($3 ~ /^nfs$/ && $4 !~ /noauto/) print $2}'` +SMBMTAB=`grep -v '^#' /proc/mounts | awk '{ if ($3 ~ /^smbfs$/ && $4 !~ /noauto/) print $2}'` +NCPMTAB=`grep -v '^#' /proc/mounts | awk '{ if ($3 ~ /^ncpfs$/ && $4 !~ /noauto/) print $2}'` + +# See how we were called. +case "$1" in + start) + [ -n "$NFSFSTAB" ] && run_cmd "Mounting NFS filesystems" mount -a -t nfs + [ -n "$SMBFSTAB" ] && run_cmd "Mounting SMB filesystems" mount -a -t smbfs + [ -n "$NCPFSTAB" ] && run_cmd "Mounting NCP filesystems" mount -a -t ncpfs + touch /var/lock/subsys/netfs + run_cmd "Mounting other filesystems" mount -a + ;; + stop) + [ -n "$NFSMTAB" ] && run_cmd "Unmounting NFS filesystems" umount -a -t nfs + [ -n "$SMBMTAB" ] && run_cmd "Unmounting SMB filesystems" umount -a -t smbfs + [ -n "$NCPMTAB" ] && run_cmd "Unmounting NCP filesystems" umount -a -t ncpfs + rm -f /var/lock/subsys/netfs + ;; + status) + if [ -f /proc/mounts ] ; then + [ -n "$NFSFSTAB" ] && { + echo "Configured NFS mountpoints:" + for fs in $NFSFSTAB; do echo $fs ; done + } + [ -n "$SMBFSTAB" ] && { + echo "Configured SMB mountpoints:" + for fs in $SMBFSTAB; do echo $fs ; done + } + [ -n "$NCPFSTAB" ] && { + echo "Configured NCP mountpoints:" + for fs in $NCPFSTAB; do echo $fs ; done + } + [ -n "$NFSMTAB" ] && { + echo "Active NFS mountpoints:" + for fs in $NFSMTAB; do echo $fs ; done + } + [ -n "$SMBMTAB" ] && { + echo "Active SMB mountpoints:" + for fs in $SMBMTAB; do echo $fs ; done + } + [ -n "$NCPMTAB" ] && { + echo "Active NCP mountpoints:" + for fs in $NCPMTAB; do echo $fs ; done + } + else + echo "/proc filesystem unavailable" + fi + ;; + restart) + $0 stop + $0 start + ;; + reload) + $0 start + ;; + *) + echo "Usage: netfs {start|stop|restart|reload|status}" + exit 1 +esac + +exit 0 + diff --git a/rc.d/init.d/network b/rc.d/init.d/network index 3950daa9..b2cb6f62 100644 --- a/rc.d/init.d/network +++ b/rc.d/init.d/network @@ -16,7 +16,7 @@ . /etc/sysconfig/network # Check that networking is up. -[ "${NETWORKING}" = "no" -o "${NETWORKING}"="" ] && exit 0 +[ "${NETWORKING}" == "no" -o "${NETWORKING}" == "" ] && exit 0 [ -x /sbin/ifconfig ] || exit 0 @@ -43,7 +43,7 @@ network_deinit() } -interfaces="`ls -1 /etc/sysconfig/interfaces/ifcfg-* | grep -v ifcfg-lo | xargs 2> /dev/null`" +interfaces="`cd /etc/sysconfig/interfaces && ls -1 ifcfg-* | grep -v ifcfg-lo | xargs 2> /dev/null`" # See how we were called. case "$1" in diff --git a/rc.d/init.d/shutdwn b/rc.d/init.d/shutdwn index ab740493..d5d9001f 100755 --- a/rc.d/init.d/shutdwn +++ b/rc.d/init.d/shutdwn @@ -25,19 +25,24 @@ daemon killall5 -9 halt -w # Turn off swap, then unmount file systems. -show "Turning off swap and accounting" -daemon swapoff -a +run_cmd "Turning off swap and accounting" swapoff -a [ -x /sbin/accton ] && /sbin/accton -show "Unmounting file systems"; busy -if ( umount -a; mount -n -o remount,ro / ); then -deltext; ok -else -deltext; fail -fi +run_cmd "Unmounting file systems" umount -a +run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro / # turn off raid if [ -x /sbin/raidstop -a -f /etc/raidtab ]; then - /sbin/raidstop -a + # we can not use raidstop -a here because this will only stop + # devices listed in the default config file which is not always + # the case. So we look only for the active raid devices + if [ -f /proc/mdstat ] ; then + mddevs=$(grep ^md /proc/mdstat | awk '{ print $1 }') + for mddev in $mddevs ; do + run_cmd "Turning off RAID for $mddev" raidstop /dev/$mddev + done + unset mddev mddevs + fi + #runcmd "Turning off RAID" /sbin/raidstop -a fi show "Remounting remaining filesystems ro mode"; busy diff --git a/rc.d/init.d/single b/rc.d/init.d/single index 790a74d9..7356a820 100644 --- a/rc.d/init.d/single +++ b/rc.d/init.d/single @@ -56,7 +56,7 @@ for i in /etc/rc.d/rc1.d/S[0-9][0-9]*; do done # Now go to the single user level. - show "Telling INIT to go to single user mode."; ok + show "Telling INIT to go to single user mode"; ok exec init -t1 S ;; esac diff --git a/rc.d/rc.serial b/rc.d/rc.serial index 54f85232..d29d19eb 100755 --- a/rc.d/rc.serial +++ b/rc.d/rc.serial @@ -14,6 +14,7 @@ SETSERIAL=/bin/setserial [ -f $SETSERIAL ] || exit 0 +. /etc/rc.d/init.d/functions ALLDEVS="/dev/ttyS*" @@ -28,11 +29,7 @@ fi for a in ${ALLDEVS}; do WHAT="`${SETSERIAL} -bg $a`" if (echo $WHAT | grep -q " at "); then - if [ -x /usr/bin/cut ]; then - show "`echo $WHAT | cut -d"/" -f3`"; ok - else - show "$WHAT"; ok - fi + show "`basename \"$WHAT\"`"; ok fi done diff --git a/rc.d/rc.sysinit b/rc.d/rc.sysinit index 8fa2fe4a..9c6b93c4 100755 --- a/rc.d/rc.sysinit +++ b/rc.d/rc.sysinit @@ -30,19 +30,22 @@ else PANIC_REBOOT_TIME=0 DELAY_LOGIN=yes CLEAN_TMP=no + CONSOLE_LOGLEVEL=1 + LOAD_SOUND=yes fi +# Set console loglevel +/sbin/loglevel $CONSOLE_LOGLEVEL + # Start up swapping. -show "Activating swap partitions"; ok -swapon -a +run_cmd "Activating swap partitions" swapon -a # Set the hostname. -hostname ${HOSTNAME} -echo "Setting hostname: `hostname`" +run_cmd "Host: ${HOSTNAME}" hostname ${HOSTNAME} # Set the NIS domain name if [ -n "$NISDOMAIN" ]; then - domainname $NISDOMAIN +run_cmd "NIS Domain: ${NISDOMAIN}" domainname $NISDOMAIN else domainname "" fi @@ -53,9 +56,14 @@ if [ -f /fsckoptions ]; then fsckoptions='' fi +if [ -f /forcefsck ]; then + fsckoptions="-f $fsckoptions" +fi + +_RUN_QUOTACHECK=0 if [ ! -f /fastboot ]; then show "Checking root filesystems."; started - fsck -V -a $fsckoptions / + initlog -c "fsck -T -a $fsckoptions /" rc=$? @@ -74,20 +82,16 @@ if [ ! -f /fastboot ]; then /bin/sh fi - echo "Unmounting file systems" - umount -a + run_cmd "Unmounting file systems" umount -a mount -n -o remount,ro / - show "Automatic reboot in progress."; busy - if reboot; then deltext; ok; else deltext; fail; fi + run_cmd "Automatic reboot in progress." reboot elif [ "$rc" = "1" -a -x /sbin/quotacheck ]; then - show "Checking root filesystem quotas"; busy - if (/sbin/quotacheck -v /); then deltext; ok; else deltext; fail; fi + _RUN_QUOTACHECK=1 fi fi if [ -x /sbin/quotaon ]; then - show "Turning on quotas on root filesystem"; busy - if (/sbin/quotaon /); then deltext; ok; else deltext; fail; fi + run_cmd "Turning on quotas on root filesystem" /sbin/quotaon / fi # check for arguments @@ -102,22 +106,19 @@ fi # set up pnp if [ -x /sbin/isapnp -a -f /etc/isapnp/isapnp.conf ]; then if [ -n "$PNP" ] && [ "$RUN_ISAPNP" == "yes" ]; then - show "Setting up ISA PNP devices"; busy - if _OUTPUT="`/sbin/isapnp /etc/isapnp/isapnp.conf 2>&1`"; then - deltext; ok - echo $_OUTPUT - else - deltext; fail - echo $_OUTPUT - fi + run_cmd "Setting up ISA PNP devices"/sbin/isapnp /etc/isapnp/isapnp.conf else - show "Skipping ISA PNP configuration at users request"; ok + show "Skipping ISA PNP configuration"; ok fi fi # Remount the root filesystem read-write. -show "Remounting root filesystem in rw mode"; busy -if (mount -n -o remount,rw /); then deltext; ok; else deltext; fail; fi +run_cmd "Remounting root filesystem in rw mode" mount -n -o remount,rw / + +# Update quotas if fsck was run on /. +if [ X"$_RUN_QUOTACHECK" = X1 -a -x /sbin/quotacheck ]; then + run_cmd "Checking root filesystem quotas" /sbin/quotacheck -v / +fi # /etc/nologin when starting system if [ "$DELAY_LOGIN" == "yes" ] && [ ! -f /etc/nologin ]; then @@ -139,7 +140,7 @@ fi mount -f / mount -f /proc -if [ -f /proc/ksyms ]; then +if ! grep -i nomodules /proc/cmdline >/dev/null && [ -f /proc/ksyms ]; then USEMODULES=y else USEMODULES= @@ -160,21 +161,20 @@ fi if [ -x /sbin/depmod -a -n "$USEMODULES" ]; then # Get ready for kerneld if module support in the kernel - show "Finding module dependencies... "; busy if [ -e /lib/modules/preferred ]; then - if depmod -a preferred; then deltext; ok; else deltext; fail; fi + run_cmd "Finding module dependencies" depmod -a preferred else - if depmod -a; then deltext; ok; else deltext; fail; fi + run_cmd "Finding module dependencies" depmod -a fi fi # load sound modules -if ! grep -i nomodules /proc/cmdline >/dev/null ; then +if (! grep -i nomodules /proc/cmdline >/dev/null) && [ "$LOAD_SOUND" == "yes" ]; then if [ -n "$USEMODULES" ]; then - if grep -s "alias sound" /etc/conf.modules > /dev/null ; then - modprobe sound + if grep -s "alias sound" /etc/modules.conf > /dev/null ; then + run_cmd "Loading sound module" modprobe sound if grep -s "alias midi" /etc/conf.modules > /dev/null ; then - modprobe midi + run_cmd "Loading midi module" modprobe midi fi fi fi @@ -186,17 +186,12 @@ if [ -f /proc/sys/kernel/modprobe ]; then fi # Add raid devices -if [ -f /proc/mdstat -a -f /etc/raidtab -a -x /sbin/raidadd ]; then +if [ -f /proc/mdstat -a -f /etc/raidtab -a -x /sbin/raidstart ]; then show "Starting up RAID devices."; started - raidadd -a + initlog -c "raidstart -a" rc=$? - if [ $rc = 0 ]; then - raidrun -a - rc=$? - fi - # A non-zero return means there were problems. if [ $rc -gt 0 ]; then echo @@ -206,24 +201,22 @@ if [ -f /proc/mdstat -a -f /etc/raidtab -a -x /sbin/raidadd ]; then echo "*** when you leave the shell." PS1="(RAID Repair) \#"; export PS1 - if [ "$RUN_SULOGIN_ON_ERR" = "yes"]; then + if [ "$RUN_SULOGIN_ON_ERR" == "yes"]; then sulogin else /bin/sh fi - show "Unmounting file systems"; busy - if (umount -a; mount -n -o remount,ro /); then - deltext; ok; else deltext; fail; fi - show "Automatic reboot in progress."; busy - if reboot; then deltext; ok; else deltext; fail; fi + run_cmd "Unmounting file systems" umount -a + run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro / + run_cmd "Automatic reboot in progress" reboot fi fi # Check filesystems if [ ! -f /fastboot ]; then show "Checking filesystems."; started - fsck -R -A -V -a $fsckoptions + initlog -c "fsck -T -R -A -a $fsckoptions" rc=$? @@ -242,21 +235,18 @@ if [ ! -f /fastboot ]; then /bin/sh fi - show "Unmounting file systems"; busy - if (umount -a; mount -n -o remount,ro /); then deltext; ok; else deltext; fail; fi - show "Automatic reboot in progress."; busy - if reboot; then deltext; ok; else deltext; fail; fi + run_cmd "Unmounting file systems" umount -a + run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro / + run_cmd "Automatic reboot in progress." reboot elif [ "$rc" = "1" -a -x /sbin/quotacheck ]; then - show "Checking filesystem quotas"; busy - if (/sbin/quotacheck -v -R -a); then deltext; ok; else deltext; fail; fi + run_cmd "Checking filesystem quotas"/sbin/quotacheck -v -R -a fi fi # Mount all other filesystems (except for NFS and /proc, which is already # mounted). Contrary to standard usage, # filesystems are NOT unmounted in single user mode. -show "Mounting local filesystems."; busy -if (mount -a -t nonfs,proc); then deltext; ok; else deltext; fail; fi +run_cmd "Mounting local filesystems." mount -a -t nonfs,smbfs,ncpfs,proc # set the console font if [ -x /sbin/setsysfont ]; then @@ -265,16 +255,15 @@ if [ -x /sbin/setsysfont ]; then fi if [ -x /sbin/quotaon ]; then - show "Turning on quotas for local filesystems"; busy - if (/sbin/quotaon -a); then deltext; ok; else deltext; fail; fi + run_cmd "Turning on quotas for local filesystems" /sbin/quotaon -a fi # Clean out /etc & /var/{run/*,log/{b,w}tmpx}}. -rm -f /etc/mtab~ /fastboot /fsckoptions +rm -f /etc/mtab~ /fastboot /fsckoptions /forcefsck rm -f /var/run/utmp :>/var/run/utmpx chown root.utmpx /var/run/utmpx -chmod 664 /var/run/utmpx +chmod 0664 /var/run/utmpx /var/log/wtmpx # Uncomment if you planing to run `utmpd' #:>/var/log/wtmp @@ -345,7 +334,7 @@ if ($CLOCK $CLOCKFLAGS); then deltext; ok; else deltext; fail; fi show "Date set to `date`"; ok # Right, now turn on swap in case we swap to files. -show "Enabling swap space."; busy +show "Enabling swap space"; busy if [ "`LANG=C swapon -a 2>&1 | grep -v "busy"`" == "" ]; then deltext; ok; else deltext; fail; fi @@ -354,18 +343,13 @@ if [ -f /etc/rc.d/rc.serial ]; then . /etc/rc.d/rc.serial fi -# Load modules (for backward compatibility with VARs) -if [ -f /etc/rc.d/rc.modules ]; then - /etc/rc.d/rc.modules -fi - # If a SCSI tape has been detected, load the st module unconditionally # since many SCSI tapes don't deal well with st being loaded and unloaded if [ -f /proc/scsi/scsi ] && cat /proc/scsi/scsi | grep -q 'Type: Sequential-Access' 2>/dev/null ; then if cat /proc/devices | grep -qv ' 9 st' ; then if [ -n "$USEMODULES" ] ; then - # Try to load the module. If it fails, ignore it... - modprobe st 2>/dev/null + # Try to load the module. If it fails, ignore it... + insmod -p st >/dev/null 2>&1 && modprobe st >/dev/null 2>&1 fi fi fi @@ -378,8 +362,7 @@ rm -f /etc/psdevtab #fi if [ -x /sbin/ldconfig ]; then -show "Setting up /etc/ld.so.cache"; busy -if (/sbin/ldconfig -X); then deltext; ok; else deltext; fail; fi +run_cmd "Setting up /etc/ld.so.cache" /sbin/ldconfig -X fi if ([ -f /proc/sys/kernel/panic ] && [ "$PANIC_REBOOT_TIME" -gt "0" ] 2>/dev/null); then diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 00000000..ad7d36bc --- /dev/null +++ b/src/Makefile @@ -0,0 +1,38 @@ +CFLAGS+=-Wall -D_GNU_SOURCE -g + +PROGS=usernetctl doexec netreport testd usleep ipcalc initlog minilogd loglevel +INITLOG_OBJS=initlog.o process.o + +all: $(PROGS) + +clean: + rm -f $(PROGS) *.o + +install: + mkdir -p $(ROOT)/bin $(ROOT)/usr/sbin $(ROOT)/usr/man/man1 + install -s -m 755 doexec $(ROOT)/bin/doexec + install -s -m 755 usleep $(ROOT)/bin/usleep + install -s -m 4755 usernetctl $(ROOT)/usr/sbin/usernetctl + install -s -m 2755 netreport $(ROOT)/sbin/netreport + install -s -m 755 ipcalc $(ROOT)/bin/ipcalc + install -s -m 755 initlog $(ROOT)/sbin/initlog + install -s -m 755 minilogd $(ROOT)/sbin/minilogd + install -s -m 755 loglevel $(ROOT)/sbin/loglevel + install -m 644 initlog.1 $(ROOT)/usr/man/man1 + install -m 644 doexec.1 $(ROOT)/usr/man/man1 + install -m 644 netreport.1 $(ROOT)/usr/man/man1 + install -m 644 usleep.1 $(ROOT)/usr/man/man1 + install -m 644 usernetctl.1 $(ROOT)/usr/man/man1 + install -m 644 ipcalc.1 $(ROOT)/usr/man/man1 + +# this daemon and initscript are useful for testing the up/down/status stuff +# not installed by default, only comes from sources. +install-test: + install -s -m 755 testd $(ROOT)/usr/sbin/testd + install -m 755 testdinit $(ROOT)/etc/rc.d/init.d/testd + +ipcalc: ipcalc.o + $(CC) $(LDFLAGS) -o $@ $< -lpopt + +initlog: $(INITLOG_OBJS) + $(CC) $(LDFLAGS) -o $@ $(INITLOG_OBJS) -lpopt diff --git a/src/initlog.1 b/src/initlog.1 new file mode 100644 index 00000000..103ef3fd --- /dev/null +++ b/src/initlog.1 @@ -0,0 +1,48 @@ +.TH initlog 8 "Sun Jan 24 1999" +.SH NAME +initlog \- log messages and events to the system logger +.SH SYNOPSIS +.B initlog +[\-cefnprs] [\-\-cmd=ARG] [\-\-event=ARG] [\-\-facility=ARG] +[\-\-name=ARG] [\-\-priority=ARG] [\-\-run=ARG] [\-\-string=ARG] +.SH DESCRIPTION +\fBinitlog\fR logs messages and events to the system logger. +It is mainly designed for use in init scripts. + +.SS OPTIONS +.TP +.I "\-c, \-\-cmd=[program]" +Execute the specified program, logging anything output to +stdout or stderr. +.TP +.I "\-e, \-\-event=[number]" +Logs that the specified event happened. Usually used in conjuction +with \fB\-\-name\fR. Currently specified events are: +.nf + \fB1\fR the action completed successfully + \fB2\fR the action failed + \fB3\fR the action was cancelled at user request + \fB4\fR the action failed due to the failure of a dependent action +.TP +.I "\-f, \-\-facility=[facility]" + +Log at the specified syslog facility. The default +is \fBdaemon\fR (see syslog(3)). +.TP +.I "\-n, \-\-name=[string]" +Log the event under the specified string, such as +"inetd". +.TP +.I "\-p, \-\-priority=[priority]" +Log at the specified syslog priority. The default +is \fBnotice\fR (see syslog(3)). +.TP +.I "\-r, \-\-run=[program]" +Execute the specified program, with an open file +descriptor so that the program can pass back +commands to initlog. +.TP +.I "\-s, \-\-string=[string] +Log the specified string to the logger. +.SH "SEE ALSO" +syslog(3), logger(1) diff --git a/src/initlog.c b/src/initlog.c new file mode 100644 index 00000000..5479ac1f --- /dev/null +++ b/src/initlog.c @@ -0,0 +1,316 @@ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define SYSLOG_NAMES +#include + +#include +#include + +#define _(String) gettext((String)) + +#include + +#include "initlog.h" +#include "process.h" + +static int logfacility=LOG_LOCAL7; +static int logpriority=LOG_NOTICE; +static int reexec=0; +static int quiet=0; +int debug=0; + +static int logEntries = 0; +struct logInfo *logData = NULL; + +char *getLine(char **data) { + /* Get one line from data */ + char *x, *y; + + if (!*data) return NULL; + + for (x = *data; *x && (*x != '\n'); x++); + if (*x) { + x++; + } else { + if (x-*data) { + y=malloc(x-*data+1); + y[x-*data] = 0; + y[x-*data-1] = '\n'; + memcpy(y,*data,x-*data); + } else { + y=NULL; + } + *data = NULL; + return y; + } + y = malloc(x-*data); + y[x-*data-1] = 0; + memcpy(y,*data,x-*data-1); + *data = x; + return y; +} + +char **toArray(char *line, int *num) { + /* Converts a long string into an array of lines. */ + char **lines; + char *tmpline; + + *num = 0; + lines = NULL; + + while ((tmpline=getLine(&line))) { + if (!*num) + lines = (char **) malloc(sizeof(char *)); + else + lines = (char **) realloc(lines, (*num+1)*sizeof(char *)); + lines[*num] = tmpline; + (*num)++; + } + return lines; +} + +int startDaemon() { + int pid; + int rc; + + if ( (pid = fork()) == -1 ) { + perror("fork"); + return -1; + } + if ( pid ) { + /* parent */ + waitpid(pid,&rc,0); + if (WIFEXITED(rc)) { + DDEBUG("minilogd returned %d!\n",WEXITSTATUS(rc)); + return WEXITSTATUS(rc); + } + else + return -1; + } else { + int fd; + + fd=open("/dev/null",O_RDWR); + dup2(fd,0); + dup2(fd,1); + dup2(fd,2); + /* kid */ + execlp("minilogd","minilogd",NULL); + perror("exec"); + exit(-1); + } +} + +int logLine(struct logInfo *logEnt) { + /* Logs a line... somewhere. */ + int x=0,y=0,z=0; + struct stat statbuf; + + /* Don't log empty or null lines */ + if (!logEnt->line || !strcmp(logEnt->line,"\n")) return 0; + + if ( ((stat(_PATH_LOG,&statbuf)==-1) ||(access("/",W_OK)==-1)) + && startDaemon() + ) { + DDEBUG("starting daemon failed, pooling entry %d\n",logEntries); + logData=realloc(logData,(logEntries+1)*sizeof(struct logInfo)); + logData[logEntries]= (*logEnt); + logEntries++; + } else { + if (logEntries>0) { + for (x=0;xline); + openlog(logEnt->cmd,0,logEnt->fac); + syslog(logEnt->pri,"%s",logEnt->line); + closelog(); + } + return 0; +} + +int logEvent(char *cmd, int eventtype,char *string) { + char *eventtable [] = { + _("%s babbles incoherently"), + _("%s succeeded"), + _("%s failed"), + _("%s cancelled at user request"), + _("%s failed due to a failed dependency"), + /* insert more here */ + NULL + }; + int x=0,len; + struct logInfo logentry; + + if (cmd) { + logentry.cmd = strdup(basename(cmd)); + if ((logentry.cmd[0] =='K' || logentry.cmd[0] == 'S') && ( 30 <= logentry.cmd[1] <= 39 ) + && ( 30 <= logentry.cmd[2] <= 39 ) ) + logentry.cmd+=3; + } else + logentry.cmd = strdup(_("(none)")); + if (!string) + string = strdup(cmd); + + while (eventtable[x] && x 0) { + switch (rc) { + case 1: + logfacility=atoi(fac); + if ((logfacility == 0) && strcmp(fac,"0")) { + int x =0; + + logfacility = LOG_DAEMON; + for (x=0;facilitynames[x].c_name;x++) { + if (!strcmp(fac,facilitynames[x].c_name)) { + logfacility = facilitynames[x].c_val; + break; + } + } + } + break; + case 2: + logpriority = atoi(pri); + if ((logpriority == 0) && strcmp(pri,"0")) { + int x=0; + + logpriority = LOG_NOTICE; + for (x=0;prioritynames[x].c_name;x++) { + if (!strcmp(pri,prioritynames[x].c_name)) { + logpriority = prioritynames[x].c_val; + break; + } + } + } + break; + case 3: + reexec = 1; + break; + default: + break; + } + } + + if ((rc < -1)) { + if (!silent) + fprintf(stderr, "%s: %s\n", + poptBadOption(context, POPT_BADOPTION_NOALIAS), + poptStrerror(rc)); + + return -1; + } + if ( (cmd && logstring) || (cmd && cmdname) ) { + if (!silent) + fprintf(stderr, _("--cmd and --run are incompatible with --string or --name\n")); + return -1; + } + if ( cmdname && (!logstring && !cmdevent)) { + if (!silent) + fprintf(stderr, _("--name requires one of --event or --string\n")); + return -1; + } + if (cmdevent) { + logEvent(cmdname,cmdevent,logstring); + } else if (logstring) { + logString(cmdname,logstring); + } else if ( cmd ) { + return(runCommand(cmd,reexec,quiet,debug)); + } else { + if (!silent) + fprintf(stderr,"nothing to do!\n"); + return -1; + } + return 0; +} + +int main(int argc, char **argv) { + + setlocale(LC_ALL,""); + bindtextdomain("initlog","/etc/locale"); + textdomain("initlog"); + exit(processArgs(argc,argv,0)); +} diff --git a/src/initlog.h b/src/initlog.h new file mode 100644 index 00000000..94f467bf --- /dev/null +++ b/src/initlog.h @@ -0,0 +1,20 @@ + +#define _GNU_SOURCE 1 + +#ifndef INITLOG_H +#define INITLOG_H + +struct logInfo { + char *cmd; + char *line; + int fac; + int pri; +}; + +char *getLine(char **data); +int logString(char *cmd, char *string); +int processArgs(int argc, char **argv, int silent); + +#define DDEBUG if (debug) printf + +#endif diff --git a/src/loglevel.c b/src/loglevel.c new file mode 100644 index 00000000..de2a4e11 --- /dev/null +++ b/src/loglevel.c @@ -0,0 +1,25 @@ + +/* Change the default console loglevel */ + +#include +#include +#include +#include +#include + +int main(int argc, char **argv) { + int level; + + if (!argv[1]) exit(0); + level=atoi(argv[1]); + if ( (level<1) || (level>8) ) { + fprintf(stderr,"invalid log level %d\n",level); + exit(-1); + } + if (!syscall(SYS_syslog,8,NULL,level)) { + exit(0); + } else { + perror("syslog"); + exit(-1); + } +} diff --git a/src/minilogd.c b/src/minilogd.c new file mode 100644 index 00000000..b0432408 --- /dev/null +++ b/src/minilogd.c @@ -0,0 +1,161 @@ + +/* minilogd.c + * + * A pale imitation of syslogd. Most notably, doesn't write anything + * anywhere except possibly back to syslogd. + * + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +static int we_own_log=0; +static char **buffer=NULL; +static int buflines=0; + +int debug; + +void freeBuffer() { + struct sockaddr_un addr; + int sock; + int x=0,conn; + + bzero(&addr,sizeof(addr)); + addr.sun_family = AF_LOCAL; + strncpy(addr.sun_path,_PATH_LOG,sizeof(addr.sun_path)-1); + /* wait for klogd to hit syslog */ + sleep(1); + sock = socket(AF_LOCAL, SOCK_STREAM,0); + conn=connect(sock,(struct sockaddr *) &addr,sizeof(addr)); + while (x0) && pfds.revents & (POLLIN | POLLPRI)) { + message = calloc(8192,sizeof(char)); + recvsock = accept(sock,(struct sockaddr *) &addr, &addrlen); + len = read(recvsock,message,8192); + if (buffer) + buffer = realloc(buffer,(buflines+1)*sizeof(char *)); + else + buffer = malloc(sizeof(char *)); + if (len>0) { + message[strlen(message)]='\n'; + buffer[buflines]=message; + buflines++; + close(recvsock); + } + else { + close(recvsock); + recvsock=-1; + } + } + if ( (x>0) && ( pfds.revents & (POLLHUP | POLLNVAL)) ) + done = 1; + /* Check to see if syslogd's yanked our socket out from under us */ + if ( (stat(_PATH_LOG,&s2)!=0) || + (s1.st_ino != s2.st_ino ) || (s1.st_ctime != s2.st_ctime) || + (s1.st_mtime != s2.st_mtime) || (s1.st_atime != s2.st_atime) ) { + done = 1; + we_own_log = 0; + } + } + cleanup(0); +} + +int main(int argc, char **argv) { + struct sockaddr_un addr; + int sock; + int pid; + + /* option processing made simple... */ + if (argc>1) debug=1; + /* just in case */ + sock = open("/dev/null",O_RDWR); + dup2(sock,0); + dup2(sock,1); + dup2(sock,2); + + bzero(&addr, sizeof(addr)); + addr.sun_family = AF_LOCAL; + strncpy(addr.sun_path,_PATH_LOG,sizeof(addr.sun_path)-1); + sock = socket(AF_LOCAL, SOCK_STREAM,0); + unlink(_PATH_LOG); + /* Bind socket before forking, so we know if the server started */ + if (!bind(sock,(struct sockaddr *) &addr, sizeof(addr))) { + we_own_log = 1; + listen(sock,5); + if ((pid=fork())==-1) { + perror("fork"); + exit(3); + } + if (pid) { + exit(0); + } else { + runDaemon(sock); + /* shouldn't get back here... */ + exit(4); + } + } else { + exit(5); + } +} diff --git a/src/process.c b/src/process.c new file mode 100644 index 00000000..0681b8f4 --- /dev/null +++ b/src/process.c @@ -0,0 +1,223 @@ + +#include +#include +#include +#include +#include + +#include +#include + +#include + +#include "initlog.h" +#include "process.h" + +int forkCommand(char **args, int *outfd, int *errfd, int *cmdfd, int quiet) { + /* Fork command 'cmd', returning pid, and optionally pointer + * to open file descriptor fd */ + int fdin, fdout, fderr, fdcmd, pid; + int outpipe[2], errpipe[2], fdpipe[2]; + + if ( (pipe(outpipe)==-1) || (pipe(errpipe)==-1) || (pipe(fdpipe)==-1) ) { + perror("pipe"); + return -1; + } + + fdin=dup(0); + if (outfd) { + fdout = outpipe[1]; + *outfd = outpipe[0]; + } else { + if (!quiet) + fdout=dup(1); + } + if (errfd) { + fderr = errpipe[1]; + *errfd = errpipe[0]; + } else { + if (!quiet) + fderr=dup(2); + } + fdcmd = fdpipe[1]; + if (cmdfd) + *cmdfd = fdpipe[0]; + if ((pid = fork())==-1) { + perror("fork"); + return -1; + } + if (pid) { + /* parent */ + close(fdin); + close(fdout); + close(fderr); + close(fdcmd); + return pid; + } else { + /* kid */ + if (outfd) { + if ( (dup2(fdout,1)==-1) ) { + perror("dup2"); + exit(-1); + } + } else if (quiet) + if ((dup2(open("/dev/null",O_WRONLY),1))==-1) { + perror("dup2"); + exit(-1); + } + + if (errfd) { + if ((dup2(fderr,2)==-1)) { + perror("dup2"); + exit(-1); + } + } else if (quiet) + if ((dup2(open("/dev/null",O_WRONLY),2))==-1) { + perror("dup2"); + exit(-1); + } + + + if ((dup2(fdcmd,CMD_FD)==-1)) { + perror("dup2"); + exit(-1); + } + close(fdout); + close(fderr); + close(fdcmd); + if (outfd) + close(*outfd); + if (errfd) + close(*errfd); + if (cmdfd) + close(*cmdfd); + execvp(args[0],args); + perror("execvp"); + exit(-1); + } +} + +int monitor(char *cmdname, int pid, int numfds, int *fds, int reexec, int quiet, int debug) { + struct pollfd *pfds; + char *buf=malloc(2048*sizeof(char)); + int outpipe[2]; + char *tmpstr=NULL; + int x,y,rc=-1; + int done=0; + int output=0; + + pipe(outpipe); + + pfds = malloc(numfds*sizeof(struct pollfd)); + for (x=0;x