# Power management problems

## bawig1

Hi,

I have been trying to get power management working on my Lenovo G560. The BIOS version is 29CN35WW (V2.12) and contains no power management options.

The instructions I have been following are here;

http://www.gentoo.org/doc/en/power-management-guide.xml

My kernel has been configured and I have installed sys-power/acpid

```

# emerge sys-power/acpid

# /etc/init.d/acpid start

# rc-update add acpid default

```

created a battery runlevel;

```

# cd /etc/runlevels

# cp -a default battery

```

installed sys-power/pm-utils

Have written the following /etc/acpi/actions/pmg_switch_runlevel.sh script

```

#!/bin/bash

# BEGIN configuration

RUNLEVEL_AC="default"

RUNLEVEL_BATTERY="battery"

# END configuration

if [ ! -d "/etc/runlevels/${RUNLEVEL_AC}" ]

then

    logger "${0}: Runlevel ${RUNLEVEL_AC} does not exist. Aborting."

    exit 1

fi

if [ ! -d "/etc/runlevels/${RUNLEVEL_BATTERY}" ]

then

    logger "${0}: Runlevel ${RUNLEVEL_BATTERY} does not exist. Aborting."

    exit 1

fi

if on_ac_power

then

    if [[ "$(</var/lib/init.d/softlevel)" != "${RUNLEVEL_AC}" ]]

    then

        logger "Switching to ${RUNLEVEL_AC} runlevel"

         /sbin/rc ${RUNLEVEL_AC}

    fi

elif [[ "$(</var/lib/init.d/softlevel)" != "${RUNLEVEL_BATTERY}" ]]

then

    logger "Switching to ${RUNLEVEL_BATTERY} runlevel"

    /sbin/rc ${RUNLEVEL_BATTERY}

fi

```

made the script executable;

```

chmod +x /etc/acpi/actions/pmg_switch_runlevel.sh

```

and created the following two scripts to handle events;

/etc/acpi/events/pmg_ac_adapter

```

# replace "ac_adapter" below with the event generated on your laptop

# For example, ac_adapter.* will match ac_adapter AC 00000080 00000000

event=ac_adapter.*

action=/etc/acpi/actions/pmg_switch_runlevel.sh %e

```

/etc/acpi/events/pmg_battery

```

# replace "battery" below with the event generated on your laptop

# For example, battery.* will match battery BAT0 00000080 00000001

event=battery.*

action=/etc/acpi/actions/pmg_switch_runlevel.sh %e

```

I then ran;

```

# /etc/init.d/acpid restart

```

when I check /var/log/messages for ACPI events when I plug in the power cord or take out the battery, I find the following;

```

Aug  6 20:18:11 localhost logger: ACPI event unhandled: button/lid LID0 00000080 00000001

Aug  6 20:18:12 localhost logger: ACPI event unhandled: button/lid LID0 00000080 00000002

Aug  6 20:18:28 localhost logger: ACPI event unhandled: button/lid LID0 00000080 00000003

Aug  6 20:18:48 localhost logger: ACPI event unhandled: battery BAT1 00000081 00000001

Aug  6 20:18:48 localhost logger: ACPI event unhandled: battery BAT1 00000080 00000001

Aug  6 20:18:48 localhost logger: ACPI event unhandled: processor CPU0 00000081 00000000

Aug  6 20:18:49 localhost logger: ACPI event unhandled: processor CPU1 00000081 00000000

Aug  6 20:18:49 localhost logger: ACPI event unhandled: ac_adapter ACAD 00000080 00000000

Aug  6 20:18:50 localhost logger: ACPI event unhandled: battery BAT1 00000080 00000001

Aug  6 20:18:50 localhost logger: ACPI event unhandled: button/lid LID0 00000080 00000004

Aug  6 20:19:13 localhost logger: ACPI event unhandled: processor CPU0 00000081 00000000

Aug  6 20:19:13 localhost logger: ACPI event unhandled: processor CPU1 00000081 00000000

Aug  6 20:19:13 localhost logger: ACPI event unhandled: ac_adapter ACAD 00000080 00000001

Aug  6 20:19:14 localhost logger: ACPI event unhandled: battery BAT1 00000080 00000001

Aug  6 20:19:17 localhost logger: ACPI event unhandled: button/lid LID0 00000080 00000005

Aug  6 20:19:20 localhost logger: ACPI event unhandled: battery BAT1 00000081 00000001

Aug  6 20:19:21 localhost logger: ACPI event unhandled: battery BAT1 00000080 00000001

Aug  6 20:19:22 localhost logger: ACPI event unhandled: button/lid LID0 00000080 00000006

Aug  6 20:21:27 localhost logger: ACPI event unhandled: button/lid LID0 00000080 00000007

Aug  6 20:21:29 localhost logger: ACPI event unhandled: button/lid LID0 00000080 00000008

Aug  6 20:24:47 localhost logger: ACPI event unhandled: button/lid LID0 00000080 00000009

Aug  6 20:24:49 localhost logger: ACPI event unhandled: button/lid LID0 00000080 0000000a

Aug  6 20:25:02 localhost logger: ACPI event unhandled: button/lid LID0 00000080 0000000b

Aug  6 20:25:10 localhost logger: ACPI event unhandled: processor CPU0 00000081 00000000

Aug  6 20:25:10 localhost logger: ACPI event unhandled: processor CPU1 00000081 00000000

Aug  6 20:25:10 localhost logger: ACPI event unhandled: ac_adapter ACAD 00000080 00000000

Aug  6 20:25:11 localhost logger: ACPI event unhandled: battery BAT1 00000080 00000001

Aug  6 20:25:11 localhost logger: ACPI event unhandled: battery BAT1 00000080 00000001

Aug  6 20:25:12 localhost logger: ACPI event unhandled: battery BAT1 00000081 00000001

Aug  6 20:25:13 localhost logger: ACPI event unhandled: battery BAT1 00000080 00000001

Aug  6 20:25:13 localhost logger: ACPI event unhandled: button/lid LID0 00000080 0000000c

Aug  6 20:25:42 localhost logger: ACPI event unhandled: processor CPU0 00000081 00000000

Aug  6 20:25:42 localhost logger: ACPI event unhandled: processor CPU1 00000081 00000000

Aug  6 20:25:42 localhost logger: ACPI event unhandled: ac_adapter ACAD 00000080 00000001

Aug  6 20:25:43 localhost logger: ACPI event unhandled: battery BAT1 00000080 00000001

Aug  6 20:25:46 localhost logger: ACPI event unhandled: button/lid LID0 00000080 0000000d

Aug  6 20:25:53 localhost logger: ACPI event unhandled: battery BAT1 00000081 00000000

Aug  6 20:25:54 localhost logger: ACPI event unhandled: battery BAT1 00000080 00000000

Aug  6 20:25:54 localhost logger: ACPI event unhandled: button/lid LID0 00000080 0000000e

Aug  6 20:39:27 localhost root: ACPI event unhandled: button/lid LID0 00000080 00000015

Aug  6 20:39:29 localhost root: ACPI event unhandled: button/lid LID0 00000080 00000016

Aug  6 20:39:40 localhost root: ACPI event unhandled: button/lid LID0 00000080 00000017

Aug  6 20:39:48 localhost root: ACPI event unhandled: processor CPU0 00000081 00000000

Aug  6 20:39:48 localhost root: ACPI event unhandled: processor CPU1 00000081 00000000

Aug  6 20:39:48 localhost root: ACPI event unhandled: ac_adapter ACAD 00000080 00000000

Aug  6 20:39:50 localhost root: ACPI event unhandled: battery BAT1 00000080 00000001

Aug  6 20:39:51 localhost root: ACPI event unhandled: battery BAT1 00000081 00000001

Aug  6 20:39:52 localhost root: ACPI event unhandled: battery BAT1 00000080 00000001

Aug  6 20:39:52 localhost root: ACPI event unhandled: button/lid LID0 00000080 00000018

Aug  6 20:40:05 localhost root: ACPI event unhandled: processor CPU0 00000081 00000000

Aug  6 20:40:05 localhost root: ACPI event unhandled: processor CPU1 00000081 00000000

Aug  6 20:40:05 localhost root: ACPI event unhandled: ac_adapter ACAD 00000080 00000001

Aug  6 20:40:06 localhost root: ACPI event unhandled: battery BAT1 00000080 00000001

Aug  6 20:40:06 localhost root: ACPI event unhandled: button/lid LID0 00000080 00000019

Aug  6 20:40:13 localhost root: ACPI event unhandled: battery BAT1 00000081 00000000

Aug  6 20:40:14 localhost root: ACPI event unhandled: battery BAT1 00000080 00000000

Aug  6 20:40:14 localhost root: ACPI event unhandled: button/lid LID0 00000080 0000001a

Aug  7 14:52:57 localhost logger: ACPI event unhandled: battery BAT1 00000080 00000000

Aug  7 22:31:15 localhost logger: ACPI event unhandled: battery BAT1 00000080 00000000

Aug  8 10:06:50 localhost logger: ACPI event unhandled: battery BAT1 00000080 00000000

Aug  8 10:36:08 localhost logger: ACPI event unhandled: battery BAT1 00000080 00000000

Aug  8 11:51:22 localhost logger: ACPI event unhandled: button/lid LID0 00000080 00000001

Aug  8 11:51:23 localhost logger: ACPI event unhandled: button/lid LID0 00000080 00000002

Aug  8 11:51:28 localhost logger: ACPI event unhandled: button/lid LID0 00000080 00000003

Aug  8 11:51:38 localhost logger: ACPI event unhandled: processor CPU0 00000081 00000000

Aug  8 11:51:38 localhost logger: ACPI event unhandled: processor CPU1 00000081 00000000

Aug  8 11:51:38 localhost logger: ACPI event unhandled: ac_adapter ACAD 00000080 00000000

Aug  8 11:51:39 localhost logger: ACPI event unhandled: battery BAT1 00000080 00000001

Aug  8 11:51:40 localhost logger: ACPI event unhandled: battery BAT1 00000081 00000001

Aug  8 11:51:41 localhost logger: ACPI event unhandled: battery BAT1 00000080 00000001

Aug  8 11:51:41 localhost logger: ACPI event unhandled: button/lid LID0 00000080 00000004

Aug  8 13:09:41 localhost logger: ACPI event unhandled: battery BAT1 00000080 00000001

Aug  8 19:10:34 localhost logger: ACPI event unhandled: battery BAT1 00000080 00000001

Aug  8 20:45:22 localhost logger: ACPI event unhandled: processor CPU0 00000081 00000000

Aug  8 20:45:22 localhost logger: ACPI event unhandled: processor CPU1 00000081 00000000

Aug  8 20:45:22 localhost logger: ACPI event unhandled: ac_adapter ACAD 00000080 00000000

Aug  8 20:45:23 localhost logger: ACPI event unhandled: battery BAT1 00000080 00000001

Aug  8 20:46:13 localhost logger: ACPI event unhandled: battery BAT1 00000080 00000001

Aug  8 20:56:59 localhost logger: ACPI event unhandled: battery BAT1 00000080 00000001

Aug  9 13:33:39 localhost logger: ACPI event unhandled: battery BAT1 00000080 00000001

Aug  9 13:59:05 localhost logger: ACPI event unhandled: battery BAT1 00000080 00000001

Aug  9 14:08:31 localhost logger: ACPI event unhandled: battery BAT1 00000080 00000001

Aug  9 14:10:56 localhost logger: ACPI event unhandled: battery BAT1 00000080 00000001

Aug  9 14:25:50 localhost logger: ACPI event unhandled: processor CPU0 00000081 00000000

Aug  9 14:25:50 localhost logger: ACPI event unhandled: processor CPU1 00000081 00000000

Aug  9 14:25:50 localhost logger: ACPI event unhandled: ac_adapter ACAD 00000080 00000001

Aug  9 14:25:51 localhost logger: ACPI event unhandled: battery BAT1 00000080 00000001

Aug 10 09:34:32 localhost logger: ACPI event unhandled: button/lid LID0 00000080 00000001

Aug 10 09:34:40 localhost logger: ACPI event unhandled: battery BAT1 00000081 00000000

Aug 10 09:34:41 localhost logger: ACPI event unhandled: battery BAT1 00000080 00000000

Aug 10 09:34:43 localhost logger: ACPI event unhandled: button/lid LID0 00000080 00000002

Aug 12 20:38:04 localhost logger: ACPI event unhandled: battery BAT1 00000080 00000001

Aug 13 14:58:51 localhost logger: ACPI event unhandled: battery BAT1 00000080 00000001

Aug 13 15:16:26 localhost logger: ACPI event unhandled: battery BAT1 00000080 00000001

```

I am running Xorg and KDE on the laptop and when I boot KDE it tells me that it's power management is not working because it cannot detect system power management. Have I missed something? Or am I doing something wrong. I've followed the instructions I linked to to the letter.

----------

## DepreTux

You probably need to edit the acpi events under /etc/acpi/events/

run "acpi_listen" and unplug the laptop and plug it back in. Then check the output. In my case, I had to set the events up this way:

```
# cat /etc/acpi/events/ac_adapter

event=ac_adapter AC 00000080 00000001.*

action=/usr/bin/acadapter
```

```
cat /etc/acpi/events/battery 

event=ac_adapter AC 00000080 00000000.*

action=/usr/bin/battery
```

----------

## fbcyborg

Hello, 

why if I put this script in /etc/acpi/actions in 

```
#!/bin/bash

if [ $(synclient -l | grep TouchpadOff | awk '{print $3}') = "2" ]; then synclient TouchpadOff=1; elif [ $(synclient -l | grep TouchpadOff | awk '{print $3}') == "1" ]; then synclient TouchpadOff=2; else synclient TouchpadOff=2; fi
```

and this event:

```
event=button/fnf1 FNF1 00000080 00000000

action=/etc/acpi/actions/toggle_touchpad.sh
```

it doesn't work?

The script toggle_touchpad.sh called by the command line works.

If I write:

```
event=button/fnf1 FNF1 00000080 00000000

action=wall hello
```

it works too... So acpid doesn't like the toggle_touchpad.sh script?

Why?

----------

## Hu

What happens if you run /etc/acpi/actions/toggle_touchpad.sh from a shell prompt?

----------

## fbcyborg

It works!

----------

## fbcyborg

By the way, I've found a solution thanks to an user on the Italian forum.

The solution was to add this before the if .... fi command

```
#!/bin/bash 

AUTH=/var/run/xauth/A:0-xBgkWa 

DISPLAY=:0 

cp $AUTH /root/.Xauthority 

export DISPLAY  
```

And this, after:

```
rm /root/.Xauthority 

unset DISPLAY
```

----------

## LiquidAcid

That makes sense, since synclient is an X application and doesn't work without a connection to the X-server.

----------

## Hu

Instead of copying the .Xauthority, why not just set $XAUTHORITY to point to the correct file?  Also, beware that this is fragile.  That authority file name looks ephemeral, so it may change when you restart X.  You should instead compute the path to the Xauthority file at runtime.

----------

