mirror of
https://github.com/kovidgoyal/kitty.git
synced 2024-09-11 14:45:31 +03:00
Match behavior of who when getting num_users by ignoring zombie pids
This commit is contained in:
parent
a8b756f040
commit
4b1fa2609d
10
kitty/utmp.c
10
kitty/utmp.c
@ -1,6 +1,14 @@
|
||||
#include "data-types.h"
|
||||
#if __has_include(<utmpx.h>)
|
||||
#include <utmpx.h>
|
||||
#include <signal.h>
|
||||
|
||||
static bool
|
||||
pid_exists(pid_t pid) {
|
||||
if (pid < 1) return false;
|
||||
if (kill(pid, 0) >= 0) return true;
|
||||
return errno != ESRCH;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
num_users(PyObject *const self UNUSED, PyObject *const args UNUSED) {
|
||||
@ -9,7 +17,7 @@ num_users(PyObject *const self UNUSED, PyObject *const args UNUSED) {
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
setutxent();
|
||||
while ((ut = getutxent())) {
|
||||
if (ut->ut_type == USER_PROCESS) users++;
|
||||
if (ut->ut_type == USER_PROCESS && ut->ut_user[0] && pid_exists(ut->ut_pid)) users++;
|
||||
}
|
||||
endutxent();
|
||||
Py_END_ALLOW_THREADS
|
||||
|
Loading…
Reference in New Issue
Block a user