summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChen Qi <Qi.Chen@windriver.com>2013-02-18 17:14:49 +0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-03-07 11:14:33 +0000
commitbf7a5b449c167a6bcd824b82517509ba6914ec0f (patch)
tree5a06e978486dee0b5c0cbf509df6943140448602
parent164a4cb2fc64e76836182ad2d412343a7b26b964 (diff)
downloadpoky-bf7a5b449c167a6bcd824b82517509ba6914ec0f.tar.gz
populate-volatile.sh: add ROOT_DIR variable to support running at rootfs time
For populate-volatile.sh script to run correctly both at rootfs time and at system boot time, it needs to be aware of which situation it is now in. We use the ROOT_DIR variable to indicate whether it is run at rootfs time or not. ROOT_DIR being "/" indicates that this script is run at system boot time, otherwise, it is run at rootfs time. Also, we ignore failures when running this script at rootfs time. For example, if ${ROOT_DIR}/var/dir1 is symlink to /var/volatile/dir1, it's possible that the link is a dead link. So if we're going to create some file under ${ROOT_DIR}/var/dir1, it will fail. But the failure does no harm, because this script will always run at system boot time to set up the correct files and directories. [YOCTO #3406] (From OE-Core rev: 45396e3edcce4a33fcbef6456f31811f30c26c63) Signed-off-by: Chen Qi <Qi.Chen@windriver.com> Signed-off-by: Saul Wold <sgw@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rwxr-xr-xmeta/recipes-core/initscripts/initscripts-1.0/populate-volatile.sh62
1 files changed, 45 insertions, 17 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 ab3af70430..c4bf70e5de 100755
--- a/meta/recipes-core/initscripts/initscripts-1.0/populate-volatile.sh
+++ b/meta/recipes-core/initscripts/initscripts-1.0/populate-volatile.sh
@@ -8,10 +8,18 @@
8# Short-Description: Populate the volatile filesystem 8# Short-Description: Populate the volatile filesystem
9### END INIT INFO 9### END INIT INFO
10 10
11. /etc/default/rcS 11# Get ROOT_DIR
12 12DIRNAME=`dirname $0`
13CFGDIR="/etc/default/volatiles" 13ROOT_DIR=`echo $DIRNAME | sed -ne 's:etc/.*::p'`
14TMPROOT="/var/tmp" 14
15[ -e ${ROOT_DIR}/etc/default/rcS ] && . ${ROOT_DIR}/etc/default/rcS
16# When running populate-volatile.sh at rootfs time, disable cache.
17[ "$ROOT_DIR" != "/" ] && VOLATILE_ENABLE_CACHE=no
18# If rootfs is read-only, disable cache.
19[ "$ROOTFS_READ_ONLY" = "yes" ] && VOLATILE_ENABLE_CACHE=no
20
21CFGDIR="${ROOT_DIR}/etc/default/volatiles"
22TMPROOT="${ROOT_DIR}/var/tmp"
15COREDEF="00_core" 23COREDEF="00_core"
16 24
17[ "${VERBOSE}" != "no" ] && echo "Populating volatile Filesystems." 25[ "${VERBOSE}" != "no" ] && echo "Populating volatile Filesystems."
@@ -27,7 +35,15 @@ create_file() {
27 [ -e "$1" ] && { 35 [ -e "$1" ] && {
28 [ "${VERBOSE}" != "no" ] && echo "Target already exists. Skipping." 36 [ "${VERBOSE}" != "no" ] && echo "Target already exists. Skipping."
29 } || { 37 } || {
30 eval $EXEC & 38 if [ "$ROOT_DIR" = "/" ]; then
39 eval $EXEC &
40 else
41 # Creating some files at rootfs time may fail and should fail,
42 # but these failures should not be logged to make sure the do_rootfs
43 # process doesn't fail. This does no harm, as this script will
44 # run on target to set up the correct files and directories.
45 eval $EXEC > /dev/null 2>&1 &
46 fi
31 } 47 }
32} 48}
33 49
@@ -41,7 +57,13 @@ mk_dir() {
41 [ -e "$1" ] && { 57 [ -e "$1" ] && {
42 [ "${VERBOSE}" != "no" ] && echo "Target already exists. Skipping." 58 [ "${VERBOSE}" != "no" ] && echo "Target already exists. Skipping."
43 } || { 59 } || {
44 eval $EXEC 60 if [ "$ROOT_DIR" = "/" ]; then
61 eval $EXEC
62 else
63 # For the same reason with create_file(), failures should
64 # not be logged.
65 eval $EXEC > /dev/null 2>&1
66 fi
45 } 67 }
46} 68}
47 69
@@ -49,11 +71,16 @@ link_file() {
49 EXEC="test -e \"$2\" -o -L $2 || ln -s \"$1\" \"$2\" >/dev/tty0 2>&1" 71 EXEC="test -e \"$2\" -o -L $2 || ln -s \"$1\" \"$2\" >/dev/tty0 2>&1"
50 72
51 test "$VOLATILE_ENABLE_CACHE" = yes && echo " $EXEC" >> /etc/volatile.cache.build 73 test "$VOLATILE_ENABLE_CACHE" = yes && echo " $EXEC" >> /etc/volatile.cache.build
52
53 [ -e "$2" ] && { 74 [ -e "$2" ] && {
54 echo "Cannot create link over existing -${TNAME}-." >&2 75 echo "Cannot create link over existing -${TNAME}-." >&2
55 } || { 76 } || {
56 eval $EXEC & 77 if [ "$ROOT_DIR" = "/" ]; then
78 eval $EXEC &
79 else
80 # For the same reason with create_file(), failures should
81 # not be logged.
82 eval $EXEC > /dev/null 2>&1 &
83 fi
57 } 84 }
58} 85}
59 86
@@ -63,7 +90,7 @@ check_requirements() {
63 rm "${TMP_DEFINED}" 90 rm "${TMP_DEFINED}"
64 rm "${TMP_COMBINED}" 91 rm "${TMP_COMBINED}"
65 } 92 }
66 93
67 CFGFILE="$1" 94 CFGFILE="$1"
68 [ `basename "${CFGFILE}"` = "${COREDEF}" ] && return 0 95 [ `basename "${CFGFILE}"` = "${COREDEF}" ] && return 0
69 96
@@ -71,7 +98,7 @@ check_requirements() {
71 TMP_DEFINED="${TMPROOT}/tmpdefined.$$" 98 TMP_DEFINED="${TMPROOT}/tmpdefined.$$"
72 TMP_COMBINED="${TMPROOT}/tmpcombined.$$" 99 TMP_COMBINED="${TMPROOT}/tmpcombined.$$"
73 100
74 cat /etc/passwd | sed 's@\(^:\)*:.*@\1@' | sort | uniq > "${TMP_DEFINED}" 101 cat ${ROOT_DIR}/etc/passwd | sed 's@\(^:\)*:.*@\1@' | sort | uniq > "${TMP_DEFINED}"
75 cat ${CFGFILE} | grep -v "^#" | cut -d " " -f 2 > "${TMP_INTERMED}" 102 cat ${CFGFILE} | grep -v "^#" | cut -d " " -f 2 > "${TMP_INTERMED}"
76 cat "${TMP_DEFINED}" "${TMP_INTERMED}" | sort | uniq > "${TMP_COMBINED}" 103 cat "${TMP_DEFINED}" "${TMP_INTERMED}" | sort | uniq > "${TMP_COMBINED}"
77 NR_DEFINED_USERS="`cat "${TMP_DEFINED}" | wc -l`" 104 NR_DEFINED_USERS="`cat "${TMP_DEFINED}" | wc -l`"
@@ -85,7 +112,7 @@ check_requirements() {
85 } 112 }
86 113
87 114
88 cat /etc/group | sed 's@\(^:\)*:.*@\1@' | sort | uniq > "${TMP_DEFINED}" 115 cat ${ROOT_DIR}/etc/group | sed 's@\(^:\)*:.*@\1@' | sort | uniq > "${TMP_DEFINED}"
89 cat ${CFGFILE} | grep -v "^#" | cut -d " " -f 3 > "${TMP_INTERMED}" 116 cat ${CFGFILE} | grep -v "^#" | cut -d " " -f 3 > "${TMP_INTERMED}"
90 cat "${TMP_DEFINED}" "${TMP_INTERMED}" | sort | uniq > "${TMP_COMBINED}" 117 cat "${TMP_DEFINED}" "${TMP_INTERMED}" | sort | uniq > "${TMP_COMBINED}"
91 118
@@ -116,6 +143,7 @@ apply_cfgfile() {
116 cat ${CFGFILE} | grep -v "^#" | \ 143 cat ${CFGFILE} | grep -v "^#" | \
117 while read LINE; do 144 while read LINE; do
118 eval `echo "$LINE" | sed -n "s/\(.*\)\ \(.*\) \(.*\)\ \(.*\)\ \(.*\)\ \(.*\)/TTYPE=\1 ; TUSER=\2; TGROUP=\3; TMODE=\4; TNAME=\5 TLTARGET=\6/p"` 145 eval `echo "$LINE" | sed -n "s/\(.*\)\ \(.*\) \(.*\)\ \(.*\)\ \(.*\)\ \(.*\)/TTYPE=\1 ; TUSER=\2; TGROUP=\3; TMODE=\4; TNAME=\5 TLTARGET=\6/p"`
146 TNAME=${ROOT_DIR}/${TNAME}
119 [ "${VERBOSE}" != "no" ] && echo "Checking for -${TNAME}-." 147 [ "${VERBOSE}" != "no" ] && echo "Checking for -${TNAME}-."
120 148
121 [ "${TTYPE}" = "l" ] && { 149 [ "${TTYPE}" = "l" ] && {
@@ -168,19 +196,19 @@ do
168done 196done
169exec 9>&- 197exec 9>&-
170 198
171if test -e /etc/volatile.cache -a "$VOLATILE_ENABLE_CACHE" = "yes" -a "x$1" != "xupdate" -a "x$clearcache" = "x0" 199if test -e ${ROOT_DIR}/etc/volatile.cache -a "$VOLATILE_ENABLE_CACHE" = "yes" -a "x$1" != "xupdate" -a "x$clearcache" = "x0"
172then 200then
173 sh /etc/volatile.cache 201 sh ${ROOT_DIR}/etc/volatile.cache
174else 202else
175 rm -f /etc/volatile.cache /etc/volatile.cache.build 203 rm -f ${ROOT_DIR}/etc/volatile.cache ${ROOT_DIR}/etc/volatile.cache.build
176 for file in `ls -1 "${CFGDIR}" | sort`; do 204 for file in `ls -1 "${CFGDIR}" | sort`; do
177 apply_cfgfile "${CFGDIR}/${file}" 205 apply_cfgfile "${CFGDIR}/${file}"
178 done 206 done
179 207
180 [ -e /etc/volatile.cache.build ] && sync && mv /etc/volatile.cache.build /etc/volatile.cache 208 [ -e ${ROOT_DIR}/etc/volatile.cache.build ] && sync && mv ${ROOT_DIR}/etc/volatile.cache.build ${ROOT_DIR}/etc/volatile.cache
181fi 209fi
182 210
183if test -f /etc/ld.so.cache -a ! -f /var/run/ld.so.cache 211if [ "${ROOT_DIR}" = "/" ] && [ -f /etc/ld.so.cache ] && [ ! -f /var/run/ld.so.cache ]
184then 212then
185 ln -s /etc/ld.so.cache /var/run/ld.so.cache 213 ln -s /etc/ld.so.cache /var/run/ld.so.cache
186fi 214fi