Date: Thu, 28 Dec 2006 13:40:53 -0700 (MST) From: "M. Warner Losh" <imp@bsdimp.com> To: freebsd-hackers@freebsd.org, erik.udo@gmail.com, olli@lurza.secnetix.de Subject: Re: Init.c, making it chroot Message-ID: <20061228.134053.-1548238884.imp@bsdimp.com> In-Reply-To: <20061228.132844.-579333856.imp@bsdimp.com> References: <4592C91C.2040801@gmail.com> <200612281237.kBSCbE2n047391@lurza.secnetix.de> <20061228.132844.-579333856.imp@bsdimp.com>
next in thread | previous in thread | raw e-mail | index | archive | help
----Next_Part(Thu_Dec_28_13_40_53_2006_777)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit BTW, here's a patch to test. Since FreeBSD has kenv(2), the patch is actually very small. Warner ----Next_Part(Thu_Dec_28_13_40_53_2006_777)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="init_chroot" Index: init.c =================================================================== RCS file: /cache/ncvs/src/sbin/init/init.c,v retrieving revision 1.62 diff -u -r1.62 init.c --- init.c 8 Jun 2006 14:04:36 -0000 1.62 +++ init.c 28 Dec 2006 20:39:33 -0000 @@ -55,6 +55,7 @@ #include <db.h> #include <errno.h> #include <fcntl.h> +#include <kenv.h> #include <libutil.h> #include <paths.h> #include <signal.h> @@ -187,6 +188,7 @@ int main(int argc, char *argv[]) { + char init_chroot[PATH_MAX]; int c; struct sigaction sa; sigset_t mask; @@ -239,6 +241,12 @@ */ openlog("init", LOG_CONS|LOG_ODELAY, LOG_AUTH); + *init_chroot = '\0'; + kenv(KENV_GET, "init_chroot", init_chroot, sizeof(init_chroot)); + if (*init_chroot) + if (chdir(init_chroot) != 0 || chroot(".") != 0) + warning("Can't chroot to %s: %m", init_chroot); + /* * Create an initial session. */ ----Next_Part(Thu_Dec_28_13_40_53_2006_777)----
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20061228.134053.-1548238884.imp>