]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
detect-virt: add message at debug level
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 20 Apr 2023 15:42:57 +0000 (17:42 +0200)
committerMike Yuan <me@yhndnzj.com>
Thu, 20 Apr 2023 19:20:24 +0000 (03:20 +0800)
Normal users do not have permissions to access /proc/1/root, so
'systemd-detect-virt -r' fails, but the output, even at debug level
is cryptic:

$ SYSTEMD_LOG_LEVEL=debug build/systemd-detect-virt -r
Failed to check for chroot() environment: Permission denied

Let's make this a bit easier to figure out:

$ SYSTEMD_LOG_LEVEL=debug build/systemd-detect-virt -r
Cannot stat /proc/1/root: Permission denied
Failed to check for chroot() environment: Permission denied

I looked over other users of files_same(), and I think in general the message
at debug level is OK for them too.

src/basic/stat-util.c

index e97770707f2099c8a29ad1d0ac2eb932287efb7b..335daca2345217443e4ca31f81688c7ea79469c8 100644 (file)
@@ -190,10 +190,10 @@ int files_same(const char *filea, const char *fileb, int flags) {
         assert(fileb);
 
         if (fstatat(AT_FDCWD, filea, &a, flags) < 0)
-                return -errno;
+                return log_debug_errno(errno, "Cannot stat %s: %m", filea);
 
         if (fstatat(AT_FDCWD, fileb, &b, flags) < 0)
-                return -errno;
+                return log_debug_errno(errno, "Cannot stat %s: %m", fileb);
 
         return stat_inode_same(&a, &b);
 }