Ubuntu

power-funcs: getXConsole() doesn't always work

Reported by DaveAbrahams on 2008-06-11
2
Affects Status Importance Assigned to Milestone
acpi-support (Ubuntu)
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/acpi-support/power-funcs, which is inadequate
# because sometimes root takes ownership of the user's .Xauthority
# file, and then gdm puts the file elsewhere (e.g. /tmp/.gdm2398).
myXconsole()
{
    console=`fgconsole`;
 displaynum=`ps ax | grep -m1 -e '[X] .* vt'$console | sed -re 's!.*/X .*:([0-9]+).*!\1!'`
    export DISPLAY=:$displaynum
    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=(.*)/\1/')
}

DaveAbrahams (boostpro) wrote :

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.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers