removed rc.status dependencies from init script.
authorFlorian Pose <fp@igh-essen.com>
Fri, 10 Aug 2007 14:28:56 +0000
changeset 698 6693ea7c9047
parent 697 6f658c2082fd
child 699 112abd5b04d2
removed rc.status dependencies from init script.
NEWS
TODO
script/init.d/ethercat
--- a/NEWS	Fri Aug 10 13:46:34 2007 +0000
+++ b/NEWS	Fri Aug 10 14:28:56 2007 +0000
@@ -49,6 +49,8 @@
   as fast as possible (with schedule()).
 * Added dummy module for simulation purpuses.
 * Limited infinite EEPROM reading, if 0xffff limiter word is missing.
+* Init script works now properly on non-SUSE distros (no rc.status dependency
+  any more).
 * Removed EtherCAT line comments from 8139too drivers.
 
 -------------------------------------------------------------------------------
--- a/TODO	Fri Aug 10 13:46:34 2007 +0000
+++ b/TODO	Fri Aug 10 14:28:56 2007 +0000
@@ -8,7 +8,6 @@
 
 * Issues for release 1.3.0:
   - Take broadcast MAC address to register the first ethernet device.
-  - Handle missing rc_status in init script.
 
 * Future features:
   - Interface/buffers for asynchronous domain IO.
--- a/script/init.d/ethercat	Fri Aug 10 13:46:34 2007 +0000
+++ b/script/init.d/ethercat	Fri Aug 10 14:28:56 2007 +0000
@@ -50,6 +50,9 @@
 #------------------------------------------------------------------------------
 
 XMLDEVICE='ecxml'
+MODPROBE=/sbin/modprobe
+RMMOD=/sbin/rmmod
+MODINFO=/sbin/modinfo
 
 #------------------------------------------------------------------------------
 
@@ -68,6 +71,47 @@
 
 #------------------------------------------------------------------------------
 
+function exit_success()
+{
+    if [ -r /etc/rc.status ]; then
+        rc_reset
+        rc_status -v
+        rc_exit
+    else
+        echo " done"
+        exit 0
+    fi
+}
+
+#------------------------------------------------------------------------------
+
+function exit_running()
+{
+    if [ -r /etc/rc.status ]; then
+        rc_reset
+        rc_status -v
+        rc_exit
+    else
+        echo " running"
+        exit 0
+    fi
+}
+
+#------------------------------------------------------------------------------
+
+function exit_fail()
+{
+    if [ -r /etc/rc.status ]; then
+        rc_failed
+        rc_exit
+    else
+        echo " failed"
+        exit 1
+    fi
+}
+
+#------------------------------------------------------------------------------
+
 function parse_mac_address()
 {
     if [ -z "${1}" ]; then
@@ -76,16 +120,16 @@
         MAC=${1}
     else
         echo Invalid MAC address \"${1}\" in ${ETHERCAT_CONFIG}
-        /bin/false
-        rc_status -v
-        rc_exit
+        exit_fail
     fi 
 }
 
 #------------------------------------------------------------------------------
 
-. /etc/rc.status
-rc_reset
+if [ -r /etc/rc.status ]; then
+    . /etc/rc.status
+    rc_reset
+fi
 
 case "${1}" in
 
@@ -116,11 +160,8 @@
     done
 
     # load master module
-    if ! modprobe ec_master main=${DEVICES} backup=${BACKUPS}; then
-        modprobe 8139too
-        /bin/false
-        rc_status -v
-        rc_exit
+    if ! ${MODPROBE} ec_master main=${DEVICES} backup=${BACKUPS}; then
+        exit_fail
     fi
 
     # remove stale device node
@@ -135,25 +176,21 @@
     # check for modules to replace
     for MODULE in ${DEVICE_MODULES}; do
         ECMODULE=ec_${MODULE}
-        if ! modinfo ${ECMODULE} > /dev/null; then
-            continue
+        if ! ${MODINFO} ${ECMODULE} > /dev/null; then
+            continue # ec_* module not found
         fi
         if lsmod | grep "^${MODULE} " > /dev/null; then
-            if ! rmmod ${MODULE}; then
-                /bin/false
-                rc_status -v
-                rc_exit
+            if ! ${RMMOD} ${MODULE}; then
+                exit_fail
             fi
         fi
-        if ! modprobe ${ECMODULE}; then
-            modprobe ${MODULE} # try to restore module
-            /bin/false
-            rc_status -v
-            rc_exit
-        fi
-    done
-
-    rc_status -v
+        if ! ${MODPROBE} ${ECMODULE}; then
+            ${MODPROBE} ${MODULE} # try to restore module
+            exit_fail
+        fi
+    done
+
+    exit_success
     ;;
 
 stop)
@@ -163,12 +200,10 @@
     for MODULE in ${DEVICE_MODULES} master; do
         ECMODULE=ec_${MODULE}
         if ! lsmod | grep -q "^${ECMODULE} "; then
-            continue
-        fi
-        if ! rmmod ${ECMODULE}; then
-            /bin/false
-            rc_status -v
-            rc_exit
+            continue # ec_* module not loaded
+        fi
+        if ! ${RMMOD} ${ECMODULE}; then
+            exit_fail
         fi;
     done
 
@@ -179,19 +214,18 @@
 
     # reload previous modules
     for MODULE in ${DEVICE_MODULES}; do
-        if ! modprobe ${MODULE}; then
+        if ! ${MODPROBE} ${MODULE}; then
             echo Warning: Failed to restore ${MODULE}.
         fi
     done
 
-    rc_status -v
+    exit_success
     ;;
 
 restart)
     $0 stop || exit 1
     sleep 1
     $0 start
-    rc_status
     ;;
 
 status)
@@ -204,9 +238,11 @@
     MASTERS_IDLE=$?
 
     # master module loaded and masters not waiting for devices?
-    test ${MASTERS_RUNNING} -eq 0 -a ${MASTERS_IDLE} -eq 0
-
-    rc_status -v
+    if [ ${MASTERS_RUNNING} -eq 0 -a ${MASTERS_IDLE} -eq 0 ]; then
+        exit_running
+    else
+        exit_fail
+    fi
     ;;
 
 *)
@@ -215,6 +251,10 @@
 
 esac
 
-rc_exit
-
-#------------------------------------------------------------------------------
+if [ -r /etc/rc.status ]; then
+    rc_exit
+else
+    exit 1
+fi
+
+#------------------------------------------------------------------------------