Make-initrd development discussion
 help / color / mirror / Atom feed
From: "Leonid Krivoshein" <klark.devel@gmail.com>
To: make-initrd@lists.altlinux.org
Subject: [make-initrd] [PATCH v6 19/22] bootchain-core: introduces additional terminal for show boot log
Date: Sun, 24 Oct 2021 17:23:01 -0000
Message-ID: <20211024172301.Uo4RCHerMBwLT6v2XcdHyXdxaIoekI82klG2TzXW7vk@z> (raw)

Also introduces configuration parameter BC_LOG_VT. It is the number
of the virtual terminal to which the debug log should be output in the
background. By default, the value is 3, respectively, the log is output
to tty3. An empty value allows you to disable log output to any terminal.

Signed-off-by: Leonid Krivoshein <klark.devel@gmail.com>
---
 features/bootchain-core/README.md             |  8 ++++-
 .../data/bin/bootchain-sh-functions           |  1 +
 .../bootchain-core/data/sbin/bootchain-logvt  | 36 +++++++++++++++++++
 features/bootchain-core/data/sbin/chaind      | 16 ++++++++-
 4 files changed, 59 insertions(+), 2 deletions(-)
 create mode 100755 features/bootchain-core/data/sbin/bootchain-logvt

diff --git a/features/bootchain-core/README.md b/features/bootchain-core/README.md
index bde5c9b..ab89181 100644
--- a/features/bootchain-core/README.md
+++ b/features/bootchain-core/README.md
@@ -22,6 +22,7 @@ us to optimize fill in `initramfs` only which we are need.
 - `/bin/bootchain-sh-functions` - common API and evolution
   of `pipeline-sh-functions`.
 - `/sbin/chaind` - daemon, evolution of `pipelined`.
+- `/sbin/bootchain-logvt` - script which allow to control sub terminal.
 - `/etc/rc.d/init.d/bootchain` - sysvinit start script.
 
 ## Reasons of making fork and rename pipeline
@@ -82,7 +83,8 @@ us to optimize fill in `initramfs` only which we are need.
   configurations of `/etc/sysconfig/bootchain`, and not only through boot
   parameters, see the details in the corresponding section.
 - The `chaind` daemon offers visual and advanced debugging. By default, the log
-  is kept in `/var/log/chaind.log`.
+  is kept in `/var/log/chaind.log` and is available on tty3, and when enabled
+  advanced debugging or self-testing functions are also copied to the stage2.
   Service step-script `debug` in advanced debugging mode is run before launching
   any other step-script and allows you to visually track the received values at
   each <IN>.
@@ -141,6 +143,10 @@ The configuration is defined in the file `/etc/sysconfig/bootchain` when
 building the initramfs image, is optional, and may contain the following
 parameters:
 
+- `BC_LOG_VT` is the number of the virtual terminal to which the debug log
+  should be output in the background. By default, the value is 3, respectively,
+  the log is output to tty3. An empty value allows you to disable log output
+  to any terminal.
 - `BC_LOGFILE` - the full path to the log file or the name of a special device,
   to which debugging messages will be output. In NATIVE mode, the default value
   is `/var/log/chaind.log`, in COMPATIBILITY mode with `pipeline` the default
diff --git a/features/bootchain-core/data/bin/bootchain-sh-functions b/features/bootchain-core/data/bin/bootchain-sh-functions
index 8c5a2f2..3a9ec6b 100644
--- a/features/bootchain-core/data/bin/bootchain-sh-functions
+++ b/features/bootchain-core/data/bin/bootchain-sh-functions
@@ -4,6 +4,7 @@ if [ -z "${__bootchain_sh_functions-}" ]; then
 __bootchain_sh_functions=1
 
 BC_DEBUG=
+BC_LOG_VT=3
 
 [ ! -s /etc/sysconfig/bootchain ] ||
 	. /etc/sysconfig/bootchain
diff --git a/features/bootchain-core/data/sbin/bootchain-logvt b/features/bootchain-core/data/sbin/bootchain-logvt
new file mode 100755
index 0000000..590cbd9
--- /dev/null
+++ b/features/bootchain-core/data/sbin/bootchain-logvt
@@ -0,0 +1,36 @@
+#!/bin/bash -efu
+
+. bootchain-sh-functions
+
+pid=
+pidfile=/var/run/chaind.pid
+
+
+exit_handler()
+{
+	local rc=$?
+
+	trap - EXIT
+
+	if [ -n "$pid" ]; then
+		kill -TERM "$pid" ||
+			kill -KILL "$pid" ||:
+		wait "$pid" ||:
+	fi >/dev/null 2>&1
+
+	clear
+	exit $rc
+}
+
+
+# Entry point
+[ -z "${CONSOLE-}" ] && [ -z "${NOASKUSER-}" ] && [ -n "$BC_LOG_VT" ] ||
+	exit 1
+set_cleanup_handler exit_handler
+exec </dev/null >"/dev/tty$BC_LOG_VT" 2>&1
+printf "bootchain logger started on tty%s\n\n" "$BC_LOG_VT"
+tail -f -- "$BC_LOGFILE" & pid="$!"
+
+while [ -f "$pidfile" ]; do
+	sleep 1
+done
diff --git a/features/bootchain-core/data/sbin/chaind b/features/bootchain-core/data/sbin/chaind
index 4c9ebaa..555f55a 100755
--- a/features/bootchain-core/data/sbin/chaind
+++ b/features/bootchain-core/data/sbin/chaind
@@ -14,6 +14,7 @@ exit_handler()
 	local rc="$?"
 	trap - EXIT
 	rm -f -- "$pidfile"
+	wait
 	exit $rc
 }
 
@@ -29,8 +30,21 @@ debug()
 set_cleanup_handler exit_handler
 echo "$$" >"$pidfile"
 
-[ "${RDLOG-}" != 'console' ] ||
+if [ "${RDLOG-}" = console ]; then
 	BC_LOGFILE=/dev/console
+elif [ -z "${CONSOLE-}" ] &&
+	[ -n "$BC_LOG_VT" ] &&
+	[ -z "${NOASKUSER-}" ] &&
+	[ ! -c "$BC_LOGFILE" ] &&
+	command -v openvt >/dev/null
+then
+	[ -z "${RDLOG-}" ] ||
+		BC_LOGFILE="$RDLOG"
+	touch -- "$BC_LOGFILE"
+	[ -e "/dev/tty$BC_LOG_VT" ] ||
+		mknod "/dev/tty$BC_LOG_VT" c 4 "$BC_LOG_VT"
+	openvt -f -w -c$BC_LOG_VT -- /sbin/bootchain-logvt &
+fi
 
 exec >"$BC_LOGFILE" 2>&1
 
-- 
2.24.1



                 reply	other threads:[~2021-10-24 17:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211024172301.Uo4RCHerMBwLT6v2XcdHyXdxaIoekI82klG2TzXW7vk@z \
    --to=klark.devel@gmail.com \
    --cc=make-initrd@lists.altlinux.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Make-initrd development discussion

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/make-initrd/0 make-initrd/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 make-initrd make-initrd/ http://lore.altlinux.org/make-initrd \
		make-initrd@lists.altlinux.org make-initrd@lists.altlinux.ru make-initrd@lists.altlinux.com
	public-inbox-index make-initrd

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.make-initrd


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git