| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/globals.h" | 5 #include "platform/globals.h" |
| 6 #if defined(TARGET_OS_LINUX) | 6 #if defined(TARGET_OS_LINUX) |
| 7 | 7 |
| 8 #include "bin/eventhandler.h" | 8 #include "bin/eventhandler.h" |
| 9 | 9 |
| 10 #include <errno.h> // NOLINT | 10 #include <errno.h> // NOLINT |
| 11 #include <pthread.h> // NOLINT | 11 #include <pthread.h> // NOLINT |
| 12 #include <stdio.h> // NOLINT | 12 #include <stdio.h> // NOLINT |
| 13 #include <string.h> // NOLINT | 13 #include <string.h> // NOLINT |
| 14 #include <sys/epoll.h> // NOLINT | 14 #include <sys/epoll.h> // NOLINT |
| 15 #include <sys/stat.h> // NOLINT | 15 #include <sys/stat.h> // NOLINT |
| 16 #include <unistd.h> // NOLINT | 16 #include <unistd.h> // NOLINT |
| 17 #include <fcntl.h> // NOLINT |
| 17 | 18 |
| 18 #include "bin/dartutils.h" | 19 #include "bin/dartutils.h" |
| 19 #include "bin/fdutils.h" | 20 #include "bin/fdutils.h" |
| 20 #include "bin/log.h" | 21 #include "bin/log.h" |
| 21 #include "bin/utils.h" | 22 #include "bin/utils.h" |
| 22 #include "platform/hashmap.h" | 23 #include "platform/hashmap.h" |
| 23 #include "platform/thread.h" | 24 #include "platform/thread.h" |
| 24 #include "platform/utils.h" | 25 #include "platform/utils.h" |
| 25 | 26 |
| 26 | 27 |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 ASSERT(msg.data == (1 << kShutdownWriteCommand)); | 217 ASSERT(msg.data == (1 << kShutdownWriteCommand)); |
| 217 // Close the socket for writing. | 218 // Close the socket for writing. |
| 218 sd->ShutdownWrite(); | 219 sd->ShutdownWrite(); |
| 219 UpdateEpollInstance(epoll_fd_, sd); | 220 UpdateEpollInstance(epoll_fd_, sd); |
| 220 } else if ((msg.data & (1 << kCloseCommand)) != 0) { | 221 } else if ((msg.data & (1 << kCloseCommand)) != 0) { |
| 221 ASSERT(msg.data == (1 << kCloseCommand)); | 222 ASSERT(msg.data == (1 << kCloseCommand)); |
| 222 // Close the socket and free system resources and move on to | 223 // Close the socket and free system resources and move on to |
| 223 // next message. | 224 // next message. |
| 224 RemoveFromEpollInstance(epoll_fd_, sd); | 225 RemoveFromEpollInstance(epoll_fd_, sd); |
| 225 intptr_t fd = sd->fd(); | 226 intptr_t fd = sd->fd(); |
| 226 sd->Close(); | 227 if (fd == STDOUT_FILENO) { |
| 228 // If stdout, redirect fd to /dev/null. |
| 229 int null_fd = TEMP_FAILURE_RETRY(open("/dev/null", O_WRONLY)); |
| 230 ASSERT(null_fd >= 0); |
| 231 VOID_TEMP_FAILURE_RETRY(dup2(null_fd, STDOUT_FILENO)); |
| 232 VOID_TEMP_FAILURE_RETRY(close(null_fd)); |
| 233 } else { |
| 234 sd->Close(); |
| 235 } |
| 227 socket_map_.Remove(GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd)); | 236 socket_map_.Remove(GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd)); |
| 228 delete sd; | 237 delete sd; |
| 229 } else { | 238 } else { |
| 230 if ((msg.data & (1 << kInEvent)) != 0 && sd->IsClosedRead()) { | 239 if ((msg.data & (1 << kInEvent)) != 0 && sd->IsClosedRead()) { |
| 231 DartUtils::PostInt32(msg.dart_port, 1 << kCloseEvent); | 240 DartUtils::PostInt32(msg.dart_port, 1 << kCloseEvent); |
| 232 } else { | 241 } else { |
| 233 // Setup events to wait for. | 242 // Setup events to wait for. |
| 234 sd->SetPortAndMask(msg.dart_port, msg.data); | 243 sd->SetPortAndMask(msg.dart_port, msg.data); |
| 235 UpdateEpollInstance(epoll_fd_, sd); | 244 UpdateEpollInstance(epoll_fd_, sd); |
| 236 } | 245 } |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 | 442 |
| 434 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { | 443 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { |
| 435 // The hashmap does not support keys with value 0. | 444 // The hashmap does not support keys with value 0. |
| 436 return dart::Utils::WordHash(fd + 1); | 445 return dart::Utils::WordHash(fd + 1); |
| 437 } | 446 } |
| 438 | 447 |
| 439 } // namespace bin | 448 } // namespace bin |
| 440 } // namespace dart | 449 } // namespace dart |
| 441 | 450 |
| 442 #endif // defined(TARGET_OS_LINUX) | 451 #endif // defined(TARGET_OS_LINUX) |
| OLD | NEW |