From owner-freebsd-questions@FreeBSD.ORG Tue Jun 1 16:03:30 2010 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id AE67B1065679 for ; Tue, 1 Jun 2010 16:03:30 +0000 (UTC) (envelope-from demelier.david@gmail.com) Received: from mail-fx0-f54.google.com (mail-fx0-f54.google.com [209.85.161.54]) by mx1.freebsd.org (Postfix) with ESMTP id 40A0E8FC1D for ; Tue, 1 Jun 2010 16:03:29 +0000 (UTC) Received: by fxm5 with SMTP id 5so3817009fxm.13 for ; Tue, 01 Jun 2010 09:03:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=HVpuLc78NmBK2JdjJmTZqR0oFu/k0PVgj6oqQ1VQP0M=; b=oZUQ+HJEWEVGdCP6jQLbWR/pkC4YPBryJxEDbKG93c+adzIEAIsrQtSOyCoSCwQ74c Ayjrw+/jCclhonq86f8hWHLvGesjAe6JTGtFV4bNYtsGZhssyw1hs6v4rzKXLky4TuF9 rK7ehYvm0nfiHua+2PfETsTTopxfXqYTBSomA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=fofK5DfseVFZ/EV3lHFolf6nP7m2sb8DImpKvHiEpYaYb7pA5M48JtnKk4mEvovOoT mu4+1aOre8QmWJ44TkB7WzupKf6XEBJEHPaFJKiJGt9U5GJwd/c5O1Ldlb86UQBaNA0q NEJtm0Wm/sCz4lhRM5RC6Vkt6uWoX+rygSrK0= MIME-Version: 1.0 Received: by 10.204.137.216 with SMTP id x24mr812676bkt.168.1275408207954; Tue, 01 Jun 2010 09:03:27 -0700 (PDT) Received: by 10.204.123.202 with HTTP; Tue, 1 Jun 2010 09:03:27 -0700 (PDT) In-Reply-To: <20100602001405.T27982@sola.nimnet.asn.au> References: <20100601120131.A070C10657ED@hub.freebsd.org> <20100602001405.T27982@sola.nimnet.asn.au> Date: Tue, 1 Jun 2010 18:03:27 +0200 Message-ID: From: David DEMELIER To: Ian Smith Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: freebsd-questions@freebsd.org Subject: Re: Automatic shutdown with devd. X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Jun 2010 16:03:30 -0000 2010/6/1 Ian Smith : > In freebsd-questions Digest, Vol 313, Issue 4, Message: 26 > On Tue, 1 Jun 2010 10:55:08 +0200 David DEMELIER wrote: > > =C2=A0> I recently asked to make an automatic shutdown when I excess a > =C2=A0> specific percent. I ran devd with -Dd flags to run in background = and > =C2=A0> when the battery was at a critical state it said : > =C2=A0> > =C2=A0> Processing event '!system=3DACPI subsystem=3DCMBAT type=3D\_SB_.B= AT0 notify=3D0x80' > =C2=A0> Pushing table > =C2=A0> setting system=3DACPI > =C2=A0> setting subsystem=3DCMBAT > =C2=A0> setting type=3D\_SB_.BAT0 > =C2=A0> setting notify=3D0x80 > > 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. > > =C2=A0> Then I tried (for testing) something like this in my /etc/devd.co= nf > =C2=A0> > =C2=A0> notify 10 { > =C2=A0> =C2=A0 =C2=A0 =C2=A0 =C2=A0 match "system" =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0"ACPI"; > =C2=A0> =C2=A0 =C2=A0 =C2=A0 =C2=A0 match "subsystem" =C2=A0 =C2=A0 =C2= =A0 "CMBAT"; > =C2=A0> =C2=A0 =C2=A0 =C2=A0 =C2=A0 match "notify" =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0"0x80"; > =C2=A0> =C2=A0 =C2=A0 =C2=A0 =C2=A0 action "logger LETGOSHUTDOWN"; > =C2=A0> }; > =C2=A0> > =C2=A0> And then I can see the following output in /var/log/messages : > =C2=A0> > =C2=A0> Jun =C2=A01 10:48:54 Melon power_profile: changed to 'performance= ' > > Reflecting your AC line state changing from Battery to AC. =C2=A0devd.con= f > and /etc/rc.d/power_profile have good clues for handling devd notifies. > > =C2=A0> Jun =C2=A01 10:48:56 Melon root: LETGOSHUTDOWN > =C2=A0> Jun =C2=A01 10:49:12 Melon root: LETGOSHUTDOWN > =C2=A0> Jun =C2=A01 10:51:06 Melon last message repeated 2 times > =C2=A0> > =C2=A0> It works, but the problem is that it makes this even the cable is > =C2=A0> plugged ! i.e : the computer was not powered on so with 3% of > =C2=A0> remaining time but AC plugged in after booting it (always with th= e AC > =C2=A0> plugged in) these messages appears too. I guess the ACPI/CMBAT do= not > =C2=A0> 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. > =C2=A0> Is there a way to make this conditional to do only if the laptop = is > =C2=A0> not charging, AC plugged in ? > > Your script can check whether the AC power is on with: > > =C2=A0 =C2=A0 =C2=A0 =C2=A0AC=3D`sysctl -n hw.acpi.acline` > =C2=A0 =C2=A0 =C2=A0 =C2=A0if [ $AC =3D 1 ]; then > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0exit 0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0# or whatever, when on AC power > =C2=A0 =C2=A0 =C2=A0 =C2=A0elif [ $AC =3D 0 ]; then > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0: =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 # do whatever when on battery > =C2=A0 =C2=A0 =C2=A0 =C2=A0else > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0: =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 # AC/Battery state unknown .. > =C2=A0 =C2=A0 =C2=A0 =C2=A0fi > > 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). =C2=A0Only if suspend/resume works of cou= rse. > 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=3Di386/146715 Thanks for your answer ;-) --=20 Demelier David