From: Phillip Berndt Date: Wed, 3 Feb 2016 07:07:48 +0000 (+0100) Subject: Workaround to fix #39 X-Git-Tag: 1.0~31 X-Git-Url: https://git.donarmstrong.com/?p=deb_pkgs%2Fautorandr.git;a=commitdiff_plain;h=adb35ed8a70b28eb5e42be778a5d323e6d41b532;hp=ac540ffafada68dfee5a992ae92f5926bc5d6849 Workaround to fix #39 --- diff --git a/contrib/pm-utils/40autorandr b/contrib/pm-utils/40autorandr index 264ba5f..8a66f39 100755 --- a/contrib/pm-utils/40autorandr +++ b/contrib/pm-utils/40autorandr @@ -18,15 +18,22 @@ detect_display() user="`w -h | awk -vD="$D" '$2 ~ ":"D"(.[0-9])?$" || $3 ~ ":"D"(.[0-9])?$" {print $1}' | head -n1`" if [ -z "$user" ]; then - # Try xinit as a fallback, see bug #39 - user="`w -h | awk -vD="$D" '$7 ~ "xinit" && $0 ~ ":"D"(.[0-9])?" {print $1}' | head -n1`" + # This fallback checks if there is exactly one user (except + # root) logged in an interactive session and assumes the + # session belongs to him. See bug #39. + user="`w -hu | awk '/^\w+/ && $1 !~ "root" { users[$1]=$1; } ENDFILE { if(asort(users) == 1) for(u in users) print users[u]; }'`" fi else user="`who --all | awk -vD="$D" '$3 ~ ":"D"(.[0-9])?$" {print $1}' | head -1`" + + if [ -z "$user" ]; then + # Same fallback as above; see bug #39. + user="`who -u | awk '/^\w+/ && $1 !~ "root" { users[$1]=$1; } ENDFILE { if(asort(users) == 1) for(u in users) print users[u]; }'`" + fi fi if [ x"$user" != x"" ]; then - logger "autorandr: Changing display configuration for user '$user'" + logger "autorandr: Changing display configuration for display :$D, user '$user'" export DISPLAY=":$D" /bin/su -c "${AUTORANDR}" "$user" fi