summaryrefslogtreecommitdiff
path: root/usr.sbin/apm
diff options
context:
space:
mode:
authorMichael Shalayeff <mickey@cvs.openbsd.org>1998-10-29 18:21:45 +0000
committerMichael Shalayeff <mickey@cvs.openbsd.org>1998-10-29 18:21:45 +0000
commitbfc0a4b8bba9b4866d44e8356d09edba55da5be8 (patch)
treeb4eb1187c662f090d624041064c1b557c081302c /usr.sbin/apm
parenteb5aeffc82b09ddf8384c9ff8d10b6fbf68f2d5f (diff)
provide an option to retreive battery life estimate in minutes
from Martin Forseen <maf@firedoor.se> some corrections from me.
Diffstat (limited to 'usr.sbin/apm')
-rw-r--r--usr.sbin/apm/apm.85
-rw-r--r--usr.sbin/apm/apm.c31
2 files changed, 26 insertions, 10 deletions
diff --git a/usr.sbin/apm/apm.8 b/usr.sbin/apm/apm.8
index f67bdb28230..f5627cf5d4a 100644
--- a/usr.sbin/apm/apm.8
+++ b/usr.sbin/apm/apm.8
@@ -24,7 +24,7 @@
.\" ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $Id: apm.8,v 1.3 1998/03/10 04:51:03 millert Exp $
+.\" $Id: apm.8,v 1.4 1998/10/29 18:21:44 mickey Exp $
.\"
.Dd March 18, 1996
.Dt APM 8
@@ -43,6 +43,7 @@
.Op Fl S
.Op Fl s
.Op Fl l
+.Op Fl m
.Op Fl b
.Op Fl a
.Op Fl v
@@ -65,6 +66,8 @@ Put the system into suspend (deep sleep) mode.
Put the system into stand-by (light sleep) mode.
.It Fl l
Display the estimated battery lifetime (in percent).
+.It Fl m
+Display the estimated battery lifetime (in minutes).
.It Fl b
Display the battery status. 0 means high, 1 means low, 2 means
critical, 3 means charging, 4 means absent, and 255 means unknown.
diff --git a/usr.sbin/apm/apm.c b/usr.sbin/apm/apm.c
index e635bd11ec7..fbb731efa17 100644
--- a/usr.sbin/apm/apm.c
+++ b/usr.sbin/apm/apm.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: apm.c,v 1.2 1997/09/12 04:07:14 millert Exp $ */
+/* $OpenBSD: apm.c,v 1.3 1998/10/29 18:21:44 mickey Exp $ */
/*
* Copyright (c) 1996 John T. Kohl
@@ -66,7 +66,7 @@ int send_command(int fd,
void
usage(void)
{
- fprintf(stderr,"usage: %s [-v] [-z | -S] [-slba] [-f socket]\n",
+ fprintf(stderr,"usage: %s [-v] [-z | -S] [-slbam] [-f socket]\n",
__progname);
exit(1);
}
@@ -147,7 +147,7 @@ open_socket(const char *sockname)
return sock;
}
-void
+int
main(int argc, char *argv[])
{
char *sockname = _PATH_APM_SOCKET;
@@ -156,6 +156,7 @@ main(int argc, char *argv[])
int doac = FALSE;
int dopct = FALSE;
int dobstate = FALSE;
+ int domin = FALSE;
int fd;
int rval;
int verbose = FALSE;
@@ -163,7 +164,7 @@ main(int argc, char *argv[])
struct apm_command command;
struct apm_reply reply;
- while ((ch = getopt(argc, argv, "lbvadsSzf:")) != -1)
+ while ((ch = getopt(argc, argv, "lmbvadsSzf:")) != -1)
switch(ch) {
case 'v':
verbose = TRUE;
@@ -199,6 +200,12 @@ main(int argc, char *argv[])
dopct = TRUE;
action = GETSTATUS;
break;
+ case 'm':
+ if (action != NONE && action != GETSTATUS)
+ usage();
+ domin = TRUE;
+ action = GETSTATUS;
+ break;
case 'a':
if (action != NONE && action != GETSTATUS)
usage();
@@ -211,14 +218,14 @@ main(int argc, char *argv[])
}
if (!strcmp(__progname, "zzz")) {
- exit(do_zzz(sockname, action));
+ return (do_zzz(sockname, action));
}
fd = open_socket(sockname);
switch (action) {
case NONE:
- verbose = doac = dopct = dobstate = dostatus = TRUE;
+ verbose = doac = dopct = dobstate = dostatus = domin = TRUE;
action = GETSTATUS;
/* fallthrough */
case GETSTATUS:
@@ -245,13 +252,17 @@ main(int argc, char *argv[])
printval:
if (verbose) {
if (dobstate)
- printf("Battery charge state: %s\n",
+ printf("Battery state: %s\n",
battstate(reply.batterystate.battery_state));
if (dopct)
printf("Battery remaining: %d percent\n",
reply.batterystate.battery_life);
+ if (domin)
+ printf("Battery life estimate: %d minutes\n",
+ reply.batterystate.minutes_left);
if (doac)
- printf("A/C adapter state: %s\n", ac_state(reply.batterystate.ac_state));
+ printf("A/C adapter state: %s\n",
+ ac_state(reply.batterystate.ac_state));
if (dostatus)
printf("Power management enabled\n");
} else {
@@ -259,6 +270,8 @@ main(int argc, char *argv[])
printf("%d\n", reply.batterystate.battery_state);
if (dopct)
printf("%d\n", reply.batterystate.battery_life);
+ if (domin)
+ printf("%d\n", reply.batterystate.minutes_left);
if (doac)
printf("%d\n", reply.batterystate.ac_state);
if (dostatus)
@@ -281,5 +294,5 @@ main(int argc, char *argv[])
} else
errx(rval, "cannot get reply from APM daemon");
- exit(0);
+ return (0);
}