X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Futil.c;h=7f5fa05dca4d1beb15da5b82db6a6792198dec9b;hp=2e5827f32dcf3671a26545d5250312e265bcb8c3;hb=b4f10a5e8956d26f0bc6b9aef12846b57caee08b;hpb=bc8c2f5c549084df93c061b061f1e5b0d9d7046c diff --git a/src/util.c b/src/util.c index 2e5827f32..7f5fa05dc 100644 --- a/src/util.c +++ b/src/util.c @@ -2825,6 +2825,25 @@ int columns(void) { return parsed_columns; } +int running_in_chroot(void) { + struct stat a, b; + + zero(a); + zero(b); + + /* Only works as root */ + + if (stat("/proc/1/root", &a) < 0) + return -errno; + + if (stat("/", &b) < 0) + return -errno; + + return + a.st_dev != b.st_dev || + a.st_ino != b.st_ino; +} + static const char *const ioprio_class_table[] = { [IOPRIO_CLASS_NONE] = "none", [IOPRIO_CLASS_RT] = "realtime",