blob: 9058207e9e90ce4515f6d6e61ad0722f32568cf5 (
plain) (
blame)
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
|
--- third_party/crashpad/crashpad/util/posix/close_multiple.cc.orig 2021-04-14 18:41:34 UTC
+++ third_party/crashpad/crashpad/util/posix/close_multiple.cc
@@ -181,11 +181,37 @@ void CloseMultipleNowOrOnExec(int fd, int preserve_fd)
}
#endif
+#if defined(OS_BSD)
+ // If preserve_fd is in the space to be freed, copy it down.
+ bool copied = false;
+ if (preserve_fd >= fd) {
+ if (preserve_fd > fd) {
+ int rv = dup2(preserve_fd, fd);
+ if (rv != 0)
+ PLOG(WARNING) << "dup2";
+ copied = true;
+ }
+ fd++;
+ }
+ // Cloexec is only used for MACOS...
+ closefrom(fd);
+ // Put it back.
+ if (copied) {
+ fd--;
+ int rv = dup2(fd, preserve_fd);
+ if (rv != 0)
+ PLOG(WARNING) << "dup2";
+ rv = IGNORE_EINTR(close(fd));
+ if (rv != 0)
+ PLOG(WARNING) << "close";
+ }
+#else
for (int entry_fd = fd; entry_fd < max_fd; ++entry_fd) {
if (entry_fd != preserve_fd) {
CloseNowOrOnExec(entry_fd, true);
}
}
+#endif
}
} // namespace crashpad
|