diff options
author | Michael Shalayeff <mickey@cvs.openbsd.org> | 2001-03-23 01:00:42 +0000 |
---|---|---|
committer | Michael Shalayeff <mickey@cvs.openbsd.org> | 2001-03-23 01:00:42 +0000 |
commit | 725f62edfcaebc734a9786b4c1d475384e9081dd (patch) | |
tree | e0b914ca37627518af38bcc3d82e1043c1e441cc | |
parent | c24c0449612c1c70d785fdc66b310fa6071772de (diff) |
ac on/off hooks; from angelos@
-rw-r--r-- | usr.sbin/apmd/apm-proto.h | 2 | ||||
-rw-r--r-- | usr.sbin/apmd/apmd.8 | 25 | ||||
-rw-r--r-- | usr.sbin/apmd/apmd.c | 40 | ||||
-rw-r--r-- | usr.sbin/apmd/apmsubr.c | 2 | ||||
-rw-r--r-- | usr.sbin/apmd/pathnames.h | 4 |
5 files changed, 63 insertions, 10 deletions
diff --git a/usr.sbin/apmd/apm-proto.h b/usr.sbin/apmd/apm-proto.h index 818b2f2c8d8..5d65c51bd32 100644 --- a/usr.sbin/apmd/apm-proto.h +++ b/usr.sbin/apmd/apm-proto.h @@ -1,3 +1,5 @@ +/* $OpenBSD: apm-proto.h,v 1.2 2001/03/23 01:00:41 mickey Exp $ */ + /* * Copyright (c) 1996 John T. Kohl * All rights reserved. diff --git a/usr.sbin/apmd/apmd.8 b/usr.sbin/apmd/apmd.8 index 464b1d4d4de..fc75ca5b0c7 100644 --- a/usr.sbin/apmd/apmd.8 +++ b/usr.sbin/apmd/apmd.8 @@ -1,3 +1,5 @@ +.\" $OpenBSD: apmd.8,v 1.16 2001/03/23 01:00:41 mickey Exp $ +.\" .\" Copyright (c) 1995 John T. Kohl .\" All rights reserved. .\" @@ -24,8 +26,6 @@ .\" ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.\" $Id: apmd.8,v 1.15 2001/03/22 06:06:27 deraadt Exp $ -.\" .Dd March 24, 1996 .Dt APMD 8 .Os @@ -154,20 +154,27 @@ flushing the buffer cache. .Pp Actions can be configured for the three transitions: .Cm suspend , -.Cm standby +.Cm standby , +.Cm resume , +.Cm powerup and -.Cm resume . +.Cm powerdown . 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. +The powerup and powerdown programs are run after the power status (AC +connected or not) changes, as well as after a resume (if the power +status changed in the mean time). .Sh FILES .Pa /etc/apm/suspend , -.Pa /etc/apm/standby +.Pa /etc/apm/standby , +.Pa /etc/apm/resume , +.Pa /etc/apm/powerup and -.Pa /etc/apm/resume +.Pa /etc/apm/powerdown 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 @@ -179,8 +186,10 @@ may determine which transition is in progress by examining its which is set to one of .Ar suspend , .Ar standby , -or -.Ar resume . +.Ar resume , +.Ar powerup +and +.Ar powerdown . .Pp .Pa /var/run/apmdev is the default UNIX-domain socket used for communication with diff --git a/usr.sbin/apmd/apmd.c b/usr.sbin/apmd/apmd.c index 55aa461ba02..5385e83d487 100644 --- a/usr.sbin/apmd/apmd.c +++ b/usr.sbin/apmd/apmd.c @@ -1,3 +1,5 @@ +/* $OpenBSD: apmd.c,v 1.14 2001/03/23 01:00:41 mickey Exp $ */ + /* * Copyright (c) 1995, 1996 John T. Kohl * All rights reserved. @@ -70,6 +72,8 @@ enum apm_state handle_client(int sock_fd, int ctl_fd); void suspend(int ctl_fd); void stand_by(int ctl_fd); void resume(int ctl_fd); +void powerup(int ctl_fd); +void powerdown(int ctl_fd); void sigexit(int signo); void make_noise(int howmany); void do_etc_file(const char *file); @@ -264,6 +268,17 @@ int howmany; return; } +void +powerup(int ctl_fd) +{ + do_etc_file(_PATH_APM_ETC_POWERUP); +} + +void +powerdown(int ctl_fd) +{ + do_etc_file(_PATH_APM_ETC_POWERDOWN); +} void suspend(int ctl_fd) @@ -305,6 +320,7 @@ main(int argc, char *argv[]) int statonly = 0; int enableonly = 0; int pctonly = 0; + int powerstatus = 0, powerbak = 0, powerchange = 0; int messages = 0; fd_set *devfdsp, *selfdsp; struct apm_event_info apmevent; @@ -404,7 +420,11 @@ main(int argc, char *argv[]) if (ready == 0) { /* wakeup for timeout: take status */ - power_status(ctl_fd, 0, 0); + powerbak = power_status(ctl_fd, 0, 0); + if (powerstatus != powerbak) { + powerstatus = powerbak; + powerchange = 1; + } } if (FD_ISSET(ctl_fd, selfdsp)) { suspends = standbys = resumes = 0; @@ -430,10 +450,19 @@ main(int argc, char *argv[]) case APM_NORMAL_RESUME: case APM_CRIT_RESUME: case APM_SYS_STANDBY_RESUME: + powerbak = power_status(ctl_fd, 0, 0); + if (powerstatus != powerbak) { + powerstatus = powerbak; + powerchange = 1; + } resumes++; break; case APM_POWER_CHANGE: - power_status(ctl_fd, 0, 0); + powerbak = power_status(ctl_fd, 0, 0); + if (powerstatus != powerbak) { + powerstatus = powerbak; + powerchange = 1; + } break; default: break; @@ -450,6 +479,13 @@ main(int argc, char *argv[]) resume(ctl_fd); syslog(LOG_NOTICE, "system resumed from APM sleep"); } + if (powerchange) { + if (powerstatus) + powerup(ctl_fd); + else + powerdown(ctl_fd); + powerchange = 0; + } ready--; } if (ready == 0) diff --git a/usr.sbin/apmd/apmsubr.c b/usr.sbin/apmd/apmsubr.c index 014361ec20c..02cc864dd47 100644 --- a/usr.sbin/apmd/apmsubr.c +++ b/usr.sbin/apmd/apmsubr.c @@ -1,3 +1,5 @@ +/* $OpenBSD: apmsubr.c,v 1.2 2001/03/23 01:00:41 mickey Exp $ */ + /* * Copyright (c) 1995,1996 John T. Kohl * All rights reserved. diff --git a/usr.sbin/apmd/pathnames.h b/usr.sbin/apmd/pathnames.h index 393f19f9151..d31e7dd5746 100644 --- a/usr.sbin/apmd/pathnames.h +++ b/usr.sbin/apmd/pathnames.h @@ -1,3 +1,5 @@ +/* $OpenBSD: pathnames.h,v 1.4 2001/03/23 01:00:41 mickey Exp $ */ + /* * Copyright (c) 1996 John T. Kohl * All rights reserved. @@ -33,5 +35,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_POWERUP _PATH_APM_ETC_DIR"/powerup" +#define _PATH_APM_ETC_POWERDOWN _PATH_APM_ETC_DIR"/powerdown" #define _PATH_APM_NORMAL "/dev/apm" #define _PATH_DEV_SPEAKER "/dev/speaker" |