Make-initrd development discussion
 help / color / mirror / Atom feed
* [make-initrd] [PATCH v6 19/22] bootchain-core: introduces additional terminal for show boot log
@ 2021-10-24 17:23 Leonid Krivoshein
  0 siblings, 0 replies; only message in thread
From: Leonid Krivoshein @ 2021-10-24 17:23 UTC (permalink / raw)
  To: make-initrd

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



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-10-24 17:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-24 17:23 [make-initrd] [PATCH v6 19/22] bootchain-core: introduces additional terminal for show boot log Leonid Krivoshein

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