apmd: run powerdown at boot when not on power

joshua stein <[email protected]>
Newsgroups gmane.os.openbsd.tech
Message-ID <20260830140113.02c6713fc2@64b1c3a020863b0>
If one has /etc/apm/powerdown set to do things when the machine goes 
on battery like set powersave on a Wi-Fi interface, that never gets 
run on a reboot because apmd only catches a transition.

I thought about running powerup at boot too but is that pointless?  
My powerdown is turning knobs from the defaults, my powerup turns 
them back to defaults, so running powerup at boot does nothing.

Also, powerup and powerdown are terrible names.


diff --git usr.sbin/apmd/apmd.c usr.sbin/apmd/apmd.c
index e87e5d2c0db..d5dd7c89c0d 100644
--- usr.sbin/apmd/apmd.c
+++ usr.sbin/apmd/apmd.c
@@ -525,7 +525,7 @@ main(int argc, char *argv[])
 
 	sock_fd = bind_socket(sockname);
 
-	power_status(ctl_fd, 1, &pinfo);
+	powerstatus = power_status(ctl_fd, 1, &pinfo);
 
 	if (statonly)
 		exit(0);
@@ -539,6 +539,9 @@ main(int argc, char *argv[])
 
 	set_driver_messages(ctl_fd, APM_PRINT_OFF);
 
+	if (ctl_fd != -1 && !powerstatus)
+		do_etc_file(_PATH_APM_ETC_POWERDOWN);
+
 	kq = kqueue();
 	if (kq <= 0)
 		error("kqueue", NULL);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.