Subject: bin/7708: some changes to /usr/sbin/apm and /usr/sbin/apmd
To: None <gnats-bugs@gnats.netbsd.org>
From: Benjamin Lorenz <lorenz@inetmail.de>
List: netbsd-bugs
Date: 06/05/1999 04:51:24
>Number:         7708
>Category:       bin
>Synopsis:       some changes to /usr/sbin/apm and /usr/sbin/apmd
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sat Jun  5 04:35:00 1999
>Last-Modified:
>Originator:     Benjamin Lorenz
>Organization:
>Release:        1.4
>Environment:
System: NetBSD suag 1.4 NetBSD 1.4 (SUAG) #0: Sat May 15 00:41:48 CEST 1999 lorenz@suag:/var/src/sys/arch/i386/compile/SUAG i386


>Description:
	There was a bug in the apmd program which caused it to be _very_
	verbose about battery power changes. I also changed some
	logging code to produce more compact information. Finally,
	in the apm program, I followed the unix tradition that no
	feedback to the user is given when everything goes well.

>How-To-Repeat:
>Fix:

	First, the diffs for usr.sbin/apmd/apmd.c:

--- apmd.c.orig	Sun Dec 20 13:18:57 1998
+++ apmd.c	Wed May 12 14:03:09 1999
@@ -110,21 +110,24 @@ power_status(int fd, int force, struct a
 	if (force || 
 	    bstate.ac_state != last.ac_state ||
 	    bstate.battery_state != last.battery_state ||
-	    (bstate.minutes_left && bstate.minutes_left < 15) ||
-	    abs(bstate.battery_life - last.battery_life) > 20) {
+	    (bstate.minutes_left && bstate.minutes_left < 11) ||
+	    abs(bstate.battery_life - last.battery_life) > 16) {
 	    if (bstate.minutes_left)
-		syslog(LOG_NOTICE,
-		       "battery status: %s. external power status: %s. "
-		       "estimated battery life %d%% (%d minutes)",
-		       battstate(bstate.battery_state),
-		       ac_state(bstate.ac_state), bstate.battery_life,
-		       bstate.minutes_left);
+		if (bstate.minutes_left > 59)
+			syslog(LOG_NOTICE,
+			       "battery power: %d%% (%dh %02dm)",
+			       bstate.battery_life,
+			       bstate.minutes_left / 60,
+			       bstate.minutes_left % 60);
+		else
+			syslog(LOG_NOTICE,
+			       "battery power: %d%% (%dm)",
+			       bstate.battery_life,
+			       bstate.minutes_left);
 	    else
 		syslog(LOG_NOTICE,
-		       "battery status: %s. external power status: %s. "
-		       "estimated battery life %d%%",
-		       battstate(bstate.battery_state),
-		       ac_state(bstate.ac_state), bstate.battery_life);
+		       "battery power: %d%%",
+		       bstate.battery_life);
 	    last = bstate;
 	}
 	if (pinfo)
@@ -263,6 +266,7 @@ int howmany;
 void
 suspend(int ctl_fd)
 {
+    syslog(LOG_NOTICE, "system going to sleep (APM suspend)");
     do_etc_file(_PATH_APM_ETC_SUSPEND);
     sync();
     make_noise(2);
@@ -275,6 +279,7 @@ suspend(int ctl_fd)
 void
 stand_by(int ctl_fd)
 {
+    syslog(LOG_NOTICE, "system going to sleep (APM standby)");
     do_etc_file(_PATH_APM_ETC_STANDBY);
     sync();
     make_noise(1);
@@ -290,6 +295,7 @@ void
 resume(int ctl_fd)
 {
     do_etc_file(_PATH_APM_ETC_RESUME);
+    syslog(LOG_NOTICE, "system resumed from APM sleep");
 }
 
 int
@@ -456,7 +462,7 @@ main(int argc, char *argv[])
 		case APM_POWER_CHANGE:
 		{
 		    struct apm_power_info pinfo;
-		    power_status(ctl_fd, 1, &pinfo);
+		    power_status(ctl_fd, 0, &pinfo);
 		    do_ac_state(pinfo.ac_state);
 		    break;
 		}
@@ -473,7 +479,6 @@ main(int argc, char *argv[])
 		stand_by(ctl_fd);
 	    } else if (resumes) {
 		resume(ctl_fd);
-		syslog(LOG_NOTICE, "system resumed from APM sleep");
 	    }
 	    ready--;
 	}



	Now, the diff for usr.sbin/apm/apm.c:

--- apm.c.orig	Fri Jan 15 13:12:07 1999
+++ apm.c	Wed May 12 13:10:40 1999
@@ -125,7 +125,6 @@ do_zzz(const char *pn, enum apm_action a
 
     if (fd == -1)
 	err(1, "cannot open connection to APM daemon");
-    printf("Suspending system...\n");
     exit(send_command(fd, &command, &reply));
 }
 
@@ -261,10 +260,6 @@ main(int argc, char *argv[])
 	    if (ioctl(fd, action == SUSPEND ?
 		      APM_IOC_SUSPEND : APM_IOC_STANDBY, 0) == -1)
 		err(1, "cannot enter requested power state");
-	    if (action == SUSPEND)
-		printf("System will enter suspend mode in a moment.\n");
-	    else
-		printf("System will enter standby mode in a moment.\n");
 	    exit(0);
 	} else if (fd == -1)
 	    err(1, "cannot contact APM daemon at socket " _PATH_APM_SOCKET);
@@ -316,10 +311,7 @@ main(int argc, char *argv[])
 	}
 	switch (reply.newstate) {
 	case SUSPEND:
-	    printf("System will enter suspend mode in a moment.\n");
-	    break;
 	case STANDBY:
-	    printf("System will enter standby mode in a moment.\n");
 	    break;
 	default:
 	    break;
>Audit-Trail:
>Unformatted: