Page MenuHomeFreeBSD

D56918.id177529.diff
No OneTemporary

D56918.id177529.diff

diff --git a/usr.sbin/zzz/Makefile b/usr.sbin/zzz/Makefile
--- a/usr.sbin/zzz/Makefile
+++ b/usr.sbin/zzz/Makefile
@@ -1,4 +1,7 @@
-SCRIPTS=zzz.sh
+.include <src.opts.mk>
+
+PACKAGE=acpi
+PROG= zzz
MAN= zzz.8
.include <bsd.prog.mk>
diff --git a/usr.sbin/zzz/zzz.c b/usr.sbin/zzz/zzz.c
new file mode 100644
--- /dev/null
+++ b/usr.sbin/zzz/zzz.c
@@ -0,0 +1,56 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2026 The FreeBSD Foundation
+ *
+ * This software was developed by Aymeric Wibo <obiwac@freebsd.org>
+ * under sponsorship from the FreeBSD Foundation.
+ */
+
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sysexits.h>
+
+#include <sys/power.h>
+
+#define POWERDEV "/dev/power"
+
+static void
+usage(void)
+{
+ (void)fprintf(stderr, "usage: zzz\n");
+ exit(1);
+}
+
+int
+main(int argc, char *argv[])
+{
+ int powerfd;
+ enum power_sstate_transition trans;
+
+ (void)argv;
+ if (argc != 0)
+ usage();
+
+ powerfd = open(POWERDEV, O_RDWR);
+ if (powerfd < 0)
+ errx(EX_OSFILE, "could not open power device: %s\n",
+ strerror(errno));
+
+ /*
+ * The previous zzz script would run apm -z if ACPI support was not
+ * detected, but the APM ioctls just end up calling to ACPI anyway.
+ * So if we have the ACPI power management backend, this behaves
+ * exactly the same.
+ */
+ trans = POWER_SSTATE_TRANSITION_SUSPEND;
+ if (ioctl(powerfd, PIOTRANSITION, &trans) != 0)
+ errx(EX_IOERR, "could not request suspend transition: %s\n",
+ strerror(errno));
+
+ return EXIT_SUCCESS;
+}
diff --git a/usr.sbin/zzz/zzz.sh b/usr.sbin/zzz/zzz.sh
deleted file mode 100644
--- a/usr.sbin/zzz/zzz.sh
+++ /dev/null
@@ -1,41 +0,0 @@
-#!/bin/sh
-#
-# Suspend the system using either ACPI or APM.
-# For APM, "apm -z" will be issued.
-# For ACPI, the configured suspend state will be looked up, checked to see
-# if it is supported, and "acpiconf -s <state>" will be issued.
-#
-# Mark Santcroos <marks@ripe.net>
-#
-
-PATH=/sbin:/usr/sbin:/usr/bin:/bin
-
-ACPI_SUSPEND_STATE=hw.acpi.suspend_state
-ACPI_SUPPORTED_STATES=hw.acpi.supported_sleep_state
-APM_SUSPEND_DELAY=machdep.apm_suspend_delay
-
-# Check for ACPI support
-if sysctl $ACPI_SUSPEND_STATE >/dev/null 2>&1; then
- # Get configured suspend state
- SUSPEND_STATE=$(sysctl -n $ACPI_SUSPEND_STATE)
-
- # Get list of supported suspend states
- SUPPORTED_STATES=$(sysctl -n $ACPI_SUPPORTED_STATES)
-
- # Check if the configured suspend state is supported by the system
- if echo "$SUPPORTED_STATES" | grep "$SUSPEND_STATE" >/dev/null; then
- # execute ACPI style suspend command
- exec acpiconf -s "$SUSPEND_STATE"
- else
- echo "Requested suspend state $SUSPEND_STATE is not supported."
- echo "Supported states: $SUPPORTED_STATES"
- fi
-# Check for APM support
-elif sysctl $APM_SUSPEND_DELAY >/dev/null 2>&1; then
- # Execute APM style suspend command
- exec apm -z
-else
- echo "Error: no ACPI or APM suspend support found."
-fi
-
-exit 1

File Metadata

Mime Type
text/plain
Expires
Thu, Aug 6, 3:31 AM (16 h, 7 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
36069367
Default Alt Text
D56918.id177529.diff (2 KB)

Event Timeline