2010/6/1 Ian Smith <[email protected]>: > In freebsd-questions Digest, Vol 313, Issue 4, Message: 26 > On Tue, 1 Jun 2010 10:55:08 +0200 David DEMELIER <[email protected]> > wrote: > > > I recently asked to make an automatic shutdown when I excess a > > specific percent. I ran devd with -Dd flags to run in background and > > when the battery was at a critical state it said : > > > > Processing event '!system=ACPI subsystem=CMBAT type=\_SB_.BAT0 notify=0x80' > > Pushing table > > setting system=ACPI > > setting subsystem=CMBAT > > setting type=\_SB_.BAT0 > > setting notify=0x80 > > You should be aware that notify 0x80 for CMBAT indicates 'BST' or > Battery State Change; you'll get these on shifting to any new state. > > You can check the new state with 'sysctl -n hw.acpi.battery.state'. > 'acpiconf -i0' shows a translation between state masks and names. > > > Then I tried (for testing) something like this in my /etc/devd.conf > > > > notify 10 { > > match "system" "ACPI"; > > match "subsystem" "CMBAT"; > > match "notify" "0x80"; > > action "logger LETGOSHUTDOWN"; > > }; > > > > And then I can see the following output in /var/log/messages : > > > > Jun 1 10:48:54 Melon power_profile: changed to 'performance' > > Reflecting your AC line state changing from Battery to AC. devd.conf > and /etc/rc.d/power_profile have good clues for handling devd notifies. > > > Jun 1 10:48:56 Melon root: LETGOSHUTDOWN > > Jun 1 10:49:12 Melon root: LETGOSHUTDOWN > > Jun 1 10:51:06 Melon last message repeated 2 times > > > > It works, but the problem is that it makes this even the cable is > > plugged ! i.e : the computer was not powered on so with 3% of > > remaining time but AC plugged in after booting it (always with the AC > > plugged in) these messages appears too. I guess the ACPI/CMBAT do not > > care if there is an AC plugged in or not. > > See /sys/dev/acpica/acpi_cmbat.c for the gory details. > > Yes, ACAD and CMBAT are independent subsystems, so rather than an inline > action like "logger .." here, you might follow the examples to run your > own script, passing the notify to that (if you may also want to check > for notify 0x81, BIF battery info changes, though these occur rarely) >
So I will check deeper. > > Is there a way to make this conditional to do only if the laptop is > > not charging, AC plugged in ? > > Your script can check whether the AC power is on with: > > AC=`sysctl -n hw.acpi.acline` > if [ $AC = 1 ]; then > exit 0 # or whatever, when on AC power > elif [ $AC = 0 ]; then > : # do whatever when on battery > else > : # AC/Battery state unknown .. > fi > > You could try just logging all state changes for a while; from critical > charging to charging to high to discharging to critical discharging, I > think that's the lot .. you can also check hw.acpi.battery.life etc. > Okay I will try a script like this one. > However, your system should do an 'emergency suspend' on critical low > battery anyway .. usually set at 1% capacity but some BIOS will let you > adjust that (see acpiconf -i0). Only if suspend/resume works of course. > It would be great if suspend/resume would works yes ! For the moment it's not the case : http://www.freebsd.org/cgi/query-pr.cgi?pr=i386/146715 Thanks for your answer ;-) -- Demelier David _______________________________________________ [email protected] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[email protected]"
