diff options
-rwxr-xr-x | rc.d/init.d/functions | 64 | ||||
-rwxr-xr-x | rc.d/init.d/halt | 7 | ||||
-rwxr-xr-x | rc.d/init.d/network | 4 | ||||
-rwxr-xr-x | rc.d/init.d/nfsfs | 4 | ||||
-rwxr-xr-x | rc.d/init.d/random | 4 | ||||
-rwxr-xr-x | rc.d/rc | 4 | ||||
-rwxr-xr-x | rc.d/rc.sysinit | 43 | ||||
-rw-r--r-- | src/Makefile | 3 | ||||
-rw-r--r-- | src/initlog.c | 59 | ||||
-rw-r--r-- | src/process.c | 9 |
10 files changed, 93 insertions, 108 deletions
diff --git a/rc.d/init.d/functions b/rc.d/init.d/functions index c3b42a65..882748f7 100755 --- a/rc.d/init.d/functions +++ b/rc.d/init.d/functions @@ -18,9 +18,14 @@ if [ -f /etc/sysconfig/init ]; then . /etc/sysconfig/init else BOOTUP=color + LOGLEVEL=1 fi - +if [ "$BOOTUP" = "color" ]; then + INITLOG_ARGS="-q" +else + INITLOG_ARGS= +fi # A function to start a program. daemon() { @@ -45,10 +50,10 @@ daemon() { ulimit -c 0 # Echo daemon - [ $BOOTUP != "color" ] && echo -n $base + [ $BOOTUP != "color" ] && echo -n " $base" # And start it up. - nice -n $nicelevel initlog -q -c "$*" && success -n "$base startup" || failure -n "$base startup" + nice -n $nicelevel initlog $INITLOG_ARGS -c "$*" && success "$base startup" || failure "$base startup" } # A function to stop a program. @@ -76,24 +81,24 @@ killproc() { # Kill it. if [ "$pid" != "" ] ; then - [ $BOOTUP != "color" ] && echo -n $base + [ $BOOTUP != "color" ] && echo -n "$base " if [ "$notset" = 1 ] ; then # TERM first, then KILL if not dead - kill -TERM $pid && success -n "$base shutdown" || failure -n "$base shutdown" + kill -TERM $pid && success "$base shutdown" || failure "$base shutdown" usleep 100000 if ps h $pid >/dev/null 2>&1 ; then sleep 1 if ps h $pid >/dev/null 2>&1 ; then sleep 3 - kill -KILL $pid && success -n "$base shutdown" || failure -n "$base shutdown" + kill -KILL $pid && success "$base shutdown" || failure "$base shutdown" fi fi # use specified level only else - kill $killlevel $pid && success -n "$base shutdown" || failure -n "$base shutdown" + kill $killlevel $pid && success "$base shutdown" || failure "$base shutdown" fi else - failure -n "$base shutdown" + failure "$base shutdown" fi # Remove pid file if any. @@ -167,62 +172,48 @@ status() { } echo_success() { - echo $* "[300C[10D[ [1;32mOK[0;39m ]" + echo -n "[300C[10D[ [1;32mOK[0;39m ]" return 0 } echo_failure() { - echo $* "[300C[10D[[1;31mFAILED[0;39m]" - return 0 + echo -n "[300C[10D[[1;31mFAILED[0;39m]" + return 1 } # Log that something succeeded success() { - if [ "$1" = "-n" ]; then - ECHOARGS="-n" - shift - else - ECHOARGS="" - fi if [ -z "$IN_INITLOG" ]; then initlog -n $0 -s "$1" -e 1 else echo "-n $0 -s \"$1\" -e 1" >&21 fi - [ "$BOOTUP" = "color" ] && echo_success $ECHOARGS + [ "$BOOTUP" = "color" ] && echo_success return 0 } # Log that something failed failure() { - if [ "$1" = "-n" ]; then - ECHOARGS="-n" - shift - else - ECHOARGS="" - fi + rc=$? if [ -z "$IN_INITLOG" ]; then initlog -n $0 -s "$1" -e 2 else echo "-n $0 -s \"$1\" -e 2" >&21 fi - [ "$BOOTUP" = "color" ] && echo_failure $ECHOARGS - return 0 + [ "$BOOTUP" = "color" ] && echo_failure + return $rc } # Run some action. Log its output. action() { - if [ "$1" = "-n" ]; then - ECHOARGS="-n" - shift - else - ECHOARGS="" - fi STRING=$1 - echo $ECHOARGS "$STRING " + echo -n "$STRING " shift if [ -z "$IN_INITLOG" ]; then - initlog -q -c "$*" && success "$STRING" || failure "$STRING" + initlog $INITLOG_ARGS -c "$*" && success "$STRING" || failure "$STRING" + rc=$? + [ "$BOOTUP" = "color" ] && echo + return $rc else # This sucks. output=`$*` @@ -234,13 +225,16 @@ action() { fi if [ $rc ]; then + [ "$BOOTUP" = "color" ] || { echo ; echo $output ; } success "$STRING" else + echo echo $output failure "$STRING" fi + [ "$BOOTUP" = "color" ] && echo + return $rc fi - return 0 } # Confirm whether we really want to run this service diff --git a/rc.d/init.d/halt b/rc.d/init.d/halt index 61eab7b3..08cf9b67 100755 --- a/rc.d/init.d/halt +++ b/rc.d/init.d/halt @@ -16,7 +16,12 @@ PATH=/sbin:/bin:/usr/bin:/usr/sbin runcmd() { echo -n $1 shift - $* && echo_success -n || echo_failure -n + if [ "$BOOTUP" = "color" ]; then + $* && echo_success || echo_failure + else + $* + fi + echo } # See how we were called. diff --git a/rc.d/init.d/network b/rc.d/init.d/network index 93f86480..fa67df29 100755 --- a/rc.d/init.d/network +++ b/rc.d/init.d/network @@ -57,7 +57,7 @@ ipv4_forward_set () fi if [ $value != `cat /proc/sys/net/ipv4/ip_forward` ]; then - action -n "$message" /bin/true + action "$message" /bin/true echo "$value" > /proc/sys/net/ipv4/ip_forward fi fi @@ -96,7 +96,7 @@ case "$1" in ;; esac ./ifdown ifcfg-lo - action -n "Disabling IPv4 packet forwarding" /bin/true + action "Disabling IPv4 packet forwarding" /bin/true echo 0 > /proc/sys/net/ipv4/ip_forward rm -f /var/lock/subsys/network ;; diff --git a/rc.d/init.d/nfsfs b/rc.d/init.d/nfsfs index 9b828248..89cd4a53 100755 --- a/rc.d/init.d/nfsfs +++ b/rc.d/init.d/nfsfs @@ -26,11 +26,11 @@ fi # See how we were called. case "$1" in start) - action -n "Mounting remote filesystems" mount -a -t nfs + action "Mounting remote filesystems" mount -a -t nfs touch /var/lock/subsys/nfsfs ;; stop) - action -n "Unmounting remote filesystems" umount -a -t nfs + action "Unmounting remote filesystems" umount -a -t nfs rm -f /var/lock/subsys/nfsfs ;; status) diff --git a/rc.d/init.d/random b/rc.d/init.d/random index 27f2abd4..57b971f9 100755 --- a/rc.d/init.d/random +++ b/rc.d/init.d/random @@ -22,7 +22,7 @@ case "$1" in else touch $random_seed fi - action -n "Initializing random number generator" /bin/true + action "Initializing random number generator" /bin/true chmod 600 $random_seed dd if=/dev/urandom of=$random_seed count=1 bs=512 2>/dev/null touch /var/lock/subsys/random @@ -33,7 +33,7 @@ case "$1" in # Save 512 bytes, which is the size of the entropy pool touch $random_seed chmod 600 $random_seed - action -n "Saving random seed" dd if=/dev/urandom of=$random_seed count=1 bs=512 2>/dev/null + action "Saving random seed" dd if=/dev/urandom of=$random_seed count=1 bs=512 2>/dev/null rm -f /var/lock/subsys/random ;; @@ -54,7 +54,7 @@ if [ -d /etc/rc.d/rc$runlevel.d ]; then if egrep -q "(killproc |action )" $i ; then $i stop else - action -n "Stopping $subsys" $i stop + action "Stopping $subsys" $i stop fi done @@ -96,7 +96,7 @@ if [ -d /etc/rc.d/rc$runlevel.d ]; then if [ "$subsys" = "halt" ] || [ "$subsys" = "reboot" ]; then $i start else - action -n "Starting $subsys" $i start + action "Starting $subsys" $i start fi fi done diff --git a/rc.d/rc.sysinit b/rc.d/rc.sysinit index ab962b70..7367b805 100755 --- a/rc.d/rc.sysinit +++ b/rc.d/rc.sysinit @@ -25,15 +25,18 @@ fi # Source functions . /etc/rc.d/init.d/functions +# Fix console loglevel +/sbin/loglevel 1 + # Start up swapping. -action -n "Activating swap partitions" swapon -a +action "Activating swap partitions" swapon -a # Set the hostname. -action -n "Setting hostname ${HOSTNAME}" hostname ${HOSTNAME} +action "Setting hostname ${HOSTNAME}" hostname ${HOSTNAME} # Set the NIS domain name if [ -n "$NISDOMAIN" ]; then - action -n "Setting NIS domain name $NISDOMAIN" domainname $NISDOMAIN + action "Setting NIS domain name $NISDOMAIN" domainname $NISDOMAIN else domainname "" fi @@ -49,7 +52,7 @@ if [ -f /forcefsck ]; then fi if [ ! -f /fastboot ]; then - action -n "Checking root filesystem" fsck -T -a $fsckoptions / + action "Checking root filesystem" fsck -T -a $fsckoptions / rc=$? # A return of 2 or higher means there were serious problems. @@ -69,12 +72,12 @@ if [ ! -f /fastboot ]; then echo "Automatic reboot in progress." reboot elif [ "$rc" = "1" -a -x /sbin/quotacheck ]; then - action -n "Checking root filesystem quotas" /sbin/quotacheck -v / + action "Checking root filesystem quotas" /sbin/quotacheck -v / fi fi if [ -x /sbin/quotaon ]; then - action -n "Turning on user and group quotas for root filesystem" /sbin/quotaon / + action "Turning on user and group quotas for root filesystem" /sbin/quotaon / fi # check for arguments @@ -90,14 +93,14 @@ fi # set up pnp if [ -x /sbin/isapnp -a -f /etc/isapnp.conf ]; then if [ -n "$PNP" ]; then - action -n "Setting up ISA PNP devices" /sbin/isapnp /etc/isapnp.conf + action "Setting up ISA PNP devices" /sbin/isapnp /etc/isapnp.conf else - action -n "Skipping ISA PNP configuration at users request" /bin/true + action "Skipping ISA PNP configuration at users request" /bin/true fi fi # Remount the root filesystem read-write. -action -n "Remounting root filesystem in read-write mode" mount -n -o remount,rw / +action "Remounting root filesystem in read-write mode" mount -n -o remount,rw / if [ -n "$IN_INITLOG" ]; then IN_INITLOG= @@ -138,9 +141,9 @@ fi if [ -x /sbin/depmod -a -n "$USEMODULES" ]; then # Get ready for kerneld if module support in the kernel if [ -e /lib/modules/preferred ]; then - action -n "Finding module dependencies" depmod -a preferred + action "Finding module dependencies" depmod -a preferred else - action -n "Finding module dependencies" depmod -a + action "Finding module dependencies" depmod -a fi fi @@ -148,9 +151,9 @@ fi if ! grep -i nomodules /proc/cmdline >/dev/null ; then if [ -n "$USEMODULES" ]; then if grep -s "alias sound" /etc/conf.modules > /dev/null ; then - action -n "Loading sound module" modprobe sound + action "Loading sound module" modprobe sound if grep -s "alias midi" /etc/conf.modules > /dev/null ; then - action -n "Loading midi module" modprobe midi + action "Loading midi module" modprobe midi fi fi fi @@ -168,7 +171,7 @@ fi # Add raid devices if [ -f /proc/mdstat -a -f /etc/raidtab -a -x /sbin/raidadd ]; then - action -n "Starting up RAID devices" raidadd -a + action "Starting up RAID devices" raidadd -a rc=$? @@ -198,7 +201,7 @@ fi # Check filesystems if [ ! -f /fastboot ]; then - action -n "Checking filesystems" fsck -T -R -A -a $fsckoptions + action "Checking filesystems" fsck -T -R -A -a $fsckoptions rc=$? @@ -219,14 +222,14 @@ if [ ! -f /fastboot ]; then echo "Automatic reboot in progress." reboot elif [ "$rc" = "1" -a -x /sbin/quotacheck ]; then - action -n "Checking filesystem quotas" /sbin/quotacheck -v -R -a + action "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. -action -n "Mounting local filesystems" mount -a -t nonfs,proc +action "Mounting local filesystems" mount -a -t nonfs,proc # set the console font if [ -x /sbin/setsysfont ]; then @@ -234,7 +237,7 @@ if [ -x /sbin/setsysfont ]; then fi if [ -x /sbin/quotaon ]; then - action -n "Turning on user and group quotas for local filesystems" /sbin/quotaon -a + action "Turning on user and group quotas for local filesystems" /sbin/quotaon -a fi # Clean out /etc. @@ -299,10 +302,10 @@ case "$ARC" in esac $CLOCK $CLOCKFLAGS -action -n "Setting clock $CLOCKDEF: `date`" date +action "Setting clock $CLOCKDEF: `date`" date # Right, now turn on swap in case we swap to files. -action -n "Enabling swap space" swapon -a 2>&1 | grep -v "busy" +action "Enabling swap space" swapon -a 2>&1 | grep -v "busy" # Initialize the serial ports. if [ -f /etc/rc.d/rc.serial ]; then diff --git a/src/Makefile b/src/Makefile index 1fcf1b6c..a93c2b48 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,6 +1,6 @@ CFLAGS+=-Wall -D_GNU_SOURCE -PROGS=usernetctl doexec netreport testd usleep ipcalc initlog minilogd +PROGS=usernetctl doexec netreport testd usleep ipcalc initlog minilogd loglevel INITLOG_OBJS=initlog.o process.o all: $(PROGS) @@ -17,6 +17,7 @@ install: 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 diff --git a/src/initlog.c b/src/initlog.c index cd787fcf..6bc6fe10 100644 --- a/src/initlog.c +++ b/src/initlog.c @@ -11,6 +11,7 @@ #define SYSLOG_NAMES #include <syslog.h> +#include <sys/stat.h> #include <sys/wait.h> #define _(String) gettext((String)) @@ -86,10 +87,10 @@ int startDaemon() { if ( pid ) { /* parent */ waitpid(pid,&rc,0); - if (rc) - return -1; - else - return 0; + if (WIFEXITED(rc)) + return WEXITSTATUS(rc); + else + return -1; } else { int fd; @@ -107,44 +108,28 @@ int startDaemon() { int logLine(struct logInfo *logEnt) { /* Logs a line... somewhere. */ int x; + struct stat statbuf; /* Don't log empty or null lines */ if (!logEnt->line || !strcmp(logEnt->line,"\n")) return 0; - if ((x=access(_PATH_LOG,W_OK))) { - /* syslog isn't running, so start something... */ - if ( (x=startDaemon()) ==-1) { - logData=realloc(logData,(logEntries+1)*sizeof(struct logInfo)); - logData[logEntries]= (*logEnt); - logEntries++; - } else { - if (logEntries>0) { - for (x=0;x<logEntries;x++) { - openlog(logData[x].cmd,0,logData[x].fac); - syslog(logData[x].pri,"%s",logData[x].line); - closelog(); - } - free(logData); - logEntries = 0; - } - openlog(logEnt->cmd,0,logEnt->fac); - syslog(logEnt->pri,"%s",logEnt->line); - closelog(); - } + if ( (stat(_PATH_LOG,&statbuf)==-1) && ((x=startDaemon())) ) { + logData=realloc(logData,(logEntries+1)*sizeof(struct logInfo)); + logData[logEntries]= (*logEnt); + logEntries++; } else { - if (logEntries>0) { - for (x=0;x<logEntries;x++) { - openlog(logData[x].cmd,0,logData[x].fac); - printf("flushing %s\n",logData[x].line); - syslog(logData[x].pri,"%s",logData[x].line); - closelog(); - } - free(logData); - logEntries = 0; - } - openlog(logEnt->cmd,0,logEnt->fac); - syslog(logEnt->pri,"%s",logEnt->line); - closelog(); + if (logEntries>0) { + for (x=0;x<logEntries;x++) { + openlog(logData[x].cmd,0,logData[x].fac); + syslog(logData[x].pri,"%s",logData[x].line); + closelog(); + } + free(logData); + logEntries = 0; + } + openlog(logEnt->cmd,0,logEnt->fac); + syslog(logEnt->pri,"%s",logEnt->line); + closelog(); } return 0; } diff --git a/src/process.c b/src/process.c index 860d9452..739e8089 100644 --- a/src/process.c +++ b/src/process.c @@ -115,7 +115,7 @@ int monitor(char *cmdname, int pid, int numfds, int *fds, int reexec, int quiet) } while (!done) { - if ((x=poll(pfds,numfds,500))==-1) { + if (((x=poll(pfds,numfds,500))==-1)&&errno!=EINTR) { perror("poll"); return -1; } @@ -164,11 +164,7 @@ int monitor(char *cmdname, int pid, int numfds, int *fds, int reexec, int quiet) y++; } } - rc = rc>>8; - - if (!rc) - return 0; - else { + if ((!WIFEXITED(rc)) || (rc=WEXITSTATUS(rc))) { /* If there was an error and we're quiet, be loud */ int x; @@ -183,6 +179,7 @@ int monitor(char *cmdname, int pid, int numfds, int *fds, int reexec, int quiet) } return (rc); } + return 0; } int runCommand(char *cmd, int reexec, int quiet) { |