summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kahn Gillmor <dkg@fifthhorseman.net>2011-12-01 20:09:49 -0500
committerClint Adams <clint@debian.org>2011-12-01 20:52:27 -0500
commitf2e785480a7611850927fbf03849f5812124a9ce (patch)
tree6e22ff815e3c1602ae4a7f1da89df35af1a54b0b
parent543ac3b0716991f60bbcf8aa554fb32d1c807dce (diff)
downloaddebianutils-f2e785480a7611850927fbf03849f5812124a9ce.tar.gz
ischroot now "detects" a chroot under fakechroot (Closes: #650141)
-rw-r--r--ischroot.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/ischroot.c b/ischroot.c
index f280602..9af6ea2 100644
--- a/ischroot.c
+++ b/ischroot.c
@@ -10,6 +10,7 @@
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
+#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
@@ -36,6 +37,18 @@ void usage()
exit(0);
}
+/* return 1 if we are operating within a fakechroot environment,
+ return 0 otherwise */
+int isfakechroot()
+{
+ const char *fakechroot, *ldpreload;
+ return ((fakechroot = getenv("FAKECHROOT")) &&
+ (strcmp("true", fakechroot) == 0) &&
+ (NULL != getenv("FAKECHROOT_BASE")) &&
+ (ldpreload = getenv("LD_PRELOAD")) &&
+ (NULL != strstr(ldpreload, "libfakechroot.so")));
+}
+
#if defined (__linux__)
/* On Linux we can detect chroots by checking if the
@@ -183,7 +196,10 @@ int main(int argc, char *argv[])
exit(1);
}
- exit_status = ischroot();
+ if (isfakechroot())
+ exit_status = 0;
+ else
+ exit_status = ischroot();
if (exit_status == 2) {
if (default_true)