commit:     9ea2c61a18715c5255266d67fbcdcf72e3c06c19
Author:     Brian Evans <grknight <AT> gentoo <DOT> org>
AuthorDate: Mon Jan 24 20:35:26 2022 +0000
Commit:     Brian Evans <grknight <AT> gentoo <DOT> org>
CommitDate: Mon Jan 24 20:35:26 2022 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=9ea2c61a

sys-power/acpilight: Add error handling to the OpenRC script

New script will not continue to save state when there is an error

Closes: https://bugs.gentoo.org/831857
Signed-off-by: Brian Evans <grknight <AT> gentoo.org>

 sys-power/acpilight/acpilight-1.2-r4.ebuild | 57 +++++++++++++++++++++++++++++
 sys-power/acpilight/files/acpilight.initd   | 17 +++++++--
 2 files changed, 70 insertions(+), 4 deletions(-)

diff --git a/sys-power/acpilight/acpilight-1.2-r4.ebuild 
b/sys-power/acpilight/acpilight-1.2-r4.ebuild
new file mode 100644
index 000000000000..6b815fddb262
--- /dev/null
+++ b/sys-power/acpilight/acpilight-1.2-r4.ebuild
@@ -0,0 +1,57 @@
+# Copyright 1999-2021 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=7
+
+PYTHON_COMPAT=( python3_7 python3_8 python3_9 )
+
+inherit python-single-r1 udev
+
+MY_P="${PN}-v${PV}"
+
+DESCRIPTION="Replacement for xbacklight that uses the ACPI interface to set 
brightness"
+HOMEPAGE="https://gitlab.com/wavexx/acpilight/";
+SRC_URI="https://gitlab.com/wavexx/acpilight/-/archive/v${PV}/${MY_P}.tar.gz";
+LICENSE="GPL-3+"
+SLOT="0"
+KEYWORDS="~amd64 ~x86"
+IUSE=""
+
+S="${WORKDIR}/${MY_P}"
+
+RDEPEND="virtual/udev
+       acct-group/video
+       !dev-libs/light
+       ${PYTHON_DEPS}
+       !x11-apps/xbacklight"
+REQUIRED_USE="${PYTHON_REQUIRED_USE}"
+DOCS=( README.rst NEWS.rst )
+
+PATCHES=( "${FILESDIR}/acpilight-1.2-fix-log10-of-zero.patch" )
+
+# Disable Makefile that installs by default
+src_compile() { :; }
+
+src_install() {
+       python_doscript xbacklight
+       udev_dorules "${S}"/90-backlight.rules
+       doman xbacklight.1
+       einstalldocs
+       newinitd "${FILESDIR}"/acpilight.initd acpilight
+       newconfd "${FILESDIR}"/acpilight.confd acpilight
+}
+
+pkg_postinst() {
+       udev_reload
+       einfo
+       elog "To use the xbacklight binary as a regular user, you must be a 
part of the video group"
+       einfo
+       elog "If this utility does not find any backlights to manipulate,"
+       elog "verify you have kernel support on the device and display driver 
enabled."
+       einfo
+       elog "To take advantage of the OpenRC init script, and automate the 
process of"
+       elog "saving and restoring the brightness level you should add 
acpilight"
+       elog "to the boot runlevel. You can do this as root like so:"
+       elog "# rc-update add acpilight boot"
+       einfo
+}

diff --git a/sys-power/acpilight/files/acpilight.initd 
b/sys-power/acpilight/files/acpilight.initd
index 0de6029867e0..780828246712 100644
--- a/sys-power/acpilight/files/acpilight.initd
+++ b/sys-power/acpilight/files/acpilight.initd
@@ -1,5 +1,5 @@
 #!/sbin/openrc-run
-# Copyright 1999-2017 Gentoo Foundation
+# Copyright 1999-2022 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 state_dir=/var/lib/acpilight
@@ -19,13 +19,22 @@ restore() {
                return 0
        fi
        xbacklight "$(cat "${state_dir}/state")"
-       eend $?
+       ewend $? "Could not restore brightness. The state file 
${state_dir}/state is invalid or the system cannot apply the value."
 }
 
 save() {
+       local newValue
        ebegin "Saving brightness level"
-       mkdir -p "${state_dir}" && xbacklight -get > "${state_dir}/state"
-       eend $?
+       # Save the value here so an error won't record an empty/invalid value
+       newValue=$(xbacklight -get) && \
+               mkdir -p "${state_dir}" && \
+               echo "${newValue}" > "${state_dir}/state"
+       if [ $? -gt 0 ]; then
+               ewarn "Could not save brightness."
+               ewarn "The state file ${state_dir}/state cannot be written to 
or the system cannot read the brightness value."
+       fi
+       # Don't fail on error
+       eend 0
 }
 
 start() {

Reply via email to