Skip to content

Reset all triggers when sleep is detected

Jean-Ralph Aviles requested to merge jraviles/xautolock:triggers into master

If a system is set to sleep with a -killer for >= killtime with -detectsleep enabled, the killer command will be executed when resuming from sleep unless the command is made to synchronously block until the system resumes.

The "hack" added in options.c:379 to add an "&" to the -killer command causes it to return immediately. The killer command will then race with xautolock. If xautolock calls setKillTrigger in engine.c:287 before the system goes to sleep, killTrigger will be set to now() + killTime. After the system resumes, and killTime seconds have passed, killTrigger will be set to a value in the past and the killer will be executed again.

-detectsleep is supposed to remedy this by resetting trigger times if the clock "jumps" by 3 seconds (actually 2 due to the sleep(1) in xautolock.c). The detectsleep logic only resets the lockTrigger however and not the killTrigger. By calling resetTriggers() instead we can reset the lockTrigger and killTrigger to make sure we don't trigger the -killer command twice.

Note, there still exists a small race condition that when a system suspends for >= killTime after the -detectsleep logic has run and before triggers are evaluated in evaluateTriggers() causing the -killer command to run immediately after resuming. We would have to remove the hacks in options.c to resolve this.

Merge request reports

Loading