commit:     d218502dd92b79e7920152d17843620d56d00756
Author:     Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
AuthorDate: Tue Aug  6 15:34:53 2019 +0000
Commit:     Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
CommitDate: Tue Aug  6 20:40:32 2019 +0000
URL:        https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=d218502d

initrd.scripts: run_shell(): Use LOCK file

We cannot write PID because we use exec and don't return
before the shell we just spawned was closed.

Signed-off-by: Thomas Deutschmann <whissi <AT> gentoo.org>

 defaults/initrd.defaults | 2 +-
 defaults/initrd.scripts  | 6 ++++--
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/defaults/initrd.defaults b/defaults/initrd.defaults
index 89d13ac..fdf948e 100644
--- a/defaults/initrd.defaults
+++ b/defaults/initrd.defaults
@@ -81,7 +81,7 @@ GK_NET_TIMEOUT_DAD=10
 GK_NET_TIMEOUT_DECONFIGURATION=10
 GK_NET_TIMEOUT_DHCP=10
 GK_NET_TIMEOUT_INTERFACE=10
-GK_SHELL_LOCKFILE='/var/run/rescueshell.pid'
+GK_SHELL_LOCKFILE='/tmp/rescueshell.lock'
 GK_SSHD_LOCKFILE='/tmp/remote-rescueshell.lock'
 GK_SSHD_PIDFILE='/var/run/dropbear.pid'
 GK_SSHD_PORT=22

diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts
index 994f0f0..2452f5f 100644
--- a/defaults/initrd.scripts
+++ b/defaults/initrd.scripts
@@ -818,6 +818,8 @@ check_loop() {
 run_shell() {
        [ -x /bin/sh ] && SH=/bin/sh || SH=/bin/ash
 
+       touch "${GK_SHELL_LOCKFILE}"
+
        export PS1='rescueshell \w \# '
 
        echo
@@ -838,9 +840,9 @@ run_shell() {
                ${SH} --login
        fi
 
-       echo
+       rm "${GK_SHELL_LOCKFILE}"
 
-       :> "${GK_SHELL_LOCKFILE}"
+       echo
 }
 
 fs_type_in_use() {

Reply via email to