- Don't ignore SIGTERM.

- Add a command line switch to trigger POWERSTATECHANGE actions on
  un-reported power state changes.

PR:		 i386/32251
Submitted by:	 Walter C. Pelissero <walter@pelissero.org>
This commit is contained in:
Matthew N. Dodd 2003-06-22 05:34:45 +00:00
parent c27e9c5100
commit f90445cf1f
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=116666
2 changed files with 20 additions and 4 deletions

View File

@ -38,6 +38,7 @@
.Nm .Nm
.Op Fl d .Op Fl d
.Op Fl f file .Op Fl f file
.Op Fl s
.Op Fl v .Op Fl v
.Sh DESCRIPTION .Sh DESCRIPTION
The The
@ -73,6 +74,13 @@ Specifies a different configuration file
.Ar file .Ar file
to be used in place of the default to be used in place of the default
.Pa /etc/apmd.conf . .Pa /etc/apmd.conf .
.It Fl s
Causes
.Nm
to 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.
.It Fl v .It Fl v
Verbose mode. Verbose mode.
.El .El

View File

@ -56,6 +56,7 @@ extern int yyparse(void);
int debug_level = 0; int debug_level = 0;
int verbose = 0; int verbose = 0;
int soft_power_state_change = 0;
const char *apmd_configfile = APMD_CONFIGFILE; const char *apmd_configfile = APMD_CONFIGFILE;
const char *apmd_pidfile = APMD_PIDFILE; const char *apmd_pidfile = APMD_PIDFILE;
int apmctl_fd = -1, apmnorm_fd = -1; int apmctl_fd = -1, apmnorm_fd = -1;
@ -71,7 +72,7 @@ struct event_config events[EVENT_MAX] = {
EVENT_CONFIG_INITIALIZER(NORMRESUME, 0) EVENT_CONFIG_INITIALIZER(NORMRESUME, 0)
EVENT_CONFIG_INITIALIZER(CRITRESUME, 0) EVENT_CONFIG_INITIALIZER(CRITRESUME, 0)
EVENT_CONFIG_INITIALIZER(BATTERYLOW, 0) EVENT_CONFIG_INITIALIZER(BATTERYLOW, 0)
EVENT_CONFIG_INITIALIZER(POWERSTATECHANGE, 0) EVENT_CONFIG_INITIALIZER(POWERSTATECHANG, 0)
EVENT_CONFIG_INITIALIZER(UPDATETIME, 0) EVENT_CONFIG_INITIALIZER(UPDATETIME, 0)
EVENT_CONFIG_INITIALIZER(CRITSUSPEND, 1) EVENT_CONFIG_INITIALIZER(CRITSUSPEND, 1)
EVENT_CONFIG_INITIALIZER(USERSTANDBYREQ, 1) EVENT_CONFIG_INITIALIZER(USERSTANDBYREQ, 1)
@ -476,7 +477,7 @@ proc_signal(int fd)
break; break;
case SIGTERM: case SIGTERM:
syslog(LOG_NOTICE, "going down on signal %d", sig); syslog(LOG_NOTICE, "going down on signal %d", sig);
rc = 1; rc = -1;
goto out; goto out;
case SIGCHLD: case SIGCHLD:
wait_child(); wait_child();
@ -515,6 +516,7 @@ check_battery()
{ {
static int first_time=1, last_state; static int first_time=1, last_state;
int status;
struct apm_info pw_info; struct apm_info pw_info;
struct battery_watch_event *p; struct battery_watch_event *p;
@ -548,6 +550,10 @@ check_battery()
* the event-caught state. * the event-caught state.
*/ */
if (last_state != AC_POWER_STATE) { if (last_state != AC_POWER_STATE) {
if (soft_power_state_change && fork() == 0) {
status = exec_event_cmd(&events[PMEV_POWERSTATECHANGE]);
exit(status);
}
last_state = AC_POWER_STATE; last_state = AC_POWER_STATE;
for (p = battery_watch_list ; p!=NULL ; p = p -> next) for (p = battery_watch_list ; p!=NULL ; p = p -> next)
p->done = 0; p->done = 0;
@ -566,7 +572,6 @@ check_battery()
p -> level, p -> level,
(p -> type == BATTERY_PERCENT)?"%":" minutes"); (p -> type == BATTERY_PERCENT)?"%":" minutes");
if (fork() == 0) { if (fork() == 0) {
int status;
status = exec_run_cmd(p -> cmdlist); status = exec_run_cmd(p -> cmdlist);
exit(status); exit(status);
} }
@ -642,7 +647,7 @@ main(int ac, char* av[])
char *prog; char *prog;
int logopt = LOG_NDELAY | LOG_PID; int logopt = LOG_NDELAY | LOG_PID;
while ((ch = getopt(ac, av, "df:v")) != EOF) { while ((ch = getopt(ac, av, "df:sv")) != EOF) {
switch (ch) { switch (ch) {
case 'd': case 'd':
daemonize = 0; daemonize = 0;
@ -651,6 +656,9 @@ main(int ac, char* av[])
case 'f': case 'f':
apmd_configfile = optarg; apmd_configfile = optarg;
break; break;
case 's':
soft_power_state_change = 1;
break;
case 'v': case 'v':
verbose = 1; verbose = 1;
break; break;