From 8bb9e8e663e5decc4bae299f8ba0177adb3fe256 Mon Sep 17 00:00:00 2001 From: Bradley Marks Date: Wed, 16 Sep 2026 09:10:41 +0200 Subject: [PATCH 1/9] Install the FaceTime HD camera driver on Intel Macs that have one The Broadcom 1570 has no in-tree driver. Detect PCI 14e4:1570 and install facetimehd firmware, calibration data, and the DKMS module so new and existing Omarchy Macs get /dev/video0 after setup or omarchy update. The packaged facetimehd-dkms must be built from patjak/facetimehd after 54fb8f2; AUR 0.7.0.2 still calls strncpy and fails to compile on Linux 7.2. --- bin/omarchy-hw-facetimehd | 6 ++ install/hardware/all.sh | 1 + install/hardware/apple/fix-facetimehd.sh | 10 ++ install/omarchy-other.packages | 5 + manual/44-mac-support.md | 2 +- migrations/1789542390.sh | 7 ++ test/shell.d/facetimehd-test.sh | 117 +++++++++++++++++++++++ 7 files changed, 147 insertions(+), 1 deletion(-) create mode 100755 bin/omarchy-hw-facetimehd create mode 100644 install/hardware/apple/fix-facetimehd.sh create mode 100644 migrations/1789542390.sh create mode 100755 test/shell.d/facetimehd-test.sh diff --git a/bin/omarchy-hw-facetimehd b/bin/omarchy-hw-facetimehd new file mode 100755 index 000000000000..d3051b5ab0a4 --- /dev/null +++ b/bin/omarchy-hw-facetimehd @@ -0,0 +1,6 @@ +#!/bin/bash + +# omarchy:summary=Detect a Broadcom FaceTime HD PCIe webcam (14e4:1570). + +# grep -q would SIGPIPE a chatty lspci under pipefail and look like "no camera". +lspci -nn | grep "14e4:1570" >/dev/null diff --git a/install/hardware/all.sh b/install/hardware/all.sh index 12add110c51f..71230e30ef67 100644 --- a/install/hardware/all.sh +++ b/install/hardware/all.sh @@ -35,6 +35,7 @@ run_logged "$OMARCHY_INSTALL/hardware/apple/fix-spi-keyboard.sh" run_logged "$OMARCHY_INSTALL/hardware/apple/fix-suspend-nvme.sh" run_logged "$OMARCHY_INSTALL/hardware/apple/fix-t2.sh" run_logged "$OMARCHY_INSTALL/hardware/apple/fix-brcmfmac-supplicant.sh" +run_logged "$OMARCHY_INSTALL/hardware/apple/fix-facetimehd.sh" run_logged "$OMARCHY_INSTALL/hardware/lenovo/fix-yoga-pro7-bass-speakers.sh" diff --git a/install/hardware/apple/fix-facetimehd.sh b/install/hardware/apple/fix-facetimehd.sh new file mode 100644 index 000000000000..6a4028c989cb --- /dev/null +++ b/install/hardware/apple/fix-facetimehd.sh @@ -0,0 +1,10 @@ +# Broadcom 720p FaceTime HD (PCI 14e4:1570) on 2013-2015 Intel Macs. There is +# no in-tree driver; facetimehd is the reverse-engineered module. Linux 7.2 +# removed strncpy, so the packaged facetimehd-dkms must be built from +# patjak/facetimehd after 54fb8f2. AUR 0.7.0.2 does not compile on linux-omarchy 7.2. + +if omarchy-hw-facetimehd; then + echo "Detected FaceTime HD camera" + + omarchy-pkg-add facetimehd-firmware facetimehd-data facetimehd-dkms +fi diff --git a/install/omarchy-other.packages b/install/omarchy-other.packages index 4a8b128ff95f..d3cbd27b1b0b 100644 --- a/install/omarchy-other.packages +++ b/install/omarchy-other.packages @@ -71,5 +71,10 @@ linux-t2 linux-t2-headers t2fanrd +# FaceTime HD camera on 2013–2015 Intel Macs +facetimehd-dkms +facetimehd-firmware +facetimehd-data + # Framework 16 qmk-hid diff --git a/manual/44-mac-support.md b/manual/44-mac-support.md index e86fdd064d8f..6b6ecb5d2970 100644 --- a/manual/44-mac-support.md +++ b/manual/44-mac-support.md @@ -35,7 +35,7 @@ It is necessary to disable Apple's Secure Boot in order to boot the bootable USB 3. Select the orange EFI Boot device 4. Proceed with the [install as normal](02-getting-started.md) -The installer detects Mac hardware and applies the needed fixes automatically: Broadcom Wi-Fi drivers and firmware, the SPI keyboard driver on the MacBook models that need it, and an NVMe suspend fix for those same models. +The installer detects Mac hardware and applies the needed fixes automatically: Broadcom Wi-Fi drivers and firmware, the FaceTime HD camera driver on machines with a Broadcom 1570, the SPI keyboard driver on the MacBook models that need it, and an NVMe suspend fix for those same models. ### Known Limitations diff --git a/migrations/1789542390.sh b/migrations/1789542390.sh new file mode 100644 index 000000000000..0c16f7f27bf4 --- /dev/null +++ b/migrations/1789542390.sh @@ -0,0 +1,7 @@ +echo "Install the FaceTime HD camera driver on Intel Macs that have one" + +# Fresh installs get this from install/hardware/apple/fix-facetimehd.sh. Existing +# Macs only pick it up on omarchy update via this migration. +if omarchy-hw-facetimehd; then + source "$OMARCHY_PATH/install/hardware/apple/fix-facetimehd.sh" +fi diff --git a/test/shell.d/facetimehd-test.sh b/test/shell.d/facetimehd-test.sh new file mode 100755 index 000000000000..6557a6a021ff --- /dev/null +++ b/test/shell.d/facetimehd-test.sh @@ -0,0 +1,117 @@ +#!/bin/bash + +set -euo pipefail + +source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" + +leaf="$ROOT/install/hardware/apple/fix-facetimehd.sh" +hw="$ROOT/bin/omarchy-hw-facetimehd" +all="$ROOT/install/hardware/all.sh" +manual="$ROOT/manual/44-mac-support.md" +other_packages="$ROOT/install/omarchy-other.packages" +migration="$ROOT/migrations/1789542390.sh" + +grep -q 'apple/fix-facetimehd.sh' "$all" || + fail "the FaceTime HD fix runs during hardware setup" +grep -q 'omarchy-hw-facetimehd' "$leaf" || + fail "the install leaf keys off the FaceTime HD detector" +grep -q 'facetimehd-dkms' "$leaf" || + fail "the install leaf installs facetimehd-dkms" +grep -qx 'facetimehd-dkms' "$other_packages" || + fail "the ISO caches facetimehd-dkms" +grep -qx 'facetimehd-firmware' "$other_packages" || + fail "the ISO caches facetimehd-firmware" +grep -qx 'facetimehd-data' "$other_packages" || + fail "the ISO caches facetimehd-data" +grep -q '14e4:1570' "$hw" || + fail "the detector matches the Broadcom 1570 PCI ID" +grep -q 'FaceTime HD' "$manual" || + fail "Mac support documents the FaceTime HD camera" +grep -q 'fix-facetimehd.sh' "$migration" || + fail "a migration applies the FaceTime HD fix on existing installs" +pass "the FaceTime HD fix is wired into hardware setup" + +test_tmp=$(mktemp -d) +trap 'rm -rf "$test_tmp"' EXIT + +stub_bin="$test_tmp/bin" +calls="$test_tmp/calls.log" +mkdir -p "$stub_bin" +: >"$calls" + +cat >"$stub_bin/lspci" <<'SH' +#!/bin/bash + +# Chatty like real lspci: keep writing well past the pipe buffer after the +# match, so a grep -q consumer would kill this stub with SIGPIPE and pipefail +# would read that as "no such hardware" (#6608). +if (( ${FACETIMEHD_HARDWARE:-0} == 1 )); then + echo '02:00.0 Multimedia controller [0480]: Broadcom Inc. 720p FaceTime HD Camera [14e4:1570]' +fi +for _ in {1..4096}; do + echo '00:00.0 Host bridge [0600]: Filler Device [ffff:0000]' +done +SH + +cat >"$stub_bin/omarchy-pkg-add" <<'SH' +#!/bin/bash + +printf 'omarchy-pkg-add' >>"$TEST_LOG" +printf '\t%s' "$@" >>"$TEST_LOG" +printf '\n' >>"$TEST_LOG" +SH + +cat >"$stub_bin/sudo" <<'SH' +#!/bin/bash + +printf 'sudo' >>"$TEST_LOG" +printf '\t%s' "$@" >>"$TEST_LOG" +printf '\n' >>"$TEST_LOG" +"$@" +SH + +install -m0755 "$hw" "$stub_bin/omarchy-hw-facetimehd" +chmod +x "$stub_bin"/* + +# Detector: present +FACETIMEHD_HARDWARE=1 PATH="$stub_bin:$PATH" "$stub_bin/omarchy-hw-facetimehd" +pass "detector matches PCI 14e4:1570" + +# Detector: absent +if FACETIMEHD_HARDWARE=0 PATH="$stub_bin:$PATH" "$stub_bin/omarchy-hw-facetimehd"; then + fail "detector ignores machines without a FaceTime HD camera" +fi +pass "detector skips machines without a FaceTime HD camera" + +run_leaf() { + local hardware="$1" + : >"$calls" + FACETIMEHD_HARDWARE="$hardware" PATH="$stub_bin:$PATH" TEST_LOG="$calls" \ + bash -euo pipefail -c 'source "$1"' _ "$leaf" +} + +run_leaf 1 +grep -Fxq $'omarchy-pkg-add\tfacetimehd-firmware\tfacetimehd-data\tfacetimehd-dkms' "$calls" || + fail "leaf installs firmware, calibration data, and the DKMS module" "$(cat "$calls")" +pass "leaf installs firmware, calibration data, and the DKMS module" + +run_leaf 0 +[[ ! -s $calls ]] || fail "non-matching hardware is a no-op" "$(cat "$calls")" +pass "leaf is a no-op on machines without a FaceTime HD camera" + +run_migration() { + local hardware="$1" + : >"$calls" + FACETIMEHD_HARDWARE="$hardware" PATH="$stub_bin:$PATH" TEST_LOG="$calls" \ + OMARCHY_PATH="$ROOT" \ + bash -euo pipefail "$migration" >/dev/null +} + +run_migration 1 +grep -Fxq $'omarchy-pkg-add\tfacetimehd-firmware\tfacetimehd-data\tfacetimehd-dkms' "$calls" || + fail "the migration installs the FaceTime HD packages" "$(cat "$calls")" +pass "the migration installs the FaceTime HD packages" + +run_migration 0 +[[ ! -s $calls ]] || fail "the migration is a no-op without a FaceTime HD camera" "$(cat "$calls")" +pass "the migration is a no-op without a FaceTime HD camera" From a82c4bdf43f2d0ae8ab3782529b9faada286870a Mon Sep 17 00:00:00 2001 From: omarchybot Date: Sat, 21 Nov 2026 19:17:35 +0100 Subject: [PATCH 2/9] Fetch the FaceTime HD firmware from Apple rather than shipping it Apple's license for the camera's firmware and calibration files says they may not be copied or redistributed, so [omarchy] cannot publish facetimehd-firmware or facetimehd-data and the ISO cannot cache them. The leaf now installs facetimehd-dkms, which is GPL, and facetimehd-firmware-fetcher, which downloads the files from Apple on the Mac itself and checks each against a pinned hash. Its service retries at boot, so an install with no network gets the camera on the first boot that has one. Each part is asked for only when pacman -T says nothing installed provides it, under its current name or the older bcwc-pcie ones. omarchy-pkg-add hands every name to pacman -S once any one is missing, so a Mac running an AUR driver would otherwise be asked to install facetimehd-dkms beside it, which conflicts, and fail the migration on every update. The migration asks for a reboot when it installed something, since the module only loads at boot, starts the fetch rather than leaving it for that boot, and takes a current timestamp. Its checks leave the test, which covers the leaf the migration sources, since a migration runs once and its test stops guarding anything. Co-Authored-By: Claude Opus 5.5 Co-Authored-By: Opus 5.5 High --- install/hardware/apple/fix-facetimehd.sh | 19 ++++-- install/omarchy-other.packages | 5 +- manual/44-mac-support.md | 6 +- migrations/1789542390.sh | 7 -- migrations/1795284903.sh | 15 +++++ test/shell.d/facetimehd-test.sh | 86 +++++++++++++++--------- 6 files changed, 92 insertions(+), 46 deletions(-) delete mode 100644 migrations/1789542390.sh create mode 100644 migrations/1795284903.sh diff --git a/install/hardware/apple/fix-facetimehd.sh b/install/hardware/apple/fix-facetimehd.sh index 6a4028c989cb..50f171286949 100644 --- a/install/hardware/apple/fix-facetimehd.sh +++ b/install/hardware/apple/fix-facetimehd.sh @@ -1,10 +1,19 @@ -# Broadcom 720p FaceTime HD (PCI 14e4:1570) on 2013-2015 Intel Macs. There is -# no in-tree driver; facetimehd is the reverse-engineered module. Linux 7.2 -# removed strncpy, so the packaged facetimehd-dkms must be built from -# patjak/facetimehd after 54fb8f2. AUR 0.7.0.2 does not compile on linux-omarchy 7.2. +# Broadcom 720p FaceTime HD (PCI 14e4:1570) on Intel Macs. There is no in-tree driver, and Apple's license forbids +# redistributing the camera's firmware, so facetimehd-firmware-fetcher downloads it from Apple on the Mac itself. if omarchy-hw-facetimehd; then echo "Detected FaceTime HD camera" - omarchy-pkg-add facetimehd-firmware facetimehd-data facetimehd-dkms + # pacman -T resolves provides, so a Mac already running an AUR driver or firmware keeps it rather than conflicting. + packages=() + pacman -T facetimehd-dkms >/dev/null || pacman -T bcwc-pcie >/dev/null || + pacman -T bcwc-pcie-dkms >/dev/null || packages+=(facetimehd-dkms) + pacman -T facetimehd-firmware >/dev/null || pacman -T facetimehd-data >/dev/null || + pacman -T bcwc-pcie-firmware >/dev/null || packages+=(facetimehd-firmware-fetcher) + (( ${#packages[@]} == 0 )) || omarchy-pkg-add "${packages[@]}" + + # An install with no network fetches on the first boot that has one. + if pacman -Q facetimehd-firmware-fetcher &>/dev/null; then + sudo systemctl enable facetimehd-firmware-fetcher.service + fi fi diff --git a/install/omarchy-other.packages b/install/omarchy-other.packages index d3cbd27b1b0b..fea1e7e044a4 100644 --- a/install/omarchy-other.packages +++ b/install/omarchy-other.packages @@ -71,10 +71,9 @@ linux-t2 linux-t2-headers t2fanrd -# FaceTime HD camera on 2013–2015 Intel Macs +# FaceTime HD camera on Intel Macs facetimehd-dkms -facetimehd-firmware -facetimehd-data +facetimehd-firmware-fetcher # Framework 16 qmk-hid diff --git a/manual/44-mac-support.md b/manual/44-mac-support.md index 6b6ecb5d2970..7bb12e1b7f9d 100644 --- a/manual/44-mac-support.md +++ b/manual/44-mac-support.md @@ -35,12 +35,16 @@ It is necessary to disable Apple's Secure Boot in order to boot the bootable USB 3. Select the orange EFI Boot device 4. Proceed with the [install as normal](02-getting-started.md) -The installer detects Mac hardware and applies the needed fixes automatically: Broadcom Wi-Fi drivers and firmware, the FaceTime HD camera driver on machines with a Broadcom 1570, the SPI keyboard driver on the MacBook models that need it, and an NVMe suspend fix for those same models. +The installer detects Mac hardware and applies the needed fixes automatically: Broadcom Wi-Fi drivers and firmware, the FaceTime HD camera driver on machines with a Broadcom 1570 (its firmware is downloaded from Apple during the install, or on the first boot that has a network), the SPI keyboard driver on the MacBook models that need it, and an NVMe suspend fix for those same models. ### Known Limitations Members of the community are constantly working on solutions to these challenges so if these are problematic for you, join #omarchy-on-other in our [Discord](https://discord.gg/tXFUdasqhY) and see if there's any up-to-date methods for resolving these. +#### FaceTime HD Camera + +Close any app using the camera before hibernating. The camera driver is unloaded for hibernation because it hangs the machine otherwise, and it cannot be unloaded while the camera is in use. + #### Devices with T1 Chip The Apple T1 chip was introduced in late 2016 and used exclusively in the first-generation MacBook Pro models with Touch Bar. diff --git a/migrations/1789542390.sh b/migrations/1789542390.sh deleted file mode 100644 index 0c16f7f27bf4..000000000000 --- a/migrations/1789542390.sh +++ /dev/null @@ -1,7 +0,0 @@ -echo "Install the FaceTime HD camera driver on Intel Macs that have one" - -# Fresh installs get this from install/hardware/apple/fix-facetimehd.sh. Existing -# Macs only pick it up on omarchy update via this migration. -if omarchy-hw-facetimehd; then - source "$OMARCHY_PATH/install/hardware/apple/fix-facetimehd.sh" -fi diff --git a/migrations/1795284903.sh b/migrations/1795284903.sh new file mode 100644 index 000000000000..cf4f595b15ca --- /dev/null +++ b/migrations/1795284903.sh @@ -0,0 +1,15 @@ +echo "Install the FaceTime HD camera driver on Intel Macs that have one" + +# Fresh installs get this from install/hardware/apple/fix-facetimehd.sh. Existing +# Macs only pick it up on omarchy update via this migration. +if omarchy-hw-facetimehd; then + source "$OMARCHY_PATH/install/hardware/apple/fix-facetimehd.sh" + + # The module only loads at boot, so the camera stays missing until then. + (( ${#packages[@]} == 0 )) || omarchy-state set reboot-required + + # The leaf only enables the fetch for the next boot; on a running system it can start now. + if pacman -Q facetimehd-firmware-fetcher &>/dev/null; then + sudo systemctl start --no-block facetimehd-firmware-fetcher.service + fi +fi diff --git a/test/shell.d/facetimehd-test.sh b/test/shell.d/facetimehd-test.sh index 6557a6a021ff..c1db674e788b 100755 --- a/test/shell.d/facetimehd-test.sh +++ b/test/shell.d/facetimehd-test.sh @@ -9,7 +9,6 @@ hw="$ROOT/bin/omarchy-hw-facetimehd" all="$ROOT/install/hardware/all.sh" manual="$ROOT/manual/44-mac-support.md" other_packages="$ROOT/install/omarchy-other.packages" -migration="$ROOT/migrations/1789542390.sh" grep -q 'apple/fix-facetimehd.sh' "$all" || fail "the FaceTime HD fix runs during hardware setup" @@ -19,16 +18,14 @@ grep -q 'facetimehd-dkms' "$leaf" || fail "the install leaf installs facetimehd-dkms" grep -qx 'facetimehd-dkms' "$other_packages" || fail "the ISO caches facetimehd-dkms" -grep -qx 'facetimehd-firmware' "$other_packages" || - fail "the ISO caches facetimehd-firmware" -grep -qx 'facetimehd-data' "$other_packages" || - fail "the ISO caches facetimehd-data" +grep -qx 'facetimehd-firmware-fetcher' "$other_packages" || + fail "the ISO caches facetimehd-firmware-fetcher" +! grep -qxE 'facetimehd-(firmware|data)' "$other_packages" || + fail "the ISO carries no Apple firmware, which may not be redistributed" grep -q '14e4:1570' "$hw" || fail "the detector matches the Broadcom 1570 PCI ID" grep -q 'FaceTime HD' "$manual" || fail "Mac support documents the FaceTime HD camera" -grep -q 'fix-facetimehd.sh' "$migration" || - fail "a migration applies the FaceTime HD fix on existing installs" pass "the FaceTime HD fix is wired into hardware setup" test_tmp=$(mktemp -d) @@ -59,6 +56,30 @@ cat >"$stub_bin/omarchy-pkg-add" <<'SH' printf 'omarchy-pkg-add' >>"$TEST_LOG" printf '\t%s' "$@" >>"$TEST_LOG" printf '\n' >>"$TEST_LOG" +printf '%s\n' "$@" >>"$TEST_INSTALLED" +SH + +# -T answers for what is installed or named in FACETIMEHD_PROVIDED, as an AUR package providing it would be. +cat >"$stub_bin/pacman" <<'SH' +#!/bin/bash + +satisfied() { + grep -qxF -- "$1" "$TEST_INSTALLED" || [[ " ${FACETIMEHD_PROVIDED:-} " == *" $1 "* ]] +} + +case "$1" in + -T) for dep in "${@:2}"; do satisfied "$dep" || { echo "$dep"; exit 127; }; done ;; + -Q) grep -qxF -- "$2" "$TEST_INSTALLED" ;; + *) exit 2 ;; +esac +SH + +cat >"$stub_bin/systemctl" <<'SH' +#!/bin/bash + +printf 'systemctl' >>"$TEST_LOG" +printf '\t%s' "$@" >>"$TEST_LOG" +printf '\n' >>"$TEST_LOG" SH cat >"$stub_bin/sudo" <<'SH' @@ -83,35 +104,40 @@ if FACETIMEHD_HARDWARE=0 PATH="$stub_bin:$PATH" "$stub_bin/omarchy-hw-facetimehd fi pass "detector skips machines without a FaceTime HD camera" +installed="$test_tmp/installed" + run_leaf() { - local hardware="$1" + local hardware="$1" provided="${2:-}" : >"$calls" - FACETIMEHD_HARDWARE="$hardware" PATH="$stub_bin:$PATH" TEST_LOG="$calls" \ - bash -euo pipefail -c 'source "$1"' _ "$leaf" + : >"$installed" + FACETIMEHD_HARDWARE="$hardware" FACETIMEHD_PROVIDED="$provided" PATH="$stub_bin:$PATH" TEST_LOG="$calls" \ + TEST_INSTALLED="$installed" bash -euo pipefail -c 'source "$1"' _ "$leaf" } +fetcher_enabled=$'systemctl\tenable\tfacetimehd-firmware-fetcher.service' + run_leaf 1 -grep -Fxq $'omarchy-pkg-add\tfacetimehd-firmware\tfacetimehd-data\tfacetimehd-dkms' "$calls" || - fail "leaf installs firmware, calibration data, and the DKMS module" "$(cat "$calls")" -pass "leaf installs firmware, calibration data, and the DKMS module" +grep -Fxq $'omarchy-pkg-add\tfacetimehd-dkms\tfacetimehd-firmware-fetcher' "$calls" || + fail "leaf installs the DKMS module and the firmware fetcher" "$(cat "$calls")" +grep -Fxq "$fetcher_enabled" "$calls" || + fail "leaf enables the fetch for a first boot with a network" "$(cat "$calls")" +pass "leaf installs the DKMS module and the firmware fetcher, and enables the fetch" + +run_leaf 1 facetimehd-dkms +grep -Fxq $'omarchy-pkg-add\tfacetimehd-firmware-fetcher' "$calls" || + fail "leaf keeps a driver the AUR already provides" "$(cat "$calls")" +pass "leaf keeps a driver the AUR already provides" + +run_leaf 1 bcwc-pcie +grep -Fxq $'omarchy-pkg-add\tfacetimehd-firmware-fetcher' "$calls" || + fail "leaf keeps the legacy bcwc-pcie driver" "$(cat "$calls")" +pass "leaf keeps the legacy bcwc-pcie driver" + +run_leaf 1 "facetimehd-dkms facetimehd-data" +! grep -q -e omarchy-pkg-add -e systemctl "$calls" || + fail "leaf installs nothing where the driver and firmware are already provided" "$(cat "$calls")" +pass "leaf installs nothing where the driver and firmware are already provided" run_leaf 0 [[ ! -s $calls ]] || fail "non-matching hardware is a no-op" "$(cat "$calls")" pass "leaf is a no-op on machines without a FaceTime HD camera" - -run_migration() { - local hardware="$1" - : >"$calls" - FACETIMEHD_HARDWARE="$hardware" PATH="$stub_bin:$PATH" TEST_LOG="$calls" \ - OMARCHY_PATH="$ROOT" \ - bash -euo pipefail "$migration" >/dev/null -} - -run_migration 1 -grep -Fxq $'omarchy-pkg-add\tfacetimehd-firmware\tfacetimehd-data\tfacetimehd-dkms' "$calls" || - fail "the migration installs the FaceTime HD packages" "$(cat "$calls")" -pass "the migration installs the FaceTime HD packages" - -run_migration 0 -[[ ! -s $calls ]] || fail "the migration is a no-op without a FaceTime HD camera" "$(cat "$calls")" -pass "the migration is a no-op without a FaceTime HD camera" From b72e735dd534b022766a596679071321eb7373cc Mon Sep 17 00:00:00 2001 From: omarchybot Date: Sat, 21 Nov 2026 22:30:14 +0100 Subject: [PATCH 3/9] Say the camera firmware arrives once the Mac is online The installer works offline, so the firmware is never fetched during the install: facetimehd-firmware-fetcher.service downloads it once the Mac has a network. Co-Authored-By: Claude Opus 5.5 --- manual/44-mac-support.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manual/44-mac-support.md b/manual/44-mac-support.md index 7bb12e1b7f9d..b29e7357f3aa 100644 --- a/manual/44-mac-support.md +++ b/manual/44-mac-support.md @@ -35,7 +35,7 @@ It is necessary to disable Apple's Secure Boot in order to boot the bootable USB 3. Select the orange EFI Boot device 4. Proceed with the [install as normal](02-getting-started.md) -The installer detects Mac hardware and applies the needed fixes automatically: Broadcom Wi-Fi drivers and firmware, the FaceTime HD camera driver on machines with a Broadcom 1570 (its firmware is downloaded from Apple during the install, or on the first boot that has a network), the SPI keyboard driver on the MacBook models that need it, and an NVMe suspend fix for those same models. +The installer detects Mac hardware and applies the needed fixes automatically: Broadcom Wi-Fi drivers and firmware, the FaceTime HD camera driver on machines with a Broadcom 1570 (its firmware is downloaded from Apple once the Mac is online, since the installer works offline), the SPI keyboard driver on the MacBook models that need it, and an NVMe suspend fix for those same models. ### Known Limitations From 442865e93c92ea2bff2d20c5b9c5c4a46b83d892 Mon Sep 17 00:00:00 2001 From: omarchybot Date: Sat, 21 Nov 2026 22:50:10 +0100 Subject: [PATCH 4/9] Refuse hibernation while the FaceTime HD camera is in use facetimehd deadlocks the kernel's hibernation freeze. Unloading it from a system-sleep hook cannot help when an app has the camera open, because the unload is refused and systemd ignores a failing sleep hook, so hibernation went ahead and hung. omarchy-system-sleep-facetimehd now runs before and after the hibernating sleep units, from drop-ins the leaf installs: it unloads the driver, or fails the unit, which cancels the sleep, and notifies the person at the seat which app to close. After the sleep it loads the driver again if it unloaded it. The leaf installs the guard on every Mac with the camera, including one that keeps an AUR driver, and asks for the fetcher whenever nothing provides the firmware itself: calibration from the AUR facetimehd-data is left alone by the fetcher rather than standing in for firmware.bin. The manual says how hibernation behaves and how to retry the fetch. Co-Authored-By: Claude Opus 5.5 Co-Authored-By: Codex XHigh --- bin/omarchy-system-sleep-facetimehd | 60 +++++++++++ .../system/omarchy-facetimehd-hibernate.conf | 5 + install/hardware/apple/fix-facetimehd.sh | 11 ++- manual/44-mac-support.md | 4 +- test/shell.d/facetimehd-test.sh | 99 +++++++++++++++++-- 5 files changed, 169 insertions(+), 10 deletions(-) create mode 100755 bin/omarchy-system-sleep-facetimehd create mode 100644 default/systemd/system/omarchy-facetimehd-hibernate.conf diff --git a/bin/omarchy-system-sleep-facetimehd b/bin/omarchy-system-sleep-facetimehd new file mode 100755 index 000000000000..2ddb4401f099 --- /dev/null +++ b/bin/omarchy-system-sleep-facetimehd @@ -0,0 +1,60 @@ +#!/bin/bash + +# omarchy:summary=Unload the FaceTime HD camera driver for hibernation, refusing to hibernate while the camera is in use +# omarchy:args= +# omarchy:group=system +# omarchy:hidden=true + +# facetimehd deadlocks the kernel's hibernation freeze, so the hibernating sleep units run this before they start and +# after they stop. The driver cannot be unloaded while an app has the camera open, and failing here is what cancels the +# sleep: systemd ignores a failing system-sleep hook. + +set -uo pipefail + +module=${OMARCHY_FACETIMEHD_MODULE:-/sys/module/facetimehd} +marker=${OMARCHY_FACETIMEHD_MARKER:-/run/omarchy-facetimehd-unloaded} +proc=${OMARCHY_FACETIMEHD_PROC:-/proc} + +camera_users() { + local fd pid + for fd in "$proc"/[0-9]*/fd/*; do + [[ $(readlink "$fd" 2>/dev/null) == /dev/video* ]] || continue + pid=${fd#"$proc"/} + cat "$proc/${pid%%/*}/comm" 2>/dev/null + done | sort -u | paste -sd, - | sed 's/,/, /g' +} + +# The menu's systemctl hibernate shows nothing when the sleep fails, so each person at a seat is told why. +notify_seats() { + local uid user + while read -r uid user; do + runuser -u "$user" -- env XDG_RUNTIME_DIR="/run/user/$uid" DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$uid/bus" \ + omarchy-notification-send -u critical "$1" "$2" >/dev/null 2>&1 || true + done < <(loginctl list-sessions --no-legend 2>/dev/null | awk '$4 ~ /^seat/ { print $2, $3 }' | sort -u) +} + +case ${1:-} in + pre) + rm -f "$marker" + [[ -d $module ]] || exit 0 + if modprobe -r facetimehd; then + touch "$marker" + else + users=$(camera_users) + echo "Not hibernating: the FaceTime HD camera is in use${users:+ by $users}, and its driver hangs hibernation" >&2 + notify_seats "Hibernation cancelled" "Close ${users:-the app using the camera}, then try again. The camera's driver hangs hibernation while it is in use." + exit 1 + fi + ;; + post) + # Only what pre unloaded comes back, so a driver unloaded on purpose stays unloaded. + if [[ -e $marker ]]; then + rm -f "$marker" + modprobe facetimehd || echo "Could not load the FaceTime HD camera driver again; it loads at the next boot" >&2 + fi + ;; + *) + echo "Usage: omarchy-system-sleep-facetimehd " >&2 + exit 1 + ;; +esac diff --git a/default/systemd/system/omarchy-facetimehd-hibernate.conf b/default/systemd/system/omarchy-facetimehd-hibernate.conf new file mode 100644 index 000000000000..c2b20136a5c2 --- /dev/null +++ b/default/systemd/system/omarchy-facetimehd-hibernate.conf @@ -0,0 +1,5 @@ +# Installed for systemd-hibernate, systemd-hybrid-sleep and systemd-suspend-then-hibernate on Macs with the FaceTime HD +# camera: its driver hangs the hibernation freeze, so it is unloaded first, and the sleep fails while it is in use. +[Service] +ExecStartPre=/usr/bin/omarchy-system-sleep-facetimehd pre +ExecStopPost=/usr/bin/omarchy-system-sleep-facetimehd post diff --git a/install/hardware/apple/fix-facetimehd.sh b/install/hardware/apple/fix-facetimehd.sh index 50f171286949..8132c76ab3c0 100644 --- a/install/hardware/apple/fix-facetimehd.sh +++ b/install/hardware/apple/fix-facetimehd.sh @@ -8,12 +8,19 @@ if omarchy-hw-facetimehd; then packages=() pacman -T facetimehd-dkms >/dev/null || pacman -T bcwc-pcie >/dev/null || pacman -T bcwc-pcie-dkms >/dev/null || packages+=(facetimehd-dkms) - pacman -T facetimehd-firmware >/dev/null || pacman -T facetimehd-data >/dev/null || - pacman -T bcwc-pcie-firmware >/dev/null || packages+=(facetimehd-firmware-fetcher) + pacman -T facetimehd-firmware >/dev/null || pacman -T bcwc-pcie-firmware >/dev/null || + packages+=(facetimehd-firmware-fetcher) (( ${#packages[@]} == 0 )) || omarchy-pkg-add "${packages[@]}" # An install with no network fetches on the first boot that has one. if pacman -Q facetimehd-firmware-fetcher &>/dev/null; then sudo systemctl enable facetimehd-firmware-fetcher.service fi + + # Whichever package provides the driver, it hangs hibernation, so every hibernating sleep is guarded. + for unit in systemd-hibernate systemd-hybrid-sleep systemd-suspend-then-hibernate; do + sudo install -Dm644 "$OMARCHY_PATH/default/systemd/system/omarchy-facetimehd-hibernate.conf" \ + "/etc/systemd/system/$unit.service.d/omarchy-facetimehd.conf" + done + sudo systemctl daemon-reload fi diff --git a/manual/44-mac-support.md b/manual/44-mac-support.md index b29e7357f3aa..3bbe86a0ff27 100644 --- a/manual/44-mac-support.md +++ b/manual/44-mac-support.md @@ -43,7 +43,9 @@ Members of the community are constantly working on solutions to these challenges #### FaceTime HD Camera -Close any app using the camera before hibernating. The camera driver is unloaded for hibernation because it hangs the machine otherwise, and it cannot be unloaded while the camera is in use. +The camera driver hangs the machine if it is loaded when the Mac hibernates, so it is unloaded first. It cannot be unloaded while an app has the camera open, so hibernation is cancelled with a notification naming the app: close it and hibernate again. + +The camera's firmware is downloaded from Apple, so the camera starts working within about 15 minutes of the Mac first being online. If it does not appear, `journalctl -u facetimehd-firmware-fetcher` says why, and `sudo systemctl restart facetimehd-firmware-fetcher` tries again. #### Devices with T1 Chip diff --git a/test/shell.d/facetimehd-test.sh b/test/shell.d/facetimehd-test.sh index c1db674e788b..840053dfaafa 100755 --- a/test/shell.d/facetimehd-test.sh +++ b/test/shell.d/facetimehd-test.sh @@ -9,6 +9,8 @@ hw="$ROOT/bin/omarchy-hw-facetimehd" all="$ROOT/install/hardware/all.sh" manual="$ROOT/manual/44-mac-support.md" other_packages="$ROOT/install/omarchy-other.packages" +guard="$ROOT/bin/omarchy-system-sleep-facetimehd" +dropin="$ROOT/default/systemd/system/omarchy-facetimehd-hibernate.conf" grep -q 'apple/fix-facetimehd.sh' "$all" || fail "the FaceTime HD fix runs during hardware setup" @@ -26,6 +28,9 @@ grep -q '14e4:1570' "$hw" || fail "the detector matches the Broadcom 1570 PCI ID" grep -q 'FaceTime HD' "$manual" || fail "Mac support documents the FaceTime HD camera" +{ grep -Fxq 'ExecStartPre=/usr/bin/omarchy-system-sleep-facetimehd pre' "$dropin" && + grep -Fxq 'ExecStopPost=/usr/bin/omarchy-system-sleep-facetimehd post' "$dropin"; } || + fail "the hibernation drop-in runs the guard before the sleep and after it" pass "the FaceTime HD fix is wired into hardware setup" test_tmp=$(mktemp -d) @@ -82,13 +87,13 @@ printf '\t%s' "$@" >>"$TEST_LOG" printf '\n' >>"$TEST_LOG" SH +# Records the privileged call without making it, so nothing reaches this machine's /etc or systemd. cat >"$stub_bin/sudo" <<'SH' #!/bin/bash printf 'sudo' >>"$TEST_LOG" printf '\t%s' "$@" >>"$TEST_LOG" printf '\n' >>"$TEST_LOG" -"$@" SH install -m0755 "$hw" "$stub_bin/omarchy-hw-facetimehd" @@ -111,17 +116,27 @@ run_leaf() { : >"$calls" : >"$installed" FACETIMEHD_HARDWARE="$hardware" FACETIMEHD_PROVIDED="$provided" PATH="$stub_bin:$PATH" TEST_LOG="$calls" \ - TEST_INSTALLED="$installed" bash -euo pipefail -c 'source "$1"' _ "$leaf" + TEST_INSTALLED="$installed" OMARCHY_PATH="$ROOT" bash -euo pipefail -c 'source "$1"' _ "$leaf" } -fetcher_enabled=$'systemctl\tenable\tfacetimehd-firmware-fetcher.service' +fetcher_enabled=$'sudo\tsystemctl\tenable\tfacetimehd-firmware-fetcher.service' + +guarded() { + local unit + for unit in systemd-hibernate systemd-hybrid-sleep systemd-suspend-then-hibernate; do + grep -Fxq "sudo"$'\t'"install"$'\t'"-Dm644"$'\t'"$dropin"$'\t'"/etc/systemd/system/$unit.service.d/omarchy-facetimehd.conf" "$calls" || + return 1 + done + grep -Fxq $'sudo\tsystemctl\tdaemon-reload' "$calls" +} run_leaf 1 grep -Fxq $'omarchy-pkg-add\tfacetimehd-dkms\tfacetimehd-firmware-fetcher' "$calls" || fail "leaf installs the DKMS module and the firmware fetcher" "$(cat "$calls")" grep -Fxq "$fetcher_enabled" "$calls" || fail "leaf enables the fetch for a first boot with a network" "$(cat "$calls")" -pass "leaf installs the DKMS module and the firmware fetcher, and enables the fetch" +guarded || fail "leaf guards every hibernating sleep" "$(cat "$calls")" +pass "leaf installs the DKMS module and the firmware fetcher, enables the fetch, and guards hibernation" run_leaf 1 facetimehd-dkms grep -Fxq $'omarchy-pkg-add\tfacetimehd-firmware-fetcher' "$calls" || @@ -133,11 +148,81 @@ grep -Fxq $'omarchy-pkg-add\tfacetimehd-firmware-fetcher' "$calls" || fail "leaf keeps the legacy bcwc-pcie driver" "$(cat "$calls")" pass "leaf keeps the legacy bcwc-pcie driver" -run_leaf 1 "facetimehd-dkms facetimehd-data" -! grep -q -e omarchy-pkg-add -e systemctl "$calls" || +run_leaf 1 facetimehd-data +grep -Fxq $'omarchy-pkg-add\tfacetimehd-dkms\tfacetimehd-firmware-fetcher' "$calls" || + fail "calibration from the AUR does not stand in for the firmware" "$(cat "$calls")" +pass "calibration from the AUR does not stand in for the firmware" + +run_leaf 1 "facetimehd-dkms facetimehd-firmware" +! grep -q -e omarchy-pkg-add -e "$fetcher_enabled" "$calls" || fail "leaf installs nothing where the driver and firmware are already provided" "$(cat "$calls")" -pass "leaf installs nothing where the driver and firmware are already provided" +guarded || fail "a Mac keeping its AUR driver still has hibernation guarded" "$(cat "$calls")" +pass "leaf installs nothing where the driver and firmware are already provided, and still guards hibernation" run_leaf 0 [[ ! -s $calls ]] || fail "non-matching hardware is a no-op" "$(cat "$calls")" pass "leaf is a no-op on machines without a FaceTime HD camera" + +# The guard, run as the hibernating sleep units run it, against a stand-in module, /proc and logind. +guard_root="$test_tmp/guard" +mkdir -p "$guard_root/proc/4242/fd" "$guard_root/module" +echo chromium >"$guard_root/proc/4242/comm" +ln -s /dev/video0 "$guard_root/proc/4242/fd/7" + +cat >"$stub_bin/modprobe" <<'SH' +#!/bin/bash + +printf 'modprobe' >>"$TEST_LOG" +printf '\t%s' "$@" >>"$TEST_LOG" +printf '\n' >>"$TEST_LOG" +[[ $1 != -r || -z ${MODULE_BUSY:-} ]] +SH + +cat >"$stub_bin/loginctl" <<'SH' +#!/bin/bash + +echo '2 1000 mac seat0 1234 user tty1 no -' +echo '5 1000 mac - 9876 manager - no -' +SH + +cat >"$stub_bin/runuser" <<'SH' +#!/bin/bash + +printf 'runuser' >>"$TEST_LOG" +printf '\t%s' "$@" >>"$TEST_LOG" +printf '\n' >>"$TEST_LOG" +SH +chmod +x "$stub_bin"/* + +run_guard() { + : >"$calls" + PATH="$stub_bin:$PATH" TEST_LOG="$calls" OMARCHY_FACETIMEHD_MODULE="$guard_root/$1" \ + OMARCHY_FACETIMEHD_MARKER="$guard_root/unloaded" OMARCHY_FACETIMEHD_PROC="$guard_root/proc" \ + MODULE_BUSY="${3:-}" "$guard" "$2" 2>"$test_tmp/guard.err" +} + +run_guard absent pre || fail "the guard lets a Mac without the driver loaded hibernate" +[[ ! -e $guard_root/unloaded && ! -s $calls ]] || fail "the guard leaves an unloaded driver alone" "$(cat "$calls")" +pass "the guard lets a Mac without the driver loaded hibernate" + +run_guard module pre || fail "the guard unloads an idle driver before hibernating" "$(cat "$test_tmp/guard.err")" +{ grep -Fxq $'modprobe\t-r\tfacetimehd' "$calls" && [[ -e $guard_root/unloaded ]]; } || + fail "the guard unloads an idle driver before hibernating" "$(cat "$calls")" +run_guard module post +{ grep -Fxq $'modprobe\tfacetimehd' "$calls" && [[ ! -e $guard_root/unloaded ]]; } || + fail "the guard loads the driver again after resuming" "$(cat "$calls")" +pass "the guard unloads an idle driver for hibernation and loads it again after" + +run_guard module post +[[ ! -s $calls ]] || fail "the guard does not load a driver it did not unload" "$(cat "$calls")" +pass "the guard does not load a driver it did not unload" + +if run_guard module pre busy; then + fail "the guard cancels hibernation while the camera is in use" +fi +grep -q 'chromium' "$test_tmp/guard.err" || fail "the refusal names the app using the camera" "$(cat "$test_tmp/guard.err")" +grep -q $'^runuser\t-u\tmac\t.*omarchy-notification-send\t-u\tcritical\tHibernation cancelled\tClose chromium' "$calls" || + fail "the refusal notifies the person at the seat" "$(cat "$calls")" +[[ $(grep -c '^runuser' "$calls") == 1 && ! -e $guard_root/unloaded ]] || + fail "only the seat session is notified, and nothing is marked unloaded" "$(cat "$calls")" +pass "the guard cancels hibernation while the camera is in use, and says which app to close" From 38fcf9646b5ce694267f6ea6bcad3229c99aff25 Mon Sep 17 00:00:00 2001 From: omarchybot Date: Sat, 21 Nov 2026 23:03:08 +0100 Subject: [PATCH 5/9] Share the driver lock with the fetcher and start the fetch on an image's first boot facetimehd-firmware-fetcher loads the camera driver once it has the firmware. The hibernation guard now unloads and reloads it under the same /run/lock/facetimehd.lock, and leaves its marker at the path the fetcher reads, so a fetch finishing mid-sleep cannot put the driver back before hibernating. An image's first boot runs the leaf after boot has queued its units, so enabling the fetch left it for the next boot; there it starts now, as the Bluetooth leaf starts its service. The manual says hibernation on a critical battery and suspend-then-hibernate are refused too, and describes the fetch's retries rather than promising a time. Co-Authored-By: Claude Opus 5.5 Co-Authored-By: Codex XHigh --- bin/omarchy-system-sleep-facetimehd | 16 +++++++++++++++- install/hardware/apple/fix-facetimehd.sh | 5 +++++ manual/44-mac-support.md | 4 ++-- test/shell.d/facetimehd-test.sh | 8 ++++++++ 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/bin/omarchy-system-sleep-facetimehd b/bin/omarchy-system-sleep-facetimehd index 2ddb4401f099..42ac70901313 100755 --- a/bin/omarchy-system-sleep-facetimehd +++ b/bin/omarchy-system-sleep-facetimehd @@ -12,7 +12,10 @@ set -uo pipefail module=${OMARCHY_FACETIMEHD_MODULE:-/sys/module/facetimehd} -marker=${OMARCHY_FACETIMEHD_MARKER:-/run/omarchy-facetimehd-unloaded} +# Shared with facetimehd-firmware-fetcher, which loads the driver once it has the firmware: under this lock it never +# loads it while the marker says a hibernating sleep has it unloaded. +lock=${OMARCHY_FACETIMEHD_LOCK:-/run/lock/facetimehd.lock} +marker=${OMARCHY_FACETIMEHD_MARKER:-/run/facetimehd-unloaded-for-sleep} proc=${OMARCHY_FACETIMEHD_PROC:-/proc} camera_users() { @@ -33,6 +36,17 @@ notify_seats() { done < <(loginctl list-sessions --no-legend 2>/dev/null | awk '$4 ~ /^seat/ { print $2, $3 }' | sort -u) } +case ${1:-} in + pre | post) + exec 8>>"$lock" + if ! flock -w 60 8; then + # A fetch is loading the driver; hibernating now could catch it loaded, while waking must still load it again. + [[ $1 == post ]] || { echo "Not hibernating: the camera driver is being loaded" >&2; exit 1; } + echo "Loading the camera driver without waiting for the firmware fetch" >&2 + fi + ;; +esac + case ${1:-} in pre) rm -f "$marker" diff --git a/install/hardware/apple/fix-facetimehd.sh b/install/hardware/apple/fix-facetimehd.sh index 8132c76ab3c0..12677fb237da 100644 --- a/install/hardware/apple/fix-facetimehd.sh +++ b/install/hardware/apple/fix-facetimehd.sh @@ -15,6 +15,11 @@ if omarchy-hw-facetimehd; then # An install with no network fetches on the first boot that has one. if pacman -Q facetimehd-firmware-fetcher &>/dev/null; then sudo systemctl enable facetimehd-firmware-fetcher.service + + # An image's first boot runs this after boot queued its units, so the fetch starts now rather than at the next boot. + if [[ ${OMARCHY_IMAGE_DEFERRED_HARDWARE:-} == "1" ]]; then + sudo systemctl start --no-block facetimehd-firmware-fetcher.service || true + fi fi # Whichever package provides the driver, it hangs hibernation, so every hibernating sleep is guarded. diff --git a/manual/44-mac-support.md b/manual/44-mac-support.md index 3bbe86a0ff27..e30fbe704af9 100644 --- a/manual/44-mac-support.md +++ b/manual/44-mac-support.md @@ -43,9 +43,9 @@ Members of the community are constantly working on solutions to these challenges #### FaceTime HD Camera -The camera driver hangs the machine if it is loaded when the Mac hibernates, so it is unloaded first. It cannot be unloaded while an app has the camera open, so hibernation is cancelled with a notification naming the app: close it and hibernate again. +The camera driver hangs the machine if it is loaded when the Mac hibernates, so it is unloaded first. It cannot be unloaded while an app has the camera open, so hibernation is cancelled with a notification naming the app: close it and hibernate again. That includes hibernating automatically on a critical battery, and suspend-then-hibernate, which is refused before it suspends. -The camera's firmware is downloaded from Apple, so the camera starts working within about 15 minutes of the Mac first being online. If it does not appear, `journalctl -u facetimehd-firmware-fetcher` says why, and `sudo systemctl restart facetimehd-firmware-fetcher` tries again. +The camera's firmware is downloaded from Apple, so the camera works only once the Mac has been online. The download starts at boot and is retried every 15 minutes until it succeeds. If the camera does not appear, `journalctl -u facetimehd-firmware-fetcher` says why, `sudo systemctl restart facetimehd-firmware-fetcher` tries again, and a reboot loads the driver if the download finished but the camera still is not there. #### Devices with T1 Chip diff --git a/test/shell.d/facetimehd-test.sh b/test/shell.d/facetimehd-test.sh index 840053dfaafa..3c0461886aba 100755 --- a/test/shell.d/facetimehd-test.sh +++ b/test/shell.d/facetimehd-test.sh @@ -136,8 +136,15 @@ grep -Fxq $'omarchy-pkg-add\tfacetimehd-dkms\tfacetimehd-firmware-fetcher' "$cal grep -Fxq "$fetcher_enabled" "$calls" || fail "leaf enables the fetch for a first boot with a network" "$(cat "$calls")" guarded || fail "leaf guards every hibernating sleep" "$(cat "$calls")" +! grep -q $'sudo\tsystemctl\tstart' "$calls" || + fail "an install leaves the fetch to the boot that follows it" "$(cat "$calls")" pass "leaf installs the DKMS module and the firmware fetcher, enables the fetch, and guards hibernation" +OMARCHY_IMAGE_DEFERRED_HARDWARE=1 run_leaf 1 +grep -Fxq $'sudo\tsystemctl\tstart\t--no-block\tfacetimehd-firmware-fetcher.service' "$calls" || + fail "an image's first boot starts the fetch it enabled" "$(cat "$calls")" +pass "an image's first boot starts the fetch it enabled" + run_leaf 1 facetimehd-dkms grep -Fxq $'omarchy-pkg-add\tfacetimehd-firmware-fetcher' "$calls" || fail "leaf keeps a driver the AUR already provides" "$(cat "$calls")" @@ -198,6 +205,7 @@ run_guard() { : >"$calls" PATH="$stub_bin:$PATH" TEST_LOG="$calls" OMARCHY_FACETIMEHD_MODULE="$guard_root/$1" \ OMARCHY_FACETIMEHD_MARKER="$guard_root/unloaded" OMARCHY_FACETIMEHD_PROC="$guard_root/proc" \ + OMARCHY_FACETIMEHD_LOCK="$guard_root/lock" \ MODULE_BUSY="${3:-}" "$guard" "$2" 2>"$test_tmp/guard.err" } From 39be195053d3bb0c9ffbcea5a0098b43471acc41 Mon Sep 17 00:00:00 2001 From: omarchybot Date: Sat, 21 Nov 2026 23:15:37 +0100 Subject: [PATCH 6/9] Mark every hibernating sleep in progress, not only one that unloaded the driver The guard left no trace when the driver was not loaded, so a firmware fetch finishing between pre and the freeze could load it and hibernation went ahead with it. pre now marks the sleep in progress under the shared lock whatever it finds, and records separately whether it unloaded the driver; a fetch that finishes meanwhile asks for the load, and post makes it with the restore it owes. The manual names the driver's own refusal of ordinary suspend while the camera is open, and that a changed download stops the retries. Co-Authored-By: Claude Opus 5.5 Co-Authored-By: Codex XHigh --- bin/omarchy-system-sleep-facetimehd | 44 ++++++++++++++++------------- manual/44-mac-support.md | 4 +-- test/shell.d/facetimehd-test.sh | 30 ++++++++++++++------ 3 files changed, 49 insertions(+), 29 deletions(-) diff --git a/bin/omarchy-system-sleep-facetimehd b/bin/omarchy-system-sleep-facetimehd index 42ac70901313..be337e273a07 100755 --- a/bin/omarchy-system-sleep-facetimehd +++ b/bin/omarchy-system-sleep-facetimehd @@ -12,12 +12,16 @@ set -uo pipefail module=${OMARCHY_FACETIMEHD_MODULE:-/sys/module/facetimehd} -# Shared with facetimehd-firmware-fetcher, which loads the driver once it has the firmware: under this lock it never -# loads it while the marker says a hibernating sleep has it unloaded. -lock=${OMARCHY_FACETIMEHD_LOCK:-/run/lock/facetimehd.lock} -marker=${OMARCHY_FACETIMEHD_MARKER:-/run/facetimehd-unloaded-for-sleep} proc=${OMARCHY_FACETIMEHD_PROC:-/proc} +# Shared with facetimehd-firmware-fetcher, which loads the driver once it has the firmware. Under the lock, it never +# loads the driver while a hibernating sleep is in progress; it asks for the load instead, and post makes it. +run=${OMARCHY_FACETIMEHD_RUN:-/run/lock} +lock=$run/facetimehd.lock +sleeping=$run/facetimehd.sleeping +unloaded=$run/facetimehd.unloaded +load_request=$run/facetimehd.load + camera_users() { local fd pid for fd in "$proc"/[0-9]*/fd/*; do @@ -36,24 +40,25 @@ notify_seats() { done < <(loginctl list-sessions --no-legend 2>/dev/null | awk '$4 ~ /^seat/ { print $2, $3 }' | sort -u) } -case ${1:-} in - pre | post) - exec 8>>"$lock" - if ! flock -w 60 8; then - # A fetch is loading the driver; hibernating now could catch it loaded, while waking must still load it again. - [[ $1 == post ]] || { echo "Not hibernating: the camera driver is being loaded" >&2; exit 1; } - echo "Loading the camera driver without waiting for the firmware fetch" >&2 - fi - ;; -esac +lock_driver() { + exec 8>>"$lock" + if ! flock -w 60 8; then + # A fetch is loading the driver; hibernating now could catch it loaded, while waking must still load it again. + [[ $1 == post ]] || { echo "Not hibernating: the camera driver is being loaded" >&2; exit 1; } + echo "Loading the camera driver without waiting for the firmware fetch" >&2 + fi +} case ${1:-} in pre) - rm -f "$marker" + lock_driver pre + rm -f "$unloaded" "$load_request" + touch "$sleeping" [[ -d $module ]] || exit 0 if modprobe -r facetimehd; then - touch "$marker" + touch "$unloaded" else + rm -f "$sleeping" users=$(camera_users) echo "Not hibernating: the FaceTime HD camera is in use${users:+ by $users}, and its driver hangs hibernation" >&2 notify_seats "Hibernation cancelled" "Close ${users:-the app using the camera}, then try again. The camera's driver hangs hibernation while it is in use." @@ -61,11 +66,12 @@ case ${1:-} in fi ;; post) - # Only what pre unloaded comes back, so a driver unloaded on purpose stays unloaded. - if [[ -e $marker ]]; then - rm -f "$marker" + lock_driver post + # Only a driver pre unloaded, or one a fetch asked for meanwhile, comes back, so one unloaded on purpose stays out. + if [[ -e $unloaded || -e $load_request ]]; then modprobe facetimehd || echo "Could not load the FaceTime HD camera driver again; it loads at the next boot" >&2 fi + rm -f "$unloaded" "$load_request" "$sleeping" ;; *) echo "Usage: omarchy-system-sleep-facetimehd " >&2 diff --git a/manual/44-mac-support.md b/manual/44-mac-support.md index e30fbe704af9..fc94179dfda8 100644 --- a/manual/44-mac-support.md +++ b/manual/44-mac-support.md @@ -43,9 +43,9 @@ Members of the community are constantly working on solutions to these challenges #### FaceTime HD Camera -The camera driver hangs the machine if it is loaded when the Mac hibernates, so it is unloaded first. It cannot be unloaded while an app has the camera open, so hibernation is cancelled with a notification naming the app: close it and hibernate again. That includes hibernating automatically on a critical battery, and suspend-then-hibernate, which is refused before it suspends. +The camera driver hangs the machine if it is loaded when the Mac hibernates, so it is unloaded first. It cannot be unloaded while an app has the camera open, so hibernation is cancelled with a notification naming the app: close it and hibernate again. That includes hibernating automatically on a critical battery, and suspend-then-hibernate, which is refused before it suspends. Ordinary suspend is refused by the driver itself while the camera is open, without a notification. -The camera's firmware is downloaded from Apple, so the camera works only once the Mac has been online. The download starts at boot and is retried every 15 minutes until it succeeds. If the camera does not appear, `journalctl -u facetimehd-firmware-fetcher` says why, `sudo systemctl restart facetimehd-firmware-fetcher` tries again, and a reboot loads the driver if the download finished but the camera still is not there. +The camera's firmware is downloaded from Apple, so the camera works only once the Mac has been online. The download starts at boot and is retried every 15 minutes while the network is the problem; if Apple's file has changed, it stops and waits for an Omarchy update. If the camera does not appear, `journalctl -u facetimehd-firmware-fetcher` says why, `sudo systemctl restart facetimehd-firmware-fetcher` tries again, and a reboot loads the driver if the download finished but the camera still is not there. #### Devices with T1 Chip diff --git a/test/shell.d/facetimehd-test.sh b/test/shell.d/facetimehd-test.sh index 3c0461886aba..58bc41b29406 100755 --- a/test/shell.d/facetimehd-test.sh +++ b/test/shell.d/facetimehd-test.sh @@ -204,25 +204,39 @@ chmod +x "$stub_bin"/* run_guard() { : >"$calls" PATH="$stub_bin:$PATH" TEST_LOG="$calls" OMARCHY_FACETIMEHD_MODULE="$guard_root/$1" \ - OMARCHY_FACETIMEHD_MARKER="$guard_root/unloaded" OMARCHY_FACETIMEHD_PROC="$guard_root/proc" \ - OMARCHY_FACETIMEHD_LOCK="$guard_root/lock" \ + OMARCHY_FACETIMEHD_RUN="$guard_root/run" OMARCHY_FACETIMEHD_PROC="$guard_root/proc" \ MODULE_BUSY="${3:-}" "$guard" "$2" 2>"$test_tmp/guard.err" } +mkdir -p "$guard_root/run" +sleeping="$guard_root/run/facetimehd.sleeping" +unloaded="$guard_root/run/facetimehd.unloaded" run_guard absent pre || fail "the guard lets a Mac without the driver loaded hibernate" -[[ ! -e $guard_root/unloaded && ! -s $calls ]] || fail "the guard leaves an unloaded driver alone" "$(cat "$calls")" +{ [[ -e $sleeping && ! -e $unloaded ]] && ! grep -q modprobe "$calls"; } || + fail "the guard marks the sleep in progress and leaves an unloaded driver alone" "$(cat "$calls")" +run_guard absent post +{ [[ ! -e $sleeping ]] && ! grep -q modprobe "$calls"; } || + fail "waking loads nothing that was not unloaded or asked for" "$(cat "$calls")" pass "the guard lets a Mac without the driver loaded hibernate" +# A fetch finishing mid-sleep asks for the load rather than making it; waking makes it. +run_guard absent pre +touch "$guard_root/run/facetimehd.load" +run_guard absent post +{ grep -Fxq $'modprobe\tfacetimehd' "$calls" && [[ ! -e $sleeping && ! -e $guard_root/run/facetimehd.load ]]; } || + fail "waking loads a driver a fetch asked for during the sleep" "$(cat "$calls")" +pass "waking loads a driver a fetch asked for during the sleep" + run_guard module pre || fail "the guard unloads an idle driver before hibernating" "$(cat "$test_tmp/guard.err")" -{ grep -Fxq $'modprobe\t-r\tfacetimehd' "$calls" && [[ -e $guard_root/unloaded ]]; } || +{ grep -Fxq $'modprobe\t-r\tfacetimehd' "$calls" && [[ -e $unloaded && -e $sleeping ]]; } || fail "the guard unloads an idle driver before hibernating" "$(cat "$calls")" run_guard module post -{ grep -Fxq $'modprobe\tfacetimehd' "$calls" && [[ ! -e $guard_root/unloaded ]]; } || +{ grep -Fxq $'modprobe\tfacetimehd' "$calls" && [[ ! -e $unloaded && ! -e $sleeping ]]; } || fail "the guard loads the driver again after resuming" "$(cat "$calls")" pass "the guard unloads an idle driver for hibernation and loads it again after" run_guard module post -[[ ! -s $calls ]] || fail "the guard does not load a driver it did not unload" "$(cat "$calls")" +! grep -q modprobe "$calls" || fail "the guard does not load a driver it did not unload" "$(cat "$calls")" pass "the guard does not load a driver it did not unload" if run_guard module pre busy; then @@ -231,6 +245,6 @@ fi grep -q 'chromium' "$test_tmp/guard.err" || fail "the refusal names the app using the camera" "$(cat "$test_tmp/guard.err")" grep -q $'^runuser\t-u\tmac\t.*omarchy-notification-send\t-u\tcritical\tHibernation cancelled\tClose chromium' "$calls" || fail "the refusal notifies the person at the seat" "$(cat "$calls")" -[[ $(grep -c '^runuser' "$calls") == 1 && ! -e $guard_root/unloaded ]] || - fail "only the seat session is notified, and nothing is marked unloaded" "$(cat "$calls")" +[[ $(grep -c '^runuser' "$calls") == 1 && ! -e $unloaded && ! -e $sleeping ]] || + fail "only the seat session is notified, and no sleep is left marked" "$(cat "$calls")" pass "the guard cancels hibernation while the camera is in use, and says which app to close" From 78549322a0b513b95717a109477f1bae726c499d Mon Sep 17 00:00:00 2001 From: omarchybot Date: Sat, 21 Nov 2026 23:24:46 +0100 Subject: [PATCH 7/9] Resume the fetcher's activation on wake instead of loading for it The guard loaded the driver on wake for a fetch that finished mid-sleep and dropped the request if that load failed, leaving nothing to retry it. The fetcher now keeps its activation pending through the sleep, and post starts its service, which loads and verifies the camera and retries until it works. A driver post fails to reload becomes that pending activation too. post waits for the shared lock rather than going on without it, since the fetcher holds it only while it loads the driver. Co-Authored-By: Claude Opus 5.5 Co-Authored-By: Codex XHigh --- bin/omarchy-system-sleep-facetimehd | 39 ++++++++++++++++------------- test/shell.d/facetimehd-test.sh | 27 ++++++++++++++------ 2 files changed, 40 insertions(+), 26 deletions(-) diff --git a/bin/omarchy-system-sleep-facetimehd b/bin/omarchy-system-sleep-facetimehd index be337e273a07..20c9ed535004 100755 --- a/bin/omarchy-system-sleep-facetimehd +++ b/bin/omarchy-system-sleep-facetimehd @@ -15,12 +15,12 @@ module=${OMARCHY_FACETIMEHD_MODULE:-/sys/module/facetimehd} proc=${OMARCHY_FACETIMEHD_PROC:-/proc} # Shared with facetimehd-firmware-fetcher, which loads the driver once it has the firmware. Under the lock, it never -# loads the driver while a hibernating sleep is in progress; it asks for the load instead, and post makes it. +# loads the driver while a hibernating sleep is in progress, and leaves its activation pending for post to resume. run=${OMARCHY_FACETIMEHD_RUN:-/run/lock} lock=$run/facetimehd.lock sleeping=$run/facetimehd.sleeping unloaded=$run/facetimehd.unloaded -load_request=$run/facetimehd.load +activate=$run/facetimehd-firmware-fetcher.activate camera_users() { local fd pid @@ -40,19 +40,12 @@ notify_seats() { done < <(loginctl list-sessions --no-legend 2>/dev/null | awk '$4 ~ /^seat/ { print $2, $3 }' | sort -u) } -lock_driver() { - exec 8>>"$lock" - if ! flock -w 60 8; then - # A fetch is loading the driver; hibernating now could catch it loaded, while waking must still load it again. - [[ $1 == post ]] || { echo "Not hibernating: the camera driver is being loaded" >&2; exit 1; } - echo "Loading the camera driver without waiting for the firmware fetch" >&2 - fi -} - case ${1:-} in pre) - lock_driver pre - rm -f "$unloaded" "$load_request" + exec 8>>"$lock" + # A fetch is loading the driver; hibernating now could catch it loaded. + flock -w 60 8 || { echo "Not hibernating: the camera driver is being loaded" >&2; exit 1; } + rm -f "$unloaded" touch "$sleeping" [[ -d $module ]] || exit 0 if modprobe -r facetimehd; then @@ -66,12 +59,22 @@ case ${1:-} in fi ;; post) - lock_driver post - # Only a driver pre unloaded, or one a fetch asked for meanwhile, comes back, so one unloaded on purpose stays out. - if [[ -e $unloaded || -e $load_request ]]; then - modprobe facetimehd || echo "Could not load the FaceTime HD camera driver again; it loads at the next boot" >&2 + # The fetcher holds the lock only while it loads the driver, so waking waits for it rather than racing it. + exec 8>>"$lock" + flock 8 + # Only a driver pre unloaded comes back, so one unloaded on purpose stays out. A load that fails becomes the + # fetcher's pending activation, which it retries until the camera works. + if [[ -e $unloaded ]] && ! modprobe facetimehd; then + echo "Could not load the FaceTime HD camera driver again; facetimehd-firmware-fetcher retries it" >&2 + touch "$activate" + fi + rm -f "$unloaded" "$sleeping" + flock -u 8 + # An activation the fetcher held back during the sleep, or the load above, resumes now rather than at the next boot. + if [[ -e $activate ]]; then + systemctl start --no-block facetimehd-firmware-fetcher.service 2>/dev/null || + echo "facetimehd-firmware-fetcher is not installed; the camera driver loads at the next boot" >&2 fi - rm -f "$unloaded" "$load_request" "$sleeping" ;; *) echo "Usage: omarchy-system-sleep-facetimehd " >&2 diff --git a/test/shell.d/facetimehd-test.sh b/test/shell.d/facetimehd-test.sh index 58bc41b29406..552115d6aa46 100755 --- a/test/shell.d/facetimehd-test.sh +++ b/test/shell.d/facetimehd-test.sh @@ -182,7 +182,7 @@ cat >"$stub_bin/modprobe" <<'SH' printf 'modprobe' >>"$TEST_LOG" printf '\t%s' "$@" >>"$TEST_LOG" printf '\n' >>"$TEST_LOG" -[[ $1 != -r || -z ${MODULE_BUSY:-} ]] +if [[ $1 == -r ]]; then [[ -z ${MODULE_BUSY:-} ]]; else [[ -z ${MODULE_LOAD_FAILS:-} ]]; fi SH cat >"$stub_bin/loginctl" <<'SH' @@ -205,11 +205,13 @@ run_guard() { : >"$calls" PATH="$stub_bin:$PATH" TEST_LOG="$calls" OMARCHY_FACETIMEHD_MODULE="$guard_root/$1" \ OMARCHY_FACETIMEHD_RUN="$guard_root/run" OMARCHY_FACETIMEHD_PROC="$guard_root/proc" \ - MODULE_BUSY="${3:-}" "$guard" "$2" 2>"$test_tmp/guard.err" + MODULE_BUSY="${3:-}" MODULE_LOAD_FAILS="${4:-}" "$guard" "$2" 2>"$test_tmp/guard.err" } mkdir -p "$guard_root/run" sleeping="$guard_root/run/facetimehd.sleeping" unloaded="$guard_root/run/facetimehd.unloaded" +activate="$guard_root/run/facetimehd-firmware-fetcher.activate" +fetch_started=$'systemctl\tstart\t--no-block\tfacetimehd-firmware-fetcher.service' run_guard absent pre || fail "the guard lets a Mac without the driver loaded hibernate" { [[ -e $sleeping && ! -e $unloaded ]] && ! grep -q modprobe "$calls"; } || @@ -219,13 +221,14 @@ run_guard absent post fail "waking loads nothing that was not unloaded or asked for" "$(cat "$calls")" pass "the guard lets a Mac without the driver loaded hibernate" -# A fetch finishing mid-sleep asks for the load rather than making it; waking makes it. +# A fetch finishing mid-sleep leaves its activation pending rather than loading the driver; waking resumes it. run_guard absent pre -touch "$guard_root/run/facetimehd.load" +touch "$activate" run_guard absent post -{ grep -Fxq $'modprobe\tfacetimehd' "$calls" && [[ ! -e $sleeping && ! -e $guard_root/run/facetimehd.load ]]; } || - fail "waking loads a driver a fetch asked for during the sleep" "$(cat "$calls")" -pass "waking loads a driver a fetch asked for during the sleep" +{ grep -Fxq "$fetch_started" "$calls" && ! grep -q modprobe "$calls" && [[ ! -e $sleeping ]]; } || + fail "waking resumes an activation the fetch held back" "$(cat "$calls")" +rm -f "$activate" +pass "waking resumes an activation the fetch held back during the sleep" run_guard module pre || fail "the guard unloads an idle driver before hibernating" "$(cat "$test_tmp/guard.err")" { grep -Fxq $'modprobe\t-r\tfacetimehd' "$calls" && [[ -e $unloaded && -e $sleeping ]]; } || @@ -236,9 +239,17 @@ run_guard module post pass "the guard unloads an idle driver for hibernation and loads it again after" run_guard module post -! grep -q modprobe "$calls" || fail "the guard does not load a driver it did not unload" "$(cat "$calls")" +! grep -q -e modprobe -e systemctl "$calls" || fail "the guard does not load a driver it did not unload" "$(cat "$calls")" pass "the guard does not load a driver it did not unload" +# A driver that will not load again after the sleep becomes the fetcher's pending activation, which it retries. +run_guard module pre +run_guard module post "" fails +{ [[ -e $activate && ! -e $unloaded && ! -e $sleeping ]] && grep -Fxq "$fetch_started" "$calls"; } || + fail "a failed reload is handed to the fetcher to retry" "$(cat "$calls")" +rm -f "$activate" +pass "a failed reload is handed to the fetcher to retry" + if run_guard module pre busy; then fail "the guard cancels hibernation while the camera is in use" fi From e929c33f2df0c9e36cf0cbddc8d573f3ad98592a Mon Sep 17 00:00:00 2001 From: omarchybot Date: Sat, 21 Nov 2026 23:31:15 +0100 Subject: [PATCH 8/9] Check the camera came back after the sleep, not only that the driver loaded A module loads even when its device fails to probe, so post took a successful modprobe for a working camera. It now waits briefly for the 1570 to be bound and to register a video device, and hands a camera that does not come back to the fetcher as pending activation, as it already did a module that would not load. Co-Authored-By: Claude Opus 5.5 Co-Authored-By: Codex XHigh --- bin/omarchy-system-sleep-facetimehd | 32 +++++++++++++++++++++++++---- test/shell.d/facetimehd-test.sh | 18 ++++++++++++++++ 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/bin/omarchy-system-sleep-facetimehd b/bin/omarchy-system-sleep-facetimehd index 20c9ed535004..f70d3f601c0c 100755 --- a/bin/omarchy-system-sleep-facetimehd +++ b/bin/omarchy-system-sleep-facetimehd @@ -13,6 +13,8 @@ set -uo pipefail module=${OMARCHY_FACETIMEHD_MODULE:-/sys/module/facetimehd} proc=${OMARCHY_FACETIMEHD_PROC:-/proc} +pci=${OMARCHY_FACETIMEHD_PCI:-/sys/bus/pci/devices} +probe_wait=${OMARCHY_FACETIMEHD_PROBE_WAIT:-10} # Shared with facetimehd-firmware-fetcher, which loads the driver once it has the firmware. Under the lock, it never # loads the driver while a hibernating sleep is in progress, and leaves its activation pending for post to resume. @@ -31,6 +33,28 @@ camera_users() { done | sort -u | paste -sd, - | sed 's/,/, /g' } +# The module loading proves nothing about the camera, since the kernel keeps a module whose device failed to probe: it +# works once the 1570's PCI function is bound to facetimehd and has registered a video device. +camera_ready() { + local device found= + for device in "$pci"/*; do + [[ $(<"$device/vendor") == 0x14e4 && $(<"$device/device") == 0x1570 ]] || continue + [[ $(readlink "$device/driver") == */facetimehd ]] && compgen -G "$device/video4linux/video*" >/dev/null || return 1 + found=1 + done 2>/dev/null + [[ -n $found ]] +} + +restore_driver() { + local _ + modprobe facetimehd || return 1 + for _ in $(seq "$probe_wait"); do + camera_ready && return 0 + sleep 1 + done + camera_ready +} + # The menu's systemctl hibernate shows nothing when the sleep fails, so each person at a seat is told why. notify_seats() { local uid user @@ -62,10 +86,10 @@ case ${1:-} in # The fetcher holds the lock only while it loads the driver, so waking waits for it rather than racing it. exec 8>>"$lock" flock 8 - # Only a driver pre unloaded comes back, so one unloaded on purpose stays out. A load that fails becomes the - # fetcher's pending activation, which it retries until the camera works. - if [[ -e $unloaded ]] && ! modprobe facetimehd; then - echo "Could not load the FaceTime HD camera driver again; facetimehd-firmware-fetcher retries it" >&2 + # Only a driver pre unloaded comes back, so one unloaded on purpose stays out. A camera that does not come back + # becomes the fetcher's pending activation, which it retries until the camera works. + if [[ -e $unloaded ]] && ! restore_driver; then + echo "The FaceTime HD camera did not come back after the sleep; facetimehd-firmware-fetcher retries it" >&2 touch "$activate" fi rm -f "$unloaded" "$sleeping" diff --git a/test/shell.d/facetimehd-test.sh b/test/shell.d/facetimehd-test.sh index 552115d6aa46..8edf7fe75953 100755 --- a/test/shell.d/facetimehd-test.sh +++ b/test/shell.d/facetimehd-test.sh @@ -205,9 +205,17 @@ run_guard() { : >"$calls" PATH="$stub_bin:$PATH" TEST_LOG="$calls" OMARCHY_FACETIMEHD_MODULE="$guard_root/$1" \ OMARCHY_FACETIMEHD_RUN="$guard_root/run" OMARCHY_FACETIMEHD_PROC="$guard_root/proc" \ + OMARCHY_FACETIMEHD_PCI="$guard_root/pci" OMARCHY_FACETIMEHD_PROBE_WAIT=0 \ MODULE_BUSY="${3:-}" MODULE_LOAD_FAILS="${4:-}" "$guard" "$2" 2>"$test_tmp/guard.err" } mkdir -p "$guard_root/run" + +# A camera the driver has bound and registered, as the kernel shows one. +camera="$guard_root/pci/0000:02:00.0" +mkdir -p "$camera/video4linux/video0" "$guard_root/drivers/facetimehd" +echo 0x14e4 >"$camera/vendor" +echo 0x1570 >"$camera/device" +ln -s "$guard_root/drivers/facetimehd" "$camera/driver" sleeping="$guard_root/run/facetimehd.sleeping" unloaded="$guard_root/run/facetimehd.unloaded" activate="$guard_root/run/facetimehd-firmware-fetcher.activate" @@ -250,6 +258,16 @@ run_guard module post "" fails rm -f "$activate" pass "a failed reload is handed to the fetcher to retry" +# The module loading again is not the camera coming back: one that fails to probe is handed over too. +rmdir "$camera/video4linux/video0" +run_guard module pre +run_guard module post +{ grep -Fxq $'modprobe\tfacetimehd' "$calls" && [[ -e $activate ]] && grep -Fxq "$fetch_started" "$calls"; } || + fail "a camera that does not come back after the sleep is handed to the fetcher" "$(cat "$calls")" +rm -f "$activate" +mkdir "$camera/video4linux/video0" +pass "a camera that does not come back after the sleep is handed to the fetcher" + if run_guard module pre busy; then fail "the guard cancels hibernation while the camera is in use" fi From aa8c505184eaabb8888b62fab0f795a8ead9d99f Mon Sep 17 00:00:00 2001 From: omarchybot Date: Sat, 21 Nov 2026 23:33:14 +0100 Subject: [PATCH 9/9] Keep the wake step within the sleep unit's stop budget The hibernating sleep units give ExecStopPost 5 s, and post waited for the camera to come back and for the driver lock without bound, so systemd killed it mid-wait and left the sleep marked in progress with nothing restored. The drop-in raises the units' stop timeout to 30 s, post waits at most 10 s for the lock and 2 s for the camera, and anything longer is the fetcher's: a camera not back yet, or a lock it could not get, becomes pending activation and starts the fetcher, with the shared markers left untouched when post holds no lock. Co-Authored-By: Claude Opus 5.5 Co-Authored-By: Codex XHigh --- bin/omarchy-system-sleep-facetimehd | 26 ++++++++++++------- .../system/omarchy-facetimehd-hibernate.conf | 2 ++ test/shell.d/facetimehd-test.sh | 15 ++++++++++- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/bin/omarchy-system-sleep-facetimehd b/bin/omarchy-system-sleep-facetimehd index f70d3f601c0c..8cf8678c6677 100755 --- a/bin/omarchy-system-sleep-facetimehd +++ b/bin/omarchy-system-sleep-facetimehd @@ -14,7 +14,9 @@ set -uo pipefail module=${OMARCHY_FACETIMEHD_MODULE:-/sys/module/facetimehd} proc=${OMARCHY_FACETIMEHD_PROC:-/proc} pci=${OMARCHY_FACETIMEHD_PCI:-/sys/bus/pci/devices} -probe_wait=${OMARCHY_FACETIMEHD_PROBE_WAIT:-10} +# post runs within the sleep unit's stop timeout, so it waits briefly and leaves anything longer to the fetcher. +probe_wait=${OMARCHY_FACETIMEHD_PROBE_WAIT:-2} +lock_wait=${OMARCHY_FACETIMEHD_LOCK_WAIT:-10} # Shared with facetimehd-firmware-fetcher, which loads the driver once it has the firmware. Under the lock, it never # loads the driver while a hibernating sleep is in progress, and leaves its activation pending for post to resume. @@ -83,17 +85,21 @@ case ${1:-} in fi ;; post) - # The fetcher holds the lock only while it loads the driver, so waking waits for it rather than racing it. exec 8>>"$lock" - flock 8 - # Only a driver pre unloaded comes back, so one unloaded on purpose stays out. A camera that does not come back - # becomes the fetcher's pending activation, which it retries until the camera works. - if [[ -e $unloaded ]] && ! restore_driver; then - echo "The FaceTime HD camera did not come back after the sleep; facetimehd-firmware-fetcher retries it" >&2 - touch "$activate" + if flock -w "$lock_wait" 8; then + # Only a driver pre unloaded comes back, so one unloaded on purpose stays out. A camera that does not come back + # becomes the fetcher's pending activation, which it retries until the camera works. + if [[ -e $unloaded ]] && ! restore_driver; then + echo "The FaceTime HD camera did not come back after the sleep; facetimehd-firmware-fetcher retries it" >&2 + touch "$activate" + fi + rm -f "$unloaded" "$sleeping" + flock -u 8 + else + # The fetcher is loading the driver; the markers are left for the next sleep to reset and the fetcher to see stale. + echo "The camera driver is busy; facetimehd-firmware-fetcher brings the camera back" >&2 + [[ ! -e $unloaded ]] || touch "$activate" fi - rm -f "$unloaded" "$sleeping" - flock -u 8 # An activation the fetcher held back during the sleep, or the load above, resumes now rather than at the next boot. if [[ -e $activate ]]; then systemctl start --no-block facetimehd-firmware-fetcher.service 2>/dev/null || diff --git a/default/systemd/system/omarchy-facetimehd-hibernate.conf b/default/systemd/system/omarchy-facetimehd-hibernate.conf index c2b20136a5c2..065278738016 100644 --- a/default/systemd/system/omarchy-facetimehd-hibernate.conf +++ b/default/systemd/system/omarchy-facetimehd-hibernate.conf @@ -3,3 +3,5 @@ [Service] ExecStartPre=/usr/bin/omarchy-system-sleep-facetimehd pre ExecStopPost=/usr/bin/omarchy-system-sleep-facetimehd post +# The sleep units allow post 5 s; it waits up to 10 s for the driver lock and a moment for the camera. +TimeoutStopSec=30s diff --git a/test/shell.d/facetimehd-test.sh b/test/shell.d/facetimehd-test.sh index 8edf7fe75953..2a1edba155ed 100755 --- a/test/shell.d/facetimehd-test.sh +++ b/test/shell.d/facetimehd-test.sh @@ -29,7 +29,8 @@ grep -q '14e4:1570' "$hw" || grep -q 'FaceTime HD' "$manual" || fail "Mac support documents the FaceTime HD camera" { grep -Fxq 'ExecStartPre=/usr/bin/omarchy-system-sleep-facetimehd pre' "$dropin" && - grep -Fxq 'ExecStopPost=/usr/bin/omarchy-system-sleep-facetimehd post' "$dropin"; } || + grep -Fxq 'ExecStopPost=/usr/bin/omarchy-system-sleep-facetimehd post' "$dropin" && + grep -Fxq 'TimeoutStopSec=30s' "$dropin"; } || fail "the hibernation drop-in runs the guard before the sleep and after it" pass "the FaceTime HD fix is wired into hardware setup" @@ -268,6 +269,18 @@ rm -f "$activate" mkdir "$camera/video4linux/video0" pass "a camera that does not come back after the sleep is handed to the fetcher" +# A post that cannot get the lock in time touches no shared state and hands the restore to the fetcher. +run_guard module pre +flock "$guard_root/run/facetimehd.lock" sleep 2 & +holder=$! +sleep 0.5 +OMARCHY_FACETIMEHD_LOCK_WAIT=0 run_guard module post +wait "$holder" +{ ! grep -q modprobe "$calls" && [[ -e $activate && -e $unloaded && -e $sleeping ]] && grep -Fxq "$fetch_started" "$calls"; } || + fail "a post that cannot get the lock leaves the markers and hands the restore to the fetcher" "$(cat "$calls")" +rm -f "$activate" "$unloaded" "$sleeping" +pass "a post that cannot get the lock leaves the markers and hands the restore to the fetcher" + if run_guard module pre busy; then fail "the guard cancels hibernation while the camera is in use" fi