mirror of https://gitee.com/bigwinds/arangodb
better detect cygwin i/o
This commit is contained in:
parent
f33d14f0d1
commit
6ab23bd56d
|
@ -120,7 +120,7 @@ void ConsoleFeature::collectOptions(std::shared_ptr<ProgramOptions> options) {
|
|||
|
||||
void ConsoleFeature::prepare() {
|
||||
#if _WIN32
|
||||
if (getenv("SHELL") != nullptr) {
|
||||
if (_is_cyg_tty (STDOUT_FILENO) || getenv("SHELL") != nullptr) {
|
||||
_cygwinShell = true;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -653,3 +653,51 @@ _cyg_isatty (int fd)
|
|||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Detect cygwin ssh / terminals
|
||||
int
|
||||
_is_cyg_tty (int fd)
|
||||
{
|
||||
// detect standard windows ttys:
|
||||
if (_isatty (fd)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
HANDLE fh;
|
||||
|
||||
char buff[sizeof(FILE_NAME_INFO) + sizeof(WCHAR)*MAX_PATH];
|
||||
FILE_NAME_INFO *FileInformation = (FILE_NAME_INFO*) buff;
|
||||
|
||||
/* get the HANDLE for the filedescriptor. */
|
||||
fh = (HANDLE) _get_osfhandle (fd);
|
||||
if (!fh || fh == INVALID_HANDLE_VALUE) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Cygwin consoles are pipes. If its not, no reason to continue: */
|
||||
if (GetFileType (fh) != FILE_TYPE_PIPE) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!GetFileInformationByHandleEx(fh, FileNameInfo,
|
||||
FileInformation, sizeof(buff))) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// we expect something along the lines of: \cygwin-0eb90a57d5759b7b-pty3-to-master?? - if we find it its a tty.
|
||||
PWCHAR cp = (PWCHAR) FileInformation->FileName;
|
||||
if (!wcsncmp (cp, L"\\cygwin-", 8)
|
||||
&& !wcsncmp (cp + 24, L"-pty", 4)) {
|
||||
cp = wcschr (cp + 28, '-');
|
||||
if (!cp) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!wcsncmp (cp, L"-from-master", sizeof("-from-master") - 1) ||
|
||||
!wcsncmp (cp, L"-to-master", sizeof("-to-master") -1)) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -141,4 +141,9 @@ void TRI_WindowsEmergencyLog(char const* func, char const* file, int line,
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
int _cyg_isatty (int fd);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief detects whether an FD is connected to a cygwin-tty.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int _is_cyg_tty (int fd);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue