Date: Mon, 04 May 2026 07:17:02 +0000 From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: 0276461a2d88 - stable/15 - bin/sh: make it possible to use as interactive init Message-ID: <69f847ee.4100c.692e8132@gitrepo.freebsd.org>
index | next in thread | raw e-mail
The branch stable/15 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=0276461a2d88aaf41158a9b4ba25342a644aa1c5 commit 0276461a2d88aaf41158a9b4ba25342a644aa1c5 Author: Konstantin Belousov <kib@FreeBSD.org> AuthorDate: 2026-04-20 18:03:39 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> 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 <fcntl.h> #include <locale.h> #include <errno.h> +#include <termios.h> +#include <paths.h> +#include <unistd.h> #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();home | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69f847ee.4100c.692e8132>
