]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lslogins: use lib/procfs.c
authorKarel Zak <kzak@redhat.com>
Tue, 7 Sep 2021 15:37:46 +0000 (17:37 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 6 Oct 2021 09:01:54 +0000 (11:01 +0200)
login-utils/lslogins.c

index 9431a50bb7ce117dc394e8cb905af6af38064f43..132046cbf405e477ffd76d76ad9d3b11794d477e 100644 (file)
@@ -55,8 +55,9 @@
 #include "strutils.h"
 #include "optutils.h"
 #include "pathnames.h"
+#include "fileutils.h"
 #include "logindefs.h"
-#include "procutils.h"
+#include "procfs.h"
 #include "timeutils.h"
 
 /*
@@ -562,9 +563,6 @@ static int get_sgroups(gid_t **list, size_t *len, struct passwd *pwd)
 
        *list = xcalloc(1, ngroups * sizeof(gid_t));
 
-fprintf(stderr, "KZAK>>> alloc '%p' for %s\n", *list, pwd->pw_name);
-
-
        /* now for the actual list of GIDs */
        if (-1 == getgrouplist(pwd->pw_name, pwd->pw_gid, *list, &ngroups))
                return -1;
@@ -587,16 +585,20 @@ fprintf(stderr, "KZAK>>> alloc '%p' for %s\n", *list, pwd->pw_name);
 #ifdef __linux__
 static int get_nprocs(const uid_t uid)
 {
+       DIR *dir;
+       struct dirent *d;
        int nprocs = 0;
-       pid_t pid;
-       struct proc_processes *proc = proc_open_processes();
 
-       proc_processes_filter_by_uid(proc, uid);
+       dir = opendir(_PATH_PROC);
+       if (!dir)
+               return 0;
 
-       while (!proc_next_pid(proc, &pid))
-               ++nprocs;
+       while ((d = xreaddir(dir))) {
+               if (procfs_dirent_match_uid(dir, d, uid))
+                       ++nprocs;
+       }
 
-       proc_close_processes(proc);
+       closedir(dir);
        return nprocs;
 }
 #endif