bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 2/2 hurd] shutdown: Try mach device acpi before /servers/acpi


From: Damien Zammit
Subject: [PATCH 2/2 hurd] shutdown: Try mach device acpi before /servers/acpi
Date: Sun, 10 Nov 2024 08:42:08 +0000

Since libmachdev cannot currently serve netfs as well as trivfs on a
path, we need to allow connecting to the bootstrapped acpi server
to shut down the machine.

---
 shutdown/shutdown.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/shutdown/shutdown.c b/shutdown/shutdown.c
index e4247397..4a2b1a41 100644
--- a/shutdown/shutdown.c
+++ b/shutdown/shutdown.c
@@ -32,6 +32,7 @@
 #include <hurd/ports.h>
 #include <hurd/trivfs.h>
 #include <hurd/paths.h>
+#include <device/device.h>
 #include <sys/file.h>
 #include <version.h>
 
@@ -55,13 +56,32 @@ int trivfs_allow_open = O_READ | O_WRITE;
 struct port_class *trivfs_protid_class;
 struct port_class *trivfs_control_class;
 
+static mach_port_t
+get_acpi(void)
+{
+  kern_return_t err;
+  mach_port_t tryacpi, device_master;
+
+  err = get_privileged_ports (0, &device_master);
+  if (!err)
+    {
+      err = device_open (device_master, D_READ | D_WRITE, "acpi", &tryacpi);
+      mach_port_deallocate (mach_task_self (), device_master);
+      if (!err)
+        return tryacpi;
+    }
+
+  tryacpi = file_name_lookup (_SERVERS_ACPI, O_RDWR, 0);
+  return tryacpi;
+}
+
 kern_return_t
 S_shutdown_shutdown(trivfs_protid_t server)
 {
   kern_return_t err;
   mach_port_t acpi;
 
-  acpi = file_name_lookup (_SERVERS_ACPI, O_RDWR, 0);
+  acpi = get_acpi();
   if (acpi == MACH_PORT_NULL)
     return EIO;
 
-- 
2.45.2





reply via email to

[Prev in Thread] Current Thread [Next in Thread]