Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 24 Nov 2001 13:42:20 GMT
From:      "Walter C. Pelissero" <walter@pelissero.org>
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   i386/32251: bugfix and new feature for apmd
Message-ID:  <200111241342.fAODgKH09420@pelissero.org>

next in thread | raw e-mail | index | archive | help

>Number:         32251
>Category:       i386
>Synopsis:       bugfix and new feature for apmd
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Nov 24 05:50:01 PST 2001
>Closed-Date:
>Last-Modified:
>Originator:     Walter C. Pelissero
>Release:        FreeBSD 4.4-STABLE i386
>Organization:
>Environment:
System: FreeBSD hyde.lpds.sublink.org 4.4-STABLE FreeBSD 4.4-STABLE #0: Wed Nov 14 13:34:31 GMT 2001 root@hyde.lpds.sublink.org:/.amd_mnt/daemon/host/usr/src/sys/compile/PCG-XG9 i386

>Description:

Apmd would benefit of the included patches.

One is to correct a bug: apmd ignores termination signals.

The other one introduces a new feature.  With the -s flag apmd
simulate a POWERSTATECHANGE event when a power state change is
detected (AC_POWER_STATE) but the bios of the laptop doesn't report
it.  This enables you to do things like dimming the LCD backlight when
you unplug the power cord.

>How-To-Repeat:

To verify the bug:

	killall apmd

To verify the new feature add this to your /atc/apmd.conf:

	apm_event POWERSTATECHANGE {
		exec "/bin/sh /usr/local/bin/my-preferred-power-state-change-script";
	}



>Fix:

--- /usr/home/wcp/tmp/apmd/apmd.c	Fri Oct 12 20:22:34 2001
+++ /usr/src/usr.sbin/apmd/apmd.c	Sat Oct 13 14:58:35 2001
@@ -55,7 +55,7 @@
 extern int	yyparse(void);
 
 int		debug_level = 0;
-int		verbose = 0;
+int		verbose = 0, soft_power_state_change = 0;
 const char	*apmd_configfile = APMD_CONFIGFILE;
 const char	*apmd_pidfile = APMD_PIDFILE;
 int             apmctl_fd = -1, apmnorm_fd = -1;
@@ -464,7 +464,6 @@
 int
 proc_signal(int fd)
 {
-	int rc = -1;
 	int sig;
 
 	while (read(fd, &sig, sizeof sig) == sizeof sig) {
@@ -476,8 +475,7 @@
 			break;
 		case SIGTERM:
 			syslog(LOG_NOTICE, "going down on signal %d", sig);
-			rc = 1;
-			goto out;
+			return -1;
 		case SIGCHLD:
 			wait_child();
 			break;
@@ -486,9 +484,7 @@
 			break;
 		}
 	}
-	rc = 0;
- out:
-	return rc;
+	return 0;
 }
 void
 proc_apmevent(int fd)
@@ -548,6 +544,8 @@
 	 * the event-caught state.
 	 */
 	if (last_state != AC_POWER_STATE) {
+	    if (soft_power_state_change && fork() == 0)
+		  exit(exec_event_cmd(&events[PMEV_POWERSTATECHANGE]));
 		last_state = AC_POWER_STATE;
 		for (p = battery_watch_list ; p!=NULL ; p = p -> next)
 			p->done = 0;
@@ -642,7 +640,7 @@
 	char	*prog;
 	int	logopt = LOG_NDELAY | LOG_PID;
 
-	while ((ch = getopt(ac, av, "df:v")) != EOF) {
+	while ((ch = getopt(ac, av, "df:vs")) != EOF) {
 		switch (ch) {
 		case 'd':
 			daemonize = 0;
@@ -653,6 +651,9 @@
 			break;
 		case 'v':
 			verbose = 1;
+			break;
+		case 's':
+			soft_power_state_change = 1;
 			break;
 		default:
 			(void) err(1, "unknown option `%c'", ch);

>Release-Note:
>Audit-Trail:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200111241342.fAODgKH09420>