mirror of
https://github.com/armbian/build.git
synced 2026-09-08 23:59:54 +08:00
firstlogin: let the console with a user take the setup
Every autologin console starts the setup at once and flock -n hands it to whichever ran first. On an image with both HDMI and a serial console that is usually the one nobody is sitting at: the setup waits for input on an empty screen, while the session the user is on prints "already running in another session" and drops to a shell. Hand it to the session that arrived last instead. The holder names itself in the lock file and is asked to step aside with SIGTERM, which its trap already turns into the same clean exit as a power loss: FIRSTLOGIN_SUCCESS stays 0, so the marker survives and the setup simply runs again in the new session. The newcomer retries rather than reading the lock file once, so a holder that has taken the lock but not yet published its pid is displaced on the next pass. A single console is unaffected, it takes the lock on the first try.
This commit is contained in:
@@ -786,13 +786,19 @@ set_user_icon() {
|
||||
|
||||
if [[ -f /root/.not_logged_in_yet ]] && tty -s; then
|
||||
|
||||
# tty1, the serial console and an early ssh login all start the setup at once.
|
||||
# Let the first one own it, or they race each other through the prompts.
|
||||
exec 9> /run/armbian-firstlogin.lock || exit 1
|
||||
if ! flock -n 9; then
|
||||
echo -e "\nFirst login setup is already running in another session.\n"
|
||||
exit 0
|
||||
fi
|
||||
# All autologin consoles start the setup at once and the one that wins is
|
||||
# often a console nobody is at, so let the newest session take it over.
|
||||
# SIGTERM is the holder's clean-exit path: the marker survives a power
|
||||
# loss the same way, and the setup simply runs again here.
|
||||
exec 9<> /run/armbian-firstlogin.lock || exit 1
|
||||
until flock -n 9; do
|
||||
kill -TERM "$(< /run/armbian-firstlogin.lock)" 2> /dev/null
|
||||
sleep 1
|
||||
done
|
||||
echo $$ > /run/armbian-firstlogin.lock
|
||||
|
||||
# it may have been finished by the session we just displaced
|
||||
[[ -f /root/.not_logged_in_yet ]] || exit 0
|
||||
|
||||
. /root/.not_logged_in_yet
|
||||
|
||||
|
||||
Reference in New Issue
Block a user