From: "Robin H. Johnson" <robbat2@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/openrc:master commit in: sh/
Date: Mon, 12 Mar 2012 08:38:02 +0000 (UTC) [thread overview]
Message-ID: <1331541451.c75352af3d787377c4aa62baa1331f37db3d1d97.robbat2@gentoo> (raw)
commit: c75352af3d787377c4aa62baa1331f37db3d1d97
Author: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
AuthorDate: Mon Mar 12 08:28:44 2012 +0000
Commit: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
CommitDate: Mon Mar 12 08:37:31 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=c75352af
sh/tmpfiles: tmpfiles.d support.
This is the baseline support for tmpfiles.d.
Still missing:
- SELinux relabel, pending upstream clarification
- LIBDIR vs multilib systems, pending upstream clarification
- Whitespace in paths?
- Clean support not implemented
- "x" exclude type not implemented
X-Gentoo-Bug: 396003
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=396003
Signed-off-by: Robin H. Johnson <robbat2 <AT> gentoo.org>
---
sh/.gitignore | 1 +
sh/Makefile | 4 +-
sh/tmpfiles.sh.in | 286 +++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 289 insertions(+), 2 deletions(-)
diff --git a/sh/.gitignore b/sh/.gitignore
index f67b992..3f6ef3f 100644
--- a/sh/.gitignore
+++ b/sh/.gitignore
@@ -9,3 +9,4 @@ init-early.sh
ifwatchd-carrier.sh
ifwatchd-nocarrier.sh
udhcpc-hook.sh
+tmpfiles.sh
diff --git a/sh/Makefile b/sh/Makefile
index 15b24d0..4df8fde 100644
--- a/sh/Makefile
+++ b/sh/Makefile
@@ -1,8 +1,8 @@
DIR= ${LIBEXECDIR}/sh
SRCS= init.sh.in functions.sh.in gendepends.sh.in init-common-post.sh.in \
- rc-functions.sh.in runscript.sh.in ${SRCS-${OS}}
+ rc-functions.sh.in runscript.sh.in tmpfiles.sh.in ${SRCS-${OS}}
INC= init-common-post.sh rc-mount.sh functions.sh rc-functions.sh
-BIN= gendepends.sh init.sh runscript.sh ${BIN-${OS}}
+BIN= gendepends.sh init.sh runscript.sh tmpfiles.sh ${BIN-${OS}}
INSTALLAFTER= _installafter
diff --git a/sh/tmpfiles.sh.in b/sh/tmpfiles.sh.in
new file mode 100755
index 0000000..9c73897
--- /dev/null
+++ b/sh/tmpfiles.sh.in
@@ -0,0 +1,286 @@
+#!/bin/sh
+# This is a reimplementation of the systemd tmpfiles.d code
+# Control creation, deletion, and cleaning of volatile and temporary files
+#
+# Copyright (c) 2012 Gentoo Foundation
+#
+# This instance based on the Arch Linux version:
+# http://projects.archlinux.org/initscripts.git/tree/arch-tmpfiles
+# As of 2012/01/01
+#
+# See the tmpfiles.d manpage as well:
+# http://0pointer.de/public/systemd-man/tmpfiles.d.html
+# This script should match the manpage as of 2012/03/12
+#
+
+warninvalid() {
+ printf "tmpfiles: ignoring invalid entry on line %d of \`%s'\n" "$LINENUM" "$FILE"
+ error=$(( error+1 ))
+} >&2
+
+relabel() {
+ local paths=$1 mode=$2 uid=$3 gid=$4
+
+ for path in ${paths}; do
+ if [ -e $path ]; then
+ [ $uid != '-' ] && chown $CHOPTS "$uid" "$path"
+ [ $gid != '-' ] && chgrp $CHOPTS "$gid" "$path"
+ [ $mode != '-' ] && chmod $CHOPTS "$mode" "$path"
+ # TODO: SELinux relabel
+ fi
+ done
+}
+_b() {
+ # Create a block device node if it doesn't exist yet
+ local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
+ [ ! -e "$path" ] && mknod $path b ${arg%:*} ${arg#*:}
+}
+
+_c() {
+ # Create a character device node if it doesn't exist yet
+ local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
+ [ ! -e "$path" ] && mknod $path c ${arg%:*} ${arg#*:}
+}
+
+
+_f() {
+ # Create a file if it doesn't exist yet
+ local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
+
+ [ $CREATE -gt 0 ] || return 0
+
+ if [ ! -e $path ]; then
+ install -m"$mode" -o"$uid" -g"$gid" /dev/null "$path"
+ [ -n "$arg" ] && _w "$@"
+ fi
+}
+
+_F() {
+ # Create or truncate a file
+ local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
+
+ [ $CREATE -gt 0 ] || return 0
+
+ install -m"$mode" -o"$uid" -g"$gid" /dev/null "$path"
+ [ -n "$arg" ] && _w "$@"
+}
+
+_d() {
+ # Create a directory if it doesn't exist yet
+ local path=$1 mode=$2 uid=$3 gid=$4
+
+ [ $CREATE -gt 0 ] || return 0
+
+ if [ ! -d "$path" ]; then
+ install -d -m"$mode" -o"$uid" -g"$gid" "$path"
+ fi
+}
+
+_D() {
+ # Create or empty a directory
+ local path=$1 mode=$2 uid=$3 gid=$4
+
+ if [ -d $path ] && [ $REMOVE -gt 0 ]; then
+ find "$path" -mindepth 1 -maxdepth 1 -xdev -exec rm -rf {} +
+ fi
+
+ if [ $CREATE -gt 0 ]; then
+ install -d -m"$mode" -o"$uid" -g"$gid" "$path"
+ fi
+}
+
+_L() {
+ # Create a symlink if it doesn't exist yet
+ local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
+ [ ! -e "$path" ] && ln -s "$args" "$path"
+}
+
+_p() {
+ # Create a named pipe (FIFO) if it doesn't exist yet
+ local path=$1 mode=$2 uid=$3 gid=$4
+
+ [ $CREATE -gt 0 ] || return 0
+
+ if [ ! -p "$path" ]; then
+ mkfifo -m$mode "$path"
+ chown "$uid:$gid" "$path"
+ fi
+}
+
+_x() {
+ # Ignore a path during cleaning. Use this type to exclude paths from clean-up as
+ # controlled with the Age parameter. Note that lines of this type do not
+ # influence the effect of r or R lines. Lines of this type accept shell-style
+ # globs in place of of normal path names.
+ :
+ # XXX: we don't implement this
+}
+
+_r() {
+ # Remove a file or directory if it exists. This may not be used to remove
+ # non-empty directories, use R for that. Lines of this type accept shell-style
+ # globs in place of normal path names.
+ local path
+ local paths=$1
+
+ [ $REMOVE -gt 0 ] || return 0
+
+ for path in "${paths}"; do
+ if [ -f $path ]; then
+ rm -f "$path"
+ elif [ -d $path ]; then
+ rmdir "$path"
+ fi
+ done
+}
+
+_R() {
+ # Recursively remove a path and all its subdirectories (if it is a directory).
+ # Lines of this type accept shell-style globs in place of normal path names.
+ local path
+ local paths=$1
+
+ [ $REMOVE -gt 0 ] || return 0
+
+ for path in "${paths}"; do
+ [ -d $path ] && rm -rf --one-file-system "$path"
+ done
+}
+
+_w() {
+ # Write the argument parameter to a file, if it exists.
+ local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
+ [ -f "$path" ] && echo "$arg" >>"$path"
+}
+
+_z() {
+ # Set ownership, access mode and relabel security context of a file or
+ # directory if it exists. Lines of this type accept shell-style globs in
+ # place of normal path names.
+ [ $CREATE -gt 0 ] || return 0
+
+ relabel "$@"
+}
+
+_Z() {
+ # Recursively set ownership, access mode and relabel security context of a
+ # path and all its subdirectories (if it is a directory). Lines of this type
+ # accept shell-style globs in place of normal path names.
+ [ $CREATE -gt 0 ] || return 0
+
+ CHOPTS=-R relabel "$@"
+}
+
+CREATE=0 REMOVE=0 CLEAN=0 VERBOSE=0 DRYRUN=0 error=0 LINENO=0
+FILE=
+fragments=
+# TODO: The systemd spec explicitly says /usr/lib/, but it should probably be
+# OUTSIDE of lib entirely, or at the very least handle multilib systems better.
+tmpfiles_dirs='/usr/lib64/tmpfiles.d/ /usr/lib/tmpfiles.d/ /etc/tmpfiles.d/ /run/tmpfiles.d/'
+tmpfiles_basenames=''
+tmpfiles_d=''
+# Build a list of sorted unique basenames
+# directories declared later in the tmpfiles_d array will override earlier
+# directories, on a per file basename basis.
+# `/etc/tmpfiles.d/foo.conf' supersedes `/usr/lib/tmpfiles.d/foo.conf'.
+# `/run/tmpfiles/foo.conf' will always be read after `/etc/tmpfiles.d/bar.conf'
+for d in ${tmpfiles_dirs} ; do
+ [ -d $d ] && for f in ${d}/*.conf ; do
+ [ -f $f ] && tmpfiles_basenames="${tmpfiles_basenames}\n${f##*/}"
+ done # for f in ${d}
+done # for d in ${tmpfiles_dirs}
+tmpfiles_basenames="`printf "${tmpfiles_basenames}\n" | sort | uniq`"
+
+for b in $tmpfiles_basenames ; do
+ real_f=''
+ for d in $tmpfiles_dirs ; do
+ f=${d}/${b}
+ [ -f "${f}" ] && real_f=$f
+ done
+ [ -f "${real_f}" ] && tmpfiles_d="${tmpfiles_d} ${real_f}"
+done
+
+while [ $# -gt 0 ]; do
+ case $1 in
+ --create) CREATE=1 ;;
+ --remove) REMOVE=1 ;;
+ --clean) CLEAN=1 ;; # TODO: Not implemented
+ --verbose) VERBOSE=1 ;;
+ --dryrun|--dry-run) DRYRUN=1 ;;
+ esac
+ shift
+done
+
+if [ $(( CREATE + REMOVE )) -ne 1 ] ; then
+ printf 'usage: %s [--create] [--remove]\n' "${0##*/}"
+ exit 1
+fi
+
+error=0
+
+# loop through the gathered fragments, sorted globally by filename.
+# `/run/tmpfiles/foo.conf' will always be read after `/etc/tmpfiles.d/bar.conf'
+for FILE in $tmpfiles_d ; do
+ LINENUM=0
+
+ ### FILE FORMAT ###
+ # XXX: We ignore the 'Age' parameter
+ # 1 2 3 4 5 6 7
+ # Cmd Path Mode UID GID Age Argument
+ # d /run/user 0755 root root 10d -
+ # Mode, UID, GID, Age, Argument may be omitted!
+
+ # TODO: Sorry, we don't handle whitespace in paths.
+ while read line; do
+ LINENUM=$(( LINENUM+1 ))
+
+ # This will fix up whitespace and comment lines
+ # skip over comments and empty lines
+ set -- $line
+
+ if [ -z "$1" -o -z "$2" ]; then
+ continue
+ fi
+
+ # whine about invalid entries
+ case $1 in
+ f|F|w|d|D|p|L|c|b|x|r|R|z|Z) ;;
+ *) warninvalid ; continue ;;
+ esac
+
+ cmd=$1
+ path=$2
+
+ # fall back on defaults when parameters are passed as '-'
+ if [ "$3" = '-' -o "$3" = '' ]; then
+ case ${1} in
+ p|f|F) mode=0644 ;;
+ d|D) mode=0755 ;;
+ z|Z|x|r|R|L) ;;
+ esac
+ else
+ mode=$3
+ fi
+ uid=$4
+ gid=$5
+ age=$6
+ arg=$7
+
+ [ ${4} = '-' ] && uid=0
+ [ ${5} = '-' ] && gid=0
+ [ ${6} = '-' ] && age=0
+ [ ${7} = '-' ] && arg=''
+ set -- "$path" "$mode" "$uid" "$gid" "$age" "$arg"
+
+ [ "$VERBOSE" -eq "1" ] && echo _$cmd "$@"
+ if [ "${DRYRUN}" -eq "0" ]; then
+ _$cmd "$@"
+ rc=$?
+ [ $rc -ne 0 ] && error=$((error + 1))
+ fi
+ done <$FILE
+done
+
+exit $error
+
+# vim: set ts=2 sw=2 sts=2 noet ft=sh:
next reply other threads:[~2012-03-12 8:38 UTC|newest]
Thread overview: 148+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-12 8:38 Robin H. Johnson [this message]
-- strict thread matches above, loose matches on Subject: below --
2018-06-15 22:45 [gentoo-commits] proj/openrc:master commit in: sh/ William Hubbs
2018-05-22 22:12 William Hubbs
2018-03-12 2:43 William Hubbs
2018-02-28 18:45 William Hubbs
2018-02-28 18:45 William Hubbs
2018-02-23 21:53 William Hubbs
2017-12-01 21:48 William Hubbs
2017-10-26 18:58 William Hubbs
2017-10-26 18:58 William Hubbs
2017-10-25 20:10 William Hubbs
2017-09-29 17:52 William Hubbs
2017-09-22 22:25 William Hubbs
2017-09-18 18:07 William Hubbs
2017-09-15 20:32 William Hubbs
2017-09-15 18:44 William Hubbs
2017-09-15 18:31 William Hubbs
2017-09-14 15:57 William Hubbs
2017-09-14 15:57 William Hubbs
2017-08-15 22:19 William Hubbs
2017-03-23 18:27 William Hubbs
2017-02-24 0:19 William Hubbs
2016-12-18 17:54 William Hubbs
2016-12-18 17:22 William Hubbs
2016-12-17 22:57 William Hubbs
2016-09-22 23:21 William Hubbs
2016-09-20 16:36 William Hubbs
2016-09-19 23:05 William Hubbs
2016-09-14 19:00 William Hubbs
2016-09-13 17:54 William Hubbs
2016-09-12 17:59 William Hubbs
2016-07-26 15:54 William Hubbs
2016-07-25 20:54 William Hubbs
2016-07-25 20:54 William Hubbs
2016-07-25 20:54 William Hubbs
2016-05-24 16:43 William Hubbs
2016-05-24 16:43 William Hubbs
2016-02-19 21:34 William Hubbs
2016-01-19 23:02 William Hubbs
2015-12-09 18:42 William Hubbs
2015-12-01 18:31 William Hubbs
2015-10-13 22:45 William Hubbs
2015-10-13 22:45 William Hubbs
2015-10-13 13:36 William Hubbs
2015-10-06 17:17 William Hubbs
2015-10-04 20:37 William Hubbs
2015-08-04 19:41 William Hubbs
2015-07-10 18:26 William Hubbs
2015-07-10 18:26 William Hubbs
2015-05-14 19:29 William Hubbs
2015-05-13 21:56 William Hubbs
2015-04-21 21:33 William Hubbs
2015-04-08 15:33 William Hubbs
2015-03-29 23:37 William Hubbs
2015-01-12 21:02 William Hubbs
2014-09-11 19:06 William Hubbs
2014-09-11 17:03 William Hubbs
2014-08-28 14:49 William Hubbs
2014-08-28 14:49 William Hubbs
2014-08-22 19:10 William Hubbs
2014-08-13 15:07 ` William Hubbs
2014-08-22 19:10 William Hubbs
2014-08-13 20:29 ` William Hubbs
2014-08-22 19:10 William Hubbs
2014-08-07 18:35 ` William Hubbs
2014-07-16 18:14 William Hubbs
2014-07-10 17:08 William Hubbs
2014-07-10 17:08 William Hubbs
2014-06-21 0:44 William Hubbs
2014-06-20 21:22 William Hubbs
2014-05-26 6:52 Robin H. Johnson
2014-04-03 18:05 William Hubbs
2014-01-18 8:50 William Hubbs
2014-01-18 7:56 William Hubbs
2013-12-11 4:47 William Hubbs
2013-11-30 21:33 Mike Frysinger
2013-10-31 21:09 William Hubbs
2013-09-27 21:22 William Hubbs
2013-07-27 16:12 William Hubbs
2013-07-26 1:56 William Hubbs
2013-07-25 6:01 William Hubbs
2013-07-23 23:01 William Hubbs
2013-07-23 23:01 William Hubbs
2013-07-16 18:56 William Hubbs
2013-07-16 18:56 William Hubbs
2013-07-16 18:56 William Hubbs
2013-06-24 20:46 William Hubbs
2013-06-24 20:46 William Hubbs
2013-05-26 2:06 William Hubbs
2013-05-26 1:15 William Hubbs
2013-05-05 19:29 William Hubbs
2013-04-03 16:34 William Hubbs
2013-03-11 6:11 William Hubbs
2013-02-24 3:38 William Hubbs
2013-02-19 22:53 William Hubbs
2013-02-17 2:49 William Hubbs
2013-02-16 7:30 William Hubbs
2013-01-17 3:14 Mike Frysinger
2013-01-15 18:36 William Hubbs
2013-01-15 18:21 William Hubbs
2012-12-22 15:47 William Hubbs
2012-12-22 14:40 William Hubbs
2012-12-19 17:43 William Hubbs
2012-12-07 15:48 William Hubbs
2012-12-06 22:51 William Hubbs
2012-11-26 3:45 William Hubbs
2012-11-06 22:41 William Hubbs
2012-11-05 21:25 Robin H. Johnson
2012-10-22 0:53 William Hubbs
2012-10-22 0:53 William Hubbs
2012-10-21 19:51 William Hubbs
2012-10-17 23:19 William Hubbs
2012-09-26 22:12 Robin H. Johnson
2012-08-16 18:45 Robin H. Johnson
2012-07-02 18:27 William Hubbs
2012-05-16 22:00 Christian Ruppert
2012-05-02 19:50 William Hubbs
2012-04-26 17:59 William Hubbs
2012-04-26 17:21 William Hubbs
2012-04-26 17:12 William Hubbs
2012-04-26 16:28 William Hubbs
2012-03-12 19:05 Robin H. Johnson
2012-02-09 9:56 Robin H. Johnson
2012-01-29 15:53 William Hubbs
2012-01-28 18:26 Christian Ruppert
2012-01-27 4:18 William Hubbs
2012-01-17 18:09 William Hubbs
2011-11-18 14:39 William Hubbs
2011-11-18 6:06 William Hubbs
2011-11-02 13:42 William Hubbs
2011-09-18 20:07 Mike Frysinger
2011-09-13 3:20 William Hubbs
2011-09-12 15:48 Christian Ruppert
2011-09-12 15:48 Christian Ruppert
2011-09-12 15:48 Christian Ruppert
2011-09-07 20:14 William Hubbs
2011-09-07 3:21 William Hubbs
2011-07-26 17:29 William Hubbs
2011-07-06 14:55 William Hubbs
2011-07-03 4:34 William Hubbs
2011-06-27 17:11 William Hubbs
2011-06-27 16:56 William Hubbs
2011-06-04 0:43 Mike Frysinger
2011-05-16 22:49 Mike Frysinger
2011-05-11 19:55 William Hubbs
2011-04-19 16:01 William Hubbs
2011-04-18 22:39 William Hubbs
2011-03-25 0:18 William Hubbs
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1331541451.c75352af3d787377c4aa62baa1331f37db3d1d97.robbat2@gentoo \
--to=robbat2@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox