Reputation:
How can a running C-program detect if it is running in "chroot" on illumos/solaris?
There is a Debian utility [1] which uses some tricks on linux, freebsd, hurd.
How to do it on illumos/solaris?
Upvotes: 1
Views: 291
Reputation:
I used this way:
#elif defined (__sun__)
/* Similar to Linux
* XXX: check zone?
* XXX: illumos kernel automatically mounts /proc on boot
*/
static int ischroot()
{
struct stat st1, st2;
if (stat("/", &st1))
return 2;
if (stat("/proc/1/root", &st2))
return 2;
if ((st1.st_dev == st2.st_dev) && (st1.st_ino == st2.st_ino))
return 1;
return 0;
}
#else
Upvotes: 1
Reputation: 18227
There's this thread on comp.unix.solaris which details various methods to find out whether Solaris runs inside a zone (container / chroot-on-lots-of-steroids) or a VM. Particularly extensive is the list in this posting (seems to have come from this blog post. I'll recreate some of the items relating to zones here - those that are available to non-root users.
/usr/bin/zonename
command tells you something different than "global"sched
in a non-zoned (or inside the "global" / admin zone) environment but zsched
inside a zone. prstat
command (similar to top
on other UN*Xes) has -z
/ -Z
command line options to restrict reporting to specific zones (-z
) or give statistics for all zones (-Z
); inside a zone, these options don't work / only show you the zone you're running inside.Hope that helps a little.
Upvotes: 2