12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- #!/bin/bash
- # Source Qubes library.
- # shellcheck source=init/functions
- . /usr/lib/qubes/init/functions
- action=$1
- [ -z "$action" ] && action=suspend
- MODULES_BLACKLIST=""
- if [ -r /etc/qubes-suspend-module-blacklist ]; then
- MODULES_BLACKLIST="$MODULES_BLACKLIST $(grep -v '^#' /etc/qubes-suspend-module-blacklist)"
- fi
- if [ -r /rw/config/suspend-module-blacklist ]; then
- MODULES_BLACKLIST="$MODULES_BLACKLIST $(grep -v '^#' /rw/config/suspend-module-blacklist)"
- fi
- if [ x"$action" = x"suspend" ]; then
- if qsvc network-manager ; then
- dbus-send --system --print-reply \
- --dest=org.freedesktop.NetworkManager \
- /org/freedesktop/NetworkManager \
- org.freedesktop.NetworkManager.Sleep boolean:true || \
- service NetworkManager stop
- fi
- # Force interfaces down, just in case when NM didn't done it
- for intf in /sys/class/net/*; do
- intf=$(basename "$intf")
- if [ "$intf" = "lo" ] || [[ "$intf" = "vif"* ]]; then
- continue
- fi
- if [ "$(cat "/sys/class/net/$intf/device/devtype" 2>/dev/null$)" = "vif" ]; then
- continue
- fi
- ip l s "$intf" down
- done
- # detach all drivers from PCI devices (the real ones, not emulated by qemu)
- echo -n > /var/run/qubes-suspend-pci-devs-detached
- for dev_path in /sys/bus/pci/devices/*; do
- subsystem_vendor=$(cat "$dev_path/subsystem_vendor")
- vendor=$(cat "$dev_path/vendor")
- class=$(cat "$dev_path/class")
- # skip qemu emulated devs
- if [ "$subsystem_vendor" = "0x1af4" ] || [ "$subsystem_vendor" = "0x5853" ]; then
- continue
- fi
- # skip Intel Graphics Device
- if [ "$vendor" = "0x8086" ] && [ "$class" = "0x030000" ]; then
- continue
- fi
- if ! [ -e "$dev_path/driver" ]; then
- continue
- fi
- bdf=$(basename "$dev_path")
- driver_path=$(readlink -f "$dev_path/driver")
- echo "$bdf" > "$driver_path/unbind"
- echo "$bdf $driver_path" >> /var/run/qubes-suspend-pci-devs-detached
- done
- LOADED_MODULES=""
- for mod in $MODULES_BLACKLIST; do
- if lsmod |grep -q "$mod"; then
- LOADED_MODULES="$LOADED_MODULES $mod"
- modprobe -r "$mod"
- fi
- done
- echo "$LOADED_MODULES" > /var/run/qubes-suspend-modules-loaded
- else
- # shellcheck disable=SC2013
- for mod in $(cat /var/run/qubes-suspend-modules-loaded); do
- modprobe "$mod"
- done
- rm -f /var/run/qubes-suspend-modules-loaded
- while read -r dev driver_path; do
- echo "$dev" > "$driver_path/bind"
- done < /var/run/qubes-suspend-pci-devs-detached
- rm -f /var/run/qubes-suspend-pci-devs-detached
- if qsvc network-manager ; then
- dbus-send --system --print-reply \
- --dest=org.freedesktop.NetworkManager \
- /org/freedesktop/NetworkManager \
- org.freedesktop.NetworkManager.Sleep boolean:false || \
- { under_systemd && systemctl start NetworkManager.service; } || service qubes-core-netvm start
- fi
- fi
|