Changeset View
Changeset View
Standalone View
Standalone View
libexec/rc/rc.d/tmp
Show All 34 Lines | |||||
name="tmp" | name="tmp" | ||||
desc="Configure tmpfs" | desc="Configure tmpfs" | ||||
stop_cmd=':' | stop_cmd=':' | ||||
load_rc_config $name | load_rc_config $name | ||||
mount_tmpmfs() | mount_tmpmfs() | ||||
{ | { | ||||
if ! /bin/df /tmp | grep -q "^/dev/md[0-9].* /tmp"; then | while read line; do | ||||
case $line in | |||||
/dev/md[0-9]*\ /tmp) | |||||
return;; | |||||
esac | |||||
done <<*EOF | |||||
$(df /tmp) | |||||
*EOF | |||||
cy: Another way to do this, might be df /tmp | while read line... To me it looks cleaner. | |||||
Done Inline ActionsMy initial attempt actually used "df /tmp | while ...", but I find the here doc version more straight forward. Here is a version that uses "df /tmp | while ...": mount_tmpmfs() { df /tmp | while read line; do case $line in /dev/md[0-9]*\ /tmp) return 1;; esac done if [ $? = 0 ]; then mount_md ${tmpsize} /tmp "${tmpmfs_flags}" chmod 01777 /tmp fi } The while loop is executed in a sub-shell and thus needs to be exited with "return 1" to pass a value to the if condition. This is easy to understand if you know about the while loop being executed in a sub-shell, I think that the here-doc version does not require such knowledge. The pipe-based version requires 2 forked sub-processes (the df command and the shell executing the while loop), but the here-doc version only forks the df process and I do prefer it for these reasons. se: My initial attempt actually used "df /tmp | while ...", but I find the here doc version more… | |||||
Not Done Inline ActionsTo me the here-doc looks more efficient than pipe. glebius: To me the here-doc looks more efficient than pipe. | |||||
mount_md ${tmpsize} /tmp "${tmpmfs_flags}" | mount_md ${tmpsize} /tmp "${tmpmfs_flags}" | ||||
chmod 01777 /tmp | chmod 01777 /tmp | ||||
fi | |||||
} | } | ||||
# If we do not have a writable /tmp, create a memory | # If we do not have a writable /tmp, create a memory | ||||
# filesystem for /tmp. If /tmp is a symlink (e.g. to /var/tmp, | # filesystem for /tmp. If /tmp is a symlink (e.g. to /var/tmp, | ||||
# then it should already be writable). | # then it should already be writable). | ||||
# | # | ||||
case "${tmpmfs}" in | case "${tmpmfs}" in | ||||
[Aa][Uu][Tt][Oo]) | [Aa][Uu][Tt][Oo]) | ||||
if _tmpdir=$(mktemp -d -q /tmp/.diskless.XXXXXX); then | _tmpdir=/tmp/.diskless.$(dd if=/dev/random bs=32 count=1 status=none | sha256) | ||||
if mkdir -m 0700 ${_tmpdir}; then | |||||
rmdir ${_tmpdir} | rmdir ${_tmpdir} | ||||
else | else | ||||
if [ -h /tmp ]; then | if [ -h /tmp ]; then | ||||
echo "*** /tmp is a symlink to a non-writable area!" | echo "*** /tmp is a symlink to a non-writable area!" | ||||
echo "dropping into shell, ^D to continue anyway." | echo "dropping into shell, ^D to continue anyway." | ||||
/bin/sh | /bin/sh | ||||
else | else | ||||
mount_tmpmfs | mount_tmpmfs | ||||
Show All 9 Lines |
Another way to do this, might be df /tmp | while read line... To me it looks cleaner.