initscripts: Speed up populate-volatiles.sh by caching the command produced by the...
authorMatthias Hentges <oe@hentges.net>
Wed, 3 May 2006 12:44:07 +0000 (12:44 +0000)
committerOpenEmbedded Project <openembedded-devel@lists.openembedded.org>
Wed, 3 May 2006 12:44:07 +0000 (12:44 +0000)
old version: 7.6s
new version: 4.5s (no chache)
new version: 0.9s (with cache)

packages/initscripts/initscripts-1.0/populate-volatile.sh
packages/initscripts/initscripts_1.0.bb

index bf49808..f22bf2f 100755 (executable)
@@ -8,6 +8,35 @@ COREDEF="00_core"
 
 [ "${VERBOSE}" != "no" ] && echo "Populating volatile Filesystems."
 
+create_file() {
+       EXEC=" 
+       touch \"$1\" 
+       chown ${TUSER}.${TGROUP} $1 || echo \"Failed to set owner -${TUSER}- for -$1-.\" >/dev/tty0 2>&1 
+       chmod ${TMODE} $1 || echo \"Failed to set mode -${TMODE}- for -$1-.\" >/dev/tty0 2>&1 " 
+
+       test "$VOLATILE_ENABLE_CACHE" = yes && echo "$EXEC" >> /etc/volatile.cache
+       
+       eval $EXEC &
+}
+
+mk_dir() {
+       EXEC=" 
+       mkdir -p \"$1\" 
+       chown ${TUSER}.${TGROUP} $1 || echo \"Failed to set owner -${TUSER}- for -$1-.\" >/dev/tty0 2>&1 
+       chmod ${TMODE} $1 || echo \"Failed to set mode -${TMODE}- for -$1-.\" >/dev/tty0 2>&1 "
+
+       test "$VOLATILE_ENABLE_CACHE" = yes && echo "$EXEC" >> /etc/volatile.cache
+       
+       eval $EXEC &
+}
+
+link_file() {
+       EXEC="test -e \"$2\" -o -L $2 || ln -s \"$1\" \"$2\" >/dev/tty0 2>&1" 
+
+       test "$VOLATILE_ENABLE_CACHE" = yes && echo "   $EXEC" >> /etc/volatile.cache
+       
+       eval $EXEC &
+}
 
 check_requirements() {
 
@@ -72,22 +101,21 @@ apply_cfgfile() {
 
   cat ${CFGFILE} | grep -v "^#" | \
   while read LINE; do
-    TTYPE=`echo ${LINE} | cut -d " " -f 1`
-    TUSER=`echo ${LINE} | cut -d " " -f 2`
-    TGROUP=`echo ${LINE} | cut -d " " -f 3`
-    TMODE=`echo ${LINE} | cut -d " " -f 4`
-    TNAME=`echo ${LINE} | cut -d " " -f 5`
+
+    # This is a hell of a lot faster than using cut or awk 5 times
+    eval `echo "$LINE" | sed -n "s/\(.*\)\ \(.*\) \(.*\)\ \(.*\)\ \(.*\)\ \(.*\)/TTYPE=\1 ; TUSER=\2; TGROUP=\3; TMODE=\4; TNAME=\5 TLTARGET=\6/p"`
 
     [ "${VERBOSE}" != "no" ] && echo "Checking for -${TNAME}-."
 
+
     [ "${TTYPE}" = "l" ] && {
       [ -e "${TNAME}" ] && {
         echo "Cannot create link over existing -${TNAME}-." >&2
         } || {
-        TSOURCE=`echo ${LINE} | cut -d " " -f 6`
+        TSOURCE="$TLTARGET"
        [ -L "${TNAME}" ] || {
           [ "${VERBOSE}" != "no" ] && echo "Creating link -${TNAME}- pointing to -${TSOURCE}-."
-          ln -s "${TSOURCE}" "${TNAME}"
+          link_file "${TSOURCE}" "${TNAME}" &
          }
         }
       continue
@@ -112,10 +140,10 @@ apply_cfgfile() {
 
     case "${TTYPE}" in
       "f")  [ "${VERBOSE}" != "no" ] && echo "Creating file -${TNAME}-."
-            touch "${TNAME}"
+            create_file "${TNAME}" &
            ;;
       "d")  [ "${VERBOSE}" != "no" ] && echo "Creating directory -${TNAME}-."
-            mkdir -p "${TNAME}"
+            mk_dir "${TNAME}" &
            # Add check to see if there's an entry in fstab to mount.
            ;;
       *)    [ "${VERBOSE}" != "no" ] && echo "Invalid type -${TTYPE}-."
@@ -123,9 +151,6 @@ apply_cfgfile() {
            ;;
     esac
 
-    chown ${TUSER} ${TNAME} || echo "Failed to set owner -${TUSER}- for -${TNAME}-." >&2
-    chgrp ${TGROUP} ${TNAME} || echo "Failed to set group -${TGROUP}- for -${TNAME}-." >&2
-    chmod ${TMODE} ${TNAME} || echo "Failed to set mode -${TMODE}- for -${TNAME}-." >&2
 
     done
 
@@ -133,8 +158,12 @@ apply_cfgfile() {
 
   }
 
-
-for file in `ls -1 "${CFGDIR}" | sort`; do
-  apply_cfgfile "${CFGDIR}/${file}"
-  done
-
+if test -e /etc/volatile.cache -a "$VOLATILE_ENABLE_CACHE" = "yes"
+then
+       sh /etc/volatile.cache
+else   
+       rm -f /etc/volatile.cache
+       for file in `ls -1 "${CFGDIR}" | sort`; do
+               apply_cfgfile "${CFGDIR}/${file}"
+       done
+fi
index 29886d0..b3c0bfb 100644 (file)
@@ -6,7 +6,7 @@ DEPENDS = "makedevs"
 DEPENDS_openzaurus = "makedevs virtual/kernel"
 RDEPENDS = "makedevs"
 LICENSE = "GPL"
-PR = "r71"
+PR = "r72"
 
 SRC_URI = "file://halt \
            file://ramdisk \