Lines 1-64
Link Here
|
1 |
--- glib/gspawn.c 2018-09-21 12:29:23.000000000 +0300 |
1 |
--- glib/gspawn.c.orig 2020-12-17 03:47:11.474608400 -0800 |
2 |
+++ glib/gspawn.c 2019-07-20 18:05:15.486558000 +0300 |
2 |
+++ glib/gspawn.c 2021-02-17 13:58:15.271434000 -0800 |
3 |
@@ -51,6 +51,13 @@ |
3 |
@@ -51,6 +51,12 @@ |
4 |
#include <sys/syscall.h> /* for syscall and SYS_getdents64 */ |
4 |
#include <sys/syscall.h> /* for syscall and SYS_getdents64 */ |
5 |
#endif |
5 |
#endif |
6 |
|
6 |
|
7 |
+#ifdef __FreeBSD__ |
7 |
+#ifdef __FreeBSD__ |
8 |
+#include <sys/param.h> |
8 |
+#include <sys/types.h> |
9 |
+#include <sys/sysctl.h> |
|
|
10 |
+#include <sys/user.h> |
9 |
+#include <sys/user.h> |
11 |
+#include <sys/file.h> |
10 |
+#include <libutil.h> |
12 |
+#endif |
11 |
+#endif |
13 |
+ |
12 |
+ |
14 |
#include "gspawn.h" |
13 |
#include "gspawn.h" |
15 |
#include "gspawn-private.h" |
14 |
#include "gspawn-private.h" |
16 |
#include "gthread.h" |
15 |
#include "gthread.h" |
17 |
@@ -1204,6 +1211,51 @@ |
16 |
@@ -1204,6 +1210,33 @@ filename_to_fd (const char *p) |
18 |
} |
17 |
} |
19 |
#endif |
18 |
#endif |
20 |
|
19 |
|
21 |
+#ifdef __FreeBSD__ |
20 |
+#ifdef __FreeBSD__ |
22 |
+static int |
21 |
+static int |
23 |
+fdwalk2(int (*func)(void *, int), void *udata, int *ret) { |
22 |
+fdwalk2(int (*func)(void *, int), void *udata, gint *ret) |
24 |
+ size_t i, bufsz = 0; |
23 |
+{ |
25 |
+ struct xfile *xfbuf, *xf; |
24 |
+ struct kinfo_file *kf; |
26 |
+ int uret = 0, pid_found = 0; |
25 |
+ int i, cnt; |
27 |
+ int mib[2] = { CTL_KERN, KERN_FILE }; |
|
|
28 |
+ pid_t pid; |
29 |
+ |
26 |
+ |
30 |
+ if (NULL == func) |
27 |
+ if (NULL == func) |
31 |
+ return EINVAL; |
28 |
+ return EINVAL; |
32 |
+ |
29 |
+ |
33 |
+ if (sysctl (mib, nitems(mib), NULL, &bufsz, NULL, 0) == -1) |
30 |
+ kf = kinfo_getfile(getpid(), &cnt); |
34 |
+ return (errno); |
31 |
+ if (kf == NULL) |
35 |
+ bufsz += 65536; |
32 |
+ return ENOMEM; |
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 |
+ |
33 |
+ |
43 |
+ pid = getpid(); |
34 |
+ for (i = 0; i < cnt; i++) { |
44 |
+ for (i = 0; i < bufsz; i++) { |
35 |
+ if (0 > kf[i].kf_fd) |
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; |
36 |
+ continue; |
56 |
+ uret = func (udata, xf->xf_fd); |
37 |
+ *ret = func (udata, kf[i].kf_fd); |
57 |
+ if (uret != 0) |
38 |
+ if (*ret != 0) |
58 |
+ break; |
39 |
+ break; |
59 |
+ |
|
|
60 |
+ } |
40 |
+ } |
61 |
+ |
41 |
+ |
|
|
42 |
+ free(kf); |
62 |
+ return 0; |
43 |
+ return 0; |
63 |
+} |
44 |
+} |
64 |
+#endif |
45 |
+#endif |
Lines 66-72
Link Here
|
66 |
/* This function is called between fork() and exec() and hence must be |
47 |
/* This function is called between fork() and exec() and hence must be |
67 |
* async-signal-safe (see signal-safety(7)). */ |
48 |
* async-signal-safe (see signal-safety(7)). */ |
68 |
static int |
49 |
static int |
69 |
@@ -1228,6 +1280,12 @@ |
50 |
@@ -1228,6 +1261,12 @@ safe_fdwalk (int (*cb)(void *data, int fd), void *data |
70 |
|
51 |
|
71 |
#if 0 && defined(HAVE_SYS_RESOURCE_H) |
52 |
#if 0 && defined(HAVE_SYS_RESOURCE_H) |
72 |
struct rlimit rl; |
53 |
struct rlimit rl; |