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

Side by Side Diff: runtime/bin/process.h

Issue 119093007: Signal handling, take 2. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years 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
« no previous file with comments | « runtime/bin/io_natives.cc ('k') | runtime/bin/process.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef BIN_PROCESS_H_ 5 #ifndef BIN_PROCESS_H_
6 #define BIN_PROCESS_H_ 6 #define BIN_PROCESS_H_
7 7
8 #include "bin/builtin.h" 8 #include "bin/builtin.h"
9 #include "bin/io_buffer.h" 9 #include "bin/io_buffer.h"
10 #include "bin/thread.h" 10 #include "bin/thread.h"
(...skipping 23 matching lines...) Expand all
34 34
35 private: 35 private:
36 Dart_Handle stdout_data_; 36 Dart_Handle stdout_data_;
37 Dart_Handle stderr_data_; 37 Dart_Handle stderr_data_;
38 intptr_t exit_code_; 38 intptr_t exit_code_;
39 39
40 DISALLOW_ALLOCATION(); 40 DISALLOW_ALLOCATION();
41 }; 41 };
42 42
43 43
44 // To be kept in sync with ProcessSignal consts in sdk/lib/io/process.dart
45 // Note that this map is as on Linux.
46 enum ProcessSignals {
47 kSighup = 1,
48 kSigint = 2,
49 kSigquit = 3,
50 kSigill = 4,
51 kSigtrap = 5,
52 kSigabrt = 6,
53 kSigbus = 7,
54 kSigfpe = 8,
55 kSigkill = 9,
56 kSigusr1 = 10,
57 kSigsegv = 11,
58 kSigusr2 = 12,
59 kSigpipe = 13,
60 kSigalrm = 14,
61 kSigterm = 15,
62 kSigchld = 17,
63 kSigcont = 18,
64 kSigstop = 19,
65 kSigtstp = 20,
66 kSigttin = 21,
67 kSigttou = 22,
68 kSigurg = 23,
69 kSigxcpu = 24,
70 kSigxfsz = 25,
71 kSigvtalrm = 26,
72 kSigprof = 27,
73 kSigwinch = 28,
74 kSigpoll = 29,
75 kSigsys = 31
76 };
77
78
44 class Process { 79 class Process {
45 public: 80 public:
46 // Start a new process providing access to stdin, stdout, stderr and 81 // Start a new process providing access to stdin, stdout, stderr and
47 // process exit streams. 82 // process exit streams.
48 static int Start(const char* path, 83 static int Start(const char* path,
49 char* arguments[], 84 char* arguments[],
50 intptr_t arguments_length, 85 intptr_t arguments_length,
51 const char* working_directory, 86 const char* working_directory,
52 char* environment[], 87 char* environment[],
53 intptr_t environment_length, 88 intptr_t environment_length,
(...skipping 23 matching lines...) Expand all
77 return global_exit_code_; 112 return global_exit_code_;
78 } 113 }
79 114
80 static void SetGlobalExitCode(int exit_code) { 115 static void SetGlobalExitCode(int exit_code) {
81 MutexLocker ml(global_exit_code_mutex_); 116 MutexLocker ml(global_exit_code_mutex_);
82 global_exit_code_ = exit_code; 117 global_exit_code_ = exit_code;
83 } 118 }
84 119
85 static intptr_t CurrentProcessId(); 120 static intptr_t CurrentProcessId();
86 121
122 static intptr_t SetSignalHandler(intptr_t signal);
123 static void ClearSignalHandler(intptr_t signal);
124
87 static Dart_Handle GetProcessIdNativeField(Dart_Handle process, 125 static Dart_Handle GetProcessIdNativeField(Dart_Handle process,
88 intptr_t* pid); 126 intptr_t* pid);
89 static Dart_Handle SetProcessIdNativeField(Dart_Handle process, 127 static Dart_Handle SetProcessIdNativeField(Dart_Handle process,
90 intptr_t pid); 128 intptr_t pid);
91 129
92 private: 130 private:
93 static int global_exit_code_; 131 static int global_exit_code_;
94 static dart::Mutex* global_exit_code_mutex_; 132 static dart::Mutex* global_exit_code_mutex_;
95 133
96 DISALLOW_ALLOCATION(); 134 DISALLOW_ALLOCATION();
97 DISALLOW_IMPLICIT_CONSTRUCTORS(Process); 135 DISALLOW_IMPLICIT_CONSTRUCTORS(Process);
98 }; 136 };
99 137
100 138
139 class SignalInfo {
140 public:
141 SignalInfo(int fd, int signal, SignalInfo* prev = NULL)
142 : fd_(fd),
143 signal_(signal),
144 // SignalInfo is expected to be created when in a isolate.
145 port_(Dart_GetMainPortId()),
146 next_(NULL),
147 prev_(prev) {
148 if (prev_ != NULL) {
149 prev_->next_ = this;
150 }
151 }
152
153 ~SignalInfo();
154
155 void Unlink() {
156 if (prev_ != NULL) {
157 prev_->next_ = next_;
158 }
159 if (next_ != NULL) {
160 next_->prev_ = prev_;
161 }
162 }
163
164 int fd() const { return fd_; }
165 int signal() const { return signal_; }
166 Dart_Port port() const { return port_; }
167 SignalInfo* next() const { return next_; }
168
169 private:
170 int fd_;
171 int signal_;
172 // The port_ is used to identify what isolate the signal-info belongs to.
173 Dart_Port port_;
174 SignalInfo* next_;
175 SignalInfo* prev_;
176 };
177
178
101 // Utility class for collecting the output when running a process 179 // Utility class for collecting the output when running a process
102 // synchronously by using Process::Wait. This class is sub-classed in 180 // synchronously by using Process::Wait. This class is sub-classed in
103 // the platform specific files to implement reading into the buffers 181 // the platform specific files to implement reading into the buffers
104 // allocated. 182 // allocated.
105 class BufferListBase { 183 class BufferListBase {
106 protected: 184 protected:
107 static const intptr_t kBufferSize = 16 * 1024; 185 static const intptr_t kBufferSize = 16 * 1024;
108 186
109 class BufferListNode { 187 class BufferListNode {
110 public: 188 public:
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 intptr_t data_size_; 274 intptr_t data_size_;
197 275
198 // Number of free bytes in the last node in the list. 276 // Number of free bytes in the last node in the list.
199 intptr_t free_size_; 277 intptr_t free_size_;
200 }; 278 };
201 279
202 } // namespace bin 280 } // namespace bin
203 } // namespace dart 281 } // namespace dart
204 282
205 #endif // BIN_PROCESS_H_ 283 #endif // BIN_PROCESS_H_
OLDNEW
« no previous file with comments | « runtime/bin/io_natives.cc ('k') | runtime/bin/process.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698