code: plan9front

Download patch

ref: ace62a81f4252c53e0f49a805aeaee691e42ea1a
parent: 4526b1a5dd7f9ecb5b0b472cc4bd6a41b05effcc
author: mia soweli <inbox@tachibana-labs.org>
date: Mon May 29 13:28:40 EDT 2023

aux/acpi: -H is for HALT

add -H option for acpi that halts immediately,
skipping enumeration of the battery, temperature, etc.

--- a/sys/man/8/acpi
+++ b/sys/man/8/acpi
@@ -7,6 +7,9 @@
 .PP
 .B aux/acpi
 [
+.B -H
+]
+[
 .B -m
 .I mountpoint
 ]
@@ -27,6 +30,12 @@
 .BI /srv/ service 
 as well.
 .PP
+With the
+.B -H
+option,
+.I aux/acpi
+will turn off the power immediately.
+.PP
 The directory contains the following files.
 .TP
 .B battery
@@ -57,7 +66,7 @@
 .SH SOURCE
 .B /sys/src/cmd/aux/acpi.c
 .SH SEE ALSO
-.IR imx8pm (8)
+.IR reform (1)
 .SH BUGS
 ACPI itself.
 .SH HISTORY
--- a/sys/src/cmd/aux/acpi.c
+++ b/sys/src/cmd/aux/acpi.c
@@ -293,7 +293,7 @@
 	(*io->write)(io, b, 1<<(wid-1), addr);
 }
 
-static void
+static int
 poweroff(void)
 {
 	int n;
@@ -302,7 +302,7 @@
 
 	if(facp.ok == 0){
 		werrstr("no FACP");
-		return;
+		return -1;
 	}
 
 	wirecpu0();
@@ -362,6 +362,7 @@
 	sleep(100);
 
 	werrstr("acpi failed");
+	return -1;
 }
 
 static void
@@ -420,7 +421,7 @@
 static void
 usage(void)
 {
-	fprint(2, "usage: aux/acpi [-Dp] [-m mountpoint] [-s service]\n");
+	fprint(2, "usage: aux/acpi [-DHp] [-m mountpoint] [-s service]\n");
 	exits("usage");
 }
 
@@ -436,11 +437,12 @@
 {
 	char *mtpt, *srv;
 	void *r, **rr;
-	int fd, n, l;
+	int fd, n, l, halt;
 	Tbl *t;
 
 	mtpt = "/dev";
 	srv = nil;
+	halt = 0;
 	ARGBEGIN{
 	case 'D':
 		chatty9p = 1;
@@ -454,6 +456,9 @@
 	case 'p':
 		amldebug++;
 		break;
+	case 'H':
+		halt = 1;
+		break;
 	default:
 		usage();
 	}ARGEND
@@ -549,6 +554,9 @@
 		facp.slpb = amlint(rr[1]);
 	}
 	close(fd);
+
+	if(halt && poweroff() < 0)
+		sysfatal("%r");
 
 	amlenum(amlroot, "_HID", enumec, nil);
 	amlenum(amlroot, "_BIF", enumbat, nil);