Chromium Code Reviews| 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 #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 Loading... | |
| 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 enum ProcessSignals { | |
|
Søren Gjesse
2013/12/19 15:05:37
Please add a comment that these constants need to
Anders Johnsen
2013/12/19 15:07:41
Done.
| |
| 45 kSighup = 1, | |
| 46 kSigint = 2, | |
| 47 kSigquit = 3, | |
| 48 kSigill = 4, | |
| 49 kSigtrap = 5, | |
| 50 kSigabrt = 6, | |
| 51 kSigbus = 7, | |
| 52 kSigfpe = 8, | |
| 53 kSigkill = 9, | |
| 54 kSigusr1 = 10, | |
| 55 kSigsegv = 11, | |
| 56 kSigusr2 = 12, | |
| 57 kSigpipe = 13, | |
| 58 kSigalrm = 14, | |
| 59 kSigterm = 15, | |
| 60 kSigchld = 17, | |
| 61 kSigcont = 18, | |
| 62 kSigstop = 19, | |
| 63 kSigtstp = 20, | |
| 64 kSigttin = 21, | |
| 65 kSigttou = 22, | |
| 66 kSigurg = 23, | |
| 67 kSigxcpu = 24, | |
| 68 kSigxfsz = 25, | |
| 69 kSigvtalrm = 26, | |
| 70 kSigprof = 27, | |
| 71 kSigwinch = 28, | |
| 72 kSigpoll = 29, | |
| 73 kSigsys = 31 | |
| 74 }; | |
| 75 | |
| 76 | |
| 44 class Process { | 77 class Process { |
| 45 public: | 78 public: |
| 46 // Start a new process providing access to stdin, stdout, stderr and | 79 // Start a new process providing access to stdin, stdout, stderr and |
| 47 // process exit streams. | 80 // process exit streams. |
| 48 static int Start(const char* path, | 81 static int Start(const char* path, |
| 49 char* arguments[], | 82 char* arguments[], |
| 50 intptr_t arguments_length, | 83 intptr_t arguments_length, |
| 51 const char* working_directory, | 84 const char* working_directory, |
| 52 char* environment[], | 85 char* environment[], |
| 53 intptr_t environment_length, | 86 intptr_t environment_length, |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 77 return global_exit_code_; | 110 return global_exit_code_; |
| 78 } | 111 } |
| 79 | 112 |
| 80 static void SetGlobalExitCode(int exit_code) { | 113 static void SetGlobalExitCode(int exit_code) { |
| 81 MutexLocker ml(global_exit_code_mutex_); | 114 MutexLocker ml(global_exit_code_mutex_); |
| 82 global_exit_code_ = exit_code; | 115 global_exit_code_ = exit_code; |
| 83 } | 116 } |
| 84 | 117 |
| 85 static intptr_t CurrentProcessId(); | 118 static intptr_t CurrentProcessId(); |
| 86 | 119 |
| 120 static intptr_t SetSignalHandler(intptr_t signal); | |
| 121 static void ClearSignalHandler(intptr_t signal); | |
| 122 | |
| 87 static Dart_Handle GetProcessIdNativeField(Dart_Handle process, | 123 static Dart_Handle GetProcessIdNativeField(Dart_Handle process, |
| 88 intptr_t* pid); | 124 intptr_t* pid); |
| 89 static Dart_Handle SetProcessIdNativeField(Dart_Handle process, | 125 static Dart_Handle SetProcessIdNativeField(Dart_Handle process, |
| 90 intptr_t pid); | 126 intptr_t pid); |
| 91 | 127 |
| 92 private: | 128 private: |
| 93 static int global_exit_code_; | 129 static int global_exit_code_; |
| 94 static dart::Mutex* global_exit_code_mutex_; | 130 static dart::Mutex* global_exit_code_mutex_; |
| 95 | 131 |
| 96 DISALLOW_ALLOCATION(); | 132 DISALLOW_ALLOCATION(); |
| 97 DISALLOW_IMPLICIT_CONSTRUCTORS(Process); | 133 DISALLOW_IMPLICIT_CONSTRUCTORS(Process); |
| 98 }; | 134 }; |
| 99 | 135 |
| 100 | 136 |
| 137 class SignalInfo { | |
| 138 public: | |
| 139 SignalInfo(int fd, int signal, SignalInfo* prev = NULL) | |
| 140 : fd_(fd), | |
| 141 signal_(signal), | |
| 142 // SignalInfo is expected to be created when in a isolate. | |
| 143 port_(Dart_GetMainPortId()), | |
| 144 next_(NULL), | |
| 145 prev_(prev) { | |
| 146 if (prev_ != NULL) { | |
| 147 prev_->next_ = this; | |
| 148 } | |
| 149 } | |
| 150 | |
| 151 ~SignalInfo(); | |
| 152 | |
| 153 void Unlink() { | |
| 154 if (prev_ != NULL) { | |
| 155 prev_->next_ = next_; | |
| 156 } | |
| 157 if (next_ != NULL) { | |
| 158 next_->prev_ = prev_; | |
| 159 } | |
| 160 } | |
| 161 | |
| 162 int fd() const { return fd_; } | |
| 163 int signal() const { return signal_; } | |
| 164 Dart_Port port() const { return port_; } | |
| 165 SignalInfo* next() const { return next_; } | |
| 166 | |
| 167 private: | |
| 168 int fd_; | |
| 169 int signal_; | |
| 170 // The port_ is used to identify what isolate the signal-info belongs to. | |
| 171 Dart_Port port_; | |
| 172 SignalInfo* next_; | |
| 173 SignalInfo* prev_; | |
| 174 }; | |
| 175 | |
| 176 | |
| 101 // Utility class for collecting the output when running a process | 177 // Utility class for collecting the output when running a process |
| 102 // synchronously by using Process::Wait. This class is sub-classed in | 178 // synchronously by using Process::Wait. This class is sub-classed in |
| 103 // the platform specific files to implement reading into the buffers | 179 // the platform specific files to implement reading into the buffers |
| 104 // allocated. | 180 // allocated. |
| 105 class BufferListBase { | 181 class BufferListBase { |
| 106 protected: | 182 protected: |
| 107 static const intptr_t kBufferSize = 16 * 1024; | 183 static const intptr_t kBufferSize = 16 * 1024; |
| 108 | 184 |
| 109 class BufferListNode { | 185 class BufferListNode { |
| 110 public: | 186 public: |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 196 intptr_t data_size_; | 272 intptr_t data_size_; |
| 197 | 273 |
| 198 // Number of free bytes in the last node in the list. | 274 // Number of free bytes in the last node in the list. |
| 199 intptr_t free_size_; | 275 intptr_t free_size_; |
| 200 }; | 276 }; |
| 201 | 277 |
| 202 } // namespace bin | 278 } // namespace bin |
| 203 } // namespace dart | 279 } // namespace dart |
| 204 | 280 |
| 205 #endif // BIN_PROCESS_H_ | 281 #endif // BIN_PROCESS_H_ |
| OLD | NEW |