Line 0
Link Here
|
|
|
1 |
--- glib/gspawn.c 2018-09-21 12:29:23.000000000 +0300 |
2 |
+++ glib/gspawn.c 2019-07-20 18:05:15.486558000 +0300 |
3 |
@@ -51,6 +51,13 @@ |
4 |
#include <sys/syscall.h> /* for syscall and SYS_getdents64 */ |
5 |
#endif |
6 |
|
7 |
+#ifdef __FreeBSD__ |
8 |
+#include <sys/param.h> |
9 |
+#include <sys/sysctl.h> |
10 |
+#include <sys/user.h> |
11 |
+#include <sys/file.h> |
12 |
+#endif |
13 |
+ |
14 |
#include "gspawn.h" |
15 |
#include "gspawn-private.h" |
16 |
#include "gthread.h" |
17 |
@@ -1204,6 +1211,51 @@ |
18 |
} |
19 |
#endif |
20 |
|
21 |
+#ifdef __FreeBSD__ |
22 |
+static int |
23 |
+fdwalk2(int (*func)(void *, int), void *udata, int *ret) { |
24 |
+ size_t i, bufsz = 0; |
25 |
+ struct xfile *xfbuf, *xf; |
26 |
+ int uret = 0, pid_found = 0; |
27 |
+ int mib[2] = { CTL_KERN, KERN_FILE }; |
28 |
+ pid_t pid; |
29 |
+ |
30 |
+ if (NULL == func) |
31 |
+ return EINVAL; |
32 |
+ |
33 |
+ if (sysctl (mib, nitems(mib), NULL, &bufsz, NULL, 0) == -1) |
34 |
+ return (errno); |
35 |
+ bufsz += 65536; |
36 |
+ xfbuf = alloca (bufsz); |
37 |
+ if (xfbuf == NULL) |
38 |
+ return errno; |
39 |
+ if (sysctl (mib, 2, xfbuf, &bufsz, NULL, 0) == -1) |
40 |
+ return errno; |
41 |
+ bufsz /= sizeof(struct xfile); |
42 |
+ |
43 |
+ pid = getpid(); |
44 |
+ for (i = 0; i < bufsz; i++) { |
45 |
+ xf = &xfbuf[i]; |
46 |
+ if (pid != xf->xf_pid) { |
47 |
+ if (pid_found) { |
48 |
+ return 0; |
49 |
+ } else { |
50 |
+ continue; |
51 |
+ } |
52 |
+ } |
53 |
+ pid_found = 1; |
54 |
+ if (0 > xf->xf_fd) |
55 |
+ continue; |
56 |
+ uret = func (udata, xf->xf_fd); |
57 |
+ if (uret != 0) |
58 |
+ break; |
59 |
+ |
60 |
+ } |
61 |
+ |
62 |
+ return 0; |
63 |
+} |
64 |
+#endif |
65 |
+ |
66 |
/* This function is called between fork() and exec() and hence must be |
67 |
* async-signal-safe (see signal-safety(7)). */ |
68 |
static int |
69 |
@@ -1228,6 +1280,12 @@ |
70 |
|
71 |
#if 0 && defined(HAVE_SYS_RESOURCE_H) |
72 |
struct rlimit rl; |
73 |
+#endif |
74 |
+ |
75 |
+#ifdef __FreeBSD__ |
76 |
+ if (fdwalk2(cb, data, &res) == 0) |
77 |
+ return res; |
78 |
+ /* If any sysctl/malloc call fails continue with the fall back method */ |
79 |
#endif |
80 |
|
81 |
#ifdef __linux__ |