Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(621)

Side by Side Diff: runtime/bin/eventhandler_linux.cc

Issue 18031003: Stop printing when stdout is closed. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Use dup2 Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
kustermann 2013/06/27 15:14:07 If you need this here, you probably also need it f
Anders Johnsen 2013/06/27 16:32:07 Done.
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
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 USE(dup2(open("/dev/null", O_WRONLY), STDOUT_FILENO));
230 } else {
231 sd->Close();
232 }
227 socket_map_.Remove(GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd)); 233 socket_map_.Remove(GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd));
228 delete sd; 234 delete sd;
229 } else { 235 } else {
230 if ((msg.data & (1 << kInEvent)) != 0 && sd->IsClosedRead()) { 236 if ((msg.data & (1 << kInEvent)) != 0 && sd->IsClosedRead()) {
231 DartUtils::PostInt32(msg.dart_port, 1 << kCloseEvent); 237 DartUtils::PostInt32(msg.dart_port, 1 << kCloseEvent);
232 } else { 238 } else {
233 // Setup events to wait for. 239 // Setup events to wait for.
234 sd->SetPortAndMask(msg.dart_port, msg.data); 240 sd->SetPortAndMask(msg.dart_port, msg.data);
235 UpdateEpollInstance(epoll_fd_, sd); 241 UpdateEpollInstance(epoll_fd_, sd);
236 } 242 }
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 439
434 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { 440 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) {
435 // The hashmap does not support keys with value 0. 441 // The hashmap does not support keys with value 0.
436 return dart::Utils::WordHash(fd + 1); 442 return dart::Utils::WordHash(fd + 1);
437 } 443 }
438 444
439 } // namespace bin 445 } // namespace bin
440 } // namespace dart 446 } // namespace dart
441 447
442 #endif // defined(TARGET_OS_LINUX) 448 #endif // defined(TARGET_OS_LINUX)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698