Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F170872122
D59296.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D59296.diff
View Options
diff --git a/etc/mtree/BSD.var.dist b/etc/mtree/BSD.var.dist
--- a/etc/mtree/BSD.var.dist
+++ b/etc/mtree/BSD.var.dist
@@ -37,6 +37,8 @@
..
/set mode=0755
db
+ backlight tags=package=rc
+ ..
entropy uname=operator gname=operator mode=0700
..
freebsd-update mode=0700
diff --git a/libexec/rc/rc.conf b/libexec/rc/rc.conf
--- a/libexec/rc/rc.conf
+++ b/libexec/rc/rc.conf
@@ -42,6 +42,7 @@
apm_enable="NO" # Set to YES to enable APM BIOS functions (or NO).
apmd_enable="NO" # Run apmd to handle APM event from userland.
apmd_flags="" # Flags to apmd (if enabled).
+backlight_enable="NO" # Save/restore backlight levels
ddb_enable="NO" # Set to YES to load ddb scripts at boot.
ddb_config="/etc/ddb.conf" # ddb(8) config file.
devd_enable="YES" # Run devd, to trigger programs on device tree changes.
diff --git a/libexec/rc/rc.d/Makefile b/libexec/rc/rc.d/Makefile
--- a/libexec/rc/rc.d/Makefile
+++ b/libexec/rc/rc.d/Makefile
@@ -11,6 +11,7 @@
NETWORKING \
SERVERS \
adjkerntz \
+ backlight \
bgfsck \
bridge \
cfumass \
diff --git a/libexec/rc/rc.d/backlight b/libexec/rc/rc.d/backlight
new file mode 100755
--- /dev/null
+++ b/libexec/rc/rc.d/backlight
@@ -0,0 +1,88 @@
+#!/bin/sh -
+#
+# Copyright (c) 2026 Kyle Evans <kevans@FreeBSD.org>
+#
+# SPDX-License-Identifier: BSD-2-Clause
+#
+
+# PROVIDE: backlight
+# REQUIRE: FILESYSTEMS kld
+# KEYWORD: nojail shutdown
+
+. /etc/rc.subr
+
+name="backlight"
+desc="Save and restore backlight values"
+rcvar="backlight_enable"
+stop_cmd="backlight_stop"
+start_cmd="backlight_start"
+reload_cmd="backlight_start"
+extra_commands="reload"
+
+backlightdb="/var/db/backlight"
+
+#
+# List current backlight devices to stdout.
+#
+list_backlights()
+{
+ ( cd /dev/backlight ; ls backlight* 2>/dev/null )
+}
+
+#
+# Save state of an individual backlight specified as $1
+#
+backlight_save()
+{
+ local dev
+
+ dev="/dev/backlight/$1"
+ if [ -r "$dev" ]; then
+ /usr/bin/backlight -f "$dev" -q > "$backlightdb/$1-state" 2>/dev/null
+ fi
+}
+
+#
+# Restore the state of an individual backlight specified as $1
+#
+backlight_restore()
+{
+ local file dev
+
+ dev="/dev/backlight/$1"
+ file="$backlightdb/$1-state"
+ if [ -r "$dev" -a -r "$file" ]; then
+ /usr/bin/backlight -f "$dev" $(cat "$file") > /dev/null
+ fi
+}
+
+#
+# Restore state of all backlights
+#
+backlight_start()
+{
+ local backlight
+
+ for backlight in $(list_backlights); do
+ backlight_restore "$backlight"
+ done
+}
+
+#
+# Save the state of all backlights
+#
+backlight_stop()
+{
+ local backlight
+
+ for backlight in $(list_backlights); do
+ backlight_save "$backlight"
+ done
+}
+
+load_rc_config $name
+
+# doesn't make sense to run in a svcj: config setting
+backlight_svcj="NO"
+
+run_rc_command "$1"
diff --git a/share/man/man5/rc.conf.5 b/share/man/man5/rc.conf.5
--- a/share/man/man5/rc.conf.5
+++ b/share/man/man5/rc.conf.5
@@ -22,7 +22,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd August 30, 2026
+.Dd September 1, 2026
.Dt RC.CONF 5
.Os
.Sh NAME
@@ -4433,6 +4433,11 @@
autobridge_interfaces="bridge0"
autobridge_bridge0="tap* dc0 vlan[345]"
.Ed
+.It Va backlight_enable
+.Pq Vt bool
+If set to
+.Dq Li YES ,
+enable saving and restoring backlight levels at shutdown and boot time.
.It Va mixer_enable
.Pq Vt bool
If set to
diff --git a/usr.bin/backlight/backlight.8 b/usr.bin/backlight/backlight.8
--- a/usr.bin/backlight/backlight.8
+++ b/usr.bin/backlight/backlight.8
@@ -20,7 +20,7 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd July 19, 2022
+.Dd September 1, 2026
.Dt BACKLIGHT 8
.Os
.Sh NAME
@@ -79,6 +79,15 @@
Decrement the backlight level.
If no value is specified a default of 10 percent is used.
.El
+.Pp
+Brightness levels may not be preserved across a reboot unless
+.Va backlight_enable
+is set to
+.Dq Li YES
+in
+.Xr rc.conf 5 .
+This is disabled by default to avoid intefering with desktop environments that
+do their own backlight management.
.Sh EXAMPLES
Show the current brightness level:
.Bd -literal -offset indent
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Sep 8, 4:40 AM (6 h, 31 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
38205156
Default Alt Text
D59296.diff (4 KB)
Attached To
Mode
D59296: rc: add a backlight service to save/restore backlight levels
Attached
Detach File
Event Timeline
Log In to Comment