-/* $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
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;
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