From nobody Tue Sep 16 20:41:39 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 4cRDMl73mVz682Bg; Tue, 16 Sep 2025 20:41:39 +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 4cRDMl6bpYz3Tk3; Tue, 16 Sep 2025 20:41:39 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1758055299; 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=yLHz3E2jhrFt/vs37j3dp32kwyHWBaAVSpjHk5iZT3g=; b=efZuIpWcQs7j840SF361Vy4Tynh1VsrfLaKBYdWKKJ+52n3Cs+GmTrTBbt1VjSxvaaBQAK c1mteD3bSpevDFFUgzrAicPN8gCoMnEvr3xnhq0j4MDhL7SVAhOXMj8AifWc0/XokQFrGJ l3G8PGMHcLtA1r33eTiCymHeqkLuHlhQkuMzEkuzdcI/yAk/1jFus508aqI6SGhaRSqrq/ xtBpOBYg/wmPt/D8IHRa5F52/IUvzTxWpgcc0a5zrvJENyyuOr3G6nonYEn9jwKlsxlv9J tvEYPD07bDj9N8f92NtSLfBugJrf0eU8R4koyK0wiyZ5wWUlb9jRkpUi1+UTwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1758055299; 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=yLHz3E2jhrFt/vs37j3dp32kwyHWBaAVSpjHk5iZT3g=; b=oD3UReUJ5N9gONNn+wv9r60BuhXcI2r6+n9Z7CIhlOeEAfPrfEvVKbxMSELU6SciOzO6uS b9iI2XEjp0Tzj0hMshNbxaNNOEA+yoJV3IDFuFaaEawdOHBsNPReqWhfYaCesKW+hn57/h DSqQQigotJWvsS+xRthbRMBtNfhmizNNkPlNXxedPaRN/Fk2ei1p6S/Trw2NRpk05KGzvL PG0FIS6KCwIQy6h5SNtOMfwr+krantEfYNyEVul3MsSkrr0yxLWMDO3/c9IHLHzh00bxLx BTveMJXp1P/ys9E7XNA0NIqLyIHNRAUQ6FNq/G/1fJB4YB6tkeg+B5jhjc5zVA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1758055299; a=rsa-sha256; cv=none; b=dRuKU277pknAJRi9aatLsiG9+rctj6FOL3Gknzs6kfsHyIDOQoLaik5A7BbaBWTwed1fUB 6CN06Mx8CabCd6Ojdw1YSYb+r5RX4JE7jiqVpwwN8Nf4BmVbCwGfBmoSrqhVMiRIdil60j W1Q2lxx5GaHApzrPbNvnoIWpZz+/JkI/C2IW6EL/L2Mx7uQvWjwI4LiaL3IpCJIs1cOj2L sYXrRQ2qz57fQHykOr/rRsWXaCoAPVPLs4QVLMuPYuMwGj4qj4ebU7R9Z42NgOiXpZwmC4 eR+7zCWGJnaKG6EVX0iIZxNQJisXNp+mTAuuAN2qmEU4Z97nU3Lm7zemfjC9qQ== 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 4cRDMl5dKCzwk1; Tue, 16 Sep 2025 20:41:39 +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 58GKfdli032630; Tue, 16 Sep 2025 20:41:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 58GKfdd1032627; Tue, 16 Sep 2025 20:41:39 GMT (envelope-from git) Date: Tue, 16 Sep 2025 20:41:39 GMT Message-Id: <202509162041.58GKfdd1032627@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Jilles Tjoelker Subject: git: 779812d66989 - main - 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/main X-Git-Reftype: branch X-Git-Commit: 779812d66989a9c3aaed09e4573400fc137f92b0 Auto-Submitted: auto-generated The branch main has been updated by jilles: URL: https://cgit.FreeBSD.org/src/commit/?id=779812d66989a9c3aaed09e4573400fc137f92b0 commit 779812d66989a9c3aaed09e4573400fc137f92b0 Author: Jilles Tjoelker AuthorDate: 2025-09-14 21:53:34 +0000 Commit: Jilles Tjoelker CommitDate: 2025-09-16 20:36:41 +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 MFC after: 1 week Relnotes: yes Differential Revision: https://reviews.freebsd.org/D52527 --- 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,