summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2012-03-26 20:17:46 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2012-03-26 20:17:46 +0000
commit7b7a83afe518f7a384a53392dd1a7ec2f4541d71 (patch)
tree56e410562b6f531a56fa141a4e40e0c577aac8a6
parentbf9d38a87a710084153b01271f80b676d3d051cf (diff)
Add hibernate request support. Also installs a ZZZ binary for the
shortcut. ok mlarkin miod
-rw-r--r--usr.sbin/apm/Makefile5
-rw-r--r--usr.sbin/apm/apm.85
-rw-r--r--usr.sbin/apm/apm.c22
-rw-r--r--usr.sbin/apmd/apm-proto.h6
-rw-r--r--usr.sbin/apmd/apmd.c18
-rw-r--r--usr.sbin/apmd/pathnames.h3
6 files changed, 49 insertions, 10 deletions
diff --git a/usr.sbin/apm/Makefile b/usr.sbin/apm/Makefile
index db902fd5542..faeb49379b3 100644
--- a/usr.sbin/apm/Makefile
+++ b/usr.sbin/apm/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.13 2010/02/28 08:36:36 otto Exp $
+# $OpenBSD: Makefile,v 1.14 2012/03/26 20:17:43 deraadt Exp $
.if (${MACHINE} == "amd64") || (${MACHINE} == "i386") || \
@@ -13,12 +13,13 @@ SRCS= apm.c apmsubr.c
CFLAGS+= -I${.CURDIR}/../apmd
PROG= apm
LINKS= ${BINDIR}/apm ${BINDIR}/zzz
+LINKS+= ${BINDIR}/apm ${BINDIR}/ZZZ
.else
NOPROG=yes
.endif
MAN= apm.8
MANSUBDIR=amd64 i386 loongson macppc sparc sparc64 zaurus
-MLINKS= apm.8 zzz.8
+MLINKS= apm.8 zzz.8 apm.8 ZZZ.8
.include <bsd.prog.mk>
diff --git a/usr.sbin/apm/apm.8 b/usr.sbin/apm/apm.8
index 49abf0a9823..976323955c1 100644
--- a/usr.sbin/apm/apm.8
+++ b/usr.sbin/apm/apm.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: apm.8,v 1.35 2010/09/19 21:59:23 jmc Exp $
+.\" $OpenBSD: apm.8,v 1.36 2012/03/26 20:17:43 deraadt Exp $
.\"
.\" Copyright (c) 1996 John T. Kohl
.\" All rights reserved.
@@ -26,7 +26,7 @@
.\" ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd $Mdocdate: September 19 2010 $
+.Dd $Mdocdate: March 26 2012 $
.Dt APM 8
.Os
.Sh NAME
@@ -34,6 +34,7 @@
.Nd Advanced Power Management control program
.Sh SYNOPSIS
.Nm zzz
+.Nm ZZZ
.Op Fl Sz
.Op Fl f Ar sockname
.Nm apm
diff --git a/usr.sbin/apm/apm.c b/usr.sbin/apm/apm.c
index f77dfa2ccfc..585e94cc51a 100644
--- a/usr.sbin/apm/apm.c
+++ b/usr.sbin/apm/apm.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: apm.c,v 1.24 2009/10/30 19:41:10 sobrado Exp $ */
+/* $OpenBSD: apm.c,v 1.25 2012/03/26 20:17:43 deraadt Exp $ */
/*
* Copyright (c) 1996 John T. Kohl
@@ -104,6 +104,9 @@ do_zzz(int fd, enum apm_action action)
case STANDBY:
command.action = STANDBY;
break;
+ case HIBERNATE:
+ command.action = HIBERNATE;
+ break;
default:
zzusage();
}
@@ -151,7 +154,7 @@ main(int argc, char *argv[])
int cpuspeed_mib[] = { CTL_HW, HW_CPUSPEED }, cpuspeed;
size_t cpuspeed_sz = sizeof(cpuspeed);
- while ((ch = getopt(argc, argv, "ACHLlmbvaPSzf:")) != -1) {
+ while ((ch = getopt(argc, argv, "ACHLlmbvaPSzZf:")) != -1) {
switch (ch) {
case 'v':
verbose = TRUE;
@@ -169,6 +172,11 @@ main(int argc, char *argv[])
usage();
action = STANDBY;
break;
+ case 'Z':
+ if (action != NONE)
+ usage();
+ action = HIBERNATE;
+ break;
case 'A':
if (action != NONE)
usage();
@@ -234,8 +242,14 @@ main(int argc, char *argv[])
err(1, "cannot connect to apmd");
else
return (do_zzz(fd, action));
+ } else if (!strcmp(__progname, "ZZZ")) {
+ if (fd < 0)
+ err(1, "cannot connect to apmd");
+ else
+ return (do_zzz(fd, HIBERNATE));
}
+
bzero(&reply, sizeof reply);
reply.batterystate.battery_state = APM_BATT_UNKNOWN;
reply.batterystate.ac_state = APM_AC_UNKNOWN;
@@ -270,6 +284,7 @@ main(int argc, char *argv[])
balony:
case SUSPEND:
case STANDBY:
+ case HIBERNATE:
command.action = action;
break;
default:
@@ -384,6 +399,9 @@ balony:
case STANDBY:
printf("System will enter standby mode momentarily.\n");
break;
+ case HIBERNATE:
+ printf("System will enter hibernate mode momentarily.\n");
+ break;
default:
break;
}
diff --git a/usr.sbin/apmd/apm-proto.h b/usr.sbin/apmd/apm-proto.h
index fee1405b72c..0d5716eb1a0 100644
--- a/usr.sbin/apmd/apm-proto.h
+++ b/usr.sbin/apmd/apm-proto.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: apm-proto.h,v 1.8 2006/03/15 20:30:28 sturm Exp $ */
+/* $OpenBSD: apm-proto.h,v 1.9 2012/03/26 20:17:45 deraadt Exp $ */
/*
* Copyright (c) 1996 John T. Kohl
@@ -33,6 +33,7 @@ enum apm_action {
NONE,
SUSPEND,
STANDBY,
+ HIBERNATE,
GETSTATUS,
SETPERF_LOW,
SETPERF_HIGH,
@@ -43,7 +44,8 @@ enum apm_action {
enum apm_state {
NORMAL,
SUSPENDING,
- STANDING_BY
+ STANDING_BY,
+ HIBERNATING
};
enum apm_perfmode {
diff --git a/usr.sbin/apmd/apmd.c b/usr.sbin/apmd/apmd.c
index 5a65d9702c7..6ddb2cfbfd3 100644
--- a/usr.sbin/apmd/apmd.c
+++ b/usr.sbin/apmd/apmd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: apmd.c,v 1.57 2011/04/21 06:45:04 jasper Exp $ */
+/* $OpenBSD: apmd.c,v 1.58 2012/03/26 20:17:45 deraadt Exp $ */
/*
* Copyright (c) 1995, 1996 John T. Kohl
@@ -79,6 +79,7 @@ int get_avg_idle_up(void);
void perf_status(struct apm_power_info *pinfo, int ncpu);
void suspend(int ctl_fd);
void stand_by(int ctl_fd);
+void hibernate(int ctl_fd);
void setperf(int new_perf);
void sigexit(int signo);
void do_etc_file(const char *file);
@@ -429,6 +430,9 @@ handle_client(int sock_fd, int ctl_fd)
case STANDBY:
reply.newstate = STANDING_BY;
break;
+ case HIBERNATE:
+ reply.newstate = HIBERNATING;
+ break;
case SETPERF_LOW:
doperf = PERF_MANUAL;
reply.newstate = NORMAL;
@@ -487,6 +491,15 @@ stand_by(int ctl_fd)
ioctl(ctl_fd, APM_IOC_STANDBY, 0);
}
+void
+hibernate(int ctl_fd)
+{
+ do_etc_file(_PATH_APM_ETC_HIBERNATE);
+ sync();
+ sleep(1);
+ ioctl(ctl_fd, APM_IOC_HIBERNATE, 0);
+}
+
#define TIMO (10*60) /* 10 minutes */
int
@@ -721,6 +734,9 @@ main(int argc, char *argv[])
case STANDING_BY:
stand_by(ctl_fd);
break;
+ case HIBERNATING:
+ hibernate(ctl_fd);
+ break;
}
}
error("kevent loop", NULL);
diff --git a/usr.sbin/apmd/pathnames.h b/usr.sbin/apmd/pathnames.h
index 9f53af6b255..2503610404f 100644
--- a/usr.sbin/apmd/pathnames.h
+++ b/usr.sbin/apmd/pathnames.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: pathnames.h,v 1.5 2005/06/14 15:18:53 deraadt Exp $ */
+/* $OpenBSD: pathnames.h,v 1.6 2012/03/26 20:17:45 deraadt Exp $ */
/*
* Copyright (c) 1996 John T. Kohl
@@ -34,6 +34,7 @@
#define _PATH_APM_ETC_DIR "/etc/apm"
#define _PATH_APM_ETC_SUSPEND _PATH_APM_ETC_DIR"/suspend"
#define _PATH_APM_ETC_STANDBY _PATH_APM_ETC_DIR"/standby"
+#define _PATH_APM_ETC_HIBERNATE _PATH_APM_ETC_DIR"/hibernate"
#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"