summaryrefslogtreecommitdiffstats
path: root/dwl-patches/patches/swallow/swallow-freebsd.patch
blob: 795a5e10b5aae6a11edd579fb96baabf1b907dbf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
From 301e1b368d92a32a7bdcd4bd1f0ede0295977e3e Mon Sep 17 00:00:00 2001
From: Nikita Ivanov <nikita.vyach.ivanov@gmail.com>
Date: Mon, 3 Mar 2025 19:49:07 +0100
Subject: [PATCH] swallow: add FreeBSD support

---
 dwl.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/dwl.c b/dwl.c
index 71d500a..52fdd9c 100644
--- a/dwl.c
+++ b/dwl.c
@@ -67,6 +67,14 @@
 #include <xcb/xcb_icccm.h>
 #endif
 
+#ifdef __FreeBSD__
+#define __BSD_VISIBLE
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <sys/user.h>
+#endif
+
 #include "util.h"
 
 /* macros */
@@ -2032,6 +2040,7 @@ outputmgrtest(struct wl_listener *listener, void *data)
 pid_t
 parentpid(pid_t pid)
 {
+#ifdef __linux__
 	unsigned int v = 0;
 	FILE *f;
 	char buf[256];
@@ -2041,6 +2050,14 @@ parentpid(pid_t pid)
 	fscanf(f, "%*u %*s %*c %u", &v);
 	fclose(f);
 	return (pid_t)v;
+#elif defined(__FreeBSD__)
+	struct kinfo_proc kip;
+	size_t len = sizeof(struct kinfo_proc);
+	int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, p };
+	if (sysctl(mib, 4, &kip, &len, NULL, 0) < 0 || len == 0)
+		return 0;
+	return kip.ki_ppid;
+#endif
 }
 
 void
-- 
2.49.0