summaryrefslogtreecommitdiff
path: root/dwm.c
diff options
context:
space:
mode:
authoraajonusonline <62964550+aajonusonline@users.noreply.github.com>2020-05-18 23:30:49 +0300
committerGitHub <noreply@github.com>2020-05-18 23:30:49 +0300
commit12c731865e92d524f91163fa0dd54bd96aa9e6ab (patch)
treeed6b757ad9c3a2d695c0a3fe6347bc42c587b184 /dwm.c
parent1c7d57451b42850ff1e81bfdaac5cf52f3ae0d50 (diff)
swallow patch: add FreeBSD support
patch from this commit: https://github.com/deadpixi/deadpixi-dwm/commit/42a798c34b4a4182599fc09f661c3b826a77bd54
Diffstat (limited to 'dwm.c')
-rw-r--r--dwm.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/dwm.c b/dwm.c
index c58300f..11dd32b 100644
--- a/dwm.c
+++ b/dwm.c
@@ -2405,18 +2405,25 @@ getparentprocess(pid_t p)
{
unsigned int v = 0;
-#ifdef __linux__
+#if defined(__linux__)
FILE *f;
char buf[256];
snprintf(buf, sizeof(buf) - 1, "/proc/%u/stat", (unsigned)p);
if (!(f = fopen(buf, "r")))
- return 0;
+ return (pid_t)0;
- fscanf(f, "%*u %*s %*c %u", &v);
+ if (fscanf(f, "%*u %*s %*c %u", (unsigned *)&v) != 1)
+ v = (pid_t)0;
fclose(f);
-#endif /* __linux__ */
+#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;
}