Commit 93132e1b authored by erik.corry@gmail.com's avatar erik.corry@gmail.com

Timeout of os.system() in d8 was timing out too soon.

Review URL: http://codereview.chromium.org/63062

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1711 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 3b7f631e
...@@ -105,17 +105,17 @@ static int LengthWithoutIncompleteUtf8(char* buffer, int len) { ...@@ -105,17 +105,17 @@ static int LengthWithoutIncompleteUtf8(char* buffer, int len) {
// Returns false on timeout, true on data ready. // Returns false on timeout, true on data ready.
static bool WaitOnFD(int fd, static bool WaitOnFD(int fd,
int read_timeout, int read_timeout,
int* total_timeout, int total_timeout,
struct timeval& start_time) { struct timeval& start_time) {
fd_set readfds, writefds, exceptfds; fd_set readfds, writefds, exceptfds;
struct timeval timeout; struct timeval timeout;
if (*total_timeout != -1) { int gone = 0;
if (total_timeout != -1) {
struct timeval time_now; struct timeval time_now;
gettimeofday(&time_now, NULL); gettimeofday(&time_now, NULL);
int seconds = time_now.tv_sec - start_time.tv_sec; int seconds = time_now.tv_sec - start_time.tv_sec;
int gone = seconds * 1000 + (time_now.tv_usec - start_time.tv_usec) / 1000; gone = seconds * 1000 + (time_now.tv_usec - start_time.tv_usec) / 1000;
if (gone >= *total_timeout) return false; if (gone >= total_timeout) return false;
*total_timeout -= gone;
} }
FD_ZERO(&readfds); FD_ZERO(&readfds);
FD_ZERO(&writefds); FD_ZERO(&writefds);
...@@ -123,8 +123,8 @@ static bool WaitOnFD(int fd, ...@@ -123,8 +123,8 @@ static bool WaitOnFD(int fd,
FD_SET(fd, &readfds); FD_SET(fd, &readfds);
FD_SET(fd, &exceptfds); FD_SET(fd, &exceptfds);
if (read_timeout == -1 || if (read_timeout == -1 ||
(*total_timeout != -1 && *total_timeout < read_timeout)) { (total_timeout != -1 && total_timeout - gone < read_timeout)) {
read_timeout = *total_timeout; read_timeout = total_timeout - gone;
} }
timeout.tv_usec = (read_timeout % 1000) * 1000; timeout.tv_usec = (read_timeout % 1000) * 1000;
timeout.tv_sec = read_timeout / 1000; timeout.tv_sec = read_timeout / 1000;
...@@ -306,7 +306,7 @@ static bool ChildLaunchedOK(int* exec_error_fds) { ...@@ -306,7 +306,7 @@ static bool ChildLaunchedOK(int* exec_error_fds) {
static Handle<Value> GetStdout(int child_fd, static Handle<Value> GetStdout(int child_fd,
struct timeval& start_time, struct timeval& start_time,
int read_timeout, int read_timeout,
int* total_timeout) { int total_timeout) {
Handle<String> accumulator = String::Empty(); Handle<String> accumulator = String::Empty();
const char* source = "function(a, b) { return a + b; }"; const char* source = "function(a, b) { return a + b; }";
Handle<Value> cons_as_obj(Script::Compile(String::New(source))->Run()); Handle<Value> cons_as_obj(Script::Compile(String::New(source))->Run());
...@@ -332,7 +332,7 @@ static Handle<Value> GetStdout(int child_fd, ...@@ -332,7 +332,7 @@ static Handle<Value> GetStdout(int child_fd,
read_timeout, read_timeout,
total_timeout, total_timeout,
start_time) || start_time) ||
(TimeIsOut(start_time, *total_timeout))) { (TimeIsOut(start_time, total_timeout))) {
return ThrowException(String::New("Timed out waiting for output")); return ThrowException(String::New("Timed out waiting for output"));
} }
continue; continue;
...@@ -502,7 +502,7 @@ Handle<Value> Shell::System(const Arguments& args) { ...@@ -502,7 +502,7 @@ Handle<Value> Shell::System(const Arguments& args) {
Handle<Value> accumulator = GetStdout(stdout_fds[kReadFD], Handle<Value> accumulator = GetStdout(stdout_fds[kReadFD],
start_time, start_time,
read_timeout, read_timeout,
&total_timeout); total_timeout);
if (accumulator->IsUndefined()) { if (accumulator->IsUndefined()) {
kill(pid, SIGINT); // On timeout, kill the subprocess. kill(pid, SIGINT); // On timeout, kill the subprocess.
return accumulator; return accumulator;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment