Make-initrd development discussion
 help / color / mirror / Atom feed
From: Alexey Gladkov <gladkov.alexey@gmail.com>
To: make-initrd@lists.altlinux.org
Subject: Re: [make-initrd] [PATCH v6 21/22] bootchain-core: adds ability to bring the daemon to the foreground
Date: Tue, 26 Oct 2021 21:16:00 +0200
Message-ID: <20211026191600.srasvg6dbltxrsjw@example.org> (raw)
In-Reply-To: <20211024172323.DBBE6A5E66@lists.altlinux.org>

On Sun, Oct 24, 2021 at 08:23:23PM +0300, Leonid Krivoshein wrote:
> Also introduces configuration parameter BC_FGVT_ACTIVATE and new pseudo-step
> "fg". This is only works together with the "bootchain-interactive" feature
> included to initramfs. Jointly features "bootchain-core" and "bootchain-
> interactive" they lay the foundation for building simple text installers
> in the stage1.

Напомни пожалуйста, а что мешает демону из бэкграунда писать на указанный
терминал и читать с него ?

Типа вот так:

exec </dev/tty2 >/dev/tty2 2>&1

> See README.md for more details.
> 
> Signed-off-by: Leonid Krivoshein <klark.devel@gmail.com>
> ---
>  features/bootchain-core/README.md             | 16 +++++++
>  .../data/bin/bootchain-sh-functions           |  2 +
>  features/bootchain-core/data/sbin/chaind      | 45 ++++++++++++++++---
>  3 files changed, 58 insertions(+), 5 deletions(-)
> 
> diff --git a/features/bootchain-core/README.md b/features/bootchain-core/README.md
> index ab89181..943b4b0 100644
> --- a/features/bootchain-core/README.md
> +++ b/features/bootchain-core/README.md
> @@ -50,11 +50,18 @@ us to optimize fill in `initramfs` only which we are need.
>  
>  - Modularity: loading methods are initially separated from the common
>    code and daemon.
> +- Provides the ability to bring the daemon to the foreground at any time. This
> +  restarts the `chaind` process on a specific terminal, although initially the
> +  daemon is started in the background.
>  - Some steps (actions) are built directly into the code of the main loop
>    of the `chaind` daemon, external scripts are not called to execute them.
>    Such pseudo-steps allow you to control, basically, the internal state of the
>    daemon and should not be taken into account in the boot chain, as if they are
>    hidden.
> +- Optionally, the daemon can work in conjunction with the `bootchain-interactive`
> +  feature, can move to the foreground and continue working on a specific terminal,
> +  by default, tty2. Jointly features `bootchain-core` and `bootchain-interactive`
> +  they lay the foundation for building simple text installers in stage1.
>  - The `chaind` daemon allows you to overload the chain with a new set of steps,
>    thanks to this, you can change the logic of work "on the fly", support loops
>    and conditional jumps, in text dialogs it is an opportunity to go back.
> @@ -147,6 +154,11 @@ parameters:
>    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_FGVT_ACTIVATE` - delay in seconds before activating the interactive
> +  terminal, by default tty2 is activated after 2 seconds in debug mode
> +  or after 8 seconds in normal mode. An empty value instructs to activate
> +  the interactive terminal immediately. This configuration option only works
> +  together with the `bootchain-interactive` features included in initramfs.
>  - `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
> @@ -165,6 +177,10 @@ embedded in the code of the main loop of the `boot chain-loop` daemon, do
>  not need additional parameters and should not be taken into account when
>  addressing, as if they are hidden.
>  
> +- `fg` - provides the transfer of the daemon to interactive mode when building
> +  initramfs with `bootchain-interactive` features. The `bootchain-core` itself
> +  is not interactivity required, but some other steps may need it, such as
> +  `altboot`.
>  - `noop` - does not perform any actions and is designed to pull off the results
>    on the <OUT> of the previous step from the <IN> of the next step, which can
>    be useful, for example, when we don`t want the results of the `waitdev` step
> diff --git a/features/bootchain-core/data/bin/bootchain-sh-functions b/features/bootchain-core/data/bin/bootchain-sh-functions
> index 3a9ec6b..743a8f9 100644
> --- a/features/bootchain-core/data/bin/bootchain-sh-functions
> +++ b/features/bootchain-core/data/bin/bootchain-sh-functions
> @@ -25,6 +25,8 @@ else
>  	pipeline_mode=
>  fi
>  
> +[ -n "$BC_DEBUG" ] && BC_FGVT_ACTIVATE=1 ||
> +	BC_FGVT_ACTIVATE="${BC_FGVT_ACTIVATE:-7}"
>  BC_NEXTCHAIN=/.initrd/bootchain/bootchain.next
>  BC_PASSED=/.initrd/bootchain/passed
>  handlerdir=/lib/bootchain
> diff --git a/features/bootchain-core/data/sbin/chaind b/features/bootchain-core/data/sbin/chaind
> index e8ce94a..68a1aae 100755
> --- a/features/bootchain-core/data/sbin/chaind
> +++ b/features/bootchain-core/data/sbin/chaind
> @@ -2,11 +2,12 @@
>  
>  . bootchain-sh-functions
>  
> -bcretry=1
> +bcretry="${bcretry:-1}"
>  pidfile="/var/run/$PROG.pid"
> -chainsteps="$BOOTCHAIN"
> -stepnum=0
> -prevdir=
> +chainsteps="${chainsteps-}"
> +stepnum="${stepnum:-0}"
> +prevdir="${prevdir-}"
> +BC_IM_supported=
>  
>  
>  exit_handler()
> @@ -25,6 +26,8 @@ debug()
>  }
>  
>  
> +# Only when daemon started first time
> +if [ "x${1-}" != "x--foreground" ]; then

"x" тут признак чего ? не надо этого.

>  	[ ! -f "$pidfile" ] ||
>  		fatal "already running"
>  	set_cleanup_handler exit_handler
> @@ -57,12 +60,44 @@ debug()
>  	mountpoint -q -- "$mntdir" ||
>  		run mount -t tmpfs tmpfs "$mntdir" ||:
>  
> +	chainsteps="$BOOTCHAIN"
> +fi
> +
> +# Check that interactive mode supports
> +if has_feature bootchain-interactive; then
> +	. interactive-sh-functions
> +
> +	[ "x${1-}" != "x--foreground" ] ||
> +		IM_activate "$BC_FGVT_ACTIVATE" "$BC_LOGFILE"
> +	BC_IM_supported=1
> +fi
> +
>  rc=0
>  while [ -n "$chainsteps" ]; do
>  	name="${chainsteps%%,*}"
>  	exe="$handlerdir/$name"
>  
> -	if [ "$name" = noop ]; then
> +	if [ "$name" = fg ]; then
> +		[ -n "$BC_IM_supported" ] ||
> +			fatal "bootchain-interactive feature required"
> +		assign "callnum" "\${callnum_$name:-0}"
> +		chainsteps="${chainsteps#$name}"
> +		chainsteps="${chainsteps#,}"
> +
> +		if IM_is_active; then
> +			message "[$callnum] Step '$name' has ignored"
> +		else
> +			message "[$callnum] Switching to foreground"
> +
> +			callnum=$((1 + $callnum))
> +			assign "callnum_$name" "\$callnum"
> +
> +			export stepnum chainsteps callnum_fg prevdir bcretry
> +
> +			IM_exec "$0" --foreground
> +		fi
> +
> +	elif [ "$name" = noop ]; then
>  		chainsteps="${chainsteps#$name}"
>  		chainsteps="${chainsteps#,}"
>  		prevdir=
> -- 
> 2.24.1
> 
> _______________________________________________
> Make-initrd mailing list
> Make-initrd@lists.altlinux.org
> https://lists.altlinux.org/mailman/listinfo/make-initrd
> 

-- 
Rgrds, legion



       reply	other threads:[~2021-10-26 19:16 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-26 19:16 ` Alexey Gladkov [this message]
2021-10-26 20:29   ` Leonid Krivoshein
2021-11-06 13:22     ` Alexey Gladkov
2021-11-06 14:57       ` Leonid Krivoshein
2021-11-06 15:05         ` Антон Мидюков
2021-11-06 15:25           ` Alexey Gladkov
2021-11-06 15:26             ` Антон Мидюков
2021-11-06 15:33               ` Alexey Gladkov
2021-11-06 15:47                 ` Leonid Krivoshein
2021-11-06 15:54                   ` Антон Мидюков
2021-11-06 16:19                     ` Leonid Krivoshein
2021-11-06 15:57                   ` Alexey Gladkov
2021-11-06 16:06                     ` Антон Мидюков
2021-11-06 16:25                       ` Leonid Krivoshein
2021-11-06 17:30                       ` Leonid Krivoshein
2021-11-06 18:16                         ` Leonid Krivoshein
2021-11-06 17:32                       ` Alexey Gladkov
2021-11-06 15:22         ` Alexey Gladkov
2021-11-06 16:52           ` Leonid Krivoshein
2021-11-06 17:41             ` Alexey Gladkov
2021-11-06 18:03               ` Leonid Krivoshein
2021-11-06 18:29                 ` Alexey Gladkov
2021-11-06 19:32                   ` Leonid Krivoshein
2021-11-06 19:54                   ` Leonid Krivoshein
2021-11-08 13:09                     ` Alexey Gladkov
2021-11-08 16:08                       ` Leonid Krivoshein
2021-11-09 12:17                         ` Alexey Gladkov

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=20211026191600.srasvg6dbltxrsjw@example.org \
    --to=gladkov.alexey@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