Bug 644629 - Please check /sys/class/power_supply/ for AC power state
Summary: Please check /sys/class/power_supply/ for AC power state
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Fedora
Classification: Fedora
Component: e2fsprogs
Version: 19
Hardware: All
OS: Linux
low
medium
Target Milestone: ---
Assignee: Eric Sandeen
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2010-10-19 20:42 UTC by Lennart Poettering
Modified: 2015-02-07 19:43 UTC (History)
4 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2015-02-07 19:43:02 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Lennart Poettering 2010-10-19 20:42:38 UTC
In unix.c's is_on_batt() function /proc/apm and /proc/acpi/ac_adapter/*/state are checked for battery state. In newer kernels the /sys/class/power_supply/ tree has replaced these interfaces and supports more than just APM/ACPI batteries.

e2fsprogs should be updated to read /sys/class/power_supply.

Comment 1 Lennart Poettering 2010-10-19 20:48:29 UTC
Hmm, as it turns out /proc/acpi is in the process of being deprecated, hence it is a really good idea to make use of /sys/class/power_supply.

Comment 2 Lennart Poettering 2010-10-25 18:22:18 UTC
Hmm, seems 2.6.36 began with removing /proc/acpi:

http://kernelnewbies.org/Linux_2_6_36-DriversArch#head-bf6fc1898f64b5015f69044c727fcfa76aa8cb08

So, that basically means that this fsck feature doesn't work anymore on current kernels unless support for /sys/class/power/supply is added.

Comment 3 Eric Sandeen 2010-10-25 18:31:10 UTC
Yes, this should be fixed.  I've always thought it's a little odd for filesystems to care about power sources, but this one does, so we'll need to look into fixing.

Thanks,
-Eric

Comment 4 Eric Sandeen 2011-03-09 20:50:02 UTC
$ ls /sys/class/power_supply/
$

Hrm.

So, ah, what file under /sys/class/power_supply tells us if we're on battery or not?

Comment 5 Lennart Poettering 2011-03-15 01:58:17 UTC
You need to enumerate through all power supply devices with the "type" = "Mains" attribute, and check if any of them have the "online" attribute as "1". If so you have AC power. If don't find any power supply of "type" = "Mains" then you are on AC power too. Only if you have one or more power supplies of "type" = "Mains" and all of them have "online" = "0" then you are on battery.

Yeah, sounds weird. In systemd we have this logic in this piece of code:

http://cgit.freedesktop.org/systemd/tree/src/ac-power.c

It links against libudev. However it is relatively trivial to implement this without libudev if you want to.

Comment 6 Eric Sandeen 2011-04-05 18:55:52 UTC
Ugh.  Maybe we should just remove the code altogether ;)

Comment 7 Lennart Poettering 2011-04-06 18:27:49 UTC
tsss. but i think it actually is a useful feature. And much nicer than the crack the Debianites came up with (they just skipped fsck entirely when no AC power was on).

Comment 8 Fedora End Of Life 2013-04-03 18:33:54 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 19 development cycle.
Changing version to '19'.

(As we did not run this process for some time, it could affect also pre-Fedora 19 development
cycle bugs. We are very sorry. It will help us with cleanup during Fedora 19 End Of Life. Thank you.)

More information and reason for this action is here:
https://fedoraproject.org/wiki/BugZappers/HouseKeeping/Fedora19

Comment 9 Fedora End Of Life 2015-01-09 16:23:28 UTC
This message is a notice that Fedora 19 is now at end of life. Fedora 
has stopped maintaining and issuing updates for Fedora 19. It is 
Fedora's policy to close all bug reports from releases that are no 
longer maintained. Approximately 4 (four) weeks from now this bug will
be closed as EOL if it remains open with a Fedora 'version' of '19'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version' 
to a later Fedora version.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora 19 is end of life. If you would still like 
to see this bug fixed and are able to reproduce it against a later version 
of Fedora, you are encouraged  change the 'version' to a later Fedora 
version prior this bug is closed as described in the policy above.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events. Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.

Comment 10 Eric Sandeen 2015-02-07 19:43:02 UTC
Oh, hey, look at that:

commit ad880a0e2bb1bef11382b4f38d440529e4cbdc2e
Author: Theodore Ts'o <tytso>
Date:   Mon Feb 20 19:10:19 2012 -0500

    e2fsck: check new sysfs interface to determine if we are on battery
    
    ...since the old way is deprecated.
    
    Addresses-SourceForge-Bug: #3439277
    
    Signed-off-by: "Theodore Ts'o" <tytso>

diff --git a/e2fsck/unix.c b/e2fsck/unix.c
index c38b67a..6f97b0f 100644
--- a/e2fsck/unix.c
+++ b/e2fsck/unix.c
@@ -252,6 +252,14 @@ static int is_on_batt(void)
        unsigned int    acflag;
        struct dirent*  de;
 
+       f = fopen("/sys/class/power_supply/AC/online", "r");
...


Note You need to log in before you can comment on or make changes to this bug.