* [PATCH] e2fsck: check new sysfs interface to determine if we are on battery
@ 2012-02-21 0:11 Theodore Ts'o
2012-02-21 0:17 ` Eric Sandeen
0 siblings, 1 reply; 3+ messages in thread
From: Theodore Ts'o @ 2012-02-21 0:11 UTC (permalink / raw)
To: Ext4 Developers List; +Cc: Theodore Ts'o
...since the old way is deprecated.
Addresses-SourceForge-Bug: #3439277
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
---
e2fsck/unix.c | 8 ++++++++
1 files changed, 8 insertions(+), 0 deletions(-)
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");
+ if (f) {
+ if (fscanf(f, "%d\n", &acflag) == 1) {
+ fclose(f);
+ return (!acflag);
+ }
+ fclose(f);
+ }
f = fopen("/proc/apm", "r");
if (f) {
if (fscanf(f, "%s %s %s %x", tmp, tmp, tmp, &acflag) != 4)
--
1.7.9.107.g97f9a
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] e2fsck: check new sysfs interface to determine if we are on battery
2012-02-21 0:11 [PATCH] e2fsck: check new sysfs interface to determine if we are on battery Theodore Ts'o
@ 2012-02-21 0:17 ` Eric Sandeen
2012-02-21 1:24 ` Ted Ts'o
0 siblings, 1 reply; 3+ messages in thread
From: Eric Sandeen @ 2012-02-21 0:17 UTC (permalink / raw)
To: Theodore Ts'o; +Cc: Ext4 Developers List
On 2/20/12 6:11 PM, Theodore Ts'o wrote:
> ...since the old way is deprecated.
>
> Addresses-SourceForge-Bug: #3439277
Red Hat bug #644629 too
But https://bugzilla.redhat.com/show_bug.cgi?id=644629#c5
made it sound harder than this, so I was ... keeping that bug
on the back burner ...
> 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.
If your patch fixes the general case, I say go for it! :)
-Eric
>
> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
> ---
> e2fsck/unix.c | 8 ++++++++
> 1 files changed, 8 insertions(+), 0 deletions(-)
>
> 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");
> + if (f) {
> + if (fscanf(f, "%d\n", &acflag) == 1) {
> + fclose(f);
> + return (!acflag);
> + }
> + fclose(f);
> + }
> f = fopen("/proc/apm", "r");
> if (f) {
> if (fscanf(f, "%s %s %s %x", tmp, tmp, tmp, &acflag) != 4)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] e2fsck: check new sysfs interface to determine if we are on battery
2012-02-21 0:17 ` Eric Sandeen
@ 2012-02-21 1:24 ` Ted Ts'o
0 siblings, 0 replies; 3+ messages in thread
From: Ted Ts'o @ 2012-02-21 1:24 UTC (permalink / raw)
To: Eric Sandeen; +Cc: Ext4 Developers List
On Mon, Feb 20, 2012 at 06:17:38PM -0600, Eric Sandeen wrote:
> > 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.
*Ugh*. Why is it that the new interfaces are always more complicated. :-(
> If your patch fixes the general case, I say go for it! :)
All's the world a Thinkpad, right? :-)
- Ted
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-02-21 1:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-21 0:11 [PATCH] e2fsck: check new sysfs interface to determine if we are on battery Theodore Ts'o
2012-02-21 0:17 ` Eric Sandeen
2012-02-21 1:24 ` Ted Ts'o
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).