base-files: run readlink on initscript name before opening services
[openwrt.git] / package / base-files / files / etc / rc.common
index 79424a6..aeec90c 100755 (executable)
@@ -1,7 +1,8 @@
 #!/bin/sh
-# Copyright (C) 2006-2011 OpenWrt.org
+# Copyright (C) 2006-2012 OpenWrt.org
 
-. $IPKG_INSTROOT/etc/functions.sh
+. $IPKG_INSTROOT/lib/functions.sh
+. $IPKG_INSTROOT/lib/functions/service.sh
 
 initscript=$1
 action=${2:-help}
@@ -74,8 +75,41 @@ $EXTRA_HELP
 EOF
 }
 
+# for procd
+start_service() {
+       return 0
+}
+
+stop_service() {
+       return 0
+}
+
+${INIT_TRACE:+set -x}
+
 . "$initscript"
 
+[ -n "$USE_PROCD" ] && {
+       . $IPKG_INSTROOT/lib/functions/procd.sh
+       basescript=$(readlink "$initscript")
+       rc_procd() {
+               procd_open_service "$(basename ${basescript:-$initscript})" "$initscript"
+               "$@"
+               procd_close_service
+       }
+
+       start() {
+               rc_procd start_service "$@"
+       }
+
+       stop() {
+               procd_kill "$(basename ${basescript:-$initscript})" "$1"
+       }
+
+       reload() {
+               start
+       }
+}
+
 ALL_COMMANDS="start stop reload restart boot shutdown enable disable enabled depends ${EXTRA_COMMANDS}"
 list_contains ALL_COMMANDS "$action" || action=help
 [ "$action" = "reload" ] && action='eval reload "$@" || restart "$@" && :'