Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F162049581
D56918.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
6 KB
Referenced Files
None
Subscribers
None
D56918.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.8 b/usr.sbin/zzz/zzz.8
--- a/usr.sbin/zzz/zzz.8
+++ b/usr.sbin/zzz/zzz.8
@@ -1,63 +1,59 @@
-.\" Copyright (c) 2003 Nate Lawson
-.\" All rights reserved.
+.\"-
+.\" SPDX-License-Identifier: BSD-2-Clause
.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
+.\" Copyright (c) 2026 The FreeBSD Foundation
.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
+.\" This documentation was written by Aymeric Wibo <obiwac@freebsd.org> under
+.\" sponsorship from the FreeBSD Foundation.
.\"
-.Dd July 13, 2003
+.Dd May 26, 2026
.Dt ZZZ 8
.Os
.Sh NAME
.Nm zzz
-.Nd suspend an ACPI or APM system
+.Nd suspend the system
.Sh SYNOPSIS
.Nm
.Sh DESCRIPTION
The
.Nm
-utility
-checks for
-.Tn ACPI
-or
-.Tn APM
-support and then suspends the system appropriately.
-For
-.Tn APM ,
-.Pp
-.Dl apm -z
-.Pp
-will be issued.
-For
-.Tn ACPI,
-the configured suspend state will be looked up, checked to see
-if it is supported and,
+utility suspends the system by writing a suspend transition request to
+.Pa /dev/power .
.Pp
-.Dl acpiconf -s <state>
-.Pp
-will be issued.
+The specific sleep method used
+.Pq e.g.\& suspend-to-idle or firmware suspend
+is determined by the
+.Va kern.power.suspend
+sysctl.
.Sh SEE ALSO
.Xr acpi 4 ,
-.Xr apm 4 ,
-.Xr acpiconf 8 ,
+.Xr acpiconf 8
+.Sh HISTORY
+The
+.Nm
+utility first appeared as a shell script in
+.Fx 5.1 .
+It suspended the system by invoking
+.Xr acpiconf 8
+with the suspend state configured via
+.Va hw.acpi.suspend_state ,
+or
.Xr apm 8
+on systems without ACPI support.
+.Pp
+It was rewritten in C in
+.Fx 16.0
+to use the generic power management interface provided by
+.Pa /dev/power .
.Sh AUTHORS
-This manual page was written by
+The original
+.Nm
+script was written by
+.An Mark Santcroos Aq Mt marks@ripe.net .
+This manual page was originally written by
.An Nate Lawson Aq Mt njl@FreeBSD.org .
+Both the current program and manual page were written by
+.An Aymeric Wibo Aq Mt obiwac@FreeBSD.org ,
+under sponsorship from the
+.Fx
+Foundation.
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,47 @@
+/*
+ * 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 <sys/power.h>
+
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <paths.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sysexits.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");
+
+ 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
Fri, Jul 10, 6:16 AM (15 h, 58 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
34918003
Default Alt Text
D56918.diff (6 KB)
Attached To
Mode
D56918: zzz: Rewrite to use new power device
Attached
Detach File
Event Timeline
Log In to Comment