From e76015738942246db70f444b3567afd1b132f824 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 18 Jun 2024 09:55:20 +0200 Subject: [PATCH] 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 (cherry picked from commit 41064a3c97c9a53c97bbe8a1de799a82c4374a2d) --- man/systemd-tmpfiles.xml | 26 ++++++++++++++++++++------ src/tmpfiles/tmpfiles.c | 4 ++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/man/systemd-tmpfiles.xml b/man/systemd-tmpfiles.xml index 9767aead85..2a494b9c5c 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 283be21d16..1704197207 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.");