While fixing/adding that, might as well go ahead and fix the signal
handler enque_signal().  I don't believe using err() in in a signal
handler is recommended as it could possible allow for undefined behavior
to occur.  

Andrew

On Sun, 14 Oct 2001, Walter C. Pelissero wrote:

: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 [EMAIL PROTECTED]
:with "unsubscribe freebsd-hackers" in the body of the message
:

*-------------.................................................
| Andrew R. Reiter 
| [EMAIL PROTECTED]
| "It requires a very unusual mind
|   to undertake the analysis of the obvious" -- A.N. Whitehead


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to