summaryrefslogtreecommitdiff
path: root/src/login
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2022-07-07 07:42:51 +0900
committerGitHub <noreply@github.com>2022-07-07 07:42:51 +0900
commit99080ed3f0cca0f5a3cc8fc02d1445f6566cca36 (patch)
tree742484b5744a29fd21932f5c51c32577d6bec778 /src/login
parent2615c1f17ab1768ebe015d0719cc1ee2e6b092f1 (diff)
parent181656fc0faa885d69bc34822b8e9b5de3fdf6bf (diff)
downloadsystemd-99080ed3f0cca0f5a3cc8fc02d1445f6566cca36.tar.gz
Merge pull request #23396 from msekletar/fix-idle-action-lock
logind: remember our idle state and use it to detect idle level transitions
Diffstat (limited to 'src/login')
-rw-r--r--src/login/logind.c23
-rw-r--r--src/login/logind.h1
2 files changed, 20 insertions, 4 deletions
diff --git a/src/login/logind.c b/src/login/logind.c
index aa85480548..d14a17274b 100644
--- a/src/login/logind.c
+++ b/src/login/logind.c
@@ -963,18 +963,33 @@ static int manager_dispatch_idle_action(sd_event_source *s, uint64_t t, void *us
n = now(CLOCK_MONOTONIC);
r = manager_get_idle_hint(m, &since);
- if (r <= 0)
+ if (r <= 0) {
/* Not idle. Let's check if after a timeout it might be idle then. */
elapse = n + m->idle_action_usec;
- else {
+ m->was_idle = false;
+ } else {
+
/* Idle! Let's see if it's time to do something, or if
* we shall sleep for longer. */
if (n >= since.monotonic + m->idle_action_usec &&
(m->idle_action_not_before_usec <= 0 || n >= m->idle_action_not_before_usec + m->idle_action_usec)) {
- log_info("System idle. Will %s now.", handle_action_verb_to_string(m->idle_action));
+ bool is_edge = false;
+
+ /* We weren't idle previously or some activity happened while we were sleeping, and now we are
+ * idle. Let's remember that for the next time and make this an edge transition. */
+ if (!m->was_idle || since.monotonic >= m->idle_action_not_before_usec) {
+ is_edge = true;
+ m->was_idle = true;
+ }
+
+ if (m->idle_action == HANDLE_LOCK && !is_edge)
+ /* We are idle and we were before so we are actually not taking any action. */
+ log_debug("System idle.");
+ else
+ log_info("System idle. Will %s now.", handle_action_verb_to_string(m->idle_action));
- manager_handle_action(m, 0, m->idle_action, false, false);
+ manager_handle_action(m, 0, m->idle_action, false, is_edge);
m->idle_action_not_before_usec = n;
}
diff --git a/src/login/logind.h b/src/login/logind.h
index 27f9e9729f..58677c9491 100644
--- a/src/login/logind.h
+++ b/src/login/logind.h
@@ -94,6 +94,7 @@ struct Manager {
usec_t idle_action_usec;
usec_t idle_action_not_before_usec;
HandleAction idle_action;
+ bool was_idle;
HandleAction handle_power_key;
HandleAction handle_power_key_long_press;