From owner-freebsd-hackers Sun Oct 14 9:33:13 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from pelissero.org (dyn35-41.sftm-212-159.plus.net [212.159.41.35]) by hub.freebsd.org (Postfix) with ESMTP id 7608B37B40F for ; Sun, 14 Oct 2001 09:32:56 -0700 (PDT) Received: (from wcp@localhost) by pelissero.org (8.11.6/8.9.3) id f9EGWfI04327; Sun, 14 Oct 2001 17:32:41 +0100 (BST) (envelope-from wcp) From: "Walter C. Pelissero" MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <15305.48681.337589.764014@hyde.lpds.sublink.org> Date: Sun, 14 Oct 2001 17:32:41 +0100 To: hackers@freebsd.org Subject: apmd fixes X-Mailer: VM 6.92 under 21.1 (patch 14) "Cuyahoga Valley" XEmacs Lucid Reply-To: walter@pelissero.org X-Attribution: WP Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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