[arch-projects] [initscripts] [PATCH 18/18] Introduce install_file() and write_file() for better readability
Kurt J. Bosch
kjb-temp-2009 at alpenjodel.de
Mon Jun 27 13:11:24 EDT 2011
These functions allow us to avoid:
* the "Redirection to File not Working because of noclobber Pitfall" (tm)
* the "Redirecting a Null-String only when using status() Pitfall" (tm)
* the "Process Substitution File Descriptor lost in status() because of Custom stat_busy() Pitfall" (tm)
* the "eval Word Splitting Pitfall" (tm)
* the "eval Extra Quoting Ugliness" (tm)
---
functions | 13 +++++++++++++
rc.shutdown | 2 +-
rc.sysinit | 10 +++++-----
3 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/functions b/functions
index 4c028df..4d58064 100644
--- a/functions
+++ b/functions
@@ -421,6 +421,19 @@ mount_all() {
stat_done
}
+install_file() {
+ local file=$1 content=$2 # remaining args go to install directly
+ shift 2
+ install -T "$@" <(printf '%s' "$content") "$file"
+}
+
+# install would fail because files can't be removed from /proc
+# moreover we don't want to remove nodes from /dev
+write_file() {
+ local file=$1 content=$2
+ printf '%s' "$content" >| "$file"
+}
+
bootlogd_stop() {
[[ -f /run/bootlogd.pid ]] || return 0
touch /var/log/boot
diff --git a/rc.shutdown b/rc.shutdown
index fe42797..e658142 100755
--- a/rc.shutdown
+++ b/rc.shutdown
@@ -21,7 +21,7 @@ kill_everything shutdown
stat_busy "Saving Random Seed"
RANDOM_SEED=/var/lib/misc/random-seed
- install -TDm 0600 <(:) $RANDOM_SEED
+ install_file $RANDOM_SEED "" -m 0600 -D
POOL_FILE=/proc/sys/kernel/random/poolsize
if [[ -r $POOL_FILE ]]; then
read POOL_SIZE < $POOL_FILE
diff --git a/rc.sysinit b/rc.sysinit
index 1559652..cb19c91 100755
--- a/rc.sysinit
+++ b/rc.sysinit
@@ -218,18 +218,18 @@ stat_busy "Removing Leftover Files"
[[ ! -L /var/run && ! -L /var/run/daemons ]] &&
rm -rf /var/run/daemons &&
ln -s /run/daemons /var/run/daemons
- install -Tm 0664 -o root -g utmp <(:) /var/run/utmp
+ install_file /var/run/utmp "" -m 0664 -o root -g utmp
# Keep {x,k,g}dm happy with xorg
mkdir -m 1777 /tmp/.{X11,ICE}-unix
stat_done
[[ $HOSTNAME ]] &&
status "Setting Hostname: $HOSTNAME" \
- eval 'echo "$HOSTNAME" >| /proc/sys/kernel/hostname'
+ write_file /proc/sys/kernel/hostname "$HOSTNAME"
# Flush old locale settings and set user defined locale
status "Setting Locale: ${LOCALE:=en_US}" \
- install -Tm 0755 <(echo "export LANG=$LOCALE") /etc/profile.d/locale.sh
+ install_file /etc/profile.d/locale.sh "export LANG=$LOCALE"$'\n' -m 0755
if [[ ${LOCALE,,} =~ utf ]]; then
stat_busy "Setting Consoles to UTF-8 mode"
@@ -261,9 +261,9 @@ set_consolefont
stat_busy "Saving dmesg Log"
if [[ -e /proc/sys/kernel/dmesg_restrict ]] &&
(( $(< /proc/sys/kernel/dmesg_restrict) == 1 )); then
- install -Tm 0600 <( dmesg ) /var/log/dmesg.log
+ install_file /var/log/dmesg.log "$( dmesg )" -m 0600
else
- install -Tm 0644 <( dmesg ) /var/log/dmesg.log
+ install_file /var/log/dmesg.log "$( dmesg )" -m 0644
fi
(( $? == 0 )) && stat_done || stat_fail
--
1.7.1
More information about the arch-projects
mailing list