GNU bug report logs - #24919
24.5; battery.el not working in FreeBSD

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Ignacio Torres <i@HIDDEN>; Keywords: patch; dated Thu, 10 Nov 2016 16:49:02 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.
Added tag(s) patch. Request was from Alan Third <alan@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at 24919 <at> debbugs.gnu.org:


Received: (at 24919) by debbugs.gnu.org; 11 Nov 2016 16:01:39 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Nov 11 11:01:39 2016
Received: from localhost ([127.0.0.1]:54096 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1c5EGo-0008D5-T2
	for submit <at> debbugs.gnu.org; Fri, 11 Nov 2016 11:01:39 -0500
Received: from out4-smtp.messagingengine.com ([66.111.4.28]:39413)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <joakim.jalap@HIDDEN>) id 1c5EGn-0008Cx-AD
 for 24919 <at> debbugs.gnu.org; Fri, 11 Nov 2016 11:01:37 -0500
Received: from compute6.internal (compute6.nyi.internal [10.202.2.46])
 by mailout.nyi.internal (Postfix) with ESMTP id 04E032067C;
 Fri, 11 Nov 2016 11:01:37 -0500 (EST)
Received: from frontend2 ([10.202.2.161])
 by compute6.internal (MEProxy); Fri, 11 Nov 2016 11:01:37 -0500
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=fastmail.com; h=cc
 :content-type:date:from:in-reply-to:message-id:mime-version
 :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc
 :x-sasl-enc; s=mesmtp; bh=YyNTNGvT632lv86W6jXn/OiArDU=; b=5/kfCN
 M64H8z/DORfxuk3r1BqPT2ax97hrLaTjDucge/FgmJNG2tGgzfA13Cu+BVTubHEs
 I1KtoNzJWxPIam8fC/vZkr2qjt7ho/u9zUZcQhpOpJASJm/ZTKwsv8Gcnj6kaaF0
 wkKMx8LJUDgV0Suo/AdnMSiLiRL21jenqWx/g=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=
 messagingengine.com; h=cc:content-type:date:from:in-reply-to
 :message-id:mime-version:references:subject:to:x-me-sender
 :x-me-sender:x-sasl-enc:x-sasl-enc; s=smtpout; bh=YyNTNGvT632lv8
 6W6jXn/OiArDU=; b=JA5LRCMM0oZ+kr39W/ALT86ou55+X+dotcCr26YZ+dKGc5
 Ibo8A2SMLWTCkxbYxbZQ6nLgAUkic0K1EOavuoL0oZbv1LpJXFSGYs1MD4/4Vbkm
 gQOgbOVdZhNg425VzbZ8eD1WzDthT2BvtSZSpX18Kn5Rs9yPqkAP8NfTH9Y2I=
X-ME-Sender: <xms:YOslWKA6fRbdwsYjX_yKljNYKZBI9Dc970jmW34qsboHERwKTzpXGQ>
X-Sasl-enc: 0ah51GriacpeHj2gIGh+7NWDQyI2ltgxapuWDVAfuo6E 1478880096
Received: from serv (unknown [5.150.202.248])
 by mail.messagingengine.com (Postfix) with ESMTPA id 1DED925081;
 Fri, 11 Nov 2016 11:01:36 -0500 (EST)
From: Joakim Jalap <joakim.jalap@HIDDEN>
To: Ignacio Torres <i@HIDDEN>
Subject: Re: bug#24919: 24.5; battery.el not working in FreeBSD
References: <86lgyq2k1l.fsf@HIDDEN>
Date: Fri, 11 Nov 2016 18:58:39 +0100
In-Reply-To: <86lgyq2k1l.fsf@HIDDEN> (Ignacio Torres's message of
 "Sun, 18 Sep 2016 01:17:26 +0200")
Message-ID: <86twbd525s.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (berkeley-unix)
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 24919
Cc: 24919 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.7 (/)

--=-=-=
Content-Type: text/plain

Ignacio Torres <i@HIDDEN> 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


--=-=-=
Content-Type: text/x-patch
Content-Disposition: inline; filename=0001-Fix-M-x-battery-on-FreeBSD.patch
Content-Description: patch

From 8af54346db52ce1939632a60cac0cbd5c5f77063 Mon Sep 17 00:00:00 2001
From: Joakim Jalap <joakim.jalap@HIDDEN>
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


--=-=-=--




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#24919; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 10 Nov 2016 16:48:57 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Nov 10 11:48:57 2016
Received: from localhost ([127.0.0.1]:52476 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1c4sX2-0000vS-Kw
	for submit <at> debbugs.gnu.org; Thu, 10 Nov 2016 11:48:57 -0500
Received: from eggs.gnu.org ([208.118.235.92]:40647)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <i@HIDDEN>) id 1c4oFX-00013O-SW
 for submit <at> debbugs.gnu.org; Thu, 10 Nov 2016 07:14:36 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <i@HIDDEN>) id 1c4oFR-0006TA-Hk
 for submit <at> debbugs.gnu.org; Thu, 10 Nov 2016 07:14:30 -0500
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: ***
X-Spam-Status: No, score=3.4 required=5.0 tests=BAYES_20,DATE_IN_PAST_96_XX,
 T_DKIM_INVALID autolearn=disabled version=3.3.2
Received: from lists.gnu.org ([2001:4830:134:3::11]:34295)
 by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32)
 (Exim 4.71) (envelope-from <i@HIDDEN>) id 1c4oFR-0006T0-Dz
 for submit <at> debbugs.gnu.org; Thu, 10 Nov 2016 07:14:29 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:59803)
 by lists.gnu.org with esmtp (Exim 4.71)
 (envelope-from <i@HIDDEN>) id 1c4oFQ-0003Rf-3K
 for bug-gnu-emacs@HIDDEN; Thu, 10 Nov 2016 07:14:29 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <i@HIDDEN>) id 1c4oFM-0006RO-GU
 for bug-gnu-emacs@HIDDEN; Thu, 10 Nov 2016 07:14:28 -0500
Received: from out4-smtp.messagingengine.com ([66.111.4.28]:53310)
 by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)
 (Exim 4.71) (envelope-from <i@HIDDEN>) id 1c4oFM-0006Pq-CQ
 for bug-gnu-emacs@HIDDEN; Thu, 10 Nov 2016 07:14:24 -0500
Received: from compute1.internal (compute1.nyi.internal [10.202.2.41])
 by mailout.nyi.internal (Postfix) with ESMTP id BC2FB218D2
 for <bug-gnu-emacs@HIDDEN>; Thu, 10 Nov 2016 07:14:19 -0500 (EST)
Received: from frontend1 ([10.202.2.160])
 by compute1.internal (MEProxy); Thu, 10 Nov 2016 07:14:19 -0500
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=itorres.net; h=
 content-type:date:from:message-id:mime-version:subject:to
 :x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=D2b
 R2c4deh2i5cYehKSuUbevJMk=; b=pauZ6/ZHc+QC3Y72Osrcb5oUP/OXMBgQE6g
 mIxcl9F0D195jKais/SdAPAWh/367oJhzxLAEq4LZZrEwW16DFaOEUpKeJ+WV9k0
 HSCtSnc/5OC/X6tMT2bOK41ozVCohE8c4ZWFb0r6zQGdLll81rlbWFrkrNlNMyUk
 rJajXT1k=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=
 messagingengine.com; h=content-type:date:from:message-id
 :mime-version:subject:to:x-me-sender:x-me-sender:x-sasl-enc
 :x-sasl-enc; s=smtpout; bh=D2bR2c4deh2i5cYehKSuUbevJMk=; b=NUXWl
 nJxH3JFyEtPiF12EZd+xlnwvBXdle2Dbe1oviHhHH/YCdx3w7MpQC1HGcbnBHy9A
 tcs5NOe7ZGT4WtCjn3eQ3JVpa+kNfeRVFjUb5+RWt3Xutq7z7whHbJrPwGQVbsqF
 ojE6Zn9Idr1cjwFGoMgeA3WT32TowPsx+SYoy0=
X-ME-Sender: <xms:m2QkWO9gbO2c5Dh4LYNW3poWIniic_2Q6Px-_yGACKFUOihxM-pJ3g>
X-Sasl-enc: qXzJW4d5FUApAJth7RdfEakCUEcU0ZTDc3g/RmEBfJwc 1478780059
Received: from gaia (unknown [5.10.206.29])
 by mail.messagingengine.com (Postfix) with ESMTPA id 336EAF29CE
 for <bug-gnu-emacs@HIDDEN>; Thu, 10 Nov 2016 07:14:19 -0500 (EST)
From: Ignacio Torres <i@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: 24.5; battery.el not working in FreeBSD
Date: Sun, 18 Sep 2016 01:17:26 +0200
Message-ID: <86lgyq2k1l.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 2001:4830:134:3::11
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: submit
X-Mailman-Approved-At: Thu, 10 Nov 2016 11:48:55 -0500
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.3 (--)


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




Acknowledgement sent to Ignacio Torres <i@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#24919; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Mon, 19 Dec 2016 09:45:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.