diff --git a/system_files/shared/etc/profile.d/uwelcome.sh b/system_files/shared/etc/profile.d/uwelcome.sh index cf1b43702..3143cd036 100644 --- a/system_files/shared/etc/profile.d/uwelcome.sh +++ b/system_files/shared/etc/profile.d/uwelcome.sh @@ -5,11 +5,15 @@ if [ -e ~/.config/no-show-user-motd ]; then mv ~/.config/no-show-user-motd ~/.config/uwelcome/disabled 2>/dev/null fi +# Only greet a terminal: GDM starts the desktop session through a login shell, +# and uwelcome run there (no tty) asks for the portal before +# graphical-session.target is up, so xdg-desktop-portal fails its dependency +# and every portal call then waits out D-Bus's 120 s activation timeout. # Skip for root: root shells (sudo su -, sudo -i) have no desktop session, # and the portal lookup uwelcome makes can stall the prompt when the portal # cannot start. Guard against double greetings when a shell chains into # another (bash login shell starting fish): the first one wins. -if [ "$(id -u)" != "0" ] && [ -z "${UWELCOME_SHOWN-}" ]; then +if [ -t 1 ] && [ "$(id -u)" != "0" ] && [ -z "${UWELCOME_SHOWN-}" ]; then UWELCOME_SHOWN=1 export UWELCOME_SHOWN uwelcome diff --git a/tests/test_motd_integration.bats b/tests/test_motd_integration.bats index d3d0fee64..5e355e751 100644 --- a/tests/test_motd_integration.bats +++ b/tests/test_motd_integration.bats @@ -48,14 +48,14 @@ teardown() { # --------------------------------------------------------------------------- @test "uwelcome.sh: invokes uwelcome" { - run bash "${UWELCOME_PROFILE}" + run script -qec "bash '${UWELCOME_PROFILE}'" /dev/null [ "${status}" -eq 0 ] [ -f "${WORKDIR}/uwelcome.log" ] } @test "uwelcome.sh: migrates legacy opt-out and still runs uwelcome" { touch "${HOME}/.config/no-show-user-motd" - run bash "${UWELCOME_PROFILE}" + run script -qec "bash '${UWELCOME_PROFILE}'" /dev/null [ "${status}" -eq 0 ] # Legacy marker is consumed, not left behind to retry every login [ ! -e "${HOME}/.config/no-show-user-motd" ] @@ -75,7 +75,7 @@ teardown() { } @test "uwelcome.sh: is a no-op migration when no legacy marker exists" { - run bash "${UWELCOME_PROFILE}" + run script -qec "bash '${UWELCOME_PROFILE}'" /dev/null [ "${status}" -eq 0 ] [ ! -e "${HOME}/.config/uwelcome/disabled" ] [ -f "${WORKDIR}/uwelcome.log" ] @@ -106,7 +106,7 @@ teardown() { @test "uwelcome.sh: skips invocation if UWELCOME_SHOWN is set" { export UWELCOME_SHOWN=1 - run bash "${UWELCOME_PROFILE}" + run script -qec "bash '${UWELCOME_PROFILE}'" /dev/null [ "${status}" -eq 0 ] [ ! -f "${WORKDIR}/uwelcome.log" ] } diff --git a/tests/test_uwelcome_profile.bats b/tests/test_uwelcome_profile.bats index b348d0335..51cb668d5 100644 --- a/tests/test_uwelcome_profile.bats +++ b/tests/test_uwelcome_profile.bats @@ -49,6 +49,12 @@ not_called() { [ ! -f "${WORKDIR}/calls" ] } +# The greeting only runs on a terminal, so tests that exercise the greeting +# guards run the profile under script(1), which gives it a pty. +run_tty() { + run script -qec "$1" /dev/null +} + @test "legacy no-show-user-motd marker migrates to uwelcome/disabled" { stub_id 1000 touch "${HOME}/.config/no-show-user-motd" @@ -86,7 +92,7 @@ not_called() { stub_id 1000 unset UWELCOME_SHOWN - run bash "$UWELCOME_PROFILE" + run_tty "bash '$UWELCOME_PROFILE'" [ "$status" -eq 0 ] called @@ -96,7 +102,7 @@ not_called() { @test "uwelcome is skipped for root" { stub_id 0 - run bash "$UWELCOME_PROFILE" + run_tty "bash '$UWELCOME_PROFILE'" [ "$status" -eq 0 ] not_called @@ -106,7 +112,7 @@ not_called() { stub_id 1000 export UWELCOME_SHOWN=1 - run bash "$UWELCOME_PROFILE" + run_tty "bash '$UWELCOME_PROFILE'" [ "$status" -eq 0 ] not_called @@ -117,7 +123,7 @@ not_called() { unset UWELCOME_SHOWN # Source the profile, then start a child shell that sources it again. - run bash -c '. "$1"; bash "$1"' _ "$UWELCOME_PROFILE" + run_tty "bash -c '. \"$UWELCOME_PROFILE\"; bash \"$UWELCOME_PROFILE\"'" [ "$status" -eq 0 ] [ "$(wc -l < "${WORKDIR}/calls")" -eq 1 ] @@ -138,8 +144,18 @@ not_called() { stub_id 1000 export UWELCOME_SHOWN="" - run bash "$UWELCOME_PROFILE" + run_tty "bash '$UWELCOME_PROFILE'" [ "$status" -eq 0 ] called } + +@test "uwelcome is skipped without a terminal (GDM's login shell)" { + stub_id 1000 + unset UWELCOME_SHOWN + + run bash "$UWELCOME_PROFILE" < /dev/null > /dev/null + + [ "$status" -eq 0 ] + not_called +}