8000 rework process handling by dothebart · Pull Request #3322 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content

rework process handling #3322

New iss 8000 ue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Sep 28, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
DRY.
  • Loading branch information
dothebart committed Sep 25, 2017
commit 92ebdcce1a78f69d330fe6db4a5b6cd34a61dbdc
242 changes: 105 additions & 137 deletions lib/V8/v8-utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3384,6 +3384,106 @@ static void JS_HMAC(v8::FunctionCallbackInfo<v8::Value> const& args) {
TRI_V8_TRY_CATCH_END
}


////////////////////////////////////////////////////////////////////////////////
/// @brief Convert programm stati to V8
////////////////////////////////////////////////////////////////////////////////
static char const* convertProcessStatusToString(ExternalProcessStatus external) {
char const* status = "UNKNOWN";

switch (external._status) {
case TRI_EXT_NOT_STARTED:
status = "NOT-STARTED";
break;
case TRI_EXT_PIPE_FAILED:
status = "FAILED";
break;
case TRI_EXT_FORK_FAILED:
status = "FAILED";
break;
case TRI_EXT_RUNNING:
status = "RUNNING";
break;
case TRI_EXT_NOT_FOUND:
status = "NOT-FOUND";
break;
case TRI_EXT_TERMINATED:
status = "TERMINATED";
break;
case TRI_EXT_ABORTED:
status = "ABORTED";
break;
case TRI_EXT_STOPPED:
status = "STOPPED";
break;
}
return status;
}

static void convertPipeStatus(v8::FunctionCallbackInfo<v8::Value> const& args,
v8::Handle<v8::Object> &result,
ExternalId &external) {
TRI_V8_TRY_CATCH_BEGIN(isolate);

result->Set(TRI_V8_ASCII_STRING(isolate, "pid"),
v8::Number::New(isolate, external._pid));

// Now report about possible stdin and stdout pipes:
#ifndef _WIN32
if (external._readPipe >= 0) {
result->Set(TRI_V8_ASCII_STRING(isolate, "readPipe"),
v8::Number::New(isolate, external._readPipe));
}
if (external._writePipe >= 0) {
result->Set(TRI_V8_ASCII_STRING(isolate, "writePipe"),
v8::Number::New(isolate, external._writePipe));
}
#else
if (external._readPipe != INVALID_HANDLE_VALUE) {
auto fn = getFileNameFromHandle(external._readPipe);
if (fn.length() > 0) {
result->Set(TRI_V8_ASCII_STRING(isolate, "readPipe"),
TRI_V8_STD_STRING(isolate, fn));
}
}
if (external._writePipe != INVALID_HANDLE_VALUE) {
auto fn = getFileNameFromHandle(external._writePipe);
if (fn.length() > 0) {
result->Set(TRI_V8_ASCII_STRING(isolate, "writePipe"),
TRI_V8_STD_STRING(isolate, fn));
}
}
#endif
TRI_V8_TRY_CATCH_END;
}

static void convertStatusToV8(v8::FunctionCallbackInfo<v8::Value> const& args,
v8::Handle<v8::Object> &result,
ExternalProcessStatus &external_status,
ExternalId &external) {
TRI_V8_TRY_CATCH_BEGIN(isolate);

convertPipeStatus(args, result, external);

result->Set(TRI_V8_ASCII_STRING(isolate, "status"),
TRI_V8_ASCII_STRING(isolate, convertProcessStatusToString(external_status)));

if (external_status._status == TRI_EXT_TERMINATED) {
result->Set(TRI_V8_ASCII_STRING(isolate, "exit"),
v8::Integer::New(isolate, static_cast<int32_t>(
external_status._exitStatus)));
} else if (external_status._status == TRI_EXT_ABORTED) {
result->Set(TRI_V8_ASCII_STRING(isolate, "signal"),
v8::Integer::New(isolate, static_cast<int32_t>(
external_status._exitStatus)));
}
if (external_status._errorMessage.length() > 0) {
result->Set(TRI_V8_ASCII_STRING(isolate, "errorMessage"),
TRI_V8_STD_STRING(isolate, external_status._errorMessage));
}
TRI_V8_TRY_CATCH_END;
}

////////////////////////////////////////////////////////////////////////////////
/// @brief executes a external program
////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -3470,34 +3570,9 @@ static void JS_ExecuteExternal(
TRI_V8_THROW_ERROR("Process could not be started");
}
v8::Handle<v8::Object> result = v8::Object::New(isolate);
result->Set(TRI_V8_ASCII_STRING(isolate, "pid"),
v8::Number::New(isolate, external._pid));
// Now report about possible stdin and stdout pipes:
#ifndef _WIN32
if (external._readPipe >= 0) {
result->Set(TRI_V8_ASCII_STRING(isolate, "readPipe"),
v8::Number::New(isolate, external._readPipe));
}
if (external._writePipe >= 0) {
result->Set(TRI_V8_ASCII_STRING(isolate, "writePipe"),
v8::Number::New(isolate, external._writePipe));
}
#else
if (external._readPipe != INVALID_HANDLE_VALUE) {
auto fn = getFileNameFromHandle(external._readPipe);
if (fn.length() > 0) {
result->Set(TRI_V8_ASCII_STRING(isolate, "readPipe"),
TRI_V8_STD_STRING(isolate, fn));
}
}
if (external._writePipe != INVALID_HANDLE_VALUE) {
auto fn = getFileNameFromHandle(external._writePipe);
if (fn.length() > 0) {
result->Set(TRI_V8_ASCII_STRING(isolate, "writePipe"),
TRI_V8_STD_STRING(isolate, fn));
}
}
#endif

convertPipeStatus(args, result, external);

TRI_V8_RETURN(result);
TRI_V8_TRY_CATCH_END
}
Expand Down Expand Up @@ -3531,36 +3606,9 @@ static void JS_StatusExternal(v8::FunctionCallbackInfo<v8::Value> const& args) {
ExternalProcessStatus external = TRI_CheckExternalProcess(pid, wait);

v8::Handle<v8::Object> result = v8::Object::New(isolate);
char const* status = "UNKNOWN";

switch (external._status) {
case TRI_EXT_NOT_STARTED:
status = "NOT-STARTED";
break;
case TRI_EXT_PIPE_FAILED:
status = "FAILED";
break;
case TRI_EXT_FORK_FAILED:
status = "FAILED";
break;
case TRI_EXT_RUNNING:
status = "RUNNING";
break;
case TRI_EXT_NOT_FOUND:
status = "NOT-FOUND";
break;
case TRI_EXT_TERMINATED:
status = "TERMINATED";
break;
case TRI_EXT_ABORTED:
status = "ABORTED";
break;
case TRI_EXT_STOPPED:
status = "STOPPED";
break;
}

result->Set(TRI_V8_ASCII_STRING(isolate, "status"), TRI_V8_STRING(isolate, status));
result->Set(TRI_V8_ASCII_STRING(isolate, "status"),
TRI_V8_STRING(isolate, convertProcessStatusToString(external)));

if (external._status == TRI_EXT_TERMINATED) {
result->Set(
Expand All @@ -3579,86 +3627,6 @@ static void JS_StatusExternal(v8::FunctionCallbackInfo<v8::Value> const& args) {
TRI_V8_RETURN(result);
TRI_V8_TRY_CATCH_END
}


static void convertStatusToV8(v8::FunctionCallbackInfo<v8::Value> const& args,
v8::Handle<v8::Object> &result,
ExternalProcessStatus &external_status,
ExternalId &external) {
TRI_V8_TRY_CATCH_BEGIN(isolate);
result->Set(TRI_V8_ASCII_STRING(isolate, "pid"),
v8::Number::New(isolate, external._pid));
// Now report about possible stdin and stdout pipes:
#ifndef _WIN32
if (external._readPipe >= 0) {
result->Set(TRI_V8_ASCII_STRING(isolate, "readPipe"),
v8::Number::New(isolate, external._readPipe));
}
if (external._writePipe >= 0) {
result->Set(TRI_V8_ASCII_STRING(isolate, "writePipe"),
v8::Number::New(isolate, external._writePipe));
}
#else
if (external._readPipe != INVALID_HANDLE_VALUE) {
auto fn = getFileNameFromHandle(external._readPipe);
if (fn.length() > 0) {
result->Set(TRI_V8_ASCII_STRING(isolate, "readPipe"),
TRI_V8_STD_STRING(isolate, fn));
}
}
if (external._writePipe != INVALID_HANDLE_VALUE) {
auto fn = getFileNameFromHandle(external._writePipe);
if (fn.length() > 0) {
result->Set(TRI_V8_ASCII_STRING(isolate, "writePipe"),
TRI_V8_STD_STRING(isolate, fn));
}
}
#endif
char const* status = "UNKNOWN";
switch (external_status._status) {
case TRI_EXT_NOT_STARTED:
status = "NOT-STARTED";
break;
case TRI_EXT_PIPE_FAILED:
status = "FAILED";
break;
case TRI_EXT_FORK_FAILED:
status = "FAILED";
break;
case TRI_EXT_RUNNING:
status = "RUNNING";
break;
case TRI_EXT_NOT_FOUND:
status = "NOT-FOUND";
break;
case TRI_EXT_TERMINATED:
status = "TERMINATED";
break;
case TRI_EXT_ABORTED:
status = "ABORTED";
break;
case TRI_EXT_STOPPED:
status = "STOPPED";
break;
}

result->Set(TRI_V8_ASCII_STRING(isolate, "status"), TRI_V8_ASCII_STRING(isolate, status));

if (external_status._status == TRI_EXT_TERMINATED) {
result->Set(TRI_V8_ASCII_STRING(isolate, "exit"),
v8::Integer::New(isolate, static_cast<int32_t>(
external_status._exitStatus)));
} else if (external_status._status == TRI_EXT_ABORTED) {
result->Set(TRI_V8_ASCII_STRING(isolate, "signal"),
v8::Integer::New(isolate, static_cast<int32_t>(
external_status._exitStatus)));
}
if (external_status._errorMessage.length() > 0) {
result->Set(TRI_V8_ASCII_STRING(isolate, "errorMessage"),
TRI_V8_STD_STRING(isolate, external_status._errorMessage));
}
TRI_V8_TRY_CATCH_END
}
////////////////////////////////////////////////////////////////////////////////
/// @brief executes a external program
////////////////////////////////////////////////////////////////////////////////
Expand Down
0