Skip to content

Commit

Permalink
Explicitly remove wireless PCI devices on shutdown.
Browse files Browse the repository at this point in the history
The guest operating system has to release the devices that were
shared via PCI pass-through otherwise they might get stuck and
can eventually bring down the entire host.

Relates to pgj/freebsd-wifibox#60
  • Loading branch information
pgj committed Aug 23, 2024
1 parent e501a72 commit 214befc
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ PACKAGES?=$(PWD)/*.apk
BOOT_SERVICES?=networking urandom bootmisc modules hostname hwclock sysctl syslog
DEFAULT_SERVICES?=acpid crond
SYSINIT_SERVICES?=devfs dmesg hwdrivers mdev
SHUTDOWN_SERVICES?=remove-wireless
ETC_SRCS?=$(PWD)/etc/wpa_supplicant

ROOT=$(PREFIX)/share/wifibox
Expand Down Expand Up @@ -116,7 +117,7 @@ $(GUESTDIR)/.done:
$(CP) -R $(PWD)/guest/ $(GUESTDIR)
.endif
# rc-update add
.for runlevel in boot default sysinit
.for runlevel in boot default sysinit shutdown
.for service in $(${runlevel:tu}_SERVICES)
$(LN) -s /etc/init.d/${service} $(GUESTDIR)/etc/runlevels/${runlevel}
.endfor
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ for development and testing.
BOOT_SERVICES=<services to launch on boot> \
DEFAULT_SERVICES=<default services> \
SYSINIT_SERVICES=<system initialization services> \
SHUTDOWN_SERVICES=<system shutdown services> \
ETC_SRCS=<location of application-specific configuration files> \
EXTRA_VIRTFS_MOUNTS=<fstab entries for shared file systems> \
FIRMWARE_FILES=<List of firmware files to keep> \
Expand Down Expand Up @@ -90,6 +91,10 @@ process:
of the guest system initialization phase, along with the kernel.
They have to be sync with the installed packages.

- `SHUTDOWN_SERVICES` should list the services that have to be invoked
on shutdown. These are usually useful for taking care of various
clean-ups.

- `ETC_SRCS` should point to a location where the guest's generic
configuration files could be found. This helps to choose between
application-specific configuration defaults. Currently, such files
Expand Down
4 changes: 3 additions & 1 deletion aports/openrc/APKBUILD
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Maintainer: Gabor Pali <pali.gabor@gmail.com>
pkgname=openrc
pkgver=0.54
pkgrel=0 # base: 1
pkgrel=1 # base: 1
pkgdesc="OpenRC manages the services, startup and shutdown of a host"
url="https://github.com/OpenRC/openrc"
arch="all"
Expand Down Expand Up @@ -36,6 +36,7 @@ source="$pkgname-$pkgver.tar.gz::https://github.com/OpenRC/openrc/archive/$pkgve
firstboot.initd
sysctl.initd
machine-id.initd
remove-wireless.initd
"
options="!check" # not updated to meson build system, require makefile build

Expand Down Expand Up @@ -152,4 +153,5 @@ d76c75c58e6f4b0801edac4e081b725ef3d50a9a8c9bbb5692bf4d0f804af7d383bf71a73d5d03ed
990855f875513a85c2b737685ac5bfdfa86f8dadacf00c1826a456547f99b69d4ecf1b9a09c0ce002f1df618b44b1febabe53f95a2c0cd02b504d565bccb50c8 firstboot.initd
2d5f9f6d41b7c0a8643cfdee1ce3c399bfe4ebff54421f33ab1e74c1c4c1b96a49e54b5cd69f0339a060342e4e5a11067bbff68c39fa487919259d73e8e46ed1 sysctl.initd
35682e1742196133b79e4a0b21fe8df039a982ba4fdd0181b1e3872f3885e40726179d4996fec83a1da11ff314d71f8910609c1c05acb3d0f9b923147e2f1d55 machine-id.initd
bd17c9cfbde230f12f608f365e7e795bba468a91b0adf3b8e61979326f55c3edcaef9ccee6eb2402c45c61b6bc32b4dec5d1a40983074ddedb9378b715e03c4e remove-wireless.initd
"
29 changes: 29 additions & 0 deletions aports/openrc/remove-wireless.initd
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/sbin/openrc-run

description="Explicitly removes wireless devices."

depend() {
after firewall
before logger
}

find_pci_wireless() {
local iface=
for iface in /sys/bus/pci/devices/*/net/*; do
if [ -e "$iface"/wireless -o -e "$iface"/phy80211 ]; then
echo "${iface%/net/*}"
fi
done
}

start() {
ebegin "Triggering remove for PCI wireless devices"
eindent
for device in $(find_pci_wireless); do
veinfo "Processing $device"
echo 1 > "$device"/remove
done
eoutdent

eend $?
}

0 comments on commit 214befc

Please sign in to comment.