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 issue

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
Show file tree
Hide file tree
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
fix windows INVALID_HANDLE_VALUE handling all over the place
  • Loading branch information
dothebart committed Sep 25, 2017
commit c809c0d77eae2b8ff3e06833494a36560eeffb3b
8 changes: 4 additions & 4 deletions lib/Basics/process-utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ ExternalProcess::ExternalProcess():
#else
_pid(0),
_process(nullptr),
_readPipe(nullptr),
_writePipe(nullptr),
_readPipe(INVALID_HANDLE_VALUE),
_writePipe(INVALID_HANDLE_VALUE),
#endif
_status(TRI_EXT_NOT_STARTED),
_exitStatus(0) {}
Expand Down Expand Up @@ -136,10 +136,10 @@ ExternalProcess::~ExternalProcess() {
}
#else
CloseHandle(_process);
if (_readPipe != nullptr) {
if (_readPipe != INVALID_HANDLE_VALUE) {
CloseHandle(_readPipe);
}
if (_writePipe != nullptr) {
if (_writePipe != INVALID_HANDLE_VALUE) {
CloseHandle(_writePipe);
}
#endif
Expand Down
13 changes: 13 additions & 0 deletions lib/Basics/win-utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -721,3 +721,16 @@ bool terminalKnowsANSIColors()
// Windows 8 onwards the CMD window understands ANSI-Colorcodes.
return IsWindows8OrGreater();
}

std::string getFileNameFromHandle(HANDLE fileHandle) {
char buff[sizeof(FILE_NAME_INFO) + sizeof(WCHAR)*MAX_PATH];
FILE_NAME_INFO *FileInformation = (FILE_NAME_INFO*) buff;

if (!GetFileInformationByHandleEx(fileHandle,
FileNameInfo,
FileInformation, sizeof(buff)
)) {
return std::string();
}
return std::string((LPCTSTR)CString(FileInformation->FileName));
}
4 changes: 4 additions & 0 deletions lib/Basics/win-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,9 @@ int _is_cyg_tty(int fd);
////////////////////////////////////////////////////////////////////////////////
bool terminalKnowsANSIColors();

////////////////////////////////////////////////////////////////////////////////
// returns returns the filename in conjunction with a handle
////////////////////////////////////////////////////////////////////////////////
std::string getFileNameFromHandle(HANDLE fileHandle);

#endif
42 changes: 16 additions & 26 deletions lib/V8/v8-utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3481,23 +3481,18 @@ static void JS_ExecuteExternal(
v8::Number::New(isolate, external._writePipe));
}
#else
size_t readPipe_len, writePipe_len;
if (0 != external._readPipe) {
char* readPipe = TRI_EncodeHexString((char const*)external._readPipe,
sizeof(HANDLE), &readPipe_len);
if (readPipe != nullptr) {
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_PAIR_STRING(isolate, readPipe, (int)readPipe_len));
TRI_FreeString(readPipe);
TRI_V8_STD_STRING(isolate, fn));
}
}
if (0 != external._writePipe) {
char* writePipe = TRI_EncodeHexString((char const*)external._writePipe,
sizeof(HANDLE), &writePipe_len);
if (writePipe != nullptr) {
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_PAIR_STRING(isolate, writePipe, (int)writePipe_len));
TRI_FreeString(writePipe);
TRI_V8_STD_STRING(isolate, fn));
}
}
#endif
Expand Down Expand Up @@ -3602,23 +3597,18 @@ static void JS_StatusExternal(v8::FunctionCallbackInfo<v8::Value> const& args) {
v8::Number::New(isolate, external._writePipe));
}
#else
size_t readPipe_len, writePipe_len;
if (0 != external._readPipe) {
char* readPipe = TRI_EncodeHexString((char const*)external._readPipe,
sizeof(HANDLE), &readPipe_len);
if (readPipe != nullptr) {
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_PAIR_STRING(isolate, readPipe, (int)readPipe_len));
TRI_FreeString(readPipe);
TRI_V8_STD_STRING(isolate, fn));
}
}
if (0 != external._writePipe) {
char* writePipe = TRI_EncodeHexString((char const*)external._writePipe,
sizeof(HANDLE), &writePipe_len);
if (writePipe != nullptr) {
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_PAIR_STRING(isolate, writePipe, (int)writePipe_len));
TRI_FreeString(writePipe);
TRI_V8_STD_STRING(isolate, fn));
}
}
#endif
Expand Down
0