From 378506597f0752e259a9f10b8d6c0c02c943ec29 Mon Sep 17 00:00:00 2001 From: enthropy7 Date: Thu, 20 Aug 2026 03:14:16 +0300 Subject: [PATCH] firstlogin: replace session kill with flock A fresh image logs root in on tty1, on the serial console and over ssh at once, and every session runs the setup. Each one killed the other root shells to get the prompts to itself, so a session could be killed while sitting at a password prompt and the setup was left unfinished. Take a lock instead and let the other sessions step aside. --- .../common/usr/lib/armbian/armbian-firstlogin | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/packages/bsp/common/usr/lib/armbian/armbian-firstlogin b/packages/bsp/common/usr/lib/armbian/armbian-firstlogin index 21d2a45389cf..b9bda297aa2a 100755 --- a/packages/bsp/common/usr/lib/armbian/armbian-firstlogin +++ b/packages/bsp/common/usr/lib/armbian/armbian-firstlogin @@ -786,6 +786,14 @@ 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 + . /root/.not_logged_in_yet # override configuration from URL @@ -926,18 +934,6 @@ if [[ -f /root/.not_logged_in_yet ]] && tty -s; then fi fi - # Get current session identifiers - current_tty=$(tty | sed 's:/dev/::') # e.g., "tty1" - current_pid=$$ - - # Kill ONLY other active root SHELL sessions (not login processes) - ps -u root -o pid,tty,comm | - awk -v me="$current_tty" -v mypid="$current_pid" ' - NR>1 && $2 != "?" && $2 != me && $1 != mypid && $3 ~ /sh$/ { - print $1 - }' | - xargs --no-run-if-empty kill -9 - # enable motd chmod +x /etc/update-motd.d/*