netstar pushed a commit to branch master.

http://git.enlightenment.org/apps/evisum.git/commit/?id=4a1c0649727dc12ee85f1981574418e39d35d4af

commit 4a1c0649727dc12ee85f1981574418e39d35d4af
Author: Alastair Poole <nets...@gmail.com>
Date:   Fri Feb 26 08:33:07 2021 +0000

    fbsd: nfiles.
    
    Interesting.
---
 meson.build              |  6 +++++-
 src/bin/system/process.c | 19 +++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/meson.build b/meson.build
index 5ffa0cc..d36f644 100644
--- a/meson.build
+++ b/meson.build
@@ -14,10 +14,14 @@ cc = meson.get_compiler('c')
 deps = dependency('elementary', version: efl_version)
 
 deps_os = declare_dependency(link_args : [] )
-if host_os == 'openbsd' or host_os == 'freebsd' or host_os == 'dragonfly'
+if host_os == 'openbsd' or host_os == 'dragonfly'
   deps_os = declare_dependency(link_args : [ '-lkvm' ])
 endif
 
+if host_os == 'freebsd'
+  deps_os = declare_dependency(link_args : [ '-lkvm', '-lprocstat' ])
+endif
+
 ##### dir locations
 dir_prefix = get_option('prefix')
 dir_bin    = join_paths(dir_prefix, get_option('bindir'))
diff --git a/src/bin/system/process.c b/src/bin/system/process.c
index 299da72..f533048 100644
--- a/src/bin/system/process.c
+++ b/src/bin/system/process.c
@@ -21,6 +21,10 @@
 # include <sys/resource.h>
 #endif
 
+#if defined(__FreeBSD__)
+#include <libprocstat.h>
+#endif
+
 #if defined(__MacOS__)
 # include <libproc.h>
 # include <sys/proc_info.h>
@@ -910,6 +914,7 @@ _proc_thread_info(struct kinfo_proc *kp, Eina_Bool 
is_thread)
    struct rusage *usage;
    const char *state;
    Proc_Info *p;
+   char buf[128];
    static int pagesize = 0;
 
    if (!pagesize) pagesize = getpagesize();
@@ -949,6 +954,20 @@ _proc_thread_info(struct kinfo_proc *kp, Eina_Bool 
is_thread)
    p->priority = kp->ki_pri.pri_level - PZERO;
    p->numthreads = kp->ki_numthreads;
 
+   struct procstat *procstat = procstat_open_sysctl();
+   struct filestat *fst;
+   struct filestat_list *head, *next;
+
+   head = procstat_getfiles(procstat, kp, 0);
+   STAILQ_FOREACH(fst, head, next)
+     {
+        if (fst->fs_fd < 0) continue;
+        snprintf(buf, sizeof(buf), "%i", fst->fs_fd);
+        p->fds = eina_list_append(p->fds, strdup(buf));
+     }
+   p->numfiles = eina_list_count(p->fds);
+   procstat_freefiles(procstat, head);
+
    p->tid = kp->ki_tid;
    p->thread_name = strdup(kp->ki_tdname);
    if (kp->ki_flag & P_KPROC) p->is_kernel = 1;

-- 


Reply via email to