Antares blocks some windows APIs. We have use socket instead of calli… (#109)
* Antares blocks some windows APIs. We have use socket instead of calling GetExtendedTcpTable to check whether the backend is listening on given port. * Use socket instead of calling GetExtendedTcpTable to check if the backend process listens on given port since Antares blocks couple APIs * Antares blocks some windows APIs. We have use socket instead of calling GetExtendedTcpTable * update format * format change
This commit is contained in:
parent
f5253459ec
commit
cee4cf7544
|
|
@ -698,9 +698,10 @@ SERVER_PROCESS::PostStartCheck(
|
|||
goto Finished;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// dwActualProcessId will be set only when NsiAPI(GetExtendedTcpTable) is supported
|
||||
//
|
||||
hr = CheckIfServerIsUp(m_dwPort, &dwActualProcessId, &fReady);
|
||||
|
||||
fDebuggerAttached = IsDebuggerIsAttached();
|
||||
|
||||
if (!fReady)
|
||||
|
|
@ -727,7 +728,11 @@ SERVER_PROCESS::PostStartCheck(
|
|||
// some error occurred - assume debugger is not attached;
|
||||
fDebuggerAttached = FALSE;
|
||||
}
|
||||
|
||||
if (!g_fNsiApiNotSupported)
|
||||
{
|
||||
//
|
||||
// NsiAPI(GetExtendedTcpTable) is supported. we should check whether processIds matche
|
||||
//
|
||||
if (dwActualProcessId == m_dwProcessId)
|
||||
{
|
||||
m_dwListeningProcessId = m_dwProcessId;
|
||||
|
|
@ -771,7 +776,26 @@ SERVER_PROCESS::PostStartCheck(
|
|||
}
|
||||
}
|
||||
|
||||
if (fReady == FALSE)
|
||||
if(!fProcessMatch)
|
||||
{
|
||||
//
|
||||
// process that we created is not listening
|
||||
// on the port we specified.
|
||||
//
|
||||
fReady = FALSE;
|
||||
pStruErrorMessage->SafeSnwprintf(
|
||||
ASPNETCORE_EVENT_PROCESS_START_WRONGPORT_ERROR_MSG,
|
||||
m_struAppFullPath.QueryStr(),
|
||||
m_pszRootApplicationPath.QueryStr(),
|
||||
pStruCommandline->QueryStr(),
|
||||
m_dwPort,
|
||||
hr);
|
||||
hr = HRESULT_FROM_WIN32(ERROR_CREATE_FAILED);
|
||||
goto Finished;
|
||||
}
|
||||
}
|
||||
|
||||
if (!fReady)
|
||||
{
|
||||
//
|
||||
// hr is already set by CheckIfServerIsUp
|
||||
|
|
@ -787,25 +811,6 @@ SERVER_PROCESS::PostStartCheck(
|
|||
m_dwPort,
|
||||
hr);
|
||||
}
|
||||
|
||||
goto Finished;
|
||||
}
|
||||
|
||||
if (!g_fNsiApiNotSupported && !fProcessMatch)
|
||||
{
|
||||
//
|
||||
// process that we created is not listening
|
||||
// on the port we specified.
|
||||
//
|
||||
fReady = FALSE;
|
||||
pStruErrorMessage->SafeSnwprintf(
|
||||
ASPNETCORE_EVENT_PROCESS_START_WRONGPORT_ERROR_MSG,
|
||||
m_struAppFullPath.QueryStr(),
|
||||
m_pszRootApplicationPath.QueryStr(),
|
||||
pStruCommandline->QueryStr(),
|
||||
m_dwPort,
|
||||
hr);
|
||||
hr = HRESULT_FROM_WIN32(ERROR_CREATE_FAILED);
|
||||
goto Finished;
|
||||
}
|
||||
|
||||
|
|
@ -1324,19 +1329,28 @@ SERVER_PROCESS::CheckIfServerIsUp(
|
|||
MIB_TCPTABLE_OWNER_PID *pTCPInfo = NULL;
|
||||
MIB_TCPROW_OWNER_PID *pOwner = NULL;
|
||||
DWORD dwSize = 0;
|
||||
int iResult = 0;
|
||||
SOCKADDR_IN sockAddr;
|
||||
SOCKET socketCheck = INVALID_SOCKET;
|
||||
|
||||
DBG_ASSERT(pfReady);
|
||||
DBG_ASSERT(pdwProcessId);
|
||||
|
||||
*pfReady = FALSE;
|
||||
//
|
||||
// it's OK for us to return processID 0 in case we cannot detect the real one
|
||||
//
|
||||
*pdwProcessId = 0;
|
||||
|
||||
if (!g_fNsiApiNotSupported)
|
||||
{
|
||||
dwResult = GetExtendedTcpTable(NULL,
|
||||
&dwSize,
|
||||
FALSE,
|
||||
AF_INET,
|
||||
TCP_TABLE_OWNER_PID_LISTENER,
|
||||
0);
|
||||
|
||||
if (dwResult != NO_ERROR && dwResult != ERROR_INSUFFICIENT_BUFFER)
|
||||
{
|
||||
hr = HRESULT_FROM_WIN32(dwResult);
|
||||
|
|
@ -1373,6 +1387,55 @@ SERVER_PROCESS::CheckIfServerIsUp(
|
|||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// We have to open socket to ping the service
|
||||
//
|
||||
socketCheck = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
|
||||
if (socketCheck == INVALID_SOCKET)
|
||||
{
|
||||
hr = HRESULT_FROM_WIN32(WSAGetLastError());
|
||||
goto Finished;
|
||||
}
|
||||
|
||||
sockAddr.sin_family = AF_INET;
|
||||
if (!inet_pton(AF_INET, LOCALHOST, &(sockAddr.sin_addr)))
|
||||
{
|
||||
hr = HRESULT_FROM_WIN32(WSAGetLastError());
|
||||
goto Finished;
|
||||
}
|
||||
|
||||
//sockAddr.sin_addr.s_addr = inet_addr( LOCALHOST );
|
||||
sockAddr.sin_port = htons((u_short)dwPort);
|
||||
|
||||
//
|
||||
// Connect to server.
|
||||
// if connection fails, socket is not closed, we reuse the same socket
|
||||
// while retrying
|
||||
//
|
||||
iResult = connect(socketCheck, (SOCKADDR *)&sockAddr, sizeof(sockAddr));
|
||||
if (iResult == SOCKET_ERROR)
|
||||
{
|
||||
hr = HRESULT_FROM_WIN32(WSAGetLastError());
|
||||
goto Finished;
|
||||
}
|
||||
|
||||
//
|
||||
// Connected successfully, close socket.
|
||||
//
|
||||
iResult = closesocket(socketCheck);
|
||||
if (iResult == SOCKET_ERROR)
|
||||
{
|
||||
hr = HRESULT_FROM_WIN32(WSAGetLastError());
|
||||
goto Finished;
|
||||
}
|
||||
|
||||
socketCheck = INVALID_SOCKET;
|
||||
*pfReady = TRUE;
|
||||
}
|
||||
|
||||
Finished:
|
||||
|
||||
|
|
@ -1608,8 +1671,8 @@ SERVER_PROCESS::IsDebuggerIsAttached(
|
|||
HANDLE hProcess = OpenProcess(
|
||||
PROCESS_QUERY_INFORMATION | SYNCHRONIZE | PROCESS_TERMINATE | PROCESS_DUP_HANDLE,
|
||||
FALSE,
|
||||
dwPid
|
||||
);
|
||||
dwPid);
|
||||
|
||||
BOOL returnValue = CheckRemoteDebuggerPresent( hProcess, &fDebuggerPresent );
|
||||
if (!returnValue)
|
||||
{
|
||||
|
|
@ -1846,7 +1909,6 @@ SERVER_PROCESS::SERVER_PROCESS() :
|
|||
m_hProcessWaitHandle(NULL),
|
||||
m_dwProcessId(0),
|
||||
m_cChildProcess(0),
|
||||
m_socket( INVALID_SOCKET ),
|
||||
m_fReady(FALSE),
|
||||
m_lStopping(0L),
|
||||
m_hStdoutHandle(NULL),
|
||||
|
|
@ -1869,12 +1931,6 @@ SERVER_PROCESS::SERVER_PROCESS() :
|
|||
|
||||
SERVER_PROCESS::~SERVER_PROCESS()
|
||||
{
|
||||
if(m_socket != NULL)
|
||||
{
|
||||
closesocket( m_socket );
|
||||
m_socket = NULL;
|
||||
}
|
||||
|
||||
if (m_hProcessWaitHandle != NULL)
|
||||
{
|
||||
UnregisterWait( m_hProcessWaitHandle );
|
||||
|
|
|
|||
Loading…
Reference in New Issue