You are not logged in.

#1 2012-12-19 06:21:23

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

[solved workaround] Wait with Udev rule on boot

This thread was subject to frequent changes. The initial question to which the following answers refer can be found in quotes below.

The final question is:

Is it possible to wait with the execution of an Udev rule during startup?

The reason is that my Udev rule runs a script which itself requires access to /sys/class/backlight.

However at the point in time when the Udev rule gets executed during boot, /sys/class/backlight does not exist yet.

How can I tell the Udev rule to wait some seconds before running the script?

The Udev rule:

[orschiro@thinkpad ~]$ cat /etc/udev/rules.d/50-powersave.rules 
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="0", RUN+="/usr/local/bin/powersaving battery"
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="1", RUN+="/usr/local/bin/powersaving AC"

The script:

[orschiro@thinkpad ~]$ cat /usr/local/bin/powersaving 
#!/bin/sh

case $1 in
    battery)
		echo "Running powersaving on AC in 15 seconds"
		sleep 15
		# screen power saving"
		echo 200000 > /sys/class/backlight/intel_backlight/brightness
    ;;
    AC)
		echo "Running powersaving on battery in 15 seconds"
	    	sleep 15
		# screen power saving
		echo 4270725 > /sys/class/backlight/intel_backlight/brightness
    ;;
esac

Hello,

Why is the following Udev rule not run on boot?

[orschiro@thinkpad ~]$ cat /etc/udev/rules.d/50-powersaving.rules
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="0", RUN+="/usr/local/bin/powersaving battery"
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="1", RUN+="/usr/local/bin/powersaving AC"

When the system is running everything works as expected and the Udev rule recognises whether my system is using battery or AC but not on boot.

Regards

Last edited by orschiro (2013-02-21 20:59:04)

Offline

#2 2012-12-19 10:57:48

mariusmeyer
Member
From: Norway
Registered: 2009-04-25
Posts: 244

Re: [solved workaround] Wait with Udev rule on boot

What do you mean "on boot"? How long into the boot process do you have to wait for it to kick in?

Offline

#3 2012-12-19 13:13:00

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: [solved workaround] Wait with Udev rule on boot

By on boot I mean that the udev rule which should check whether I am running on battery or AC is not executed. Thus, my /usr/local/binpowersaving script is not executed either and I stuck with battery settings if I was on battery before I had shutdown my system.

Last edited by orschiro (2012-12-19 13:13:43)

Offline

#4 2012-12-19 13:39:11

mariusmeyer
Member
From: Norway
Registered: 2009-04-25
Posts: 244

Re: [solved workaround] Wait with Udev rule on boot

But you say that it works when the system is running. So, after you have booted and logged into you DE or whatever, does it suddenly start working? Or do you need to do something manually to make it start applying the udev rule? Do you have /usr on a separate partition?

Offline

#5 2012-12-19 13:41:15

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: [solved workaround] Wait with Udev rule on boot

No, /usr is on the same partition as /.

What I meant by "when the system is running" is that the rule itself works when I plug/unplug the cable to switch between battery and AC state. In this cases the udev rule recognises a change in power supply and runs my powersaving script.

Offline

#6 2012-12-19 16:53:18

brebs
Member
Registered: 2007-04-03
Posts: 3,742

Re: [solved workaround] Wait with Udev rule on boot

What if POWER_SUPPLY_ONLINE can have a value other than 0 or 1?

So this would be safer, in your 2nd rule:

ENV{POWER_SUPPLY_ONLINE}!="1"

Offline

#7 2012-12-19 22:43:20

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: [solved workaround] Wait with Udev rule on boot

Thanks brebs but that did not help either. Actually I am running out of ideas. I created a bunch of different rules but none of them worked.

[orschiro@thinkpad ~]$ ls /etc/udev/rules.d/
00-powersaving2.rules     01-powersaving.rules      50-powersaving.rules      60-powersaving2.rules     90-powersaving.rules      powerdown3.rules
00-powersaving.rules      0-powersaving2.rules      51-powerdown.rules        60-powersaving.rules      network_persistent.rules  powerdown.rules
01-powersaving2.rules     50-powerdown.rules        51-powersaving.rules      90-powersaving2.rules     powerdown2.rules          
[orschiro@thinkpad ~]$ cat /etc/udev/rules.d/*
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="0", RUN+="/usr/local/bin/powersaving battery"
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="1", RUN+="/usr/local/bin/powersaving AC"
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="0", RUN+="/usr/local/bin/powersaving battery"
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}!="1", RUN+="/usr/local/bin/powersaving AC"
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="0", RUN+="/usr/local/bin/powersaving battery"
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="1", RUN+="/usr/local/bin/powersaving AC"
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="0", RUN+="/usr/local/bin/powersaving battery"
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}!="1", RUN+="/usr/local/bin/powersaving AC"
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="0", RUN+="/usr/local/bin/powersaving battery"
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="1", RUN+="/usr/local/bin/powersaving AC"
KERNEL=="AC", SUBSYSTEM=="power_supply", ATTR{online}=="0", RUN+="/usr/local/bin/powersaving battery"
KERNEL=="AC", SUBSYSTEM=="power_supply", ATTR{online}=="1", RUN+="/usr/local/bin/powersaving AC"
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="0", RUN+="/usr/local/bin/powersaving battery"
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="1", RUN+="/usr/local/bin/powersaving AC"
SUBSYSTEM=="power_supply", ATTR{online}=="0", RUN+="/usr/local/bin/powersaving battery"
SUBSYSTEM=="power_supply", ATTR{online}=="1", RUN+="/usr/local/bin/powersaving AC"
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_AC_ONLINE}=="0", RUN+="/usr/local/bin/powersaving battery"
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_AC_ONLINE}=="1", RUN+="/usr/local/bin/powersaving AC"
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="0", RUN+="/usr/local/bin/powersaving battery"
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="1", RUN+="/usr/local/bin/powersaving AC"
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="0", RUN+="/usr/local/bin/powersaving battery"
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}!="1", RUN+="/usr/local/bin/powersaving AC"
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="0", RUN+="/usr/local/bin/powersaving battery"
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="1", RUN+="/usr/local/bin/powersaving AC"
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="0", RUN+="/usr/local/bin/powersaving battery"
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}!="1", RUN+="/usr/local/bin/powersaving AC"
KERNEL=="AC", SUBSYSTEM=="power_supply", ATTR{online}=="0", RUN+="/usr/local/bin/powersaving battery"
KERNEL=="AC", SUBSYSTEM=="power_supply", ATTR{online}=="1", RUN+="/usr/local/bin/powersaving AC"
KERNEL=="AC1", SUBSYSTEM=="power_supply", ATTR{online}=="0", RUN+="/usr/local/bin/powersaving battery"
KERNEL=="AC1", SUBSYSTEM=="power_supply", ATTR{online}=="1", RUN+="/usr/local/bin/powersaving AC"
KERNEL=="AC0", SUBSYSTEM=="power_supply", ATTR{online}=="0", RUN+="/usr/local/bin/powersaving battery"
KERNEL=="AC0", SUBSYSTEM=="power_supply", ATTR{online}=="1", RUN+="/usr/local/bin/powersaving AC"

Is it maybe a subsystem path problem?

[orschiro@thinkpad ~]$ cat /sys/class/power_supply/AC/online
1

Last edited by orschiro (2012-12-19 22:43:53)

Offline

#8 2013-01-22 18:23:39

jordz
Member
Registered: 2006-02-01
Posts: 250

Re: [solved workaround] Wait with Udev rule on boot

Hey orschiro,

I had the same issue as you have. Since 3.7.3-1-ARCH the cpufreq module isn't automatically loaded anymore. I created a file in /etc/modules-load.d/ and now the udev rule works as expected at boot. I'm not sure if it's the module getting loaded manually or it is a fix in the new kernel (or systemd).

~ > cat /etc/udev/rules.d/10-power.rules 
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="0", RUN+="/usr/bin/cpupower frequency-set -g ondemand"
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="1", RUN+="/usr/bin/cpupower frequency-set -g performance"
~ > cat /etc/modules-load.d/cpufreq.conf 
acpi_cpufreq
~ > uname -r
3.7.3-1-ARCH

Offline

#9 2013-02-13 14:48:12

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: [solved workaround] Wait with Udev rule on boot

Thanks jordz but this cannot be my problem since my powersaving script that I want to to run through the udev rule just contains a xbacklight command which does not require any special module to be loaded, I guess?

Offline

#10 2013-02-13 17:46:10

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: [solved workaround] Wait with Udev rule on boot

orschiro wrote:

Thanks jordz but this cannot be my problem since my powersaving script that I want to to run through the udev rule just contains a xbacklight command which does not require any special module to be loaded, I guess?

It requires that udev knows about your X display, which isn't going to happen. Your rule is being triggered. Your script is not doing what you think it is.

Offline

#11 2013-02-16 07:36:30

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: [solved workaround] Wait with Udev rule on boot

I cannot say what I have changed but now the above rule in the first post does not even work during run time. My script is not run. No error appears in journalctl. I checked the udev monitor and nothing changed underneath:

error log:

Feb 16 09:05:50 thinkpad kernel: thinkpad_acpi: EC reports that Thermal Table has changed
Feb 16 09:05:52 thinkpad kernel: thinkpad_acpi: EC reports that Thermal Table has changed
Feb 16 09:05:54 thinkpad sudo[5863]: orschiro : TTY=pts/1 ; PWD=/home/orschiro ; USER=root ; COMMAND=/usr/bin/journalctl -b
Feb 16 09:05:54 thinkpad sudo[5863]: pam_unix(sudo:session): session opened for user root by orschiro(uid=0)
Feb 16 09:05:55 thinkpad kernel: e1000e 0000:00:19.0: irq 44 for MSI/MSI-X
[orschiro@thinkpad ~]$ udevadm info --path=/sys/class/power_supply/AC
P: /devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:00/PNP0C09:00/ACPI0003:00/power_supply/AC
E: DEVPATH=/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:00/PNP0C09:00/ACPI0003:00/power_supply/AC
E: POWER_SUPPLY_NAME=AC
E: POWER_SUPPLY_ONLINE=1
E: SUBSYSTEM=power_supply
[orschiro@thinkpad ~]$ udevadm monitor --subsystem-match=power_supply
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing
KERNEL - the kernel uevent

KERNEL[1328.641620] change   /devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:00/PNP0C09:00/ACPI0003:00/power_supply/AC (power_supply)
UDEV  [1328.652545] change   /devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:00/PNP0C09:00/ACPI0003:00/power_supply/AC (power_supply)
KERNEL[1328.883670] change   /devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:00/PNP0C09:00/PNP0C0A:00/power_supply/BAT0 (power_supply)
UDEV  [1328.885382] change   /devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:00/PNP0C09:00/PNP0C0A:00/power_supply/BAT0 (power_supply)
KERNEL[1340.615512] change   /devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:00/PNP0C09:00/ACPI0003:00/power_supply/AC (power_supply)
UDEV  [1340.636953] change   /devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:00/PNP0C09:00/ACPI0003:00/power_supply/AC (power_supply)
KERNEL[1340.717207] change   /devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:00/PNP0C09:00/PNP0C0A:00/power_supply/BAT0 (power_supply)
UDEV  [1340.726467] change   /devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:00/PNP0C09:00/PNP0C0A:00/power_supply/BAT0 (power_supply)

Can someone please help me to create a Udev rule that works for the AC changes?

Last edited by orschiro (2013-02-16 08:07:00)

Offline

#12 2013-02-21 07:13:17

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: [solved workaround] Wait with Udev rule on boot

Another progress. After fiddling around for a while I have it now configured to run successfully during run time. When I plug/unplug the cable the Udev rule gets applied.

The rule:

[orschiro@thinkpad ~]$ cat /etc/udev/rules.d/50-powersave.rules 
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="0", RUN+="/home/orschiro/Scripts/powersaving battery"
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="1", RUN+="/home/orschiro/Scripts/powersaving AC"

And the script to adjust the brightness:

[orschiro@thinkpad ~]$ cat Scripts/powersaving 
#!/bin/sh

case $1 in
    battery)
		echo "Running powersaving on AC"
		
		# screen power saving"
		echo 200000 > /sys/class/backlight/intel_backlight/brightness
    ;;
    AC)
		echo "Running powersaving on battery"
	    
		# screen power saving
		echo 4270725 > /sys/class/backlight/intel_backlight/brightness
    ;;
esac

However, the problem on boot persists. That is, if I turn down brightness completely and reboot whilst being on AC, my brightness does not get adjusted according to the rule. Thus, after the reboot I have to unplug/plug the cable to have the correct settings restored. Any other ideas why this may happen?

Offline

#13 2013-02-21 21:00:51

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: [solved workaround] Wait with Udev rule on boot

If I cannot delay the Udev rule on boot, then I will delay my power saving script by a few seconds:

[orschiro@thinkpad ~]$ cat /usr/local/bin/powersaving 
#!/bin/sh

case $1 in
    battery)
		echo "Running powersaving on AC in 3 seconds"
		sleep 3
		# screen power saving"
		echo 200000 > /sys/class/backlight/intel_backlight/brightness
    ;;
    AC)
		echo "Running powersaving on battery in 3 seconds"
	    	sleep 3
		# screen power saving
		echo 4270725 > /sys/class/backlight/intel_backlight/brightness
    ;;
esac

Problem solved with this workaround.

Offline

Board footer

Powered by FluxBB