From 1401882fdd0ac5c024b2c50ef584c1e06c911c0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 26 Sep 2022 14:46:08 +0200 Subject: tmpfiles: downgrade message about unitialized-/etc If we're running with --root, or in a chroot (*), it's expected that machine-id and other specifiers will be unresolvable, so downgrade the warning to debug. Fixes #24655. (*) sd_booted() in principle means more than that, but nowadays systemd dominates and those others things are infrequently seen. --- src/tmpfiles/tmpfiles.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'src/tmpfiles') diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index 6cd19d929b..020219b176 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -69,6 +69,7 @@ #include "terminal-util.h" #include "umask-util.h" #include "user-util.h" +#include "virt.h" /* This reads all files listed in /etc/tmpfiles.d/?*.conf and creates * them in the file system. This is intended to be used to create @@ -285,20 +286,28 @@ static int specifier_directory(char specifier, const void *data, const char *roo static int log_unresolvable_specifier(const char *filename, unsigned line) { static bool notified = false; - /* In system mode, this is called when /etc is not fully initialized (e.g. - * in a chroot environment) where some specifiers are unresolvable. In user - * mode, this is called when some variables are not defined. These cases are - * not considered as an error so log at LOG_NOTICE only for the first time - * and then downgrade this to LOG_DEBUG for the rest. */ + /* In system mode, this is called when /etc is not fully initialized and some specifiers are + * unresolvable. In user mode, this is called when some variables are not defined. These cases are + * not considered a fatal error, so log at LOG_NOTICE only for the first time and then downgrade this + * to LOG_DEBUG for the rest. + * + * If we're running in a chroot (--root was used or sd_booted() reports that systemd is not running), + * always use LOG_DEBUG. We may be called to initialize a chroot before booting and there is no + * expectation that machine-id and other files will be populated. + */ + + int log_level = notified || arg_root || running_in_chroot() > 0 ? + LOG_DEBUG : LOG_NOTICE; log_syntax(NULL, - notified ? LOG_DEBUG : LOG_NOTICE, + log_level, filename, line, 0, - "Failed to resolve specifier: %s, skipping", + "Failed to resolve specifier: %s, skipping.", arg_user ? "Required $XDG_... variable not defined" : "uninitialized /etc/ detected"); if (!notified) - log_notice("All rules containing unresolvable specifiers will be skipped."); + log_full(log_level, + "All rules containing unresolvable specifiers will be skipped."); notified = true; return 0; -- cgit v1.2.1