summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlastair Poole <netstar@gmail.com>2020-04-29 09:50:55 +0100
committerAlastair Poole <netstar@gmail.com>2020-04-29 09:50:55 +0100
commitbda2a5112476a6185574740a857729de4fa9a485 (patch)
tree00de3a1d0d5ccd02f58d0e415eb5b61340fa2af8
parent41a8e8b7ca911448c0c4f6a0a960aba961afd36c (diff)
FreeBSD: Obtain correct PID_MAX (Fallback).v0.4.0
-rw-r--r--src/bin/process.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/src/bin/process.c b/src/bin/process.c
index c48c41a..0d12298 100644
--- a/src/bin/process.c
+++ b/src/bin/process.c
@@ -676,6 +676,30 @@ proc_info_by_pid(int pid)
676#endif 676#endif
677 677
678#if defined(__FreeBSD__) || defined(__DragonFly__) 678#if defined(__FreeBSD__) || defined(__DragonFly__)
679
680static int
681_pid_max(void)
682{
683 size_t len;
684 static int pid_max = 0;
685
686 if (pid_max != 0) return pid_max;
687
688 len = sizeof(pid_max);
689 if (sysctlbyname("kern.pid_max", &pid_max, &len, NULL, 0) == -1)
690 {
691#if defined(__FreeBSD__)
692 pid_max = 99999;
693#elif defined(__DragonFly__)
694 pid_max = 999999;
695#else
696 pid_max = PID_MAX;
697#endif
698 }
699
700 return pid_max;
701}
702
679static Eina_List * 703static Eina_List *
680_process_list_freebsd_fallback_get(void) 704_process_list_freebsd_fallback_get(void)
681{ 705{
@@ -684,18 +708,20 @@ _process_list_freebsd_fallback_get(void)
684 struct kinfo_proc kp; 708 struct kinfo_proc kp;
685 int mib[4]; 709 int mib[4];
686 size_t len; 710 size_t len;
687 static int pagesize = 0; 711 static int pid_max, pagesize = 0;
688 712
689 if (!pagesize) 713 if (!pagesize)
690 pagesize = getpagesize(); 714 pagesize = getpagesize();
691 715
716 pid_max = _pid_max();
717
692 list = NULL; 718 list = NULL;
693 719
694 len = sizeof(int); 720 len = sizeof(int);
695 if (sysctlnametomib("kern.proc.pid", mib, &len) == -1) 721 if (sysctlnametomib("kern.proc.pid", mib, &len) == -1)
696 return NULL; 722 return NULL;
697 723
698 for (int i = 1; i <= PID_MAX; i++) 724 for (int i = 1; i <= pid_max; i++)
699 { 725 {
700 mib[3] = i; 726 mib[3] = i;
701 len = sizeof(kp); 727 len = sizeof(kp);