threads / patch / 39598

patchFix power checking on OS X

Subject: [PATCH] Fix power checking on OS X

## tl;dr

5 messages between Jun 11, 2015 and Jun 12, 2015. Diffs are folded; open one to read it.

replies: 4people: 3as markdown or json

Panagiotis Astithas· Jun 11, 2015, 14:37 UTC · lore

The output of "pmset -g batt" changed at some point from "Currently drawing from 'AC Power'" to the slightly different "Now drawing from 'AC Power'". Starting the match from "drawing" makes the check work in both old and new versions of OS X.

Signed-off-by: Panagiotis Astithas <pastith@gmail.com>
---
 contrib/hooks/pre-auto-gc-battery | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Show changes to contrib/hooks/pre-auto-gc-battery +1 −1
diff --git a/contrib/hooks/pre-auto-gc-battery b/contrib/hooks/pre-auto-gc-battery
index 9d0c2d1..6a2cdeb 100755
--- a/contrib/hooks/pre-auto-gc-battery
+++ b/contrib/hooks/pre-auto-gc-battery
@@ -33,7 +33,7 @@ elif grep -q "AC Power \+: 1" /proc/pmu/info 2>/dev/null
 then
 	exit 0
 elif test -x /usr/bin/pmset && /usr/bin/pmset -g batt |
-	grep -q "Currently drawing from 'AC Power'"
+	grep -q "drawing from 'AC Power'"
 then
 	exit 0
 fi
-- 
2.4.1
Eric Sunshine· Jun 12, 2015, 03:46 UTC · re: Panagiotis Astithas · lore

Re: [PATCH] Fix power checking on OS X

On Thu, Jun 11, 2015 at 10:37 AM, Panagiotis Astithas <pastith@gmail.com> wrote:
> The output of "pmset -g batt" changed at some point from
> "Currently drawing from 'AC Power'" to the slightly different
> "Now drawing from 'AC Power'". Starting the match from "drawing"
> makes the check work in both old and new versions of OS X.

Would it make sense to try to future-proof this further by searching only for "'AC" (including the leading single-quote) or just "AC" (without the leading quote)?

(Genuine question. I don't have a strong feeling about it.)
Show 17 quoted lines
> Signed-off-by: Panagiotis Astithas <pastith@gmail.com>
> ---
> diff --git a/contrib/hooks/pre-auto-gc-battery b/contrib/hooks/pre-auto-gc-battery
> index 9d0c2d1..6a2cdeb 100755
> --- a/contrib/hooks/pre-auto-gc-battery
> +++ b/contrib/hooks/pre-auto-gc-battery
> @@ -33,7 +33,7 @@ elif grep -q "AC Power \+: 1" /proc/pmu/info 2>/dev/null
>  then
>         exit 0
>  elif test -x /usr/bin/pmset && /usr/bin/pmset -g batt |
> -       grep -q "Currently drawing from 'AC Power'"
> +       grep -q "drawing from 'AC Power'"
>  then
>         exit 0
>  fi
> --
> 2.4.1
Panagiotis Astithas· Jun 12, 2015, 08:53 UTC · re: Eric Sunshine · lore

Re: [PATCH] Fix power checking on OS X

On Fri, Jun 12, 2015 at 6:46 AM, Eric Sunshine <sunshine@sunshineco.com> wrote:
Show 11 quoted lines
> On Thu, Jun 11, 2015 at 10:37 AM, Panagiotis Astithas <pastith@gmail.com> wrote:
>> The output of "pmset -g batt" changed at some point from
>> "Currently drawing from 'AC Power'" to the slightly different
>> "Now drawing from 'AC Power'". Starting the match from "drawing"
>> makes the check work in both old and new versions of OS X.
>
> Would it make sense to try to future-proof this further by searching
> only for "'AC" (including the leading single-quote) or just "AC"
> (without the leading quote)?
>
> (Genuine question. I don't have a strong feeling about it.)

It's a reasonable idea, although I'm wondering what are the odds of pmset changing to output a string when running on battery in the future, containing something like "no longer on 'AC Power'". That's probably too far out though.

Junio C Hamano· Jun 12, 2015, 14:54 UTC · re: Panagiotis Astithas · lore

Re: [PATCH] Fix power checking on OS X

Panagiotis Astithas <pastith@gmail.com> writes:
Show 17 quoted lines
> On Fri, Jun 12, 2015 at 6:46 AM, Eric Sunshine <sunshine@sunshineco.com> wrote:
>> On Thu, Jun 11, 2015 at 10:37 AM, Panagiotis Astithas <pastith@gmail.com> wrote:
>>> The output of "pmset -g batt" changed at some point from
>>> "Currently drawing from 'AC Power'" to the slightly different
>>> "Now drawing from 'AC Power'". Starting the match from "drawing"
>>> makes the check work in both old and new versions of OS X.
>>
>> Would it make sense to try to future-proof this further by searching
>> only for "'AC" (including the leading single-quote) or just "AC"
>> (without the leading quote)?
>>
>> (Genuine question. I don't have a strong feeling about it.)
>
> It's a reasonable idea, although I'm wondering what are the odds of
> pmset changing to output a string when running on battery in the
> future, containing something like "no longer on 'AC Power'". That's
> probably too far out though.

Once they start drawing from USB-C, they may stop referring to AC altogether; unless you have a crystal ball, it is futile to spend too many brain cycles to try futureproofing.

Prediction is very difficult, especially if it's about the future.
Eric Sunshine· Jun 12, 2015, 15:58 UTC · re: Panagiotis Astithas · lore

Re: [PATCH] Fix power checking on OS X

On Fri, Jun 12, 2015 at 4:53 AM, Panagiotis Astithas <pastith@gmail.com> wrote:
Show 17 quoted lines
> On Fri, Jun 12, 2015 at 6:46 AM, Eric Sunshine <sunshine@sunshineco.com> wrote:
>> On Thu, Jun 11, 2015 at 10:37 AM, Panagiotis Astithas <pastith@gmail.com> wrote:
>>> The output of "pmset -g batt" changed at some point from
>>> "Currently drawing from 'AC Power'" to the slightly different
>>> "Now drawing from 'AC Power'". Starting the match from "drawing"
>>> makes the check work in both old and new versions of OS X.
>>
>> Would it make sense to try to future-proof this further by searching
>> only for "'AC" (including the leading single-quote) or just "AC"
>> (without the leading quote)?
>>
>> (Genuine question. I don't have a strong feeling about it.)
>
> It's a reasonable idea, although I'm wondering what are the odds of
> pmset changing to output a string when running on battery in the
> future, containing something like "no longer on 'AC Power'". That's
> probably too far out though.
That was my concern, as well, hence not feeling strongly about it.

← back to recent threads