Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F170908373
D56918.id178358.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D56918.id178358.diff
View Options
diff --git a/include/paths.h b/include/paths.h
--- a/include/paths.h
+++ b/include/paths.h
@@ -54,6 +54,7 @@
#define _PATH_DEFTAPE "/dev/sa0"
#define _PATH_DEVGPIOC "/dev/gpioc"
#define _PATH_DEVNULL "/dev/null"
+#define _PATH_DEVPOWER "/dev/power"
#define _PATH_DEVZERO "/dev/zero"
#define _PATH_DRUM "/dev/drum"
#define _PATH_ESDB "/usr/share/i18n/esdb"
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,6 @@
-SCRIPTS=zzz.sh
+.include <src.opts.mk>
+
+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,53 @@
+/*
+ * 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 <paths.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sysexits.h>
+
+#include <sys/power.h>
+
+static void
+usage(void)
+{
+ (void)fprintf(stderr, "usage: zzz\n");
+ exit(1);
+}
+
+int
+main(int argc, char *argv[])
+{
+ int powerfd;
+ enum power_transition trans;
+
+ (void)argv;
+ if (argc != 1)
+ usage();
+
+ powerfd = open(_PATH_DEVPOWER, O_RDWR);
+ if (powerfd < 0)
+ err(EX_OSFILE, "could not open power device");
+
+ /*
+ * 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_TRANSITION_SUSPEND;
+ if (ioctl(powerfd, PIOTRANSITION, &trans) != 0)
+ err(EX_IOERR, "could not request suspend transition");
+
+ 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
Details
Attached
Mime Type
text/plain
Expires
Tue, Sep 8, 12:16 PM (4 h, 10 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
38484653
Default Alt Text
D56918.id178358.diff (3 KB)
Attached To
Mode
D56918: zzz: Rewrite to use new power device
Attached
Detach File
Event Timeline
Log In to Comment