Index: runtime/bin/process_android.cc |
diff --git a/runtime/bin/process_android.cc b/runtime/bin/process_android.cc |
index 6f2394dd14ffecc7df57bb607c2c80d3aaa5ffc6..5e53dbeb7728092954209a589d3e283f7f829b4b 100644 |
--- a/runtime/bin/process_android.cc |
+++ b/runtime/bin/process_android.cc |
@@ -25,10 +25,8 @@ |
#include "platform/signal_blocker.h" |
#include "platform/utils.h" |
- |
extern char **environ; |
- |
namespace dart { |
namespace bin { |
@@ -54,6 +52,8 @@ class ProcessInfo { |
pid_t pid_; |
intptr_t fd_; |
ProcessInfo* next_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ProcessInfo); |
}; |
@@ -108,6 +108,9 @@ class ProcessInfoList { |
// Mutex protecting all accesses to the linked list of active |
// processes. |
static Mutex* mutex_; |
+ |
+ DISALLOW_ALLOCATION(); |
+ DISALLOW_IMPLICIT_CONSTRUCTORS(ProcessInfoList); |
}; |
@@ -175,7 +178,7 @@ class ExitCodeHandler { |
while (true) { |
{ |
MonitorLocker locker(monitor_); |
- while (running_ && process_count_ == 0) { |
+ while (running_ && (process_count_ == 0)) { |
monitor_->Wait(Monitor::kNoTimeout); |
} |
if (!running_) { |
@@ -204,9 +207,9 @@ class ExitCodeHandler { |
// pipe has been closed. It is therefore not a problem that |
// write fails with a broken pipe error. Other errors should |
// not happen. |
- if (result != -1 && result != sizeof(message)) { |
+ if ((result != -1) && (result != sizeof(message))) { |
FATAL("Failed to write entire process exit message"); |
- } else if (result == -1 && errno != EPIPE) { |
+ } else if ((result == -1) && (errno != EPIPE)) { |
FATAL1("Failed to write exit code: %d", errno); |
} |
ProcessInfoList::RemoveProcess(pid); |
@@ -223,6 +226,9 @@ class ExitCodeHandler { |
static int process_count_; |
static bool running_; |
static Monitor* monitor_; |
+ |
+ DISALLOW_ALLOCATION(); |
+ DISALLOW_IMPLICIT_CONSTRUCTORS(ExitCodeHandler); |
}; |
@@ -265,7 +271,8 @@ class ProcessStarter { |
exec_control_[0] = -1; |
exec_control_[1] = -1; |
- program_arguments_ = new char*[arguments_length + 2]; |
+ program_arguments_ = reinterpret_cast<char**>(Dart_ScopeAllocate( |
+ (arguments_length + 2) * sizeof(*program_arguments_))); |
program_arguments_[0] = const_cast<char*>(path_); |
for (int i = 0; i < arguments_length; i++) { |
program_arguments_[i + 1] = arguments[i]; |
@@ -274,7 +281,8 @@ class ProcessStarter { |
program_environment_ = NULL; |
if (environment != NULL) { |
- program_environment_ = new char*[environment_length + 1]; |
+ program_environment_ = reinterpret_cast<char**>(Dart_ScopeAllocate( |
+ (environment_length + 1) * sizeof(*program_environment_))); |
for (int i = 0; i < environment_length; i++) { |
program_environment_[i] = environment[i]; |
} |
@@ -283,16 +291,12 @@ class ProcessStarter { |
} |
- ~ProcessStarter() { |
- delete[] program_arguments_; |
- delete[] program_environment_; |
- } |
- |
- |
int Start() { |
// Create pipes required. |
int err = CreatePipes(); |
- if (err != 0) return err; |
+ if (err != 0) { |
+ return err; |
+ } |
// Fork to create the new process. |
pid_t pid = TEMP_FAILURE_RETRY(fork()); |
@@ -312,7 +316,9 @@ class ProcessStarter { |
// Register the child process if not detached. |
if (mode_ == kNormal) { |
err = RegisterProcess(pid); |
- if (err != 0) return err; |
+ if (err != 0) { |
+ return err; |
+ } |
} |
// Notify child process to start. This is done to delay the call to exec |
@@ -491,8 +497,8 @@ class ProcessStarter { |
SetupDetachedWithStdio(); |
} |
- if (working_directory_ != NULL && |
- TEMP_FAILURE_RETRY(chdir(working_directory_)) == -1) { |
+ if ((working_directory_ != NULL) && |
+ (TEMP_FAILURE_RETRY(chdir(working_directory_)) == -1)) { |
ReportChildError(); |
} |
@@ -534,9 +540,8 @@ class ProcessStarter { |
// Read exec result from child. If no data is returned the exec was |
// successful and the exec call closed the pipe. Otherwise the errno |
// is written to the pipe. |
- bytes_read = |
- FDUtils::ReadFromBlocking( |
- exec_control_[0], &child_errno, sizeof(child_errno)); |
+ bytes_read = FDUtils::ReadFromBlocking( |
+ exec_control_[0], &child_errno, sizeof(child_errno)); |
if (bytes_read == sizeof(child_errno)) { |
ReadChildError(); |
return child_errno; |
@@ -555,8 +560,7 @@ class ProcessStarter { |
// is written to the pipe as well. |
int result[2]; |
bytes_read = |
- FDUtils::ReadFromBlocking( |
- exec_control_[0], result, sizeof(result)); |
+ FDUtils::ReadFromBlocking(exec_control_[0], result, sizeof(result)); |
if (bytes_read == sizeof(int)) { |
*pid = result[0]; |
} else if (bytes_read == 2 * sizeof(int)) { |
@@ -576,7 +580,9 @@ class ProcessStarter { |
// Close all open file descriptors except for exec_control_[1]. |
int max_fds = sysconf(_SC_OPEN_MAX); |
- if (max_fds == -1) max_fds = _POSIX_OPEN_MAX; |
+ if (max_fds == -1) { |
+ max_fds = _POSIX_OPEN_MAX; |
+ } |
for (int fd = 0; fd < max_fds; fd++) { |
if (fd != exec_control_[1]) { |
VOID_TEMP_FAILURE_RETRY(close(fd)); |
@@ -605,12 +611,14 @@ class ProcessStarter { |
// exec_control_[1], write_out_[0], read_in_[1] and |
// read_err_[1]. |
int max_fds = sysconf(_SC_OPEN_MAX); |
- if (max_fds == -1) max_fds = _POSIX_OPEN_MAX; |
+ if (max_fds == -1) { |
+ max_fds = _POSIX_OPEN_MAX; |
+ } |
for (int fd = 0; fd < max_fds; fd++) { |
- if (fd != exec_control_[1] && |
- fd != write_out_[0] && |
- fd != read_in_[1] && |
- fd != read_err_[1]) { |
+ if ((fd != exec_control_[1]) && |
+ (fd != write_out_[0]) && |
+ (fd != read_in_[1]) && |
+ (fd != read_err_[1])) { |
VOID_TEMP_FAILURE_RETRY(close(fd)); |
} |
} |
@@ -731,6 +739,9 @@ class ProcessStarter { |
intptr_t* id_; |
intptr_t* exit_event_; |
char** os_error_message_; |
+ |
+ DISALLOW_ALLOCATION(); |
+ DISALLOW_IMPLICIT_CONSTRUCTORS(ProcessStarter); |
}; |
@@ -766,10 +777,14 @@ int Process::Start(const char* path, |
class BufferList: public BufferListBase { |
public: |
+ BufferList() {} |
+ |
bool Read(int fd, intptr_t available) { |
// Read all available bytes. |
while (available > 0) { |
- if (free_size_ == 0) Allocate(); |
+ if (free_size_ == 0) { |
+ Allocate(); |
+ } |
ASSERT(free_size_ > 0); |
ASSERT(free_size_ <= kBufferSize); |
intptr_t block_size = dart::Utils::Minimum(free_size_, available); |
@@ -777,13 +792,18 @@ class BufferList: public BufferListBase { |
fd, |
reinterpret_cast<void*>(FreeSpaceAddress()), |
block_size)); |
- if (bytes < 0) return false; |
+ if (bytes < 0) { |
+ return false; |
+ } |
data_size_ += bytes; |
free_size_ -= bytes; |
available -= bytes; |
} |
return true; |
} |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(BufferList); |
}; |
@@ -835,7 +855,7 @@ bool Process::Wait(intptr_t pid, |
// Process incoming data. |
int current_alive = alive; |
for (int i = 0; i < current_alive; i++) { |
- if (fds[i].revents & POLLIN) { |
+ if ((fds[i].revents & POLLIN) != 0) { |
intptr_t avail = FDUtils::AvailableBytes(fds[i].fd); |
if (fds[i].fd == out) { |
if (!out_data.Read(out, avail)) { |
@@ -857,7 +877,7 @@ bool Process::Wait(intptr_t pid, |
UNREACHABLE(); |
} |
} |
- if (fds[i].revents & POLLHUP) { |
+ if ((fds[i].revents & POLLHUP) != 0) { |
VOID_TEMP_FAILURE_RETRY(close(fds[i].fd)); |
alive--; |
if (i < alive) { |
@@ -874,7 +894,9 @@ bool Process::Wait(intptr_t pid, |
// Calculate the exit code. |
intptr_t exit_code = exit_code_data.ints[0]; |
intptr_t negative = exit_code_data.ints[1]; |
- if (negative) exit_code = -exit_code; |
+ if (negative != 0) { |
+ exit_code = -exit_code; |
+ } |
result->set_exit_code(exit_code); |
return true; |
@@ -936,7 +958,9 @@ intptr_t Process::SetSignalHandler(intptr_t signal) { |
break; |
} |
} |
- if (!found) return -1; |
+ if (!found) { |
+ return -1; |
+ } |
int fds[2]; |
if (NO_RETRY_EXPECTED(pipe2(fds, O_CLOEXEC)) != 0) { |
return -1; |
@@ -986,7 +1010,9 @@ void Process::ClearSignalHandler(intptr_t signal) { |
bool remove = false; |
if (handler->signal() == signal) { |
if (handler->port() == Dart_GetMainPortId()) { |
- if (signal_handlers == handler) signal_handlers = handler->next(); |
+ if (signal_handlers == handler) { |
+ signal_handlers = handler->next(); |
+ } |
handler->Unlink(); |
remove = true; |
} else { |
@@ -994,7 +1020,9 @@ void Process::ClearSignalHandler(intptr_t signal) { |
} |
} |
SignalInfo* next = handler->next(); |
- if (remove) delete handler; |
+ if (remove) { |
+ delete handler; |
+ } |
handler = next; |
} |
if (unlisten) { |