From: Lennart Poettering Date: Tue, 18 Jun 2024 07:55:20 +0000 (+0200) Subject: tmpfiles: insist on at least one configuration file being specified on --purge X-Git-Tag: v257-rc1~1111^2~7 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=41064a3c97c9a53c97bbe8a1de799a82c4374a2d;p=thirdparty%2Fsystemd.git tmpfiles: insist on at least one configuration file being specified on --purge Also, extend the man page explanation substantially, matching more closely what --create says. Fixes: #33349 --- diff --git a/man/systemd-tmpfiles.xml b/man/systemd-tmpfiles.xml index 9767aead851..2a494b9c5c7 100644 --- a/man/systemd-tmpfiles.xml +++ b/man/systemd-tmpfiles.xml @@ -151,12 +151,26 @@ - If this option is passed, all files and directories created by a - tmpfiles.d/ entry will be deleted. Keep in mind that by default, - /home is created by systemd-tmpfiles - (see /usr/lib/tmpfiles.d/home.conf). Therefore it is recommended - to first run systemd-tmpfiles --dry-run --purge to be certain which files - and directories will be deleted. + + If this option is passed, all files and directories marked for + creation by the tmpfiles.d/ files specified on the command + line will be deleted. Specifically, this acts on all files and directories + marked with f, F, d, D, + v, q, Q, p, + L, c, b, C, + w, e. If this switch is used at least one + tmpfiles.d/ file (or - for standard input) must be + specified on the command line or the invocation will be refused, for safety reasons (as otherwise + much of the installed system files might be removed). + + The primary usecase for this option is to automatically remove files and directories that + originally have been created on behalf of an installed packaged at package removal time. + + It is recommended to first run this command in combination with + (see below) to verify which files and directories will be deleted. + + Warning! This is is usually not the command you want! In most cases + is what you are looking for. diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index 3b3489ee622..9895e946964 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -4344,6 +4344,10 @@ static int parse_argv(int argc, char *argv[]) { return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "You need to specify at least one of --clean, --create, --remove, or --purge."); + if (FLAGS_SET(arg_operation, OPERATION_PURGE) && optind >= argc) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), + "Refusing --purge without specification of a configuration file."); + if (arg_replace && arg_cat_flags != CAT_CONFIG_OFF) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Option --replace= is not supported with --cat-config/--tldr.");