power-funcs: getXConsole() doesn't always work
Bug #239191 reported by
DaveAbrahams
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
acpi-support (Ubuntu) |
New
|
Undecided
|
Unassigned |
Bug Description
Binary package hint: acpi-support
The following code contains a comment explaining the problem. To reproduce, chown root:root ~/.Xauthority and restart X.
# based on /usr/share/
# because sometimes root takes ownership of the user's .Xauthority
# file, and then gdm puts the file elsewhere (e.g. /tmp/.gdm2398).
myXconsole()
{
console=
displaynum=`ps ax | grep -m1 -e '[X] .* vt'$console | sed -re 's!.*/X .*:([0-9]+).*!\1!'`
export DISPLAY=
pid=`ps ax | grep -m1 -e '[X] .* vt'$console | cut -d' ' -f 1`
export XAUTHORITY=$(grep -zx "XAUTHORITY=.*" /proc/$pid/environ | sed -r -e 's/XAUTHORITY=
}
To post a comment you must log in.
Oops; the output of ps begins with a space, so the 2nd to last line needs to be either
pid=`ps ax | grep -m1 -e '[X] .* vt'$console | cut -d' ' -f 2`
or perhaps the more-resilient
pid=`ps ax | grep -m1 -e '[X] .* vt'$console | sed -re 's/[^0- 9]*([0- 9]+).*/ \1/'`
which is what I'm currently using.