From 8c69fc11402949ab5f488cc4c45df3adf61b418f Mon Sep 17 00:00:00 2001 From: rewine Date: Thu, 21 May 2026 15:15:46 +0800 Subject: [PATCH] fix: add error handling when sourcing profile scripts Suppress stderr and emit a warning to stderr when sourcing /etc/profile, /etc/xprofile, /usr/local/etc/xprofile, $HOME/.profile, $HOME/.xprofile, $HOME/.xsessionrc, or $HOME/.xsession fails, preventing broken user configs from crashing the session startup. --- data/scripts/Xsession | 18 +++++++++--------- data/scripts/wayland-session | 8 ++++---- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/data/scripts/Xsession b/data/scripts/Xsession index a971d40..b305266 100755 --- a/data/scripts/Xsession +++ b/data/scripts/Xsession @@ -26,22 +26,22 @@ case $SHELL in rm -f $xsess_tmp ;; */fish) - [ -f /etc/profile ] && . /etc/profile - [ -f $HOME/.profile ] && . $HOME/.profile + [ -f /etc/profile ] && { . /etc/profile 2>/dev/null || echo "Warning: Failed to source /etc/profile" >&2; } + [ -f $HOME/.profile ] && { . $HOME/.profile 2>/dev/null || echo "Warning: Failed to source $HOME/.profile" >&2; } xsess_tmp=`mktemp /tmp/xsess-env-XXXXXX` $SHELL --login -c "/bin/sh -c 'export -p' > $xsess_tmp" . $xsess_tmp rm -f $xsess_tmp ;; *) # Plain sh, ksh, and anything we do not know. - [ -f /etc/profile ] && . /etc/profile - [ -f $HOME/.profile ] && . $HOME/.profile + [ -f /etc/profile ] && { . /etc/profile 2>/dev/null || echo "Warning: Failed to source /etc/profile" >&2; } + [ -f $HOME/.profile ] && { . $HOME/.profile 2>/dev/null || echo "Warning: Failed to source $HOME/.profile" >&2; } ;; esac -[ -f /etc/xprofile ] && . /etc/xprofile -[ -f /usr/local/etc/xprofile ] && . /usr/local/etc/xprofile -[ -f $HOME/.xprofile ] && . $HOME/.xprofile +[ -f /etc/xprofile ] && { . /etc/xprofile 2>/dev/null || echo "Warning: Failed to source /etc/xprofile" >&2; } +[ -f /usr/local/etc/xprofile ] && { . /usr/local/etc/xprofile 2>/dev/null || echo "Warning: Failed to source /usr/local/etc/xprofile" >&2; } +[ -f $HOME/.xprofile ] && { . $HOME/.xprofile 2>/dev/null || echo "Warning: Failed to source $HOME/.xprofile" >&2; } # run all system xinitrc shell scripts. if [ -d /etc/X11/xinit/xinitrc.d ]; then @@ -81,10 +81,10 @@ fi [ -f $HOME/.Xresources ] && xrdb -merge $HOME/.Xresources if [ -f "$USERXSESSIONRC" ]; then - . "$USERXSESSIONRC" + { . "$USERXSESSIONRC" 2>/dev/null || echo "Warning: Failed to source $USERXSESSIONRC" >&2; } fi if [ -f "$USERXSESSION" ]; then - . "$USERXSESSION" + { . "$USERXSESSION" 2>/dev/null || echo "Warning: Failed to source $USERXSESSION" >&2; } fi if [ -z "$*" ]; then diff --git a/data/scripts/wayland-session b/data/scripts/wayland-session index 6b8479d..f4e1d4f 100755 --- a/data/scripts/wayland-session +++ b/data/scripts/wayland-session @@ -30,16 +30,16 @@ case $SHELL in rm -f $wlsess_tmp ;; */fish) - [ -f /etc/profile ] && . /etc/profile - [ -f $HOME/.profile ] && . $HOME/.profile + [ -f /etc/profile ] && { . /etc/profile 2>/dev/null || echo "Warning: Failed to source /etc/profile" >&2; } + [ -f $HOME/.profile ] && { . $HOME/.profile 2>/dev/null || echo "Warning: Failed to source $HOME/.profile" >&2; } xsess_tmp=`mktemp /tmp/xsess-env-XXXXXX` $SHELL --login -c "/bin/sh -c 'export -p' > $xsess_tmp" . $xsess_tmp rm -f $xsess_tmp ;; *) # Plain sh, ksh, and anything we do not know. - [ -f /etc/profile ] && . /etc/profile - [ -f $HOME/.profile ] && . $HOME/.profile + [ -f /etc/profile ] && { . /etc/profile 2>/dev/null || echo "Warning: Failed to source /etc/profile" >&2; } + [ -f $HOME/.profile ] && { . $HOME/.profile 2>/dev/null || echo "Warning: Failed to source $HOME/.profile" >&2; } ;; esac