[monitoring-plugins] check_users: Discard sessions with invalid or ...
GitHub
git at monitoring-plugins.org
Sun Sep 6 23:40:13 CEST 2026
Module: monitoring-plugins
Branch: master
Commit: c7430767d83a4429ffeb55f1f1b13ba5ee3477cd
Author: Hilko Bengen <bengen--github at hilluzination.de>
Committer: GitHub <noreply at github.com>
Date: Sun Sep 6 23:35:55 2026 +0200
URL: https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=c7430767
check_users: Discard sessions with invalid or missing pid in utmp (#2336)
The `signal(pid, 0)` check matches what who(1) from coreutils does.
(I have checked versions 9.4 and 9.7.)
---
plugins/check_users.d/users.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/plugins/check_users.d/users.c b/plugins/check_users.d/users.c
index ec7e0bac..289d0ed5 100644
--- a/plugins/check_users.d/users.c
+++ b/plugins/check_users.d/users.c
@@ -83,6 +83,8 @@ get_num_of_users_wrapper get_num_of_users_systemd() {
# ifdef HAVE_UTMPX_H
# include <utmpx.h>
+# include <errno.h>
+# include <signal.h>
get_num_of_users_wrapper get_num_of_users_utmp() {
int users = 0;
@@ -92,9 +94,13 @@ get_num_of_users_wrapper get_num_of_users_utmp() {
struct utmpx *putmpx;
while ((putmpx = getutxent()) != NULL) {
- if (putmpx->ut_type == USER_PROCESS) {
- users++;
+ if (putmpx->ut_type != USER_PROCESS) {
+ continue;
+ }
+ if ((putmpx->ut_pid <= 0) || ((kill(putmpx->ut_pid, 0) != 0) && (errno == ESRCH))) {
+ continue;
}
+ users++;
}
endutxent();
More information about the Commits
mailing list