Commit Graph

615 Commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek
983dbcefe8 systemd-tmpfiles: use statx_mount_same
It was pointed out in review that the preexisting code should be updated
(https://github.com/systemd/systemd/pull/30380#discussion_r1426899180).
2024-02-12 13:34:25 +01:00
Zbigniew Jędrzejewski-Szmek
9e90d4f42e tmpfiles: implement --dry-run
The idea is simple: skip the final operation that creates or removes things
or changes the attributes, but otherwise go through the rest of the code.
This results in quite a lot of fairly repetitive conditions in the low-level
code. Another approach would be to print earlier, at a higher level, but then
we'd have less precise information about what is about to happen.
2024-02-12 13:33:30 +01:00
Zbigniew Jędrzejewski-Szmek
117aa0140f tmpfiles: simplify how a helper function is called
No functional change.
2024-02-09 17:57:42 +01:00
Zbigniew Jędrzejewski-Szmek
b1935cc943 tmpfiles: use dir_cleanup() for R and D
... i.e. apply nested config (exclusions and such) when executing R and D.

This fixes a long-standing RFE. The existing logic seems to have been an
accident of implementation. After all, if somebody specifies a config with
'R /foo; x /tmp/bar', then probably the goal is to remove stuff from under /foo,
but keep /tmp/bar. If they just wanted to nuke everything, then would not specify
the second item.

This also makes R and D use O_NOATIME, i.e. the access times of the directories
that are accessed will not be changed by the cleanup.

Obviously, we'll have to add this to NEWS and such.
Looking at the whole tmpfiles.d config in Fedora, this change has no effect.

The test cases are adjusted as appropriate. I also added another test case for
'R'/'D' with a file, just to test this code path more.

Replaces #20641.
Fixes #1633.
2024-02-09 17:57:42 +01:00
Zbigniew Jędrzejewski-Szmek
7eeda1da90 tmpfiles: split out helper to open a directory
In preparation for future commits.
2024-02-09 17:57:41 +01:00
Zbigniew Jędrzejewski-Szmek
db6873bfeb tmpfiles: drop unnecessary assignment 2024-02-09 17:57:41 +01:00
Zbigniew Jędrzejewski-Szmek
9c8a0ca69e tmpfiles: split out verbs in help
One of the three must always be specified, but they buried in a long list of
options in the output of --help. Make them more visible to draw the eye.

Also, drop "marked" from the description. It's supposed to mean "configured",
but it's a strange way to say that, and also it's generally obvious that the
program does what its configuration tells it to, and it's not going to remove
all files found on the system.
2024-02-09 17:57:41 +01:00
Zbigniew Jędrzejewski-Szmek
f7862b2a00 tree-wide: use normal spelling of "reopen"
It's a commonly used verb meaning "to open again".
2024-02-09 17:57:41 +01:00
Zbigniew Jędrzejewski-Szmek
ad36bb9fbb tmpfiles: break long log invocations and comments 2024-02-09 17:57:41 +01:00
Zbigniew Jędrzejewski-Szmek
e5876c29ad tmpfiles: inline variable declarations, use FOREACH_ARRAY and RET_GATHER 2024-02-09 17:57:41 +01:00
Zbigniew Jędrzejewski-Szmek
f6a1346e4e tmpfiles: split out helper to open and read a "config file"
No functional change.

Note that this function will be modified in subsequent commits, and the API
will change.
2024-02-09 17:57:41 +01:00
Zbigniew Jędrzejewski-Szmek
376d0495f5 tmpfiles: only populate uid and gid caches once
a3451c2c4c added offline uid/gid support in a way
where the <root>/etc/passwd and <root>/etc/group would be read anew for each
configuration file that was parsed. The result would always be the same, so I
assume that this was an oversight. Let's use a global cache and and read the
file just once.
2024-02-09 17:57:41 +01:00
Zbigniew Jędrzejewski-Szmek
5ac41a1672 tmpfiles: adjust vertical whitespace 2024-02-09 17:57:41 +01:00
Zbigniew Jędrzejewski-Szmek
37ee46f7c8 sysusers,tmpfiles: clarify error message for --replace
I was trying to run sysusers --replace, but the input file didn't have the right
suffix, and the message was very confusing. Let's split the message in two to
make it clearer that we care about the extension.
2024-02-09 17:57:41 +01:00
r-vdp
25e6ce1c11 Fix bug where systemd-tmpfiles gets stuck on fifos in tmp.
Fixes #30690.
2024-01-29 12:16:38 +00:00
Lennart Poettering
69f3c61990 tree-wide: port over various pieces of code to strv_extend_many() 2024-01-17 11:32:11 +01:00
Mike Yuan
bdd2036e81 hexdecoct: make unbase64mem and unhexmem always use SIZE_MAX 2024-01-09 03:59:15 +09:00
Antonio Alvarez Feijoo
7f13af72f8 tmpfiles: fix memory leak in arg_exclude_prefixes
When using the `--image` or `-E` options, `arg_exclude_prefixes` is extended via
the `exclude_default_prefixes` function, which calls `strv_extend_strv`, adding
values using `strdup` that must be freed on exit.

Also changing `arg_include_prefixes` to use the same model, although there is no
leak here.
2024-01-08 19:08:42 +01:00
Lennart Poettering
e745400bee Merge pull request #30769 from AdrianVovk/statx-timestamp
stat-util: Add statx version of timespec_load
2024-01-05 09:59:40 +01:00
Lennart Poettering
86e62e9e02 Merge pull request #30749 from poettering/tmpfiles-verb-fix
tmpfiles: correctly apply globbing when cleaning 'x' lines
2024-01-04 22:55:23 +01:00
Adrian Vovk
41fea218ee tmpfiles: Use statx_timestamp_load
This is a new utility function recently added. Let's use it.
2024-01-04 12:49:39 -05:00
Luca Boccassi
81a183800f tmpfiles: add --purge switch
Any file/directory created by a tmpfiles.d will be deleted. Useful for
purge/factory reset patterns.
2024-01-04 17:36:43 +01:00
Lennart Poettering
9cb3204f43 tmpfiles: 'x' takes globs, hence clean it with globbing 2024-01-04 14:58:40 +01:00
Lennart Poettering
d88b65f66d tmpfiles: always list tmpfiles line types in same order
otherwise it just gets too confusing to follow.
2024-01-04 14:57:59 +01:00
Frantisek Sumsal
f939a403ca tmpfiles: ignore EINVAL with --graceful
Add EINVAL to the list of ignored errnos, since acl_from_text() returns
EINVAL if it can't translate the given string.

~# cat /tmp/tmpfiles-test.conf
a+ /tmp/foo - - - - default:group:foo:rwx
~# build/systemd-tmpfiles /tmp/tmpfiles-test.conf --create --graceful
Failed to parse ACL "default:group:foo:rwx", ignoring: Invalid argument

Resolves: #29742
2023-10-28 10:14:07 +01:00
Yu Watanabe
1bd0cefcab tree-wide: fix typo 2023-10-26 12:42:49 +09:00
Luca Boccassi
7470e161cf Merge pull request #29553 from keszybz/analyze-cat-config-tldr
analyze/cat-config: add switch to print only "interesting" parts of conffiles
2023-10-25 09:53:19 +01:00
Zbigniew Jędrzejewski-Szmek
1be6a5db21 tmpfiles: add --tldr
This is like --cat-config, but omits the comments and empty lines.
The name is incoungrous with --cat-config, but I don't see a nice way to
call it that wouldn't be annoyingly long.

pager_open() is moved to cat_config() to remove some lines from run().
2023-10-24 18:32:17 +02:00
Lennart Poettering
0ff6ff2b29 tree-wide: port various parsers over to read_stripped_line() 2023-10-17 14:36:54 +02:00
Joerg Behrmann
7227dd816f treewide: fix typos
- mostly: usecase -> use case
- continously -> continuously
- single typos in docs/FILE_DESCRIPTOR_STORE.md
2023-09-19 10:05:38 +02:00
Mike Yuan
e22c60a9d5 io-util: introduce loop_write_full that takes a timeout
Also drop do_poll as the use case is covered
by timeout.
2023-09-07 20:30:44 +08:00
Lennart Poettering
cf1ab844a9 tree-wide: drop "static inline" use in .c files
"static inline" makes sense in .h files. But in .c files it's useless
decoration, the compiler should just make its own decisions there, and
it can do that.

hence, replace all remaining uses of "static line" by a simple" static"
in all .c files (but keep them in .h files, where they make sense)
2023-08-21 23:15:12 +02:00
Zbigniew Jędrzejewski-Szmek
13d84288bc tree-wide: use cocinnelle to apply _NEG_ macros 2023-08-16 12:52:56 +02:00
Daan De Meyer
ad6fae7ffc copy: Add support for creating subvolumes to copy_tree_at()
The subvolumes set is a set of source inodes similar to how the
denylist hashmap contains source inodes as keys. It indicates
directories in the source tree that should become subvolumes in
the target tree.
2023-08-14 18:46:08 +02:00
Daan De Meyer
e54c79ccc2 btrfs-util: Move subvolume creation to basic/btrfs.h
Also make btrfs_subvol_make() an openat style function.
2023-08-14 18:46:08 +02:00
Lennart Poettering
a5e4f3ab4e tmpfiles: move static vars into Context object
Same as #28722, but for tmpfiles rather than sysusers
2023-08-10 19:12:06 +01:00
Daan De Meyer
5dd814d7cd tmpfiles: Consider ENOPKG as information not available
We already handle the case where /etc/machine-id is empty. Let's make
sure we also handle the case where /etc/machine-id is "uninitialized".
2023-08-04 20:16:23 +02:00
Yu Watanabe
130c87b16a meson: merge declarations of normal and test executables 2023-08-03 20:37:16 +09:00
Yu Watanabe
6fab49e4ff meson: move declarations of hwdb, sysusers, and tmpfiles 2023-08-01 21:37:31 +09:00
Dmitry V. Levin
08b8e9130e btrfs-util,tmpfiles: cleanup use of ERRNO_IS_NOT_SUPPORTED()
Given that ERRNO_IS_NOT_SUPPORTED() also matches positive values,
make sure this macro is not called with arguments that do not have
errno semantics.

In this case the arguments passed to ERRNO_IS_NOT_SUPPORTED() are the
values returned by btrfs_subvol_make_fd() which is not expected to
return any positive values, but let's be consistent anyway and move
ERRNO_IS_NOT_SUPPORTED() invocations to the branches where
the return values are known to be negative.
2023-07-28 12:28:35 +00:00
Lennart Poettering
b50aadaff2 tmpfiles: teach tmpfiles the new XDG_STATE_HOME variable too 2023-06-28 22:13:13 +02:00
Daan De Meyer
08c25eee34 tmpfiles: Don't log about harmless errors when trying to lock file
Let's make sure we don't log if the file is a symlink or does not
exist.
2023-06-20 15:22:47 +02:00
Daan De Meyer
b572e8da41 tmpfiles: Fix BSD lock logging messages 2023-06-20 15:22:47 +02:00
Frantisek Sumsal
9a27ef092e tree-wide: fix a couple of typos
As reported by Fossies.org.
2023-06-15 20:52:45 +02:00
Daan De Meyer
cf91b9155c chattr-util: Make chattr_full() an openat() style function 2023-06-06 14:42:03 +02:00
Yu Watanabe
5d2a48da12 tree-wide: use _cleanup_set_free_ and friends
Instead of _cleanup_(set_freep) or so.
2023-06-01 06:47:48 +09:00
Daan De Meyer
420d2e3136 fs-util: Add XOpenFlags with XO_LABEL flag to have xopenat() MAC label files/dirs 2023-05-31 13:15:56 +02:00
Daan De Meyer
a452c807a4 label: Introduce LabelOps to do pre/post labelling operations
By default, label_ops is initialized with a NULL pointer which translates
to noop labelling operations. In mac_selinux_init() and the new mac_smack_init(),
we initialize label_ops with a MAC specific LabelOps pointer.

We also introduce mac_init() to initialize any configured MACs and replace all
usages of mac_selinux_init() with mac_init().
2023-05-31 13:15:53 +02:00
Daan De Meyer
0690160e2c label: Rename to label-util.h 2023-05-30 14:50:56 +02:00
Will Fancher
4b6621fef3 tmpfiles: Allow C escapes
Fixes #26955
2023-05-26 00:45:54 -04:00