summaryrefslogtreecommitdiff
path: root/usr.sbin/apmd/apmd.c
diff options
context:
space:
mode:
authorJeremie Courreges-Anglas <jca@cvs.openbsd.org>2021-04-18 23:51:48 +0000
committerJeremie Courreges-Anglas <jca@cvs.openbsd.org>2021-04-18 23:51:48 +0000
commit9dcf06442d37ef54db36258d57b85998c01cc273 (patch)
tree5276912a6b439cab439e398035261243ef31a2dc /usr.sbin/apmd/apmd.c
parent3addda9aa5d30f16dafe09d248dc2344458de4e7 (diff)
Simpler error handling for suspend()/hibernate()
Save errno when we get an error so we can pass it to the apm(8) client. ok kn@
Diffstat (limited to 'usr.sbin/apmd/apmd.c')
-rw-r--r--usr.sbin/apmd/apmd.c41
1 files changed, 25 insertions, 16 deletions
diff --git a/usr.sbin/apmd/apmd.c b/usr.sbin/apmd/apmd.c
index a6a302978e2..b4fdf482e05 100644
--- a/usr.sbin/apmd/apmd.c
+++ b/usr.sbin/apmd/apmd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: apmd.c,v 1.104 2021/04/06 22:12:48 jca Exp $ */
+/* $OpenBSD: apmd.c,v 1.105 2021/04/18 23:51:47 jca Exp $ */
/*
* Copyright (c) 1995, 1996 John T. Kohl
@@ -271,18 +271,15 @@ handle_client(int sock_fd, int ctl_fd)
switch (cmd.action) {
case SUSPEND:
reply.newstate = SUSPENDING;
- if (suspend(ctl_fd) == -1)
- reply.error = errno;
+ reply.error = suspend(ctl_fd);
break;
case STANDBY:
reply.newstate = STANDING_BY;
- if (stand_by(ctl_fd) == -1)
- reply.error = errno;
+ reply.error = stand_by(ctl_fd);
break;
case HIBERNATE:
reply.newstate = HIBERNATING;
- if (hibernate(ctl_fd) == -1)
- reply.error = errno;
+ reply.error = hibernate(ctl_fd);
break;
case SETPERF_LOW:
reply.newstate = NORMAL;
@@ -329,46 +326,58 @@ handle_client(int sock_fd, int ctl_fd)
int
suspend(int ctl_fd)
{
- int ret;
+ int error = 0;
logmsg(LOG_NOTICE, "system suspending");
power_status(ctl_fd, 1, NULL);
do_etc_file(_PATH_APM_ETC_SUSPEND);
sync();
sleep(1);
- if ((ret = ioctl(ctl_fd, APM_IOC_SUSPEND, 0)) == -1)
+
+ if (ioctl(ctl_fd, APM_IOC_SUSPEND, 0) == -1) {
+ error = errno;
logmsg(LOG_WARNING, "%s: %s", __func__, strerror(errno));
- return (ret);
+ }
+
+ return error;
}
int
stand_by(int ctl_fd)
{
- int ret;
+ int error = 0;
logmsg(LOG_NOTICE, "system entering standby");
power_status(ctl_fd, 1, NULL);
do_etc_file(_PATH_APM_ETC_STANDBY);
sync();
sleep(1);
- if ((ret = ioctl(ctl_fd, APM_IOC_STANDBY, 0)) == -1)
+
+ if (ioctl(ctl_fd, APM_IOC_STANDBY, 0) == -1) {
+ error = errno;
logmsg(LOG_WARNING, "%s: %s", __func__, strerror(errno));
- return (ret);
+ }
+
+ return error;
}
int
hibernate(int ctl_fd)
{
- int ret;
+ int error = 0;
logmsg(LOG_NOTICE, "system hibernating");
power_status(ctl_fd, 1, NULL);
do_etc_file(_PATH_APM_ETC_HIBERNATE);
sync();
sleep(1);
- if ((ret = ioctl(ctl_fd, APM_IOC_HIBERNATE, 0)) == -1)
+
+ if (ioctl(ctl_fd, APM_IOC_HIBERNATE, 0) == -1) {
+ error = errno;
logmsg(LOG_WARNING, "%s: %s", __func__, strerror(errno));
- return (ret);
+ }
+
+ return error;
}
void