Timeout now works
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@1302 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
89c7fa3204
commit
dfbd9e93c0
2 changed files with 201 additions and 202 deletions
|
@ -28,24 +28,18 @@ freely, subject to the following restrictions:
|
||||||
#ifndef false
|
#ifndef false
|
||||||
#define false FALSE
|
#define false FALSE
|
||||||
#endif
|
#endif
|
||||||
#define TIMEOUT 15000
|
|
||||||
#define NOLOG_TIMEOUT 600000
|
|
||||||
#define LOOPTIMEOUT 100
|
#define LOOPTIMEOUT 100
|
||||||
|
|
||||||
HINSTANCE g_hInstance;
|
|
||||||
HWND g_hwndParent;
|
HWND g_hwndParent;
|
||||||
HWND g_hwndList;
|
HWND g_hwndList;
|
||||||
HWND g_hwndDlg;
|
|
||||||
char * g_exec;
|
char * g_exec;
|
||||||
char * g_szto;
|
unsigned int g_to;
|
||||||
BOOL g_foundto;
|
|
||||||
int g_to;
|
|
||||||
|
|
||||||
|
|
||||||
void ExecScript(BOOL log);
|
void ExecScript(BOOL log);
|
||||||
void LogMessage(const char *pStr);
|
void LogMessage(const char *pStr);
|
||||||
char *my_strstr(const char *string, const char *strCharSet);
|
char *my_strstr(const char *string, const char *strCharSet);
|
||||||
int my_atoi(char *s);
|
unsigned int my_atoi(char *s);
|
||||||
|
|
||||||
void __declspec(dllexport) Exec(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) {
|
void __declspec(dllexport) Exec(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) {
|
||||||
g_hwndParent=hwndParent;
|
g_hwndParent=hwndParent;
|
||||||
|
@ -64,34 +58,24 @@ void __declspec(dllexport) ExecToLog(HWND hwndParent, int string_size, char *var
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL WINAPI _DllMainCRTStartup(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) {
|
BOOL WINAPI _DllMainCRTStartup(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) {
|
||||||
g_hInstance=hInst;
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExecScript(BOOL log) {
|
void ExecScript(BOOL log) {
|
||||||
g_to = INFINITE;
|
g_to = 0; // default is no timeout
|
||||||
g_foundto = FALSE;
|
g_hwndList = FindWindowEx(FindWindowEx(g_hwndParent,NULL,"#32770",NULL),NULL,"SysListView32",NULL);
|
||||||
g_hwndDlg = FindWindowEx(g_hwndParent,NULL,"#32770",NULL);
|
|
||||||
g_hwndList = FindWindowEx(g_hwndDlg,NULL,"SysListView32",NULL);
|
|
||||||
g_exec = (char *)GlobalAlloc(GPTR, sizeof(char)*g_stringsize+1);
|
g_exec = (char *)GlobalAlloc(GPTR, sizeof(char)*g_stringsize+1);
|
||||||
g_szto = (char *)GlobalAlloc(GPTR, sizeof(char)*g_stringsize+1);
|
if (!popstring(g_exec)) {
|
||||||
if (!popstring(g_szto)) {
|
if (my_strstr(g_exec,"/TIMEOUT=")) {
|
||||||
if (my_strstr(g_szto,"/TIMEOUT=")) {
|
char *szTimeout = g_exec + 9;
|
||||||
g_szto += 9;
|
g_to = my_atoi(szTimeout);
|
||||||
g_to = my_atoi(g_szto);
|
popstring(g_exec);
|
||||||
if (g_to<0) g_to = log?TIMEOUT:NOLOG_TIMEOUT;
|
|
||||||
g_foundto = TRUE;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (g_foundto) {
|
if (!g_exec[0]) {
|
||||||
if (popstring(g_exec)) {
|
|
||||||
pushstring("error");
|
pushstring("error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else {
|
|
||||||
lstrcpy(g_exec,g_szto);
|
|
||||||
}
|
|
||||||
{
|
{
|
||||||
STARTUPINFO si={sizeof(si),};
|
STARTUPINFO si={sizeof(si),};
|
||||||
SECURITY_ATTRIBUTES sa={sizeof(sa),};
|
SECURITY_ATTRIBUTES sa={sizeof(sa),};
|
||||||
|
@ -101,10 +85,11 @@ void ExecScript(BOOL log) {
|
||||||
HANDLE newstdout=0,read_stdout=0;
|
HANDLE newstdout=0,read_stdout=0;
|
||||||
DWORD dwRead = 1;
|
DWORD dwRead = 1;
|
||||||
DWORD dwExit = !STILL_ACTIVE;
|
DWORD dwExit = !STILL_ACTIVE;
|
||||||
|
DWORD dwLastOutput;
|
||||||
static char szBuf[1024];
|
static char szBuf[1024];
|
||||||
static char szRet[128];
|
char szRet[128] = "";
|
||||||
HGLOBAL hUnusedBuf;
|
HGLOBAL hUnusedBuf;
|
||||||
static char *szUnusedBuf;
|
char *szUnusedBuf = 0;
|
||||||
|
|
||||||
if (log) {
|
if (log) {
|
||||||
hUnusedBuf = GlobalAlloc(GHND, sizeof(szBuf)*4);
|
hUnusedBuf = GlobalAlloc(GHND, sizeof(szBuf)*4);
|
||||||
|
@ -113,6 +98,7 @@ void ExecScript(BOOL log) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
szUnusedBuf = (char *)GlobalLock(hUnusedBuf);
|
szUnusedBuf = (char *)GlobalLock(hUnusedBuf);
|
||||||
|
}
|
||||||
|
|
||||||
GetVersionEx(&osv);
|
GetVersionEx(&osv);
|
||||||
if (osv.dwPlatformId == VER_PLATFORM_WIN32_NT) {
|
if (osv.dwPlatformId == VER_PLATFORM_WIN32_NT) {
|
||||||
|
@ -126,7 +112,6 @@ void ExecScript(BOOL log) {
|
||||||
pushstring("error");
|
pushstring("error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
GetStartupInfo(&si);
|
GetStartupInfo(&si);
|
||||||
si.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;
|
si.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;
|
||||||
|
@ -134,19 +119,25 @@ void ExecScript(BOOL log) {
|
||||||
si.hStdOutput = newstdout;
|
si.hStdOutput = newstdout;
|
||||||
si.hStdError = newstdout;
|
si.hStdError = newstdout;
|
||||||
if (!CreateProcess(NULL,g_exec,NULL,NULL,TRUE,CREATE_NEW_CONSOLE,NULL,NULL,&si,&pi)) {
|
if (!CreateProcess(NULL,g_exec,NULL,NULL,TRUE,CREATE_NEW_CONSOLE,NULL,NULL,&si,&pi)) {
|
||||||
|
pushstring("error");
|
||||||
CloseHandle(newstdout);
|
CloseHandle(newstdout);
|
||||||
CloseHandle(read_stdout);
|
CloseHandle(read_stdout);
|
||||||
pushstring("error");
|
if (log) {
|
||||||
|
GlobalUnlock(hUnusedBuf);
|
||||||
|
GlobalFree(hUnusedBuf);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (log) {
|
dwLastOutput = GetTickCount();
|
||||||
|
|
||||||
while (dwExit == STILL_ACTIVE || dwRead) {
|
while (dwExit == STILL_ACTIVE || dwRead) {
|
||||||
PeekNamedPipe(read_stdout, 0, 0, 0, &dwRead, NULL);
|
PeekNamedPipe(read_stdout, 0, 0, 0, &dwRead, NULL);
|
||||||
if (dwRead) {
|
if (dwRead) {
|
||||||
|
dwLastOutput = GetTickCount();
|
||||||
ReadFile(read_stdout, szBuf, sizeof(szBuf)-1, &dwRead, NULL);
|
ReadFile(read_stdout, szBuf, sizeof(szBuf)-1, &dwRead, NULL);
|
||||||
szBuf[dwRead] = 0;
|
szBuf[dwRead] = 0;
|
||||||
{
|
if (log) {
|
||||||
char *p, *lineBreak;
|
char *p, *lineBreak;
|
||||||
SIZE_T iReqLen = lstrlen(szBuf) + lstrlen(szUnusedBuf);
|
SIZE_T iReqLen = lstrlen(szBuf) + lstrlen(szUnusedBuf);
|
||||||
if (GlobalSize(hUnusedBuf) < iReqLen) {
|
if (GlobalSize(hUnusedBuf) < iReqLen) {
|
||||||
|
@ -158,6 +149,10 @@ void ExecScript(BOOL log) {
|
||||||
CloseHandle(pi.hProcess);
|
CloseHandle(pi.hProcess);
|
||||||
CloseHandle(newstdout);
|
CloseHandle(newstdout);
|
||||||
CloseHandle(read_stdout);
|
CloseHandle(read_stdout);
|
||||||
|
if (log) {
|
||||||
|
GlobalUnlock(hUnusedBuf);
|
||||||
|
GlobalFree(hUnusedBuf);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
szUnusedBuf = (char *)GlobalLock(hUnusedBuf);
|
szUnusedBuf = (char *)GlobalLock(hUnusedBuf);
|
||||||
|
@ -179,22 +174,29 @@ void ExecScript(BOOL log) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
if (g_to && GetTickCount() > dwLastOutput+g_to) {
|
||||||
|
TerminateProcess(pi.hProcess, -1);
|
||||||
|
lstrcpy(szRet, "timeout");
|
||||||
|
}
|
||||||
else Sleep(LOOPTIMEOUT);
|
else Sleep(LOOPTIMEOUT);
|
||||||
|
}
|
||||||
GetExitCodeProcess(pi.hProcess, &dwExit);
|
GetExitCodeProcess(pi.hProcess, &dwExit);
|
||||||
if (dwExit != STILL_ACTIVE) {
|
if (dwExit != STILL_ACTIVE) {
|
||||||
PeekNamedPipe(read_stdout, 0, 0, 0, &dwRead, NULL);
|
PeekNamedPipe(read_stdout, 0, 0, 0, &dwRead, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (*szUnusedBuf) LogMessage(szUnusedBuf);
|
if (log && *szUnusedBuf) LogMessage(szUnusedBuf);
|
||||||
}
|
if (!szRet[0]) wsprintf(szRet,"%d",dwExit);
|
||||||
else WaitForSingleObject(pi.hProcess, g_to);
|
|
||||||
wsprintf(szRet,"%d",dwExit);
|
|
||||||
pushstring(szRet);
|
pushstring(szRet);
|
||||||
CloseHandle(pi.hThread);
|
CloseHandle(pi.hThread);
|
||||||
CloseHandle(pi.hProcess);
|
CloseHandle(pi.hProcess);
|
||||||
CloseHandle(newstdout);
|
CloseHandle(newstdout);
|
||||||
CloseHandle(read_stdout);
|
CloseHandle(read_stdout);
|
||||||
if (log) GlobalUnlock(hUnusedBuf);
|
if (log) {
|
||||||
|
GlobalUnlock(hUnusedBuf);
|
||||||
|
GlobalFree(hUnusedBuf);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,7 +232,7 @@ char *my_strstr(const char *string, const char *strCharSet) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int my_atoi(char *s) {
|
unsigned int my_atoi(char *s) {
|
||||||
unsigned int v=0;
|
unsigned int v=0;
|
||||||
if (*s == '0' && (s[1] == 'x' || s[1] == 'X')) {
|
if (*s == '0' && (s[1] == 'x' || s[1] == 'X')) {
|
||||||
s+=2;
|
s+=2;
|
||||||
|
@ -255,15 +257,12 @@ int my_atoi(char *s) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int sign=0;
|
|
||||||
if (*s == '-') { s++; sign++; }
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
int c=*s++ - '0';
|
int c=*s++ - '0';
|
||||||
if (c < 0 || c > 9) break;
|
if (c < 0 || c > 9) break;
|
||||||
v*=10;
|
v*=10;
|
||||||
v+=c;
|
v+=c;
|
||||||
}
|
}
|
||||||
if (sign) return -(int) v;
|
|
||||||
}
|
}
|
||||||
return (int)v;
|
return (int)v;
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue