git: 24f44a445c48 - main - Remove dependency on files in /usr/bin
Stefan EÃer
se at FreeBSD.org
Tue Jan 19 11:56:51 UTC 2021
The branch main has been updated by se:
URL: https://cgit.FreeBSD.org/src/commit/?id=24f44a445c4875a329d3947c50083f3e8b9b37db
commit 24f44a445c4875a329d3947c50083f3e8b9b37db
Author: Stefan Eßer <se at FreeBSD.org>
AuthorDate: 2021-01-19 11:46:52 +0000
Commit: Stefan Eßer <se at FreeBSD.org>
CommitDate: 2021-01-19 11:56:23 +0000
Remove dependency on files in /usr/bin
In order to reduce the pre-requisites of this file, implement the
pattern matching and creation of a temporary test directory without
use of grep respectively mktemp.
The new version makes it possible to provide a writable /tmp in any
case and independently of other local or remote file systems (except /
and /dev) being mounted.
The use of "dd if=/dev/random" has the same dependency on /dev/random
being operational as the previous version that used "mktemp". If this
is found to be an issue on platforms that do not have gathered
sufficient entropy at the time when this scriot is run, I suggest to
replace the "dd" command with "ps lauxww" to get a somewhat random
test directory name.
Approved by: rgrimes, glebius, cy
MFC after: 4 weeks
Differential Revision: https://reviews.freebsd.org/D28209
---
libexec/rc/rc.d/tmp | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/libexec/rc/rc.d/tmp b/libexec/rc/rc.d/tmp
index a61321e058ee..7d270335cb27 100755
--- a/libexec/rc/rc.d/tmp
+++ b/libexec/rc/rc.d/tmp
@@ -40,10 +40,16 @@ load_rc_config $name
mount_tmpmfs()
{
- if ! /bin/df /tmp | grep -q "^/dev/md[0-9].* /tmp"; then
- mount_md ${tmpsize} /tmp "${tmpmfs_flags}"
- chmod 01777 /tmp
- fi
+ while read line; do
+ case $line in
+ /dev/md[0-9]*\ /tmp)
+ return;;
+ esac
+ done <<*EOF
+$(df /tmp)
+*EOF
+ mount_md ${tmpsize} /tmp "${tmpmfs_flags}"
+ chmod 01777 /tmp
}
# If we do not have a writable /tmp, create a memory
@@ -52,7 +58,8 @@ mount_tmpmfs()
#
case "${tmpmfs}" in
[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}
else
if [ -h /tmp ]; then
More information about the dev-commits-src-main
mailing list