From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on sa.local.altlinux.org X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=VyCSThacEvoA0sCO1pt7RBAJ8ctrR/J72aFp7v4D28Q=; b=OC5p5sdHzUoVYB/RHRr24VaCGZlStJkIvI4p0mK5pllYZUfnWD5+fPDjVpuIFFn1HB m7mglAUG4v+f8Xq9y+pLQsLWEHfWQpjl7/wHdVqLd5e8Fsayy+kOe/4D9TTG0DHyvizB tuN1eOBDkCJQVuQUMbsHPw3XXnDmXLhiBqeIpsQmTiEcAY1f1R9W2TV7pw5S/gobW7z5 ZugtLXan2nSxF6Z0LrV3DOkuhjoePCLzIQsoJQFJ7nydOO28tcSI+wevviRHOEQtbXIf avabz02xoD7sBe+bUpiGCfRmjV2uToeKF4zfPYUmopQsAHeYIVPo1wsWU04jQpl78mdI r0ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=VyCSThacEvoA0sCO1pt7RBAJ8ctrR/J72aFp7v4D28Q=; b=32B/amgSuN2VBA49gbtBfg4UXu5arQNv1xouBgQrv63w7yCu5otZGy4FJXWK0Fiobu vCym+Xp8P0xbNTdp/3cIngJodq/poUdyrKUpL6zEUOILE3pQ4ZEu7kwvEj4pwU9lTDNa GJEXwaaW0fZ1PKTA2KypZnA2zVI5SVs44x/U+vtWnyG3ZuMkbGP+zZX39R6XqzNa3gRG h2G1eS912OAtpQ2tHnNAmZUizT+r/cUdA0IwgOpesQLS3eUaUh53T8rhVlDJmuwSxrRW 8ivOh/MohkhusL0btT4nqH2bw4SpppU2g7hR/wReYXFql+o04xJsZIr+gCsXEEoovPbJ /gow== X-Gm-Message-State: AOAM531R9LU6373mROXpHENod6WJlgklXMmzLKhww2yNqcKbqU8aWUz+ YQVb/+t7kAx7cr/yUnnq/KjvVGHiing= X-Google-Smtp-Source: ABdhPJxfabpMqMPYsSdkoGnok/JTV/ITntIGBNZGIgd7njEUpRhW2RKQo8lrq3Yz6wdgTwgbbc5l1A== X-Received: by 2002:a2e:8151:: with SMTP id t17mr7524519ljg.289.1636210664984; Sat, 06 Nov 2021 07:57:44 -0700 (PDT) To: make-initrd@lists.altlinux.org References: <20211024172323.DBBE6A5E66@lists.altlinux.org> <20211026191600.srasvg6dbltxrsjw@example.org> <595e8a7c-1b6b-361d-b597-60031d25e0f6@gmail.com> <20211106132213.2qojchid4yqymcvb@example.org> From: Leonid Krivoshein Message-ID: Date: Sat, 6 Nov 2021 17:57:44 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20211106132213.2qojchid4yqymcvb@example.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: ru Subject: Re: [make-initrd] [PATCH v6 21/22] bootchain-core: adds ability to bring the daemon to the foreground X-BeenThere: make-initrd@lists.altlinux.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: make-initrd@lists.altlinux.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 06 Nov 2021 14:57:48 -0000 Archived-At: List-Archive: 06.11.2021 16:22, Alexey Gladkov пишет: > On Tue, Oct 26, 2021 at 11:29:43PM +0300, Leonid Krivoshein wrote: >> 26.10.2021 22:16, Alexey Gladkov пишет: >>> 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 2>&1 >> Там ровно этот код и отрабатывает. Суть усложнения концепции заключалась в >> другом: хотелось получить выделенный интерактивный терминал с диалогами, >> отличный от tty1, и активировать его, при необходимости, по таймауту или >> сразу. Чтобы быстрый процесс загрузки не мелькал перед глазами, если в этом >> нет необходимости. И чтобы вывод демонов make-initrd не смешивался на tty1 с >> диалогами. > Так я же и написал tty2. Вопрос был о том, зачем демону перезапускаться ? > Он же может перенаправить свой ввод-вывод на любой терминал. Перенаправить-то он может свой ввод/вывод, но на переднем плане (на tty2) продолжает работать одна часть (перезапущенная), в то время как другая часть следит за истечением таймаута, чтобы переключиться на этот терминал (tty2). Есть условия, при которых мы должны переключаться на tty2 сразу, но данное разделение и перезапуск через openvt позволяют реализовать концепцию отложенного переключения на tty2. Иначе мы должны были бы переключиться туда немедленно и наблюдать все быстро проскакивающие диалоги, например, в течение первых 3-6 секунд загрузки altboot. Данное концептуальное усложнение позволило избавиться от мелькания диалогов на ранней стадии загрузки, когда никакого ввода от пользователя не требуется, и вся загрузка укладывается в отведённые 8 секунд таймаута. >> Переход в интерактивный режим был разделён на две части: IM_exec() и >> IM_activate() подобно тому, как приложения запускаются в NIX-системах через >> fork() и exec(). Исходно запущенный демон запускает вспомогательный терминал >> для отладки и есть код, который ждёт его завершения. Изначально демон был >> вообще разделён на две части, перезапускалась только вторая часть. Причина >> -- в использовании openvt ... так как другие варианты не подходили. >> >> Алексей Шепляков предложил тут хорошую идею: использовать для тех же целей >> screen или tmux. Собственно задача: восстановить после себя консоль. Вариант >> идеальный, но у меня пока не вышло из-за проблем с настройкой utf8 в stage1, >> там одно другое цепляет, есть конфликты с plymouth и kbd, который сейчас, >> кажется, совсем нерабочий. > Кто совсем нерабочий ? make-initrd с фичей kbd у меня не собирается, фейлится. Вообще не проблема руками настроить консоль и utf8. Но проблемы начинаются, когда это начинают делать сразу несколько фич, когда с ресурсами типа tty2 или console начинают работать несколько разных фич, типа plymouth, kbd, rdshell. Надо с этим чего-то придумать на верхнем уровне make-initrd. Некий общий аналог console-sh-functions, через API которого можно будет избежать гонок и конфликтов при инициализации консолей. > >> Так что переключение на другие консоли через >> openvt -- пока единственная рабочая, но не лучшая реализация, надо обсудить, >> как это улучшить, не меняя API. >> >> >>>> See README.md for more details. >>>> >>>> Signed-off-by: Leonid Krivoshein >>>> --- >>>> 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 of the previous step from the 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" тут признак чего ? не надо этого. >> Признак Debian-way! :-) Ну, я боялся, что в этом месте "--" может быть не >> так истолковано. >> >> >>>> [ ! -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 >>>> >> -- >> Best regards, >> Leonid Krivoshein. >> >> _______________________________________________ >> Make-initrd mailing list >> Make-initrd@lists.altlinux.org >> https://lists.altlinux.org/mailman/listinfo/make-initrd -- Best regards, Leonid Krivoshein.