/* Interestingly /proc/1/sched actually shows the host's PID for what we see as PID 1. If the PID
* shown there is not 1, we know we are in a PID namespace and hence a container. */
check_sched:
- r = read_one_line_file("/proc/1/sched", &m);
- if (r >= 0) {
- const char *t;
+ if (getpid_cached() == 1) {
+ r = read_one_line_file("/proc/1/sched", &m);
+ if (r >= 0) {
+ const char *t;
- t = strrchr(m, '(');
- if (!t)
- return -EIO;
+ t = strrchr(m, '(');
+ if (!t)
+ return -EIO;
- if (!startswith(t, "(1,")) {
- r = VIRTUALIZATION_CONTAINER_OTHER;
- goto finish;
- }
- } else if (r != -ENOENT)
- return r;
+ if (!startswith(t, "(1,")) {
+ r = VIRTUALIZATION_CONTAINER_OTHER;
+ goto finish;
+ }
+ } else if (r != -ENOENT)
+ return r;
+ }
/* If that didn't work, give up, assume no container manager. */
r = VIRTUALIZATION_NONE;