From owner-svn-src-all@freebsd.org Wed May 11 10:03:15 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 3DD1BB34B06; Wed, 11 May 2016 10:03:15 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id EA79112DD; Wed, 11 May 2016 10:03:14 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u4BA3EMX008411; Wed, 11 May 2016 10:03:14 GMT (envelope-from trasz@FreeBSD.org) Received: (from trasz@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u4BA3ERv008410; Wed, 11 May 2016 10:03:14 GMT (envelope-from trasz@FreeBSD.org) Message-Id: <201605111003.u4BA3ERv008410@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: trasz set sender to trasz@FreeBSD.org using -f From: Edward Tomasz Napierala Date: Wed, 11 May 2016 10:03:14 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r299419 - head/sbin/init X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 May 2016 10:03:15 -0000 Author: trasz Date: Wed May 11 10:03:13 2016 New Revision: 299419 URL: https://svnweb.freebsd.org/changeset/base/299419 Log: When rerooting, take the init(8) path from argv[0] instead of fetching it via kern.proc.pathname sysctl(2). In some cases - booting from NFS or rerooting after replacing the init binary with a new one - the sysctl would fail. In other cases - after upgrading, which moves the old init to /sbin/init.bak - it would return /sbin/init.bak, which is the actual path of the running init, instead of /sbin/init. Reported by: Melissa Jenkins , jilles@ MFC after: 1 month Sponsored by: The FreeBSD Foundation Modified: head/sbin/init/init.c Modified: head/sbin/init/init.c ============================================================================== --- head/sbin/init/init.c Wed May 11 09:42:24 2016 (r299418) +++ head/sbin/init/init.c Wed May 11 10:03:13 2016 (r299419) @@ -138,6 +138,7 @@ static int Reboot = FALSE; static int howto = RB_AUTOBOOT; static int devfs; +static char *init_path_argv0; static void transition(state_t); static state_t requested_transition; @@ -246,6 +247,11 @@ invalid: #endif errx(1, "already running"); } + + init_path_argv0 = strdup(argv[0]); + if (init_path_argv0 == NULL) + err(1, "strdup"); + /* * Note that this does NOT open a file... * Does 'init' deserve its own facility number? @@ -755,25 +761,12 @@ static state_func_t reroot(void) { void *buf; - char init_path[PATH_MAX]; - size_t bufsize, init_path_len; - int error, name[4]; + size_t bufsize; + int error; buf = NULL; bufsize = 0; - name[0] = CTL_KERN; - name[1] = KERN_PROC; - name[2] = KERN_PROC_PATHNAME; - name[3] = -1; - init_path_len = sizeof(init_path); - error = sysctl(name, 4, init_path, &init_path_len, NULL, 0); - if (error != 0) { - emergency("failed to get kern.proc.pathname: %s", - strerror(errno)); - goto out; - } - revoke_ttys(); runshutdown(); @@ -792,7 +785,7 @@ reroot(void) * Copy the init binary into tmpfs, so that we can unmount * the old rootfs without committing suicide. */ - error = read_file(init_path, &buf, &bufsize); + error = read_file(init_path_argv0, &buf, &bufsize); if (error != 0) goto out; error = mount_tmpfs(_PATH_REROOT);