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;
|
goto Finished;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//
|
||||||
|
// dwActualProcessId will be set only when NsiAPI(GetExtendedTcpTable) is supported
|
||||||
|
//
|
||||||
hr = CheckIfServerIsUp(m_dwPort, &dwActualProcessId, &fReady);
|
hr = CheckIfServerIsUp(m_dwPort, &dwActualProcessId, &fReady);
|
||||||
|
|
||||||
fDebuggerAttached = IsDebuggerIsAttached();
|
fDebuggerAttached = IsDebuggerIsAttached();
|
||||||
|
|
||||||
if (!fReady)
|
if (!fReady)
|
||||||
|
|
@ -727,7 +728,11 @@ SERVER_PROCESS::PostStartCheck(
|
||||||
// some error occurred - assume debugger is not attached;
|
// some error occurred - assume debugger is not attached;
|
||||||
fDebuggerAttached = FALSE;
|
fDebuggerAttached = FALSE;
|
||||||
}
|
}
|
||||||
|
if (!g_fNsiApiNotSupported)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// NsiAPI(GetExtendedTcpTable) is supported. we should check whether processIds matche
|
||||||
|
//
|
||||||
if (dwActualProcessId == m_dwProcessId)
|
if (dwActualProcessId == m_dwProcessId)
|
||||||
{
|
{
|
||||||
m_dwListeningProcessId = 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
|
// hr is already set by CheckIfServerIsUp
|
||||||
|
|
@ -787,25 +811,6 @@ SERVER_PROCESS::PostStartCheck(
|
||||||
m_dwPort,
|
m_dwPort,
|
||||||
hr);
|
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;
|
goto Finished;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1324,19 +1329,28 @@ SERVER_PROCESS::CheckIfServerIsUp(
|
||||||
MIB_TCPTABLE_OWNER_PID *pTCPInfo = NULL;
|
MIB_TCPTABLE_OWNER_PID *pTCPInfo = NULL;
|
||||||
MIB_TCPROW_OWNER_PID *pOwner = NULL;
|
MIB_TCPROW_OWNER_PID *pOwner = NULL;
|
||||||
DWORD dwSize = 0;
|
DWORD dwSize = 0;
|
||||||
|
int iResult = 0;
|
||||||
|
SOCKADDR_IN sockAddr;
|
||||||
|
SOCKET socketCheck = INVALID_SOCKET;
|
||||||
|
|
||||||
DBG_ASSERT(pfReady);
|
DBG_ASSERT(pfReady);
|
||||||
DBG_ASSERT(pdwProcessId);
|
DBG_ASSERT(pdwProcessId);
|
||||||
|
|
||||||
*pfReady = FALSE;
|
*pfReady = FALSE;
|
||||||
|
//
|
||||||
|
// it's OK for us to return processID 0 in case we cannot detect the real one
|
||||||
|
//
|
||||||
*pdwProcessId = 0;
|
*pdwProcessId = 0;
|
||||||
|
|
||||||
|
if (!g_fNsiApiNotSupported)
|
||||||
|
{
|
||||||
dwResult = GetExtendedTcpTable(NULL,
|
dwResult = GetExtendedTcpTable(NULL,
|
||||||
&dwSize,
|
&dwSize,
|
||||||
FALSE,
|
FALSE,
|
||||||
AF_INET,
|
AF_INET,
|
||||||
TCP_TABLE_OWNER_PID_LISTENER,
|
TCP_TABLE_OWNER_PID_LISTENER,
|
||||||
0);
|
0);
|
||||||
|
|
||||||
if (dwResult != NO_ERROR && dwResult != ERROR_INSUFFICIENT_BUFFER)
|
if (dwResult != NO_ERROR && dwResult != ERROR_INSUFFICIENT_BUFFER)
|
||||||
{
|
{
|
||||||
hr = HRESULT_FROM_WIN32(dwResult);
|
hr = HRESULT_FROM_WIN32(dwResult);
|
||||||
|
|
@ -1373,6 +1387,55 @@ SERVER_PROCESS::CheckIfServerIsUp(
|
||||||
break;
|
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:
|
Finished:
|
||||||
|
|
||||||
|
|
@ -1608,8 +1671,8 @@ SERVER_PROCESS::IsDebuggerIsAttached(
|
||||||
HANDLE hProcess = OpenProcess(
|
HANDLE hProcess = OpenProcess(
|
||||||
PROCESS_QUERY_INFORMATION | SYNCHRONIZE | PROCESS_TERMINATE | PROCESS_DUP_HANDLE,
|
PROCESS_QUERY_INFORMATION | SYNCHRONIZE | PROCESS_TERMINATE | PROCESS_DUP_HANDLE,
|
||||||
FALSE,
|
FALSE,
|
||||||
dwPid
|
dwPid);
|
||||||
);
|
|
||||||
BOOL returnValue = CheckRemoteDebuggerPresent( hProcess, &fDebuggerPresent );
|
BOOL returnValue = CheckRemoteDebuggerPresent( hProcess, &fDebuggerPresent );
|
||||||
if (!returnValue)
|
if (!returnValue)
|
||||||
{
|
{
|
||||||
|
|
@ -1846,7 +1909,6 @@ SERVER_PROCESS::SERVER_PROCESS() :
|
||||||
m_hProcessWaitHandle(NULL),
|
m_hProcessWaitHandle(NULL),
|
||||||
m_dwProcessId(0),
|
m_dwProcessId(0),
|
||||||
m_cChildProcess(0),
|
m_cChildProcess(0),
|
||||||
m_socket( INVALID_SOCKET ),
|
|
||||||
m_fReady(FALSE),
|
m_fReady(FALSE),
|
||||||
m_lStopping(0L),
|
m_lStopping(0L),
|
||||||
m_hStdoutHandle(NULL),
|
m_hStdoutHandle(NULL),
|
||||||
|
|
@ -1869,12 +1931,6 @@ SERVER_PROCESS::SERVER_PROCESS() :
|
||||||
|
|
||||||
SERVER_PROCESS::~SERVER_PROCESS()
|
SERVER_PROCESS::~SERVER_PROCESS()
|
||||||
{
|
{
|
||||||
if(m_socket != NULL)
|
|
||||||
{
|
|
||||||
closesocket( m_socket );
|
|
||||||
m_socket = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_hProcessWaitHandle != NULL)
|
if (m_hProcessWaitHandle != NULL)
|
||||||
{
|
{
|
||||||
UnregisterWait( m_hProcessWaitHandle );
|
UnregisterWait( m_hProcessWaitHandle );
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue