Add support for running scripts for line power to battery transitions

(and vice versa).
This commit is contained in:
kenh 1998-11-19 19:39:14 +00:00
parent db3051d720
commit 0c2d06b6ae
3 changed files with 54 additions and 13 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: apmd.8,v 1.7 1997/10/17 04:57:31 lukem Exp $
.\" $NetBSD: apmd.8,v 1.8 1998/11/19 19:39:14 kenh Exp $
.\"
.\" Copyright (c) 1996 The NetBSD Foundation, Inc.
.\" All rights reserved.
@ -126,21 +126,29 @@ replies with the intended state to the client and then places the system
in the requested mode after running the configuration script and
flushing the buffer cache.
.Pp
Actions can be configured for the three transitions:
Actions can be configured for the five transitions:
.Cm suspend ,
.Cm standby
and
.Cm resume .
.Cm standby ,
.Cm resume ,
.Cm line
or
.Cm battery .
The suspend and standby actions are run prior to
.Nm
performing any other actions (such as disk syncs) and entering the new
mode. The resume program is run after resuming from a stand-by or
suspended state.
.Pp
The line and battery actions are run after switching power sources to
AC (line) or battery, respectively. The appropriate line or battery action
is also run upon the startup of apmd based on the current power source.
.Sh FILES
.Pa /etc/apm/suspend ,
.Pa /etc/apm/standby
.Pa /etc/apm/standby ,
.Pa /etc/apm/resume ,
.Pa /etc/apm/line
and
.Pa /etc/apm/resume
.Pa /etc/apm/battery
are the files that contain the host's customized actions.
Each file must be an executable binary or shell script suitable
for execution by the
@ -152,8 +160,10 @@ may determine which transition is in progress by examining its
which is set to one of
.Ar suspend ,
.Ar standby ,
.Ar resume ,
.Ar line
or
.Ar resume .
.Ar battery .
.Pp
.Pa /var/run/apmdev
is the default UNIX-domain socket used for communication with

View File

@ -1,4 +1,4 @@
/* $NetBSD: apmd.c,v 1.8 1998/07/18 05:04:39 lukem Exp $ */
/* $NetBSD: apmd.c,v 1.9 1998/11/19 19:39:14 kenh Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
@ -79,6 +79,7 @@ void resume(int ctl_fd);
void sigexit(int signo);
void make_noise(int howmany);
void do_etc_file(const char *file);
void do_ac_state(int state);
void
sigexit(int signo)
@ -386,20 +387,29 @@ main(int argc, char *argv[])
setlogmask(LOG_UPTO(LOG_NOTICE));
daemon(0, 0);
}
power_status(ctl_fd, 1, 0);
if (statonly)
if (statonly) {
power_status(ctl_fd, 1, 0);
exit(0);
} else {
struct apm_power_info pinfo;
power_status(ctl_fd, 1, &pinfo);
do_ac_state(pinfo.ac_state);
}
(void) signal(SIGTERM, sigexit);
(void) signal(SIGHUP, sigexit);
(void) signal(SIGINT, sigexit);
(void) signal(SIGPIPE, SIG_IGN);
sock_fd = bind_socket(sockname, mode, uid, gid);
FD_ZERO(&devfds);
FD_SET(ctl_fd, &devfds);
FD_SET(sock_fd, &devfds);
for (selcopy = devfds, errno = 0, stv = tv;
(ready = select(MAX(ctl_fd,sock_fd)+1, &selcopy, 0, 0, &stv)) >= 0 ||
errno == EINTR;
@ -437,8 +447,12 @@ main(int argc, char *argv[])
resumes++;
break;
case APM_POWER_CHANGE:
power_status(ctl_fd, 1, 0);
{
struct apm_power_info pinfo;
power_status(ctl_fd, 1, &pinfo);
do_ac_state(pinfo.ac_state);
break;
}
default:
break;
}
@ -516,3 +530,18 @@ do_etc_file(const char *file)
break;
}
}
void do_ac_state(int state)
{
switch (state) {
case APM_AC_OFF:
do_etc_file(_PATH_APM_ETC_BATTERY);
break;
case APM_AC_ON:
case APM_AC_BACKUP:
do_etc_file(_PATH_APM_ETC_LINE);
break;
default:
/* Silently ignore */
}
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: pathnames.h,v 1.3 1997/07/30 22:54:14 jtc Exp $ */
/* $NetBSD: pathnames.h,v 1.4 1998/11/19 19:39:14 kenh Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
@ -42,5 +42,7 @@
#define _PATH_APM_ETC_SUSPEND _PATH_APM_ETC_DIR"/suspend"
#define _PATH_APM_ETC_STANDBY _PATH_APM_ETC_DIR"/standby"
#define _PATH_APM_ETC_RESUME _PATH_APM_ETC_DIR"/resume"
#define _PATH_APM_ETC_LINE _PATH_APM_ETC_DIR"/line"
#define _PATH_APM_ETC_BATTERY _PATH_APM_ETC_DIR"/battery"
#define _PATH_APM_NORMAL "/dev/apm"
#define _PATH_DEV_SPEAKER "/dev/speaker"