| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <dirent.h> | 5 #include <dirent.h> |
| 6 #include <errno.h> | 6 #include <errno.h> |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <stdarg.h> | 8 #include <stdarg.h> |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 for (int *fd, i = 0; (fd = va_arg(ap, int *)) != NULL; ++i) { | 111 for (int *fd, i = 0; (fd = va_arg(ap, int *)) != NULL; ++i) { |
| 112 *fd = (reinterpret_cast<int *>(CMSG_DATA(cmsg)))[i]; | 112 *fd = (reinterpret_cast<int *>(CMSG_DATA(cmsg)))[i]; |
| 113 } | 113 } |
| 114 va_end(ap); | 114 va_end(ap); |
| 115 return true; | 115 return true; |
| 116 } | 116 } |
| 117 | 117 |
| 118 void Util::closeAllBut(int fd, ...) { | 118 void Util::closeAllBut(int fd, ...) { |
| 119 int proc_fd; | 119 int proc_fd; |
| 120 int fdir; | 120 int fdir; |
| 121 if ((proc_fd = Sandbox::getProcFd()) < 0 || | 121 if ((proc_fd = Sandbox::proc_fd()) < 0 || |
| 122 (fdir = openat(proc_fd, "self/fd", O_RDONLY|O_DIRECTORY)) < 0) { | 122 (fdir = openat(proc_fd, "self/fd", O_RDONLY|O_DIRECTORY)) < 0) { |
| 123 Sandbox::die("Cannot access \"/proc/self/fd\""); | 123 Sandbox::die("Cannot access \"/proc/self/fd\""); |
| 124 } | 124 } |
| 125 int dev_null = open("/dev/null", O_RDWR); | 125 int dev_null = open("/dev/null", O_RDWR); |
| 126 DIR *dir = fdopendir(fdir); | 126 DIR *dir = fdopendir(fdir); |
| 127 struct dirent de, *res; | 127 struct dirent de, *res; |
| 128 while (!readdir_r(dir, &de, &res) && res) { | 128 while (!readdir_r(dir, &de, &res) && res) { |
| 129 if (res->d_name[0] < '0') { | 129 if (res->d_name[0] < '0') { |
| 130 continue; | 130 continue; |
| 131 } | 131 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 155 } | 155 } |
| 156 } | 156 } |
| 157 closedir(dir); | 157 closedir(dir); |
| 158 if (dev_null >= 0) { | 158 if (dev_null >= 0) { |
| 159 if (HANDLE_EINTR(close(dev_null))) { } | 159 if (HANDLE_EINTR(close(dev_null))) { } |
| 160 } | 160 } |
| 161 return; | 161 return; |
| 162 } | 162 } |
| 163 | 163 |
| 164 } // namespace | 164 } // namespace |
| OLD | NEW |