unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#24919: 24.5; battery.el not working in FreeBSD
@ 2016-09-17 23:17 Ignacio Torres
  2016-11-11 17:58 ` Joakim Jalap
  0 siblings, 1 reply; 6+ messages in thread
From: Ignacio Torres @ 2016-09-17 23:17 UTC (permalink / raw)
  To: 24919


Running M-x battery in FreeBSD returns:

Power disconnected, battery high (illegal% load, remaining time 0:00)

The battery-bsd-apm function was contributed in [1]. It contains:

(apm-cmd (concat "/usr/sbin/apm -ablm" apm-flag))

The -m flag used in NetBSD[2] and OpenBSD[3] to show the remaining time
in minutes does not exist in FreeBSD[4]. Instead -t should be used to
show the remaining time in seconds.

Also the resulting output is in a different order than that expected by
the parser. battery-bsd-apm expects the order to be:

battery-status
battery-percentage
battery-life
line-status
apm-mode

In FreeBSD it is:

line-status
battery-status
battery-percentage
apm-mode
battery-life

As can be seen in the source of /usr/sbin/apm.c[5]

[1] http://git.savannah.gnu.org/cgit/emacs.git/commit/lisp/battery.el?id=19b748ad448c37d08ae1df1212aec22ee1d55956
[2] http://netbsd.gw.com/cgi-bin/man-cgi?apm++NetBSD-current
[3] http://man.openbsd.org/OpenBSD-current/man8/amd64/apm.8
[4] https://www.freebsd.org/cgi/man.cgi?query=apm&manpath=FreeBSD+10.3-RELEASE+and+Ports
[5] https://svnweb.freebsd.org/base/stable/11/usr.sbin/apm/apm.c?revision=302408&view=markup#l472



In GNU Emacs 24.5.1 (amd64-portbld-freebsd12.0, GTK+ Version 2.24.29)
 of 2016-08-27 on builds.trueos.org
Windowing system distributor `The X.Org Foundation', version 11.0.11804000
Configured using:
 `configure --localstatedir=/var --disable-acl --with-dbus
 --without-file-notification --with-gconf --with-gif --with-gnutls
 --with-gsettings --with-jpeg --with-m17n-flt --with-imagemagick
 --with-libotf --with-png --with-toolkit-scroll-bars --with-rsvg
 --with-tiff --with-x --with-xft --with-xim --with-xml2 --with-xpm
 --with-x-toolkit=gtk2 --with-sound=oss --x-libraries=/usr/local/lib
 --x-includes=/usr/local/include --prefix=/usr/local
 --mandir=/usr/local/man --infodir=/usr/local/share/emacs/info/
 --build=amd64-portbld-freebsd12.0 'CFLAGS=-O2 -pipe -isystem
 /usr/local/include -fstack-protector -fno-strict-aliasing'
 'CPPFLAGS=-isystem /usr/local/include' 'LDFLAGS= -L/usr/local/lib
 -Wl,-rpath=/usr/lib:/usr/local/lib -fstack-protector''

Important settings:
  value of $LC_ALL: en_US.UTF-8
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#24919: 24.5; battery.el not working in FreeBSD
  2016-09-17 23:17 bug#24919: 24.5; battery.el not working in FreeBSD Ignacio Torres
@ 2016-11-11 17:58 ` Joakim Jalap
  2017-03-08 13:58   ` Alan Third
  0 siblings, 1 reply; 6+ messages in thread
From: Joakim Jalap @ 2016-11-11 17:58 UTC (permalink / raw)
  To: Ignacio Torres; +Cc: 24919

[-- Attachment #1: Type: text/plain, Size: 310 bytes --]

Ignacio Torres <i@itorres.net> writes:

> Running M-x battery in FreeBSD returns:
>
> Power disconnected, battery high (illegal% load, remaining time 0:00)
>
Here's a patch witch makes it return something else :)

Unfortunately I can't tets it on an actual laptop atm, but I /think/ it
might work.

-- Joakim


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-patch, Size: 2472 bytes --]

From 8af54346db52ce1939632a60cac0cbd5c5f77063 Mon Sep 17 00:00:00 2001
From: Joakim Jalap <joakim.jalap@fastmail.com>
Date: Fri, 11 Nov 2016 18:00:22 +0100
Subject: [PATCH] Fix M-x battery on FreeBSD

	* lisp/battery.el (battery-bsd-apm): Fix to work with FreeBSD's apm(8)
---
 lisp/battery.el | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/lisp/battery.el b/lisp/battery.el
index e6e79b0..ddb0114 100644
--- a/lisp/battery.el
+++ b/lisp/battery.el
@@ -552,30 +552,40 @@ battery-bsd-apm
 %t Remaining battery charge time in the form `h:min'"
   (let* ((os-name (car (split-string
 			(shell-command-to-string "/usr/bin/uname"))))
-	 (apm-flag (if (equal os-name "OpenBSD") "P" "s"))
-	 (apm-cmd (concat "/usr/sbin/apm -ablm" apm-flag))
+         (os-freebsd (string= os-name "FreeBSD"))
+         (os-openbsd (string= os-name "OpenBSD"))
+         (battery-status-idx (if os-freebsd 1 0))
+         (percentage-idx (if os-freebsd 2 1))
+         (life-idx (if os-freebsd 4 2))
+         (line-status-idx (if os-freebsd 0 3))
+         (mode-idx (if os-freebsd 3 4))
+	 (apm-flags
+          (cond (os-freebsd "-ablts")
+                (os-openbsd "-ablmP")
+                (t "-ablms")))
+	 (apm-cmd (concat "/usr/sbin/apm " apm-flags))
 	 (apm-output (split-string (shell-command-to-string apm-cmd)))
 	 ;; Battery status
 	 (battery-status
-	  (let ((stat (string-to-number (nth 0 apm-output))))
+	  (let ((stat (string-to-number (nth battery-status-idx apm-output))))
 	    (cond ((eq stat 0) '("high" . ""))
 		  ((eq stat 1) '("low" . "-"))
 		  ((eq stat 2) '("critical" . "!"))
 		  ((eq stat 3) '("charging" . "+"))
 		  ((eq stat 4) '("absent" . nil)))))
 	 ;; Battery percentage
-	 (battery-percentage (nth 1 apm-output))
+	 (battery-percentage (nth percentage-idx apm-output))
 	 ;; Battery life
-	 (battery-life (nth 2 apm-output))
+	 (battery-life (nth life-idx apm-output))
 	 ;; AC status
 	 (line-status
-	  (let ((ac (string-to-number (nth 3 apm-output))))
+	  (let ((ac (string-to-number (nth line-status-idx apm-output))))
 	    (cond ((eq ac 0) "disconnected")
 		  ((eq ac 1) "connected")
 		  ((eq ac 2) "backup power"))))
 	 ;; Advanced power savings mode
 	 (apm-mode
-	  (let ((apm (string-to-number (nth 4 apm-output))))
+	  (let ((apm (string-to-number (nth mode-idx apm-output))))
 	    (if (string= os-name "OpenBSD")
 		(cond ((eq apm 0) "manual")
 		      ((eq apm 1) "automatic")
-- 
2.9.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* bug#24919: 24.5; battery.el not working in FreeBSD
  2016-11-11 17:58 ` Joakim Jalap
@ 2017-03-08 13:58   ` Alan Third
  2019-10-14 20:16     ` Joseph Mingrone
  0 siblings, 1 reply; 6+ messages in thread
From: Alan Third @ 2017-03-08 13:58 UTC (permalink / raw)
  To: Joakim Jalap; +Cc: Ignacio Torres, 24919

Joakim Jalap <joakim.jalap@fastmail.com> writes:

> Ignacio Torres <i@itorres.net> writes:
>
>> Running M-x battery in FreeBSD returns:
>>
>> Power disconnected, battery high (illegal% load, remaining time 0:00)
>>
> Here's a patch witch makes it return something else :)
>
> Unfortunately I can't tets it on an actual laptop atm, but I /think/ it
> might work.

Has anyone been able to test Joakim's patch?
-- 
Alan Third





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#24919: 24.5; battery.el not working in FreeBSD
  2017-03-08 13:58   ` Alan Third
@ 2019-10-14 20:16     ` Joseph Mingrone
  2019-10-15  6:45       ` Stefan Kangas
  0 siblings, 1 reply; 6+ messages in thread
From: Joseph Mingrone @ 2019-10-14 20:16 UTC (permalink / raw)
  To: Alan Third; +Cc: Ignacio Torres, Joakim Jalap, Stefan Kangas, 24919

Alan Third <alan@idiocy.org> writes:

> Joakim Jalap <joakim.jalap@fastmail.com> writes:

>> Ignacio Torres <i@itorres.net> writes:

>>> Running M-x battery in FreeBSD returns:

>>> Power disconnected, battery high (illegal% load, remaining time 0:00)

>> Here's a patch witch makes it return something else :)

>> Unfortunately I can't tets it on an actual laptop atm, but I /think/ it
>> might work.

> Has anyone been able to test Joakim's patch?

I don't see any commits related to this bug/patch, but I just tested M-x
battery in an Emacs master branch build (604a985) on FreeBSD 12.0 and
the output looks correct.

Here is some example output.

Power connected, battery high (100% load, remaining time N/A)
Power disconnected, battery high (100% load, remaining time 4:21)
Power disconnected, battery high (99% load, remaining time 3:30)

Joseph





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#24919: 24.5; battery.el not working in FreeBSD
  2019-10-14 20:16     ` Joseph Mingrone
@ 2019-10-15  6:45       ` Stefan Kangas
  2019-11-11  3:26         ` Stefan Kangas
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Kangas @ 2019-10-15  6:45 UTC (permalink / raw)
  To: Joseph Mingrone; +Cc: Ignacio Torres, Alan Third, 24919, Joakim Jalap

Joseph Mingrone <jrm@ftfl.ca> writes:

> I don't see any commits related to this bug/patch, but I just tested M-x
> battery in an Emacs master branch build (604a985) on FreeBSD 12.0 and
> the output looks correct.
>
> Here is some example output.
>
> Power connected, battery high (100% load, remaining time N/A)
> Power disconnected, battery high (100% load, remaining time 4:21)
> Power disconnected, battery high (99% load, remaining time 3:30)

Thanks.  Does that mean that the patch is not necessary for FreeBSD?

Is there anyone that could help test this also on OpenBSD?

Best regards,
Stefan Kangas





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#24919: 24.5; battery.el not working in FreeBSD
  2019-10-15  6:45       ` Stefan Kangas
@ 2019-11-11  3:26         ` Stefan Kangas
  0 siblings, 0 replies; 6+ messages in thread
From: Stefan Kangas @ 2019-11-11  3:26 UTC (permalink / raw)
  To: Joseph Mingrone; +Cc: Ignacio Torres, Alan Third, 24919-done, Joakim Jalap

Stefan Kangas <stefan@marxist.se> writes:

> Joseph Mingrone <jrm@ftfl.ca> writes:
>
>> I don't see any commits related to this bug/patch, but I just tested M-x
>> battery in an Emacs master branch build (604a985) on FreeBSD 12.0 and
>> the output looks correct.
>>
>> Here is some example output.
>>
>> Power connected, battery high (100% load, remaining time N/A)
>> Power disconnected, battery high (100% load, remaining time 4:21)
>> Power disconnected, battery high (99% load, remaining time 3:30)
>
> Thanks.  Does that mean that the patch is not necessary for FreeBSD?
>
> Is there anyone that could help test this also on OpenBSD?

I re-read the original report, and it seems like I misread: this was
*not* an issue on OpenBSD, and should therefore need no further
testing here.

Since Joseph has helped confirm that things are now working also on
FreeBSD, and no one else has commented in 3.5 weeks, I'll go ahead and
close this bug.

If anyone is still seeing issues with M-x battery on any *BSD system,
please reopen the bug report.

Best regards,
Stefan Kangas





^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-11-11  3:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-17 23:17 bug#24919: 24.5; battery.el not working in FreeBSD Ignacio Torres
2016-11-11 17:58 ` Joakim Jalap
2017-03-08 13:58   ` Alan Third
2019-10-14 20:16     ` Joseph Mingrone
2019-10-15  6:45       ` Stefan Kangas
2019-11-11  3:26         ` Stefan Kangas

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).