From 4e0318919dd726f485ea3a495ff0989f69f35630 Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Sat, 6 Jun 2020 19:56:41 -0700 Subject: hand added swallow patch --- sys/cmd/dwm/util.c | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) (limited to 'sys/cmd/dwm/util.c') diff --git a/sys/cmd/dwm/util.c b/sys/cmd/dwm/util.c index 1306c9c..445d479 100644 --- a/sys/cmd/dwm/util.c +++ b/sys/cmd/dwm/util.c @@ -1,8 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include -#include -#include -#include +#include "dwm.h" void fatal(char *fmt, ...) { @@ -31,3 +28,39 @@ ecalloc(size_t nmemb, size_t size) fatal("calloc:"); return p; } + +pid_t +getparentprocess(pid_t p) +{ + uint v = 0; + +#if defined(__linux__) + Stream *f; + char buf[256]; + snprintf(buf, sizeof(buf) - 1, "/proc/%u/stat", (unsigned)p); + + if (!(f = fopen(buf, "r"))) + return (pid_t)0; + + if (fscanf(f, "%*u %*s %*c %u", (unsigned *)&v) != 1) + v = (pid_t)0; + fclose(f); +#elif defined(__FreeBSD__) + struct kinfo_proc *proc = kinfo_getproc(p); + if (!proc) + return (pid_t)0; + + v = proc->ki_ppid; + free(proc); +#endif + return (pid_t)v; +} + +int +isdescendent(pid_t p, pid_t c) +{ + while (p != c && c != 0) + c = getparentprocess(c); + + return (int)c; +} -- cgit v1.2.1