sh/tmpfiles: Upstream clarifications & quoting fixes.
Upstream has clarified via IRC: - hardcoding /usr/lib/ is an explicit choice. It should NOT consider $libdir at all. - The z/Z relabel types should call restorecon, not chcon. - Whitespace is not allowed in tmpfiles.d/*.conf path entries, but is allowed in globs results. Fixed quoting of path arguments for this. Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
This commit is contained in:
parent
c75352af3d
commit
65be94a34a
@ -19,17 +19,19 @@ warninvalid() {
|
|||||||
} >&2
|
} >&2
|
||||||
|
|
||||||
relabel() {
|
relabel() {
|
||||||
|
local path
|
||||||
local paths=$1 mode=$2 uid=$3 gid=$4
|
local paths=$1 mode=$2 uid=$3 gid=$4
|
||||||
|
|
||||||
for path in ${paths}; do
|
for path in ${paths}; do
|
||||||
if [ -e $path ]; then
|
if [ -e "$path" ]; then
|
||||||
[ $uid != '-' ] && chown $CHOPTS "$uid" "$path"
|
[ $uid != '-' ] && chown $CHOPTS "$uid" "$path"
|
||||||
[ $gid != '-' ] && chgrp $CHOPTS "$gid" "$path"
|
[ $gid != '-' ] && chgrp $CHOPTS "$gid" "$path"
|
||||||
[ $mode != '-' ] && chmod $CHOPTS "$mode" "$path"
|
[ $mode != '-' ] && chmod $CHOPTS "$mode" "$path"
|
||||||
# TODO: SELinux relabel
|
[ -x /sbin/restorecon ] && restorecon $CHOPTS "$path"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
_b() {
|
_b() {
|
||||||
# Create a block device node if it doesn't exist yet
|
# Create a block device node if it doesn't exist yet
|
||||||
local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
|
local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
|
||||||
@ -49,7 +51,7 @@ _f() {
|
|||||||
|
|
||||||
[ $CREATE -gt 0 ] || return 0
|
[ $CREATE -gt 0 ] || return 0
|
||||||
|
|
||||||
if [ ! -e $path ]; then
|
if [ ! -e "$path" ]; then
|
||||||
install -m"$mode" -o"$uid" -g"$gid" /dev/null "$path"
|
install -m"$mode" -o"$uid" -g"$gid" /dev/null "$path"
|
||||||
[ -n "$arg" ] && _w "$@"
|
[ -n "$arg" ] && _w "$@"
|
||||||
fi
|
fi
|
||||||
@ -80,7 +82,7 @@ _D() {
|
|||||||
# Create or empty a directory
|
# Create or empty a directory
|
||||||
local path=$1 mode=$2 uid=$3 gid=$4
|
local path=$1 mode=$2 uid=$3 gid=$4
|
||||||
|
|
||||||
if [ -d $path ] && [ $REMOVE -gt 0 ]; then
|
if [ -d "$path" ] && [ $REMOVE -gt 0 ]; then
|
||||||
find "$path" -mindepth 1 -maxdepth 1 -xdev -exec rm -rf {} +
|
find "$path" -mindepth 1 -maxdepth 1 -xdev -exec rm -rf {} +
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -125,10 +127,10 @@ _r() {
|
|||||||
|
|
||||||
[ $REMOVE -gt 0 ] || return 0
|
[ $REMOVE -gt 0 ] || return 0
|
||||||
|
|
||||||
for path in "${paths}"; do
|
for path in ${paths}; do
|
||||||
if [ -f $path ]; then
|
if [ -f "$path" ]; then
|
||||||
rm -f "$path"
|
rm -f "$path"
|
||||||
elif [ -d $path ]; then
|
elif [ -d "$path" ]; then
|
||||||
rmdir "$path"
|
rmdir "$path"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
@ -142,8 +144,8 @@ _R() {
|
|||||||
|
|
||||||
[ $REMOVE -gt 0 ] || return 0
|
[ $REMOVE -gt 0 ] || return 0
|
||||||
|
|
||||||
for path in "${paths}"; do
|
for path in ${paths}; do
|
||||||
[ -d $path ] && rm -rf --one-file-system "$path"
|
[ -d "$path" ] && rm -rf --one-file-system "$path"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,9 +176,8 @@ _Z() {
|
|||||||
CREATE=0 REMOVE=0 CLEAN=0 VERBOSE=0 DRYRUN=0 error=0 LINENO=0
|
CREATE=0 REMOVE=0 CLEAN=0 VERBOSE=0 DRYRUN=0 error=0 LINENO=0
|
||||||
FILE=
|
FILE=
|
||||||
fragments=
|
fragments=
|
||||||
# TODO: The systemd spec explicitly says /usr/lib/, but it should probably be
|
# XXX: The harcoding of /usr/lib/ is an explicit choice by upstream
|
||||||
# OUTSIDE of lib entirely, or at the very least handle multilib systems better.
|
tmpfiles_dirs='/usr/lib/tmpfiles.d/ /etc/tmpfiles.d/ /run/tmpfiles.d/'
|
||||||
tmpfiles_dirs='/usr/lib64/tmpfiles.d/ /usr/lib/tmpfiles.d/ /etc/tmpfiles.d/ /run/tmpfiles.d/'
|
|
||||||
tmpfiles_basenames=''
|
tmpfiles_basenames=''
|
||||||
tmpfiles_d=''
|
tmpfiles_d=''
|
||||||
# Build a list of sorted unique basenames
|
# Build a list of sorted unique basenames
|
||||||
@ -212,7 +213,7 @@ while [ $# -gt 0 ]; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
if [ $(( CREATE + REMOVE )) -ne 1 ] ; then
|
if [ $(( CREATE + REMOVE )) -ne 1 ] ; then
|
||||||
printf 'usage: %s [--create] [--remove]\n' "${0##*/}"
|
printf 'usage: %s [--create] [--remove] [--clean] [--verbose] [--dry-run]\n' "${0##*/}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -230,14 +231,15 @@ for FILE in $tmpfiles_d ; do
|
|||||||
# d /run/user 0755 root root 10d -
|
# d /run/user 0755 root root 10d -
|
||||||
# Mode, UID, GID, Age, Argument may be omitted!
|
# Mode, UID, GID, Age, Argument may be omitted!
|
||||||
|
|
||||||
# TODO: Sorry, we don't handle whitespace in paths.
|
# XXX: Upstream says whitespace is NOT permitted in the Path argument.
|
||||||
|
# But IS allowed when globs are expanded for the x/r/R/z/Z types.
|
||||||
while read line; do
|
while read line; do
|
||||||
LINENUM=$(( LINENUM+1 ))
|
LINENUM=$(( LINENUM+1 ))
|
||||||
|
|
||||||
# This will fix up whitespace and comment lines
|
# This will skip over comments and empty lines
|
||||||
# skip over comments and empty lines
|
|
||||||
set -- $line
|
set -- $line
|
||||||
|
|
||||||
|
# Unless we have both command and path, skip this line.
|
||||||
if [ -z "$1" -o -z "$2" ]; then
|
if [ -z "$1" -o -z "$2" ]; then
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
Loading…
x
Reference in New Issue
Block a user