2016-10-22 17:43:16 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Source Qubes library.
|
2017-09-30 04:56:02 +02:00
|
|
|
# shellcheck source=init/functions
|
2016-10-22 17:43:16 +02:00
|
|
|
. /usr/lib/qubes/init/functions
|
2012-07-13 14:40:52 +02:00
|
|
|
|
|
|
|
action=$1
|
|
|
|
[ -z "$action" ] && action=suspend
|
|
|
|
|
2013-10-24 04:13:27 +02:00
|
|
|
MODULES_BLACKLIST=""
|
2013-10-23 04:34:47 +02:00
|
|
|
if [ -r /etc/qubes-suspend-module-blacklist ]; then
|
2017-09-30 04:45:31 +02:00
|
|
|
MODULES_BLACKLIST="$MODULES_BLACKLIST $(grep -v '^#' /etc/qubes-suspend-module-blacklist)"
|
2013-10-23 04:34:47 +02:00
|
|
|
fi
|
|
|
|
if [ -r /rw/config/suspend-module-blacklist ]; then
|
2017-09-30 04:45:31 +02:00
|
|
|
MODULES_BLACKLIST="$MODULES_BLACKLIST $(grep -v '^#' /rw/config/suspend-module-blacklist)"
|
2013-10-23 04:34:47 +02:00
|
|
|
fi
|
|
|
|
|
2015-02-05 03:14:41 +01:00
|
|
|
if [ x"$action" = x"suspend" ]; then
|
2016-10-22 17:43:16 +02:00
|
|
|
if qsvc network-manager ; then
|
2016-01-11 19:40:32 +01:00
|
|
|
dbus-send --system --print-reply \
|
|
|
|
--dest=org.freedesktop.NetworkManager \
|
|
|
|
/org/freedesktop/NetworkManager \
|
|
|
|
org.freedesktop.NetworkManager.Sleep boolean:true || \
|
|
|
|
service NetworkManager stop
|
|
|
|
fi
|
2012-07-13 14:40:52 +02:00
|
|
|
# Force interfaces down, just in case when NM didn't done it
|
2017-09-30 04:45:31 +02:00
|
|
|
for intf in /sys/class/net/*; do
|
|
|
|
intf=$(basename "$intf")
|
|
|
|
if [ "$intf" = "lo" ] || [[ "$intf" = "vif"* ]]; then
|
2014-10-27 15:07:06 +01:00
|
|
|
continue
|
|
|
|
fi
|
2017-09-30 04:45:31 +02:00
|
|
|
if [ "$(cat "/sys/class/net/$intf/device/devtype" 2>/dev/null$)" = "vif" ]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
ip l s "$intf" down
|
2012-07-13 14:40:52 +02:00
|
|
|
done
|
2018-01-22 19:14:07 +01:00
|
|
|
|
|
|
|
# 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
|
|
|
|
# skip qemu emulated devs
|
|
|
|
subsystem_vendor=$(cat "$dev_path/subsystem_vendor")
|
|
|
|
if [ "$subsystem_vendor" = "0x1af4" ] || [ "$subsystem_vendor" = "0x5853" ]; 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
|
|
|
|
|
2013-10-23 04:34:47 +02:00
|
|
|
LOADED_MODULES=""
|
|
|
|
for mod in $MODULES_BLACKLIST; do
|
2017-09-30 04:45:31 +02:00
|
|
|
if lsmod |grep -q "$mod"; then
|
2013-10-23 04:34:47 +02:00
|
|
|
LOADED_MODULES="$LOADED_MODULES $mod"
|
2017-09-30 04:45:31 +02:00
|
|
|
modprobe -r "$mod"
|
2013-10-23 04:34:47 +02:00
|
|
|
fi
|
|
|
|
done
|
2018-01-22 19:11:50 +01:00
|
|
|
echo "$LOADED_MODULES" > /var/run/qubes-suspend-modules-loaded
|
2012-07-13 14:40:52 +02:00
|
|
|
else
|
2017-09-30 04:45:31 +02:00
|
|
|
# shellcheck disable=SC2013
|
2018-01-22 19:11:50 +01:00
|
|
|
for mod in $(cat /var/run/qubes-suspend-modules-loaded); do
|
2017-09-30 04:45:31 +02:00
|
|
|
modprobe "$mod"
|
2013-10-23 04:34:47 +02:00
|
|
|
done
|
2018-01-22 19:11:50 +01:00
|
|
|
rm -f /var/run/qubes-suspend-modules-loaded
|
2018-01-22 19:14:07 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2016-10-22 17:43:16 +02:00
|
|
|
if qsvc network-manager ; then
|
2016-01-11 19:40:32 +01:00
|
|
|
dbus-send --system --print-reply \
|
|
|
|
--dest=org.freedesktop.NetworkManager \
|
|
|
|
/org/freedesktop/NetworkManager \
|
|
|
|
org.freedesktop.NetworkManager.Sleep boolean:false || \
|
2016-10-22 17:43:16 +02:00
|
|
|
{ under_systemd && systemctl start NetworkManager.service; } || service qubes-core-netvm start
|
2016-01-11 19:40:32 +01:00
|
|
|
fi
|
2012-07-13 14:40:52 +02:00
|
|
|
fi
|