Skip to content

Commit d6d0473

Browse files
poetteringkeszybz
authored andcommitted
Revert "util: Fine tune running_in_chroot() a bit" (systemd#5506)
This reverts commit 295ee98. Let'd revert this for now, see systemd#5446 for discussions. We want systemd-detect-virt --chroot to return true for all chroot-like stuff, for example mock environments which have use a mount namespace. The downside of this revert that systemctl will not work from our own namespaced services, anything with RootDirectory=/RootImage= set.
1 parent b7a09e3 commit d6d0473

File tree

1 file changed

+5
-20
lines changed

1 file changed

+5
-20
lines changed

src/basic/virt.c

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include "env-util.h"
2929
#include "fd-util.h"
3030
#include "fileio.h"
31-
#include "fs-util.h"
3231
#include "macro.h"
3332
#include "process-util.h"
3433
#include "stat-util.h"
@@ -570,30 +569,16 @@ int running_in_userns(void) {
570569
}
571570

572571
int running_in_chroot(void) {
573-
_cleanup_free_ char *self_mnt = NULL, *pid1_mnt = NULL;
574-
int r;
575-
576-
/* Try to detect whether we are running in a chroot() environment. Specifically, check whether we have a
577-
* different root directory than PID 1, even though we live in the same mount namespace as it. */
572+
int ret;
578573

579574
if (getenv_bool("SYSTEMD_IGNORE_CHROOT") > 0)
580575
return 0;
581576

582-
r = files_same("/proc/1/root", "/");
583-
if (r < 0)
584-
return r;
585-
if (r > 0)
586-
return 0;
587-
588-
r = readlink_malloc("/proc/self/ns/mnt", &self_mnt);
589-
if (r < 0)
590-
return r;
591-
592-
r = readlink_malloc("/proc/1/ns/mnt", &pid1_mnt);
593-
if (r < 0)
594-
return r;
577+
ret = files_same("/proc/1/root", "/");
578+
if (ret < 0)
579+
return ret;
595580

596-
return streq(self_mnt, pid1_mnt); /* Only if we live in the same namespace! */
581+
return ret == 0;
597582
}
598583

599584
static const char *const virtualization_table[_VIRTUALIZATION_MAX] = {

0 commit comments

Comments
 (0)