You are not logged in.

#1 2013-03-09 21:40:21

narrakan
Member
From: Italy
Registered: 2012-02-06
Posts: 15

[SOLVED] ACPI events not detected when running acpid from systemd

I'm trying to use acpi to listen for changes in the AC adapter state (plugging/unplugging the power cord) to activate xautolock in case the laptop is running on battery.

The problem is that when I use systemctl to enable and start acpid, I can see the ac_adapter events in the output of acpi_listen, but these events are not passed to the handler script. Strangely enough, if I run acpid manually with the debug option activated, the handler script runs correctly.

Relevant section of handler.sh (it's slightly modified since it didn't match the second argument when I first installed it):

ac_adapter)
        case "$2" in
            AC*|AD*)
                case "$4" in
                    00000000)
                        logger 'AC unpluged'
			xautolock -time 30 -locker "pm-suspend" &
                        ;;
                    00000001)
                        logger 'AC pluged'
			pkill xautolock &
                        ;;
                esac
                ;;
            *)
                logger "ACPI action undefined: $2"
                ;;
        esac
        ;;

Output of acpi_listen upon unplugging the cord:

$ acpi_listen 
battery PNP0C0A:00 00000080 00000001
battery PNP0C0A:00 00000001 00000001
battery PNP0C0A:00 00000080 00000001
processor LNXCPU:00 00000080 00000001
 PNP0C14:00 00000080 00000000
 PNP0C14:00 00000080 00000000
ac_adapter ACPI0003:00 00000000 00000000
ac_adapter ACPI0003:00 00000000 00000000
 PNP0C14:00 00000080 00000000
processor LNXCPU:00 00000082 00000000

And systemctl status:

$ sudo systemctl status acpid.service 
acpid.service - ACPI event daemon
	  Loaded: loaded (/usr/lib/systemd/system/acpid.service; enabled)
	  Active: active (running) since Sat 2013-03-09 22:16:52 CET; 19min ago
	Main PID: 17198 (acpid)
	  CGroup: name=systemd:/system/acpid.service
		  └─17198 /usr/sbin/acpid -f

Mar 09 22:35:36 arch su[17753]: (to root) root on none
Mar 09 22:35:36 arch su[17753]: pam_unix(su:session): session opened for user root by (uid=0)
Mar 09 22:35:44 arch su[17791]: (to root) root on none
Mar 09 22:35:44 arch su[17791]: pam_unix(su:session): session opened for user root by (uid=0)
Mar 09 22:35:44 arch su[17794]: (to root) root on none
Mar 09 22:35:44 arch su[17794]: pam_unix(su:session): session opened for user root by (uid=0)
Mar 09 22:35:44 arch su[17813]: (to root) root on none
Mar 09 22:35:44 arch su[17813]: pam_unix(su:session): session opened for user root by (uid=0)
Mar 09 22:35:44 arch su[17816]: (to root) root on none
Mar 09 22:35:44 arch su[17816]: pam_unix(su:session): session opened for user root by (uid=0)

I've been searching the wiki and Google for about two hours now, but I've come up with nothing that explains this behaviour.
Any thoughts?

Last edited by narrakan (2013-03-10 16:35:12)

Offline

#2 2013-03-10 02:45:06

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,132

Re: [SOLVED] ACPI events not detected when running acpid from systemd

You could try enabling logging for acpid maybe? See if it logs the events or not.

That is, copy the service to /etc/systemd/system and modify the service file so it enables logging.


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

#3 2013-03-10 13:23:05

narrakan
Member
From: Italy
Registered: 2012-02-06
Posts: 15

Re: [SOLVED] ACPI events not detected when running acpid from systemd

I've enabled logging by copying the service file and adding the -l switch to acpid, but I can't find the log anywhere. Shouldn't it be in /var/log or something?

$ sudo systemctl start acpid.service 
$ sudo systemctl status acpid.service 
acpid.service - ACPI event daemon
	  Loaded: loaded (/etc/systemd/system/acpid.service; disabled)
	  Active: active (running) since Sun 2013-03-10 14:17:03 CET; 7s ago
	Main PID: 1131 (acpid)
	  CGroup: name=systemd:/system/acpid.service
		  └─1131 /usr/sbin/acpid -fl

Mar 10 14:17:03 arch systemd[1]: Starting ACPI event daemon...
Mar 10 14:17:03 arch systemd[1]: Started ACPI event daemon.
Mar 10 14:17:06 arch acpid[1131]: starting up with netlink and the input layer
Mar 10 14:17:06 arch acpid[1131]: 3 rules loaded
Mar 10 14:17:06 arch acpid[1131]: waiting for events: event logging is on

Also, enabling debug mode in the service file and starting it using systemctl has the same issue. It's worth noting that the handler script is invoked, because other rules I've added are correctly parsed and applied (i.e. closing the lid when on battery causes the laptop to suspend). So I think the problem is strictly related to the AC adapter section and systemd.

EDIT: I've found out just now that the events are logged by journald, and as it turns out, they are received from acpi which calls handler.sh with the right arguments:

Mar 10 15:09:04 arch acpid[3172]: received netlink event "ac_adapter ACPI0003:00 00000000 00000000"
Mar 10 15:09:04 arch acpid[3172]: rule from /etc/acpi/events/anything matched
Mar 10 15:09:04 arch acpid[3505]: executing action "/etc/acpi/handler.sh ac_adapter ACPI0003:00 00000000 00000000"
Mar 10 15:09:04 arch acpid[3172]: action exited with status 0
Mar 10 15:09:04 arch acpid[3172]: rule from /etc/acpi/events/a-ac-aticonfig matched
Mar 10 15:09:04 arch acpid[3508]: executing action "/etc/acpi/ati-powermode.sh"
Mar 10 15:09:04 arch logger[3506]: AC unpluged

The problem does still persist, xautolock doesn't start, but if I manually execute the line "/etc/acpi/handler.sh ac_adapter ACPI0003:00 00000000 00000000" from the terminal, it's launched correctly. What the heck?

Last edited by narrakan (2013-03-10 14:15:17)

Offline

#4 2013-03-10 16:34:51

narrakan
Member
From: Italy
Registered: 2012-02-06
Posts: 15

Re: [SOLVED] ACPI events not detected when running acpid from systemd

Ok, after looking a bit further into the matter, I've realized that it's not acpi's or systemd's fault. I think that acpid, when launched through systemctl, does not have a display associated with it, so xautolock can't really perform any operation.

Following this guide and adapting it to Arch, I've managed to make xautolock run and appear in the process list, but still, when the timeout expires, nothing happens (I think the script is ok, since launching it manually as a normal user as well as root, it works). This is the script, if anyone should need it:

#!/bin/bash

user=`loginctl | egrep "^[0-9]*" | awk '{print $3}' | head -1`
export DISPLAY=:0.0 # matching my display, configuration may differ on other machines

su $user -c "xautolock -time 20 -locker 'systemctl suspend' &"

Since I've not been able to solve this issue, I've decided to avoid the problem completely by running xautolock at startup and making it invoke a script that checks if the AC adapter is plugged in before suspending.

I'll mark the topic as solved since it wasn't really a "problem" in the first place.

Offline

#5 2013-03-10 22:43:21

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,132

Re: [SOLVED] ACPI events not detected when running acpid from systemd

OK. I don't know if this is in any way at all relevant to xautolock but take a look at http://unix.stackexchange.com/questions … session-id anyway, just in case. I used this to get notifications working from scripts started by cron jobs. (Although it doesn't seem to work right when the cron job is a system job.) Basically, I split the notifications off from the main script so I could run the notification code as my normal user. However, maybe it might help in some way. (But probably not.)

I suspect there is now a much neater way of doing this with systemd but haven't got around to investigating.

Last edited by cfr (2013-03-10 22:43:59)


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

#6 2015-02-03 21:29:10

Alad
Wiki Admin/IRC Op
From: Bagelstan
Registered: 2014-05-04
Posts: 2,412
Website

Re: [SOLVED] ACPI events not detected when running acpid from systemd

I wouldn't call this solved. For me any command, be it X related or not, doesn't work when the events are handled by logind as well (even if you set the right Ignore options in logind.conf)

edit: reinstalled acpid, rebooted and now it seems to work (with necessary user hacks).. nevermind then.

Last edited by Alad (2015-02-04 09:05:50)


Mods are just community members who have the occasionally necessary option to move threads around and edit posts. -- Trilby

Offline

Board footer

Powered by FluxBB