From fed22c2d6008b39f57e692b1fa58407f7ca109be Mon Sep 17 00:00:00 2001 From: Guillaume Girol Date: Sat, 5 Mar 2022 12:00:00 +0000 Subject: [PATCH] inspiron-5515: fix race for fix-touchpad.sh On rare occasions, the module would be removed before suspend and the touchpad would be disabled on boot. --- dell/inspiron/5515/default.nix | 11 ++++++++--- dell/inspiron/5515/fix_touchpad.sh | 5 +++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/dell/inspiron/5515/default.nix b/dell/inspiron/5515/default.nix index 5f9f7c2..5e1fa64 100644 --- a/dell/inspiron/5515/default.nix +++ b/dell/inspiron/5515/default.nix @@ -12,13 +12,18 @@ # hack around it by unloading and reloading module i2c_hid systemd.services.fix-touchpad = { path = [ pkgs.kmod ]; - serviceConfig.ExecStart = "${./fix_touchpad.sh}"; + serviceConfig.ExecStart = ''${pkgs.systemd}/bin/systemd-inhibit --what=sleep --why="fixing touchpad must finish before sleep" --mode=delay ${./fix_touchpad.sh}''; + serviceConfig.Type = "oneshot"; description = "reload touchpad driver"; # must run at boot (and not too early), and after suspend - wantedBy = [ "display-manager.service" "sleep.target" ]; - after = [ "sleep.target" ]; + wantedBy = [ "display-manager.service" "post-resume.target" ]; + # prevent running before suspend + after = [ "post-resume.target" ]; }; + # so that post-resume.service exists + powerManagement.enable = true; + # fix suspend # https://bbs.archlinux.org/viewtopic.php?id=266108 says linux >= 5.12 required diff --git a/dell/inspiron/5515/fix_touchpad.sh b/dell/inspiron/5515/fix_touchpad.sh index b776dce..46388c4 100755 --- a/dell/inspiron/5515/fix_touchpad.sh +++ b/dell/inspiron/5515/fix_touchpad.sh @@ -11,10 +11,11 @@ unload () { wait_unload() { while sleep 1; do - case "$(unload "$1")" in + output="$(unload "$1")" + case "$output" in *is\ in\ use*) :;; *ok*) return 0;; - *) echo giving up; return 1; + *) echo "modprobe said: $output"; echo giving up; return 1; esac done }