Commit Graph

135 Commits

Author SHA1 Message Date
daurnimator 657cf7f4f8 tmpfiles: port to unquote_many_words() 2015-03-10 16:08:20 +01:00
Martin Pitt 6487ada88d tmpfiles: Fix handling of duplicate lines
Commit 3f93da987 accidentally dropped the "return 0" after detection of a
duplicate line. Put it back, to get back the documented and intended "first
match wins" behaviour.

https://launchpad.net/bugs/1428540
2015-03-05 16:14:07 +01:00
Hans-Peter Deifel d873e8778c tmpfiles: quietly ignore ACLs on unsupported filesystems
A warning is printed if ACLs cannot be retrieved for any reason other
than -ENOSYS. For -ENOSYS, debug log is printed.
2015-03-03 10:17:17 -05:00
Thomas Hindoe Paaboel Andersen 2eec67acbb remove unused includes
This patch removes includes that are not used. The removals were found with
include-what-you-use which checks if any of the symbols from a header is
in use.
2015-02-23 23:53:42 +01:00
Martin Pitt 484adfd914 tmpfiles: Fix parse_acl error message
parse_acl() returns the error instead of setting errno.
2015-02-17 12:47:51 +01:00
Zbigniew Jędrzejewski-Szmek 35888b67f7 tmpfiles: fix compilation without acl support 2015-02-03 21:28:46 -05:00
Thomas Hindoe Paaboel Andersen 4cd552bc50 partial revert of fed6df8
This one was acutally used to free xattr
2015-02-03 21:40:30 +01:00
Thomas Hindoe Paaboel Andersen fed6df828d remove unused variables 2015-02-02 22:58:06 +01:00
Lennart Poettering 7a7d5db71f tmpfiles: let's always use DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING() instead of defining our own string tables 2015-02-02 21:34:09 +01:00
Zbigniew Jędrzejewski-Szmek 294929f891 tmpfiles: accurately report creation results 2015-02-01 12:44:04 -05:00
Zbigniew Jędrzejewski-Szmek 612532206c tmpfiles: remove dead branch
In the test, p is a path to a directory, always absolute. dent->d_name
is a single path component, so they cannot be equal. The comparison
was wrong also for other reasons: D type supports globs, so direct
comparisons using streq are not enough.
2015-02-01 12:44:04 -05:00
Zbigniew Jędrzejewski-Szmek 79ca888f5a tmpfiles: fix help text
The help text, apart from being too long, did not describe what the options
really do.
2015-01-27 21:48:12 -05:00
Zbigniew Jędrzejewski-Szmek ebf31a1f58 tmpfiles: use casts instead of warning suppression
This warning got its own name only in gcc5, so the suppression does
not work in gcc4, and generates a warning of its own. Use a cast,
which is ugly too, but less so.
2015-01-26 10:39:03 -05:00
Zbigniew Jędrzejewski-Szmek df99a9ef5b tmpfiles: do not bump access times of directories we are cleaning up
Both plain opendir() and glob() will bump access time. Privileged
option O_NOATIME can be used to prevent the access time from being
updated. We already used it for subdirectories of the directories
which we were cleaning up. But for the directories specified directly
in the config files, we wouldn't do that. This means that,
paradoxically, our own temporary directories for PrivateTmp would stay
around forever, as long as one let systemd-tmpfiles-clean.service run
regularly, because they had their own glob patterns specified.

https://bugzilla.redhat.com/show_bug.cgi?id=1183684
2015-01-24 23:38:59 -05:00
Zbigniew Jędrzejewski-Szmek 582deb8446 tmpfiles: add debug statements for all actions
systemd-tmpfiles can be used by users, but it can be quite hard to
figure out the logic it follows, especially since the logic is in some
places rather torturous. Hopefuly this will make it easier for users
to understand what is happening.
2015-01-24 23:38:44 -05:00
Zbigniew Jędrzejewski-Szmek 7fcb4b9b17 tmpfiles: minor simplification 2015-01-23 00:12:52 -05:00
Zbigniew Jędrzejewski-Szmek dd4105b0a9 shared/acl-util: add mask only when needed, always add base ACLs
For ACLs to be valid, a set of entries for user, group, and other
must be always present. Always add those entries.

While at it, only add the mask ACL if it is actually required, i.e.
when at least on ACL for non-owner group or user exists.
2015-01-22 01:14:53 -05:00
Zbigniew Jędrzejewski-Szmek 50d9e46dbb tmpfiles: implement augmenting of existing ACLs
This is much more useful in practice (equivalent to setfacl -m).
2015-01-22 01:14:53 -05:00
Zbigniew Jędrzejewski-Szmek b705ab6a83 tmpfiles: make t and a globby, add their recursive versions T and A
For types which adapt existing files it is generally more useful to accept
globs.

In analogy to z and Z, add recursive versions using uppercase letters.

Technically, making a accept globs is backwards incompatible, but in
practice it probably isn't yet widely used and we can assume that most
people don't create files with wildcards in names.

Functions which are used as callbacks, but not directly on items, are
renamed not to have "item_" prefix.
2015-01-22 01:14:53 -05:00
Zbigniew Jędrzejewski-Szmek 081043cf06 tmpfiles: make recursive operation generic 2015-01-22 01:14:53 -05:00
Zbigniew Jędrzejewski-Szmek f8eeeaf9b7 tmpfiles: add 'a' type to set ACLs 2015-01-22 01:14:53 -05:00
Zbigniew Jędrzejewski-Szmek 3f93da9879 tmpfiles: attach an array of items to each path
The data structure used by tmpfiles is changed: instead of hashmaps
mapping {path → Item*} we now have hashmaps containing
{path -> ItemArray}, where ItemArray contains a pointer
to an array of Items.

For current code it doesn't matter much, but when we add new types it
is easier to simply add a new Item for a given path, then to coalesce
multiple lines into one Item.

In the future, this change will also make it possible to remember the
file and line where each Item originates, and use that in reporting
errors. Currently this is not possible, since each Item can be created
from multiple lines.
2015-01-22 01:14:53 -05:00
Zbigniew Jędrzejewski-Szmek 222c47f476 tmpfiles: make sure not to concatenate non-absolute path
If the path is absolute was only checked later.
Also do not check if path if absolute if we just
specified it starting with a slash.
2015-01-22 01:14:52 -05:00
Zbigniew Jędrzejewski-Szmek 5f255144ae tmpfiles: detect all combinations of + and !
The same algorithm as with - and @ in ExecStart= is used.
2015-01-22 01:14:52 -05:00
Zbigniew Jędrzejewski-Szmek 505ef0e36c tmpfiles: simplification
Certain conditions were checked more than once. Warning message
is improved.
2015-01-22 01:14:52 -05:00
Zbigniew Jędrzejewski-Szmek 2695c5c44e Add initialization helper for file_handle_union 2015-01-18 19:06:48 -05:00
Lennart Poettering 1e95893a89 tmpfiles: make gcc shut up 2015-01-06 20:33:46 +01:00
Zbigniew Jędrzejewski-Szmek 1db50423ba tmpfiles: finish with EXIT_FAILURE if anything failed
Return value is successful only if everything succeeded.
2015-01-06 09:57:40 -05:00
Lennart Poettering 65d6d8e32b tmpfiles: fix 'D' lines
https://bugs.freedesktop.org/show_bug.cgi?id=87953
2015-01-05 16:32:59 +01:00
Lennart Poettering d7b8eec7dc tmpfiles: add new line type 'v' for creating btrfs subvolumes 2014-12-28 02:08:40 +01:00
Filipe Brandenburger 2395eb17eb tmpfiles: remove spurious include of <sys/capability.h>
It does not use any functions from libcap directly. The CAP_MKNOD constant in
use by this file comes from <linux/capability.h> imported through "missing.h".

Tested that "systemd-tmpfiles" builds cleanly and works after this change.
2014-12-25 10:56:21 -05:00
Maciej Wereski ebf4e8013b tmpfiles, man: Add xattr support to tmpfiles
This patch makes it possible to set extended attributes on files created
by tmpfiles. This can be especially used to set SMACK security labels on
volatile files and directories.

It is done by adding new line of type "t". Such line should contain
attributes in Argument field, using following format:

name=value

All other fields are ignored.

If value contains spaces, then it must be surrounded by quotation marks.
User can also put quotation mark in value by escaping it with backslash.

Example:
D /var/run/cups - - - -
t /var/run/cups - - - - security.SMACK64=printing
2014-12-04 20:21:45 +01:00
Lennart Poettering fed1e721fd treewide: introduce UID_INVALID (and friends) as macro for (uid_t) -1 2014-11-28 20:55:04 +01:00
Michal Schmidt 4a62c710b6 treewide: another round of simplifications
Using the same scripts as in f647962d64 "treewide: yet more log_*_errno
+ return simplifications".
2014-11-28 19:57:32 +01:00
Michal Schmidt 56f64d9576 treewide: use log_*_errno whenever %m is in the format string
If the format string contains %m, clearly errno must have a meaningful
value, so we might as well use log_*_errno to have ERRNO= logged.

Using:
find . -name '*.[ch]' | xargs sed -r -i -e \
's/log_(debug|info|notice|warning|error|emergency)\((".*%m.*")/log_\1_errno(errno, \2/'

Plus some whitespace, linewrap, and indent adjustments.
2014-11-28 19:49:27 +01:00
Michal Schmidt 8d3d7072e6 treewide: a few more log_*_errno + return simplifications
The one in tmpfiles.c:create_item() even looks like it fixes a bug.
2014-11-28 19:17:24 +01:00
Michal Schmidt f647962d64 treewide: yet more log_*_errno + return simplifications
Using:
find . -name '*.[ch]' | while read f; do perl -i.mmm -e \
 'local $/;
  local $_=<>;
  s/(if\s*\([^\n]+\))\s*{\n(\s*)(log_[a-z_]*_errno\(\s*([->a-zA-Z_]+)\s*,[^;]+);\s*return\s+\g4;\s+}/\1\n\2return \3;/msg;
  print;'
 $f
done

And a couple of manual whitespace fixups.
2014-11-28 18:56:16 +01:00
Michal Schmidt da927ba997 treewide: no need to negate errno for log_*_errno()
It corrrectly handles both positive and negative errno values.
2014-11-28 13:29:21 +01:00
Michal Schmidt 0a1beeb642 treewide: auto-convert the simple cases to log_*_errno()
As a followup to 086891e5c1 "log: add an "error" parameter to all
low-level logging calls and intrdouce log_error_errno() as log calls
that take error numbers", use sed to convert the simple cases to use
the new macros:

find . -name '*.[ch]' | xargs sed -r -i -e \
's/log_(debug|info|notice|warning|error|emergency)\("(.*)%s"(.*), strerror\(-([a-zA-Z_]+)\)\);/log_\1_errno(-\4, "\2%m"\3);/'

Multi-line log_*() invocations are not covered.
And we also should add log_unit_*_errno().
2014-11-28 12:04:41 +01:00
Josh Triplett 7f0a55d432 Introduce CONF_DIRS_NULSTR helper to define standard conf dirs
Several different systemd tools define a nulstr containing a standard
series of configuration file directories, in /etc, /run, /usr/local/lib,
/usr/lib, and (#ifdef HAVE_SPLIT_USR) /lib.  Factor that logic out into
a new helper macro, CONF_DIRS_NULSTR.
2014-11-26 19:11:37 -05:00
Lennart Poettering ecabcf8b6e selinux: clean up selinux label function naming 2014-10-23 21:36:56 +02:00
WaLyong Cho cc56fafeeb mac: rename apis with mac_{selinux/smack}_ prefix 2014-10-23 17:13:15 +02:00
Dave Reisner e7aab54128 tmpfiles: compare return against correct errno
name_to_handle_at returns -EOPNOTSUPP, not -ENOTSUP.
2014-10-12 21:41:57 -04:00
Zbigniew Jędrzejewski-Szmek 9348f0e690 tmpfiles: use allocated buffer for path
Paths can in principle be longer then PATH_MAX, so
simply allocate the buffer with malloc().

CID #1237773
2014-10-01 08:43:09 -04:00
Richard Weinberger 9ed2a35e93 systemd-tmpfiles: Fix IGNORE_DIRECTORY_PATH age handling
If one has a config like:
d /tmp 1777 root root -
X /tmp/important_mount

All files below /tmp/important_mount will be deleted as the
/tmp/important_mount item will spuriously inherit a max age of 0
from /tmp.
/tmp has a max age of 0 but age_set is (of course) false.

This affects also the PrivateTmp feature of systemd.
All tmp files of such services will be deleted unconditionally
and can cause service failures and data loss.

Fix this by checking ->age_set in the IGNORE_DIRECTORY_PATH logic.
2014-09-26 17:38:40 +02:00
Michal Schmidt d5099efc47 hashmap: introduce hash_ops to make struct Hashmap smaller
It is redundant to store 'hash' and 'compare' function pointers in
struct Hashmap separately. The functions always comprise a pair.
Store a single pointer to struct hash_ops instead.

systemd keeps hundreds of hashmaps, so this saves a little bit of
memory.
2014-09-15 16:08:50 +02:00
Michael Olbrich 1924a97db5 tmpfiles: only execute chmod()/chown() when needed
This avoids errors like this, when the paths are already there with the
correct permissions and owner:

chmod(/var/spool) failed: Read-only file system
2014-08-18 18:25:30 +02:00
Zbigniew Jędrzejewski-Szmek 601185b43d Unify parse_argv style
getopt is usually good at printing out a nice error message when
commandline options are invalid. It distinguishes between an unknown
option and a known option with a missing arg. It is better to let it
do its job and not use opterr=0 unless we actually want to suppress
messages. So remove opterr=0 in the few places where it wasn't really
useful.

When an error in options is encountered, we should not print a lengthy
help() and overwhelm the user, when we know precisely what is wrong
with the commandline. In addition, since help() prints to stdout, it
should not be used except when requested with -h or --help.

Also, simplify things here and there.
2014-08-03 21:46:07 -04:00
Kay Sievers 2f3b873a49 tmpfiles: copy/link /usr/share/factory/ files when the source argument is omitted 2014-06-20 15:57:43 +02:00
Lennart Poettering e156347e04 tmpfiles: make sure "C" doesn't copy anything if the destination already exists
Previously it would recursively copy the entire tree in, and descend
into subdirectories even if the destination already exists. Let's do
what the documentation says and not do that.

If files down the tree shall be copied too, they should get their own
"C" lines.
2014-06-19 19:36:08 +02:00