3JU7T/RQXa5ujDmzCbL34+uSxeK6YZVjU0ntpygdq U/qWlre2O5KNWAVEsrm9/E2+Uv0U2viF6QTjh9ZzDiL3aMLoiYegfZtJb5OoXfhhOOPlih TIno89XX3epz8csBPiPecIZ9iP+lT1tdSu7Jzv4fZPnxlMhWmPAMwBsknAeSzwERJBdJKd 3SP0WDX4aflb81DbIw7hx+UDSbJrTkVpgkFD0vPKiQxnjQHZHrGps1ST1O1fd7T4rEZE1L zep70+V8zF42rA0QqHXXct9g3yRclOoMMYfefnccrEI22eccHlDz40SBCiV4kg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1777879022; 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=KU62D0PjwiQELbFoTghX5r7AIGRSrMIFV29f9ulJCNE=; b=PMhzR+jfohVr9mgp16VtqvUe8rAH0sMz1Tp1Sc8SE4SZg25EUljGdU1n7pfCiK6HpKRMtt tkXXR9XTCGyaRXDE1kqwUxM6SoujUcsOj6hfOJhKMfbulcS3WV3NxAqDFP+hOWIpH5Td71 pyQ16TKoP79TNbxq6OxbgygCJsaRRu9AjGvl6qdx1FCA35rV3hU3xcAzEBr04IFyBajVPx QVtGezmA5bq9jowehnZMewMs3zm3iIRLJmpeicbAKhDTGGxpNg/Hx/zsJy79zyI8tduzIH ImsnFFQKreST+fcHmU6usydcg4nwV/u3JfjkQdcaLdKOjZCzBnRgU1Ihs7LyZA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4g8CdB49SBz17ZT for ; Mon, 04 May 2026 07:17:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 4100c by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 04 May 2026 07:17:02 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 0276461a2d88 - stable/15 - bin/sh: make it possible to use as interactive init 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 List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: 0276461a2d88aaf41158a9b4ba25342a644aa1c5 Auto-Submitted: auto-generated Date: Mon, 04 May 2026 07:17:02 +0000 Message-Id: <69f847ee.4100c.692e8132@gitrepo.freebsd.org> The branch stable/15 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=0276461a2d88aaf41158a9b4ba25342a644aa1c5 commit 0276461a2d88aaf41158a9b4ba25342a644aa1c5 Author: Konstantin Belousov AuthorDate: 2026-04-20 18:03:39 +0000 Commit: Konstantin Belousov CommitDate: 2026-05-04 07:16:39 +0000 bin/sh: make it possible to use as interactive init (cherry picked from commit d7338bb4914d120e5719d3216b23a509c49ed3be) --- bin/sh/main.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/bin/sh/main.c b/bin/sh/main.c index 94e8da6b4921..0ca2d4942426 100644 --- a/bin/sh/main.c +++ b/bin/sh/main.c @@ -39,6 +39,9 @@ #include #include #include +#include +#include +#include #include "shell.h" #include "main.h" @@ -124,6 +127,22 @@ main(int argc, char *argv[]) trputs("Shell args: "); trargs(argv); #endif rootpid = getpid(); + if (rootpid == 1) { + /* + * Make sh usable for invocation as interactive init + * substitute with init_path=/bin/sh, by opening + * file descriptors 0, 1, and 2 on /dev/console. + */ + if (fcntl(STDIN_FILENO, F_GETFL, NULL) == -1 && errno == EBADF) { + (void)open(_PATH_CONSOLE, O_RDWR); + (void)setsid(); + (void)tcsetsid(STDIN_FILENO, rootpid); + } + if (fcntl(STDOUT_FILENO, F_GETFL, NULL) == -1 && errno == EBADF) + (void)dup2(STDIN_FILENO, STDOUT_FILENO); + if (fcntl(STDERR_FILENO, F_GETFL, NULL) == -1 && errno == EBADF) + (void)dup2(STDIN_FILENO, STDERR_FILENO); + } rootshell = 1; INTOFF; initvar();