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

Unified Diff: runtime/bin/process_linux.cc

Issue 1800863002: Cleanup in //runtime/bin (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/process_android.cc ('k') | runtime/bin/process_macos.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/process_linux.cc
diff --git a/runtime/bin/process_linux.cc b/runtime/bin/process_linux.cc
index 572ced76e1b25188d4e86d1d6c4caf57b2c76d7f..b65723511f195ef5a6d6df1c7f388e75a851537a 100644
--- a/runtime/bin/process_linux.cc
+++ b/runtime/bin/process_linux.cc
@@ -24,10 +24,8 @@
#include "platform/signal_blocker.h"
#include "platform/utils.h"
-
extern char **environ;
-
namespace dart {
namespace bin {
@@ -53,6 +51,8 @@ class ProcessInfo {
pid_t pid_;
intptr_t fd_;
ProcessInfo* next_;
+
+ DISALLOW_COPY_AND_ASSIGN(ProcessInfo);
};
@@ -107,6 +107,9 @@ class ProcessInfoList {
// Mutex protecting all accesses to the linked list of active
// processes.
static Mutex* mutex_;
+
+ DISALLOW_ALLOCATION();
+ DISALLOW_IMPLICIT_CONSTRUCTORS(ProcessInfoList);
};
@@ -203,9 +206,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);
@@ -222,6 +225,9 @@ class ExitCodeHandler {
static int process_count_;
static bool running_;
static Monitor* monitor_;
+
+ DISALLOW_ALLOCATION();
+ DISALLOW_IMPLICIT_CONSTRUCTORS(ExitCodeHandler);
};
@@ -264,7 +270,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];
@@ -273,7 +280,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];
}
@@ -282,16 +290,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());
@@ -311,7 +315,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
@@ -490,8 +496,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();
}
@@ -533,9 +539,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;
@@ -554,8 +559,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)) {
@@ -575,7 +579,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));
@@ -604,12 +610,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));
}
}
@@ -659,9 +667,8 @@ class ProcessStarter {
const int kBufferSize = 1024;
char error_buf[kBufferSize];
char* os_error_message = Utils::StrError(errno, error_buf, kBufferSize);
- int bytes_written =
- FDUtils::WriteToBlocking(
- exec_control_[1], &child_errno, sizeof(child_errno));
+ int bytes_written = FDUtils::WriteToBlocking(
+ exec_control_[1], &child_errno, sizeof(child_errno));
if (bytes_written == sizeof(child_errno)) {
FDUtils::WriteToBlocking(
exec_control_[1], os_error_message, strlen(os_error_message) + 1);
@@ -730,6 +737,9 @@ class ProcessStarter {
intptr_t* id_;
intptr_t* exit_event_;
char** os_error_message_;
+
+ DISALLOW_ALLOCATION();
+ DISALLOW_IMPLICIT_CONSTRUCTORS(ProcessStarter);
};
@@ -765,10 +775,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);
@@ -776,13 +790,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);
};
@@ -834,7 +853,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)) {
@@ -856,7 +875,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) {
@@ -873,7 +892,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;
@@ -935,7 +956,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;
@@ -982,7 +1005,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 {
@@ -990,7 +1015,9 @@ void Process::ClearSignalHandler(intptr_t signal) {
}
}
SignalInfo* next = handler->next();
- if (remove) delete handler;
+ if (remove) {
+ delete handler;
+ }
handler = next;
}
if (unlisten) {
« no previous file with comments | « runtime/bin/process_android.cc ('k') | runtime/bin/process_macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698