Date: Fri, 24 Oct 2003 14:00:40 -0700 (PDT) From: "Poul-Henning Kamp" <phk@phk.freebsd.dk> To: freebsd-bugs@FreeBSD.org Subject: Re: kern/58497: sysctl knob to return current process' jid Message-ID: <200310242100.h9OL0e2W048561@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR kern/58497; it has been noted by GNATS.
From: "Poul-Henning Kamp" <phk@phk.freebsd.dk>
To: "C. Stephen Gunn" <csg@waterspout.com>
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: kern/58497: sysctl knob to return current process' jid
Date: Fri, 24 Oct 2003 22:57:39 +0200
>There is no easy way to tell if a process is operating in a Jail
>environment.
Yes, in fact there is:
#include <stdio.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#include <sys/param.h>
#include <sys/user.h>
/*
* Exit 0 = no
* Exit 1 = maybe
* Exit 2 = yes
*/
int
main(int argc, char **argv)
{
int mib[4];
int i, l;
struct kinfo_proc buf;
mib[0] = CTL_KERN;
mib[1] = KERN_PROC;
mib[2] = KERN_PROC_PID;
mib[3] = getpid();
l = sizeof buf;
i = sysctl(mib, 4, &buf, &l, NULL, 0);
if (i != 0 || l != sizeof buf)
exit(1);
if (buf.kp_proc.p_flag & P_JAILED)
exit(2);
exit (0);
}
--
Poul-Henning Kamp | UNIX since Zilog Zeus 3.20
phk@FreeBSD.ORG | TCP/IP since RFC 956
FreeBSD committer | BSD since 4.3-tahoe
Never attribute to malice what can adequately be explained by incompetence.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200310242100.h9OL0e2W048561>
