]> git.pld-linux.org Git - projects/rc-scripts.git/blobdiff - rc.d/init.d/functions
Synced with latest from old repo
[projects/rc-scripts.git] / rc.d / init.d / functions
index d34c5f3f109e3bfcb556722f6f8cd2554e29aa8a..2ead74cbbaafeb9068326c694c676e1b4e2ac6ff 100644 (file)
@@ -1,52 +1,67 @@
 # 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.3 $ $Date: 1999/06/14 20:08:16 $
+# Version:     @(#) /etc/init.d/functions $Revision: 1.7 $ $Date: 1999/06/14 21:17:10 $
 #
 # Author:      Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
 # Hacked by:    Greg Galloway and Marc Ewing
-# Modified for PLD by Marek Obuchowicz <elephant@shadow.eu.org>
-#
+# Modified for PLD by:
+#              Marek Obuchowicz <elephant@shadow.eu.org>
+#              Arkadiusz Mi¶kiewicz <misiek@pld.org.pl> 
 
 # First set up a default search path.
 PATH="/sbin:/usr/sbin:/bin:/usr/bin"; export PATH
 
+[ -z "$COLUMNS" ] && COLUMNS=80
+
 # Some functions to handle PLD-style messages
-function show {
+show() 
+{
   text="$*".............................................
   echo -ne `echo $text | cut -c1-45`
 }
 
-function busy {
-  echo -ne "`tput setaf 6`[`tput setaf 5` BUSY `tput setaf 6`]`tput setaf 7`"
+busy() 
+{
+  echo -n "`tput setaf 6`[`tput setaf 5` BUSY `tput setaf 6`]`tput setaf 7`"
 }
 
-function ok {
-  echo -ne "`tput setaf 6`[`tput setaf 2` DONE `tput setaf 6`]`tput setaf 7`"
+ok() 
+{
+  echo  "`tput setaf 6`[`tput setaf 2` DONE `tput setaf 6`]`tput setaf 7`"
 }
 
-function fail {
-  echo -ne "`tput setaf 6`[`tput setaf 1` FAIL `tput setaf 6`]`tput setaf 7`"
+started()
+{
+  echo  "`tput setaf 6`[`tput setaf 2` WORK `tput setaf 6`]`tput setaf 7`"
 }
 
-function died {
-  echo -ne "`tput setaf 6`[`tput setaf 1` DIED `tput setaf 6`]`tput setaf 7`"
+fail() 
+{
+  echo  "`tput setaf 6`[`tput setaf 1` FAIL `tput setaf 6`]`tput setaf 7`"
 }
 
-function deltext {
+died() 
+{
+  echo  "`tput setaf 6`[`tput setaf 1` DIED `tput setaf 6`]`tput setaf 7`"
+}
+
+deltext() 
+{
   echo -ne '\b\b\b\b\b\b\b\b'
 }
 
-# A function to start a program.
-daemon() {
-       TMPFILE=`mktemp /tmp/init-XXXXXX`
-       
+# A function to start a program (now it's usefull on read-only filesystem too)
+daemon() 
+{
        nicelevel=0
+       _ERRORS=""
+       [ -z "$DEFAULT_SERVICE_RUN_NICE_LEVEL" ] && DEFAULT_SERVICE_RUN_NICE_LEVEL=0
        # Test syntax.
        case $1 in
            '')    echo '$0: Usage: daemon [+/-nicelevel] {program}'
                   return 1;;
-           -*|+*) nicelevel=$1
+           -*|+*) SERVICE_RUN_NICE_LEVEL=$1
                   shift;;
        esac
 
@@ -56,19 +71,20 @@ daemon() {
 
        # And start it up.
        busy
-       if nice -n $nicelevel "$@" &> $TMPFILE; then
+       if _ERRORS="`nice -n ${SERVICE_RUN_NICE_LEVEL:-$DEFAULT_SERVICE_RUN_NICE_LEVEL} initlog -c \"$@\" 2>&1`"; then
          deltext
          ok
        else
          deltext
          fail
-         cat $TMPFILE
+         echo $_ERRORS
        fi
-       rm -f $TMPFILE
+       unset _ERRORS
 }
 
 # A function to stop a program.
-killproc() {
+killproc() 
+{
        # Test syntax.
        if [ $# = 0 ]; then
                echo "Usage: killproc {program} [signal]"
@@ -98,16 +114,16 @@ killproc() {
         if [ "$pid" != "" ] ; then
                if [ "$notset" = 1 ] ; then
                        # TERM first, then KILL if not dead
-                       kill -TERM $pid &> $TMPFILE
+                       kill -TERM $pid >$TMPFILE 2>&1
                        usleep 100000
                        dead=`ps -o pid= $pid`
                        if [ "$dead" != "" ]; then
                                sleep 3
-                               kill -KILL $pid &> $TMPFILE
+                               kill -KILL $pid >$TMPFILE 2>&1
                        fi
                # use specified level only
                else
-                       kill $killlevel $pid &> $TMPFILE
+                       kill $killlevel $pid >$TMPFILE 2>&1
                fi
        else
          rm -f /var/run/$base.pid
@@ -130,7 +146,8 @@ killproc() {
 }
 
 # A function to find the pid of a program.
-pidofproc() {
+pidofproc() 
+{
        # Test syntax.
        if [ $# = 0 ] ; then
                echo "Usage: pidofproc {program}"
@@ -154,11 +171,21 @@ pidofproc() {
        fi
 
        # Finally try to extract it from ps
-       echo `ps -C $1 -o pid=`
-       return 0
+       pids=`ps -C $1 -o pid=`
+
+       # Return the first PID, which is not our
+       for pid in $pids ; do
+               if [ $pid != $$ ] ; then
+                       echo $pid
+                       return 0
+               fi
+       done  
+       
+       return 1
 }
 
-status() {
+status() 
+{
        # Test syntax.
        if [ $# = 0 ] ; then
                echo "Usage: status {program}"
This page took 0.043799 seconds and 4 git commands to generate.