Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 14 Oct 2001 17:32:41 +0100
From:      "Walter C. Pelissero" <walter@pelissero.org>
To:        hackers@freebsd.org
Subject:   apmd fixes
Message-ID:  <15305.48681.337589.764014@hyde.lpds.sublink.org>

next in thread | raw e-mail | index | archive | help
Here are a couple of patches to apmd (as of FreeBSD 4.4-STABLE) to fix
a bug and add a feature necessary on my Vaio PCG-XG9.

The fix is to handle properly termination signals (currently ignored).

The feature is the -s option that lets you fake POWERSTATECHANGE when
the BIOS doesn't report it.  This enables you to do fancy things like
reducing the LCD backlight brightness when you unplug the power
supply.  Something like this in apmd.conf:

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


Here is the patch:

--- /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);


-- 
walter pelissero
http://www.pelissero.org

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




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