From daebc1a8c4ef28c8a52f7549f18d42702abd7cdc Mon Sep 17 00:00:00 2001
From: huyubiao <huyubiao@huawei.com>
Date: Tue, 12 Nov 2024 15:36:21 +0800
Subject: [PATCH] systemd-logind button_dispatch add log to display devices that triggered the button

---
 src/login/logind-action.c | 7 +++++++
 src/login/logind-button.c | 7 +++++++
 2 files changed, 14 insertions(+)

diff --git a/src/login/logind-action.c b/src/login/logind-action.c
index e678edd..17e8b26 100644
--- a/src/login/logind-action.c
+++ b/src/login/logind-action.c
@@ -191,6 +191,13 @@ static int handle_action_execute(
                 return is_edge ? -EPERM : 0;
         }
 
+        // Extra log to console
+        LogTarget old_target = log_get_target();
+        log_set_always_reopen_console(true);
+        log_set_target_and_open(LOG_TARGET_CONSOLE);
+        log_info("%s", message_table[handle]);
+        log_set_always_reopen_console(false);
+        log_set_target_and_open(old_target);
         log_info("%s", message_table[handle]);
 
         r = bus_manager_shutdown_or_sleep_now_or_later(m, handle_action_lookup(handle), &error);
diff --git a/src/login/logind-button.c b/src/login/logind-button.c
index 7f95fa7..54e877e 100644
--- a/src/login/logind-button.c
+++ b/src/login/logind-button.c
@@ -205,6 +205,13 @@ static int button_dispatch(sd_event_source *s, int fd, uint32_t revents, void *u
         assert(s);
         assert(fd == b->fd);
 
+        LogTarget old_target = log_get_target();
+        log_set_always_reopen_console(true);
+        log_set_target_and_open(LOG_TARGET_CONSOLE);
+        log_info("button:%s event", b->name);
+        log_set_always_reopen_console(false);
+        log_set_target_and_open(old_target);
+
         l = read(b->fd, &ev, sizeof(ev));
         if (l < 0)
                 return errno != EAGAIN ? -errno : 0;
-- 
2.33.0

