From 385745f002e113d9c06093d0b1b227d239500bb0 Mon Sep 17 00:00:00 2001 From: litenglong Date: Mon, 1 Jul 2024 18:12:23 +0800 Subject: [PATCH] fix-w-print-when-systemd-get-tty-is-empty --- ...-print-when-systemd-get-tty-is-empty.patch | 69 +++++++++++++++++++ procps-ng.spec | 6 +- 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 fix-w-print-when-systemd-get-tty-is-empty.patch diff --git a/fix-w-print-when-systemd-get-tty-is-empty.patch b/fix-w-print-when-systemd-get-tty-is-empty.patch new file mode 100644 index 0000000..3076638 --- /dev/null +++ b/fix-w-print-when-systemd-get-tty-is-empty.patch @@ -0,0 +1,69 @@ +From b33fbca4309d6afa2b25ab10b05d39c0a27bafc7 Mon Sep 17 00:00:00 2001 +From: litenglong +Date: Fri, 28 Jun 2024 18:20:00 +0800 +Subject: [PATCH] fix w print when systemd get tty is empty + +--- + src/w.c | 32 ++++++++++++++++++++++++++++++++ + 1 file changed, 32 insertions(+) + +diff --git a/src/w.c b/src/w.c +index 4d25905..8f3f0a0 100644 +--- a/src/w.c ++++ b/src/w.c +@@ -44,6 +44,7 @@ + #include + #include + #include ++#include + #ifdef HAVE_UTMPX_H + #include + #ifndef HAVE_UT_HOSTSIZE_IN_UTMPX +@@ -508,6 +509,29 @@ static int find_best_proc( + #undef PIDS_GETSTR + } + ++#if (defined(WITH_SYSTEMD) || defined(WITH_ELOGIND)) && defined(HAVE_SD_SESSION_GET_LEADER) ++static bool check_sd_session_get_tty(int sessions, const char **sessions_list) ++{ ++ char *sd_tty; ++ ++ if ((sessions == 0) || (sessions_list == NULL)) { ++ return false; ++ } ++ ++ for (int i = 0; i < sessions; i++) { ++ if (sessions_list[i]) { ++ if (sd_session_get_tty(sessions_list[i], &sd_tty) >= 0) { // get tty is ok ++ free(sd_tty); ++ } else { ++ return false; ++ } ++ } ++ } ++ ++ return true; ++} ++#endif ++ + static void showinfo( + #if (defined(WITH_SYSTEMD) || defined(WITH_ELOGIND)) && defined(HAVE_SD_SESSION_GET_LEADER) + const char *session, const char *name, +@@ -814,6 +838,14 @@ int main(int argc, char **argv) + if (sessions < 0 && sessions != -ENOENT) + error(EXIT_FAILURE, -sessions, _("error getting sessions")); + ++ if (check_sd_session_get_tty(sessions, sessions_list) == false) { ++ for (int i = 0; i < sessions; i++) { ++ free(sessions_list[i]); ++ } ++ free(sessions_list); ++ sessions = 0; ++ } ++ + if (sessions > 0) { + for (int i = 0; i < sessions; i++) { + char *name; +-- +2.25.1 + diff --git a/procps-ng.spec b/procps-ng.spec index 4a0bac7..340ae63 100644 --- a/procps-ng.spec +++ b/procps-ng.spec @@ -1,6 +1,6 @@ Name: procps-ng Version: 4.0.4 -Release: 6 +Release: 7 Summary: Utilities that provide system information. License: GPL+ and GPLv2 and GPLv2+ and GPLv3+ and LGPLv2+ URL: https://sourceforge.net/projects/procps-ng/ @@ -19,6 +19,7 @@ Patch7: openeuler-uptime-Fix-uptime-return-0-user-when-systemd-pam-is-.patch Patch8: openeuler-w-Fix-w-print-0-user-when-systemd-pam-is-not-install.patch Patch9: backport-library-implement-guest-total-tics-change-stat-api.patch Patch10: backport-top-adapt-to-that-guest-total-tics-change-stat-api.patch +Patch11: fix-w-print-when-systemd-get-tty-is-empty.patch BuildRequires: ncurses-devel libtool autoconf automake gcc gettext-devel systemd-devel @@ -101,6 +102,9 @@ ln -s %{_bindir}/pidof %{buildroot}%{_sbindir}/pidof %{_mandir}/man* %changelog +* Mon Jul 01 2024 litenglong - 4.0.4-7 +- w: fix-w-print-when-systemd-get-tty-is-empty.patch + * Tue Jun 25 2024 Liu Chao - 4.0.4-6 - top: adapt to guest/total tics change, api -- Gitee