diff options
author | Lans Zhang <jia.zhang@windriver.com> | 2017-07-03 15:48:25 +0800 |
---|---|---|
committer | Lans Zhang <jia.zhang@windriver.com> | 2017-07-03 15:48:25 +0800 |
commit | 3816bb03fd895b37d9eca3b2e4f68283a999c3e6 (patch) | |
tree | be58fe2907ad9167558fd299cea25c216448567d /meta/recipes-core | |
parent | 81553a81fb36e214479fb406e9f5214c4adeb45b (diff) | |
download | meta-secure-core-3816bb03fd895b37d9eca3b2e4f68283a999c3e6.tar.gz |
init: clean up code style
Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
Diffstat (limited to 'meta/recipes-core')
-rw-r--r-- | meta/recipes-core/initrdscripts/files/init | 64 |
1 files changed, 30 insertions, 34 deletions
diff --git a/meta/recipes-core/initrdscripts/files/init b/meta/recipes-core/initrdscripts/files/init index 628b307..656a4e7 100644 --- a/meta/recipes-core/initrdscripts/files/init +++ b/meta/recipes-core/initrdscripts/files/init | |||
@@ -1,6 +1,6 @@ | |||
1 | #!/bin/sh | 1 | #!/bin/sh |
2 | 2 | ||
3 | PATH=/sbin:/bin:/usr/sbin:/usr/bin | 3 | PATH="/sbin:/bin:/usr/sbin:/usr/bin" |
4 | 4 | ||
5 | ROOT_MOUNT="/rootfs" | 5 | ROOT_MOUNT="/rootfs" |
6 | MOUNT="/bin/mount" | 6 | MOUNT="/bin/mount" |
@@ -10,19 +10,19 @@ ROOT_DELAY="0" | |||
10 | # Copied from initramfs-framework. The core of this script probably should be | 10 | # Copied from initramfs-framework. The core of this script probably should be |
11 | # turned into initramfs-framework modules to reduce duplication. | 11 | # turned into initramfs-framework modules to reduce duplication. |
12 | udev_daemon() { | 12 | udev_daemon() { |
13 | OPTIONS="/sbin/udev/udevd /sbin/udevd /lib/udev/udevd /lib/systemd/systemd-udevd" | 13 | PROGS="/sbin/udev/udevd /sbin/udevd /lib/udev/udevd /lib/systemd/systemd-udevd" |
14 | 14 | ||
15 | for o in $OPTIONS; do | 15 | for o in $PROGS; do |
16 | if [ -x "$o" ]; then | 16 | if [ -x "$o" ]; then |
17 | echo $o | 17 | echo "$o" |
18 | return 0 | 18 | return 0 |
19 | fi | 19 | fi |
20 | done | 20 | done |
21 | 21 | ||
22 | return 1 | 22 | return 1 |
23 | } | 23 | } |
24 | 24 | ||
25 | _UDEV_DAEMON=`udev_daemon` | 25 | _UDEV_DAEMON="`udev_daemon`" |
26 | 26 | ||
27 | early_setup() { | 27 | early_setup() { |
28 | mkdir -p /proc | 28 | mkdir -p /proc |
@@ -31,10 +31,6 @@ early_setup() { | |||
31 | mount -t sysfs sysfs /sys | 31 | mount -t sysfs sysfs /sys |
32 | mount -t devtmpfs none /dev | 32 | mount -t devtmpfs none /dev |
33 | 33 | ||
34 | # support modular kernel | ||
35 | # modprobe isofs | ||
36 | # modprobe raid0 | ||
37 | |||
38 | mkdir -p /run | 34 | mkdir -p /run |
39 | mkdir -p /var/run | 35 | mkdir -p /var/run |
40 | 36 | ||
@@ -47,16 +43,19 @@ early_setup() { | |||
47 | } | 43 | } |
48 | 44 | ||
49 | read_args() { | 45 | read_args() { |
50 | [ -z "$CMDLINE" ] && CMDLINE=`cat /proc/cmdline` | 46 | [ -z "$CMDLINE" ] && CMDLINE="`cat /proc/cmdline`" |
51 | for arg in $CMDLINE; do | 47 | for arg in $CMDLINE; do |
52 | optarg=`expr "x$arg" : 'x[^=]*=\(.*\)'` | 48 | optarg=`expr "x$arg" : 'x[^=]*=\(.*\)'` |
53 | case $arg in | 49 | case "$arg" in |
54 | root=*) | 50 | root=*) |
55 | ROOT_DEVICE=$optarg ;; | 51 | ROOT_DEVICE="$optarg" |
52 | ;; | ||
56 | rootdelay=*) | 53 | rootdelay=*) |
57 | ROOT_DELAY=$optarg ;; | 54 | ROOT_DELAY="$optarg" |
55 | ;; | ||
58 | init=*) | 56 | init=*) |
59 | INIT=$optarg ;; | 57 | INIT="$optarg" |
58 | ;; | ||
60 | esac | 59 | esac |
61 | done | 60 | done |
62 | } | 61 | } |
@@ -67,10 +66,6 @@ fatal() { | |||
67 | exec sh | 66 | exec sh |
68 | } | 67 | } |
69 | 68 | ||
70 | |||
71 | |||
72 | ####################################### | ||
73 | |||
74 | early_setup | 69 | early_setup |
75 | 70 | ||
76 | read_args | 71 | read_args |
@@ -78,21 +73,22 @@ read_args | |||
78 | [ -z "$CONSOLE" ] && CONSOLE="/dev/console" | 73 | [ -z "$CONSOLE" ] && CONSOLE="/dev/console" |
79 | [ -z "$INIT" ] && INIT="/sbin/init" | 74 | [ -z "$INIT" ] && INIT="/sbin/init" |
80 | 75 | ||
81 | |||
82 | udevadm settle --timeout=3 | 76 | udevadm settle --timeout=3 |
83 | killall "${_UDEV_DAEMON##*/}" 2>/dev/null | 77 | killall "${_UDEV_DAEMON##*/}" 2>/dev/null |
84 | 78 | ||
85 | mkdir -p $ROOT_MOUNT/ | 79 | mkdir -p "$ROOT_MOUNT" |
86 | 80 | ||
87 | sleep ${ROOT_DELAY} | 81 | sleep "$ROOT_DELAY" |
88 | 82 | ||
89 | try_to_mount_rootfs() { | 83 | try_to_mount_rootfs() { |
90 | local mount_flags="rw,noatime,iversion" | 84 | local mount_flags="rw,noatime,iversion" |
91 | 85 | ||
92 | mount -o $mount_flags "${ROOT_DEVICE}" "${ROOT_MOUNT}" 2>/dev/null && return 0 | 86 | mount -o "$mount_flags" "$ROOT_DEVICE" "$ROOT_MOUNT" \ |
87 | 2>/dev/null && return 0 | ||
93 | 88 | ||
94 | [ -x /init.cryptfs ] && | 89 | [ -x /init.cryptfs ] && |
95 | /init.cryptfs "${ROOT_MOUNT}" "${ROOT_DEVICE}" $mount_flags "OVERCROOTFS" && return 0 | 90 | /init.cryptfs "$ROOT_MOUNT" "$ROOT_DEVICE" \ |
91 | "$mount_flags" OVERCROOTFS && return 0 | ||
96 | 92 | ||
97 | return 1 | 93 | return 1 |
98 | } | 94 | } |
@@ -105,12 +101,12 @@ done | |||
105 | 101 | ||
106 | # Move the mount points of some filesystems over to | 102 | # Move the mount points of some filesystems over to |
107 | # the corresponding directories under the real root filesystem. | 103 | # the corresponding directories under the real root filesystem. |
108 | for dir in `cat /proc/mounts | grep -v rootfs | awk '{print $2}'` ; do | 104 | for dir in `cat /proc/mounts | grep -v rootfs | awk '{ print $2 }'` ; do |
109 | mkdir -p ${ROOT_MOUNT}/${dir##*/} | 105 | mkdir -p $ROOT_MOUNT/${dir##*/} |
110 | mount -nv --move $dir ${ROOT_MOUNT}/${dir##*/} | 106 | mount -nv --move $dir $ROOT_MOUNT/${dir##*/} |
111 | done | 107 | done |
112 | 108 | ||
113 | cd $ROOT_MOUNT | 109 | cd "$ROOT_MOUNT" |
114 | 110 | ||
115 | # If we pass args to bash, it will assume they are text files | 111 | # If we pass args to bash, it will assume they are text files |
116 | # to source and run. | 112 | # to source and run. |
@@ -123,7 +119,7 @@ fi | |||
123 | # The IMA policy may enforce appraising the executable and verifying the | 119 | # The IMA policy may enforce appraising the executable and verifying the |
124 | # signature stored in xattr. However, ramfs doesn't support xattr, and all | 120 | # signature stored in xattr. However, ramfs doesn't support xattr, and all |
125 | # other initializations must *NOT* be placed after IMA initialization! | 121 | # other initializations must *NOT* be placed after IMA initialization! |
126 | [ -x /init.ima ] && /init.ima $ROOT_MOUNT && { | 122 | [ -x /init.ima ] && /init.ima "$ROOT_MOUNT" && { |
127 | # switch_root is an exception. We call it in the real rootfs and it | 123 | # switch_root is an exception. We call it in the real rootfs and it |
128 | # should be already signed properly. | 124 | # should be already signed properly. |
129 | switch_root="usr/sbin/switch_root.static" | 125 | switch_root="usr/sbin/switch_root.static" |
@@ -131,5 +127,5 @@ fi | |||
131 | switch_root="switch_root" | 127 | switch_root="switch_root" |
132 | } | 128 | } |
133 | 129 | ||
134 | exec $switch_root $ROOT_MOUNT $INIT $CMDLINE || | 130 | exec "$switch_root" "$ROOT_MOUNT" "$INIT" "$CMDLINE" || |
135 | fatal "Couldn't switch_root, dropping to shell" | 131 | fatal "Couldn't switch_root, dropping to shell" |