From owner-freebsd-hackers@FreeBSD.ORG Fri Dec 29 21:23:46 2006 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 71E9A16A412 for ; Fri, 29 Dec 2006 21:23:46 +0000 (UTC) (envelope-from erik.udo@gmail.com) Received: from satakieli.dnainternet.net (satakieli.dnainternet.net [212.149.75.40]) by mx1.freebsd.org (Postfix) with ESMTP id 3693413C486 for ; Fri, 29 Dec 2006 21:23:46 +0000 (UTC) (envelope-from erik.udo@gmail.com) Received: from [192.168.1.11] (host-212-149-186-30.kpylaajakaista.net [212.149.186.30]) by satakieli.dnainternet.net (Postfix) with ESMTP id 5AB71C8D7 for ; Fri, 29 Dec 2006 23:23:42 +0200 (EET) Message-ID: <4595875B.20609@gmail.com> Date: Fri, 29 Dec 2006 23:23:39 +0200 From: Erik Udo User-Agent: Thunderbird 1.5.0.9 (X11/20061226) MIME-Version: 1.0 To: freebsd-hackers@freebsd.org References: <4592C91C.2040801@gmail.com> <200612281237.kBSCbE2n047391@lurza.secnetix.de> <20061228.132844.-579333856.imp@bsdimp.com> <20061228.134053.-1548238884.imp@bsdimp.com> In-Reply-To: <20061228.134053.-1548238884.imp@bsdimp.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: Init.c, making it chroot X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Dec 2006 21:23:46 -0000 That's nice. But NetBSDs init.c executes /etc/rc before calling chroot(), and that's what i'm looking for, and for a moment tried to implement, but i'm not very familiar with FreeBSD code :) For example that kenv() came to me as a suprise. I'll have to try to implement the NetBSD way where /etc/rc is executed before chroot(). Ofcourse now that i dont have to use sysctls, it's alot easier. M. Warner Losh wrote: > BTW, here's a patch to test. Since FreeBSD has kenv(2), the patch is > actually very small. > > Warner > > > > ------------------------------------------------------------------------ > > 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 > #include > #include > +#include > #include > #include > #include > @@ -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. > */