File: psd-suspend-sync

package info (click to toggle)
profile-sync-daemon 6.50-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 312 kB
  • sloc: sh: 798; makefile: 74
file content (45 lines) | stat: -rw-r--r-- 1,464 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash

dbus_interface="org.freedesktop.login1"
dbus_member="PrepareForSleep"

# system suspends when 'PrepareForSleep' signal is 'true':
# ... /org/freedesktop/login1: org.freedesktop.login1.Manager.PrepareForSleep (true,) ...
# system resumes when 'PrepareForSleep' signal is 'false'
# ... /org/freedesktop/login1: org.freedesktop.login1.Manager.PrepareForSleep (false,) ...
dbus_process_sleep() {
  local line
  while read -r line; do
    if [[ "$line" =~ $dbus_member ]]; then
      if [[ "$line" =~ 'true' ]]; then
        ### SUSPEND ###
        logger '[psd-suspend-sync] Issuing suspend-sync request...'
        /usr/bin/profile-sync-daemon suspend-sync
        # the lock will be released now
        break
      elif [[ "$line" =~ 'false' ]]; then
        ### RESUME ###
        logger '[psd-suspend-sync] re-taking inhibit lock...'
        /usr/bin/profile-sync-daemon recycle-inhibit-lock
        break
      fi
    fi
  done
}

coproc bus (
  systemd-inhibit --mode="delay" --what="sleep" \
    --who="profile-sync-daemon" --why="psd resync on suspend" \
    gdbus monitor --system --dest "$dbus_interface"
)

# keeps the inhibitor running until the system is about to sleep
dbus_process_sleep <& "${bus[0]}"

# starts running before the system goes to sleep
dbus_process_sleep < <(gdbus monitor --system --dest "$dbus_interface") &

# kill the inhibitor so that the system can sleep
[ -n "$bus_PID" ] && kill "$bus_PID"

# vim:set ts=2 sw=2 et: