All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Sandeen <sandeen@redhat.com>
To: "Theodore Ts'o" <tytso@mit.edu>
Cc: Ext4 Developers List <linux-ext4@vger.kernel.org>
Subject: Re: [PATCH] e2fsck: check new sysfs interface to determine if we are on battery
Date: Mon, 20 Feb 2012 18:17:38 -0600	[thread overview]
Message-ID: <4F42E2A2.1020703@redhat.com> (raw)
In-Reply-To: <1329783103-4017-1-git-send-email-tytso@mit.edu>

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)


  reply	other threads:[~2012-02-21  0:17 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2012-02-21  1:24   ` Ted Ts'o

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4F42E2A2.1020703@redhat.com \
    --to=sandeen@redhat.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=tytso@mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.