From 6f4113bcac8e9aace2e5b771fd2b86893b2549c4 Mon Sep 17 00:00:00 2001 From: Al Poole Date: Sun, 25 Jun 2017 09:24:35 +0100 Subject: [PATCH] debugpanel: fix OSX and add OpenBSD support. Reviewers: ajwillia.ms Reviewed By: ajwillia.ms Differential Revision: https://phab.enlightenment.org/D4893 --- src/bin/edi_debugpanel.c | 51 +++++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/src/bin/edi_debugpanel.c b/src/bin/edi_debugpanel.c index e7e4096..60dc420 100644 --- a/src/bin/edi_debugpanel.c +++ b/src/bin/edi_debugpanel.c @@ -2,12 +2,16 @@ # include "config.h" #endif -#if defined(__FreeBSD__) || defined(__DragonFly__) || defined (__APPLE__) +#if defined(__FreeBSD__) || defined(__DragonFly__) || defined (__APPLE__) || defined(__OpenBSD__) #include #include #include #include #endif +#if defined(__OpenBSD__) + #include +#endif + #include #include #include @@ -56,7 +60,9 @@ _debugpanel_stdout_handler(void *data EINA_UNUSED, int type EINA_UNUSED, void *e { if (ev->size >= (int)(sizeof(buf) -2)) return ECORE_CALLBACK_DONE; - snprintf(buf, ev->size + 1, "%s", (char *)ev->data); + memcpy(buf, ev->data, ev->size); + buf[ev->size] = 0; + pos = buf; start = pos; if (*start == '\n') start++; @@ -133,9 +139,9 @@ _edi_debug_process_id(int *state) { const char *program_name; int my_pid, child_pid = -1; -#if defined(__FreeBSD__) || defined(__DragonFly__) || defined (__APPLE__) +#if defined(__FreeBSD__) || defined(__DragonFly__) || defined (__APPLE__) || defined(__OpenBSD__) struct kinfo_proc kp; - int mib[4]; + int mib[6]; size_t len; int max_pid, i; @@ -143,20 +149,37 @@ _edi_debug_process_id(int *state) if (!_debug_exe) return -1; +#if defined(__FreeBSD__) || defined(__DragonFly__) len = sizeof(max_pid); max_pid = _sysctlfromname("kern.lastpid", mib, 2, &len); - +#elif defined(PID_MAX) + max_pid = PID_MAX; +#else + max_pid = 99999; +#endif my_pid = ecore_exe_pid_get(_debug_exe); +#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__APPLE__) if (sysctlnametomib("kern.proc.pid", mib, &len) < 0) return -1; - +#elif defined(__OpenBSD__) + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = KERN_PROC_PID; + mib[4] = sizeof(struct kinfo_proc); + mib[5] = 1; +#endif program_name = ecore_file_file_get(_edi_project_config->launch.path); for (i = my_pid; i <= max_pid; i++) { mib[3] = i; len = sizeof(kp); - sysctl(mib, 4, &kp, &len, NULL, 0); +#if defined(__OpenBSD__) + if (sysctl(mib, 6, &kp, &len, NULL, 0) == -1) continue; +#else + if (sysctl(mib, 4, &kp, &len, NULL, 0) == -1) continue; +#endif + #if defined(__FreeBSD__) || defined(__DragonFly__) if (kp.ki_ppid != my_pid) continue; if (strcmp(program_name, kp.ki_comm)) continue; @@ -168,7 +191,19 @@ _edi_debug_process_id(int *state) else *state = DEBUG_PROCESS_SLEEPING; } -#else +#elif defined(__OpenBSD__) + if (kp.p_ppid != my_pid) continue; + if (strcmp(program_name, kp.p_comm)) continue; + child_pid = kp.p_pid; + + if (state) + { + if (kp.p_stat == SRUN || kp.p_stat == SSLEEP) + *state = DEBUG_PROCESS_ACTIVE; + else + *state = DEBUG_PROCESS_SLEEPING; + } +#else /* APPLE */ if (kp.kp_proc.p_oppid != my_pid) continue; if (strcmp(program_name, kp.kp_proc.p_comm)) continue; child_pid = kp.kp_proc.p_pid;