From nobody Tue Sep 23 21:39:23 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4cWYK80LSlz67ysX; Tue, 23 Sep 2025 21:39:24 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4cWYK76kHmz3lVT; Tue, 23 Sep 2025 21:39:23 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1758663564; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=47FoaFoJT34si0eYiMkygv+0PBmnrvOzjRK3VX55GbU=; b=QV3t4AVDYd2AxwFksWR5h9/2jbfuKCpBZqFdOJ3STWXH9Gh0SbTN4UxAjyxD0ZWR5UoWA2 lb99GI31fBo95Z96NeSxLG36uelwwHhP9xH6G5ZFPy/VPznUmKenKDcPQJqAe2MZ2t9jCI bAoxMMTbLJ8as8D4YVy+ai7a34OSv3dHasJ4dgeucaQQ3zrg1DqtvxoY5YFzptm4JnupCi e7VvdgzI+mynfahU1JKlyNLCnoE5e470R2jrfBJIXnoBQTulwLS6/+rPuXS51jBSnKpGD8 /HIPyYqGLI1nfomygPUzKN9Di07g+WoA/ofA1Ftt5wHg3Dr/5jORzdCzQ2kubQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1758663564; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=47FoaFoJT34si0eYiMkygv+0PBmnrvOzjRK3VX55GbU=; b=x0x5Z5Jx9KnidhdHm9KL1eGYbCGwup8b1OZOve1oZ56ZudfOcDZ6s8rGTBm+rmimOb4f27 LBphnF/j88qch0TdJIv0Nf4t9lCF7HFSW5TKzD5tUgPTxcjxsZOjYuVnBs6ucihJEY18qj Nl6gaky4QhkRwDylo53NFHodDrQTp9i8wal1xnh+WhZzf3cd3v3Klv8NWK7CFr8MAc5mrG +Ennh3cNOQ8ZTyl0eOclHqVDRiyISRtgngzVfCKvq+nc0jlWKavPxTgBhkWPicU+0CRIn8 LVanPyYgWHrrBP1KfncIOYpPkuEsV6ySFifUd8dDbTp29vwnyPUPC+sPwmkHCw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1758663564; a=rsa-sha256; cv=none; b=DrK18D/zRXgm6FeKLl6ttBiSllMGywF0ezonnHHfyS3jul3MQVytLXZfPb8goka+I8jMIv VfXuDj6uIYeQlKxCDRIkSzq5oaJn/uOuTmHdcZAkrG6pfeHyaEB3X6qwcCZhbVzkrknHxc 9ORtgPfGlxS31iBtiVUiwEsU877r7S+tnsYsDY22kl9UF/Lznu1PDlkz116tcvZe2TfVJl i0vpj4XGfivbsRlZ/nvlzWN31jNQ+UHdtxN5Ux2bS86kZtfJCil/AbO0aWFBuJ68zqFkk9 FeTVIggU62hI0hPgwEk/74PnzRRTAl4IhcbzIKXoFVa/FWkjeVT+QEVNBAtu3Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4cWYK76GyKz13KL; Tue, 23 Sep 2025 21:39:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 58NLdNea086599; Tue, 23 Sep 2025 21:39:23 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 58NLdNww086596; Tue, 23 Sep 2025 21:39:23 GMT (envelope-from git) Date: Tue, 23 Sep 2025 21:39:23 GMT Message-Id: <202509232139.58NLdNww086596@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Jilles Tjoelker Subject: git: ca771d7ae527 - stable/15 - init: Use root's home directory in single-user mode List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jilles X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: ca771d7ae527f4d3dcff20cd38c5be594d3a5730 Auto-Submitted: auto-generated The branch stable/15 has been updated by jilles: URL: https://cgit.FreeBSD.org/src/commit/?id=ca771d7ae527f4d3dcff20cd38c5be594d3a5730 commit ca771d7ae527f4d3dcff20cd38c5be594d3a5730 Author: Jilles Tjoelker AuthorDate: 2025-09-14 21:53:34 +0000 Commit: Jilles Tjoelker CommitDate: 2025-09-23 21:38:07 +0000 init: Use root's home directory in single-user mode When starting single-user mode, use the home directory from user root as current directory and for the HOME environment variable. If the directory does not exist, set HOME=/. Also adjust /root/.profile to stop setting HOME, since it should always have been set now. This is intended to keep shell startup files working in single-user mode after /.profile has been removed. Reviewed by: emaste, ivy, kevans Relnotes: yes Differential Revision: https://reviews.freebsd.org/D52527 (cherry picked from commit 779812d66989a9c3aaed09e4573400fc137f92b0) --- bin/sh/dot.profile | 2 -- sbin/init/init.c | 14 +++++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/bin/sh/dot.profile b/bin/sh/dot.profile index d27a2ae2fdbe..cba9bcf18ad9 100644 --- a/bin/sh/dot.profile +++ b/bin/sh/dot.profile @@ -1,6 +1,4 @@ # -HOME=/root -export HOME PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:~/bin export PATH TERM=${TERM:-xterm} diff --git a/sbin/init/init.c b/sbin/init/init.c index b345c8fa219a..d28501053c7f 100644 --- a/sbin/init/init.c +++ b/sbin/init/init.c @@ -851,9 +851,9 @@ single_user(void) const char *shell; char *argv[2]; struct timeval tv, tn; + struct passwd *pp; #ifdef SECURE struct ttyent *typ; - struct passwd *pp; static const char banner[] = "Enter root password, or ^D to go multi-user\n"; char *clear, *password; @@ -885,6 +885,7 @@ single_user(void) */ open_console(); + pp = getpwnam("root"); #ifdef SECURE /* * Check the root password. @@ -892,7 +893,6 @@ single_user(void) * it's the only tty that can be 'off' and 'secure'. */ typ = getttynam("console"); - pp = getpwnam("root"); if (typ && (typ->ty_status & TTY_SECURE) == 0 && pp && *pp->pw_passwd) { write_stderr(banner); @@ -909,7 +909,6 @@ single_user(void) } } endttyent(); - endpwent(); #endif /* SECURE */ #ifdef DEBUGSHELL @@ -930,6 +929,15 @@ single_user(void) } #endif /* DEBUGSHELL */ + if (pp != NULL && pp->pw_dir != NULL && *pp->pw_dir != '\0' && + chdir(pp->pw_dir) == 0) { + setenv("HOME", pp->pw_dir, 1); + } else { + chdir("/"); + setenv("HOME", "/", 1); + } + endpwent(); + /* * Unblock signals. * We catch all the interesting ones,