diff options
Diffstat (limited to 'meta/recipes-core/initscripts/initscripts-1.0/populate-volatile.sh')
-rwxr-xr-x | meta/recipes-core/initscripts/initscripts-1.0/populate-volatile.sh | 69 |
1 files changed, 55 insertions, 14 deletions
diff --git a/meta/recipes-core/initscripts/initscripts-1.0/populate-volatile.sh b/meta/recipes-core/initscripts/initscripts-1.0/populate-volatile.sh index ce4622a5e5..1c525b71bd 100755 --- a/meta/recipes-core/initscripts/initscripts-1.0/populate-volatile.sh +++ b/meta/recipes-core/initscripts/initscripts-1.0/populate-volatile.sh @@ -25,9 +25,19 @@ COREDEF="00_core" [ "${VERBOSE}" != "no" ] && echo "Populating volatile Filesystems." create_file() { + EXEC="" + [ -z "$2" ] && { + EXEC=" + touch \"$1\"; + " + } || { + EXEC=" + cp \"$2\" \"$1\"; + " + } EXEC=" - touch \"$1\"; - chown ${TUSER}.${TGROUP} $1 || echo \"Failed to set owner -${TUSER}- for -$1-.\" >/dev/tty0 2>&1; + ${EXEC} + 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.build @@ -36,7 +46,7 @@ create_file() { [ "${VERBOSE}" != "no" ] && echo "Target already exists. Skipping." } || { if [ -z "$ROOT_DIR" ]; then - eval $EXEC & + eval $EXEC else # Creating some files at rootfs time may fail and should fail, # but these failures should not be logged to make sure the do_rootfs @@ -50,7 +60,7 @@ create_file() { mk_dir() { EXEC=" mkdir -p \"$1\"; - chown ${TUSER}.${TGROUP} $1 || echo \"Failed to set owner -${TUSER}- for -$1-.\" >/dev/tty0 2>&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.build @@ -70,7 +80,7 @@ mk_dir() { link_file() { EXEC=" if [ -L \"$2\" ]; then - [ \"\$(readlink -f \"$2\")\" != \"\$(readlink -f \"$1\")\" ] && { rm -f \"$2\"; ln -sf \"$1\" \"$2\"; }; + [ \"\$(readlink \"$2\")\" != \"$1\" ] && { rm -f \"$2\"; ln -sf \"$1\" \"$2\"; }; elif [ -d \"$2\" ]; then if awk '\$2 == \"$2\" {exit 1}' /proc/mounts; then cp -a $2/* $1 2>/dev/null; @@ -86,7 +96,7 @@ link_file() { test "$VOLATILE_ENABLE_CACHE" = yes && echo " $EXEC" >> /etc/volatile.cache.build if [ -z "$ROOT_DIR" ]; then - eval $EXEC & + eval $EXEC else # For the same reason with create_file(), failures should # not be logged. @@ -102,7 +112,6 @@ check_requirements() { } CFGFILE="$1" - [ `basename "${CFGFILE}"` = "${COREDEF}" ] && return 0 TMP_INTERMED="${TMPROOT}/tmp.$$" TMP_DEFINED="${TMPROOT}/tmpdefined.$$" @@ -144,15 +153,18 @@ check_requirements() { apply_cfgfile() { CFGFILE="$1" + SKIP_REQUIREMENTS="$2" + + [ "${VERBOSE}" != "no" ] && echo "Applying ${CFGFILE}" - check_requirements "${CFGFILE}" || { + [ "${SKIP_REQUIREMENTS}" == "yes" ] || check_requirements "${CFGFILE}" || { echo "Skipping ${CFGFILE}" return 1 } - cat ${CFGFILE} | grep -v "^#" | \ - while read LINE; do - eval `echo "$LINE" | sed -n "s/\(.*\)\ \(.*\) \(.*\)\ \(.*\)\ \(.*\)\ \(.*\)/TTYPE=\1 ; TUSER=\2; TGROUP=\3; TMODE=\4; TNAME=\5 TLTARGET=\6/p"` + cat ${CFGFILE} | sed 's/#.*//' | \ + while read TTYPE TUSER TGROUP TMODE TNAME TLTARGET; do + test -z "${TLTARGET}" && continue TNAME=${ROOT_DIR}${TNAME} [ "${VERBOSE}" != "no" ] && echo "Checking for -${TNAME}-." @@ -187,7 +199,9 @@ apply_cfgfile() { case "${TTYPE}" in "f") [ "${VERBOSE}" != "no" ] && echo "Creating file -${TNAME}-." - create_file "${TNAME}" & + TSOURCE="$TLTARGET" + [ "${TSOURCE}" = "none" ] && TSOURCE="" + create_file "${TNAME}" "${TSOURCE}" & ;; "d") [ "${VERBOSE}" != "no" ] && echo "Creating directory -${TNAME}-." mk_dir "${TNAME}" @@ -219,10 +233,37 @@ then sh ${ROOT_DIR}/etc/volatile.cache else rm -f ${ROOT_DIR}/etc/volatile.cache ${ROOT_DIR}/etc/volatile.cache.build - for file in `ls -1 "${CFGDIR}" | sort`; do - apply_cfgfile "${CFGDIR}/${file}" + + # Apply the core file with out checking requirements. ${TMPROOT} is + # needed by check_requirements but is setup by this file, so it must be + # processed first and without being checked. + [ -e "${CFGDIR}/${COREDEF}" ] && apply_cfgfile "${CFGDIR}/${COREDEF}" "yes" + + # Fast path: check_requirements is slow and most of the time doesn't + # find any problems. If there are a lot of config files, it is much + # faster to to concatenate them all together and process them once to + # avoid the overhead of calling check_requirements repeatedly + TMP_FILE="${TMPROOT}/tmp_volatile.$$" + rm -f "$TMP_FILE" + + CFGFILES="`ls -1 "${CFGDIR}" | grep -v "^${COREDEF}\$" | sort`" + for file in ${CFGFILES}; do + cat "${CFGDIR}/${file}" >> "$TMP_FILE" done + if check_requirements "$TMP_FILE" + then + apply_cfgfile "$TMP_FILE" "yes" + else + # Slow path: One or more config files failed requirements. + # Process each one individually so the offending one can be + # skipped + for file in ${CFGFILES}; do + apply_cfgfile "${CFGDIR}/${file}" + done + fi + rm "$TMP_FILE" + [ -e ${ROOT_DIR}/etc/volatile.cache.build ] && sync && mv ${ROOT_DIR}/etc/volatile.cache.build ${ROOT_DIR}/etc/volatile.cache fi |