From owner-freebsd-arch@FreeBSD.ORG Tue Aug 24 08:03:10 2010 Return-Path: Delivered-To: freebsd-arch@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 506B01065697 for ; Tue, 24 Aug 2010 08:03:10 +0000 (UTC) (envelope-from ed@hoeg.nl) Received: from mx0.hoeg.nl (unknown [IPv6:2a01:4f8:101:5343::aa]) by mx1.freebsd.org (Postfix) with ESMTP id 9B9FE8FC15 for ; Tue, 24 Aug 2010 08:03:09 +0000 (UTC) Received: by mx0.hoeg.nl (Postfix, from userid 1000) id 0EA7B2A28CF5; Tue, 24 Aug 2010 10:03:09 +0200 (CEST) Date: Tue, 24 Aug 2010 10:03:09 +0200 From: Ed Schouten To: Marcel Moolenaar Message-ID: <20100824080309.GK64651@hoeg.nl> References: <20100823.171201.107001114053031707.imp@bsdimp.com> <8C76250B-E272-4807-BD0D-9F50D0BC5E10@mac.com> <20100824002350.042A45B3B@mail.bitblocks.com> <4CB9F7C8-39E8-4C3B-A3F8-A5A9EC178E7D@mac.com> <20100824080128.GJ64651@hoeg.nl> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="RVlUGXxwBj5SDcM9" Content-Disposition: inline In-Reply-To: <20100824080128.GJ64651@hoeg.nl> User-Agent: Mutt/1.5.20 (2009-06-14) Cc: "freebsd-arch@FreeBSD.org" Subject: Re: RFC: enhancing the root mount logic X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Aug 2010 08:03:10 -0000 --RVlUGXxwBj5SDcM9 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable * Ed Schouten wrote: > See the attachment. It seems like Mailman ate the attachment. %%% /*- * Copyright (c) 2010 Ed Schouten * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPO= SE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTI= AL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRI= CT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #include #include #include #include #include #include #include #include #include static void die(const char *msg) { int fd, serrno; serrno =3D errno; fd =3D open("/dev/console", O_RDWR); if (fd !=3D -1 && fd !=3D STDERR_FILENO) dup2(fd, STDERR_FILENO); errno =3D serrno; perror(msg); sleep(10); exit(1); } static void domount(const char * const list[], unsigned int elems) { struct iovec iov[elems]; unsigned int i; for (i =3D 0; i < elems; i++) { iov[i].iov_base =3D (char *)list[i]; iov[i].iov_len =3D strlen(list[i]) + 1; } if (nmount(iov, elems, 0) !=3D 0) die(list[1]); } static char const * const cdfs[] =3D { "fstype", "cd9660", "from", "/dev/iso9660/freebsd", "fspath", "/ro" }; static char const * const tmpfs[] =3D { "fstype", "tmpfs", "fspath", "/rw" }; static char const * const unionfs[] =3D { "fstype", "unionfs", "from", "/ro", "fspath", "/rw", "below", "", "whiteout", "whenneeded" }; static char const * const devfs[] =3D { "fstype", "devfs", "fspath", "/rw/dev" }; int main(int argc, char *argv[]) { /* Prevent foot shooting. */ if (getpid() !=3D 1) return (1); /* Perform mounts. */ domount(cdfs, sizeof cdfs / sizeof(char *)); domount(tmpfs, sizeof tmpfs / sizeof(char *)); domount(unionfs, sizeof unionfs / sizeof(char *)); domount(devfs, sizeof devfs / sizeof(char *)); /* chroot() into system and continue boot process. */ if (chroot("/rw") !=3D 0) die("chroot"); chdir("/"); /* Execute the real /sbin/init. */ execv(argv[0], argv); die("execv"); return (1); } %%% --=20 Ed Schouten WWW: http://80386.nl/ --RVlUGXxwBj5SDcM9 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.16 (FreeBSD) iEYEARECAAYFAkxzfL0ACgkQ52SDGA2eCwVX4gCfXGwT+BrR2p/fcSDwzlgtDk4r LREAn1cIzCh1vFzUWnlRdCLCc48wwe8e =vd94 -----END PGP SIGNATURE----- --RVlUGXxwBj5SDcM9--