On Mon, Feb 01, 2016 at 07:41:59AM -0800, Josh Triplett wrote: > On Mon, Feb 01, 2016 at 04:24:21PM +0100, Ondřej Surý wrote: > > Hi Michael, > > > > I never bothered to implement more than 'd', but I am happy to > > contribute my sysvrc shell snippet I use as replacement for systems > > without systemd-tmpfiles installed. > > > > ``` > > do_tmpfiles() { > > local type path mode user group age argument > > if [ -r "$1" ]; then > > if [ -x /bin/systemd-tmpfiles ]; then > > /bin/systemd-tmpfiles --create "$1" > > else > > while read type path mode user group age argument; do > > case "$type" in > > d) > > mkdir -p "$path"; > > chmod "$mode" "$path"; > > chown "$user:$group" "$path"; > > ;; > > \#*) > > ;; > > *) > > log_warning_msg "tmpfile.d type '$type' is not > > supported yet" > > ;; > > esac > > done < "$1" > > fi > > else > > log_warning_msg "tmpfiles.d file '$1' doesn't exist or is not > > readable" > > fi > > } > > ``` > > > > It should be fairly easy to implement the most common stuff used in > > Debian. > > Implementing the various operation letters makes up half the problem. > The other half involves handling the various tmpfiles.d directories and > the precedence between them. That includes the usual "override files > with the same filename" mechanism, but also: > > > All configuration files are sorted by their filename in lexicographic > > order, regardless of which of the directories they reside in. If > > multiple files specify the same path, the entry in the file with the > > lexicographically earliest name will be applied. All other conflicting > > entries will be logged as errors. When two lines are prefix and suffix > > of each other, then the prefix is always processed first, the suffix > > later. Lines that take globs are applied after those accepting no > > globs. If multiple operations shall be applied on the same file, (such > > as ACL, xattr, file attribute adjustments), these are always done in > > the same fixed order. Otherwise, the files/directories are processed > > in the order they are listed. > > That logic seems relatively straightforward (though fiddly) to implement > in a language with associative arrays, such as bash or Python, but not > in a language without them, such as POSIX sh.
Also, "Fields may be enclosed within quotes and contain C-style escapes.". And fields can contain a few substitution fields. See "man tmpfiles.d".