Now doesn't crash when using Exec and not ExecToLog. ExecToLog timeout is not yet implemented.
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@1271 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
3d1c70f375
commit
5c5ce97e25
3 changed files with 60 additions and 53 deletions
|
@ -17,7 +17,9 @@ to the logwindow.
|
||||||
|
|
||||||
The timeout value is optional and is used to set the time in
|
The timeout value is optional and is used to set the time in
|
||||||
milliseconds for the plugin to wait for the process to return
|
milliseconds for the plugin to wait for the process to return
|
||||||
before it quits.
|
before it quits, or the time in milliseconds for the plugin
|
||||||
|
to wait for output to come out before it quits if using
|
||||||
|
ExecToLog. The default is no timeout.
|
||||||
|
|
||||||
|
|
||||||
Return Value
|
Return Value
|
||||||
|
|
|
@ -29,6 +29,7 @@ freely, subject to the following restrictions:
|
||||||
#define false FALSE
|
#define false FALSE
|
||||||
#endif
|
#endif
|
||||||
#define TIMEOUT 15000
|
#define TIMEOUT 15000
|
||||||
|
#define NOLOG_TIMEOUT 600000
|
||||||
#define LOOPTIMEOUT 100
|
#define LOOPTIMEOUT 100
|
||||||
|
|
||||||
HINSTANCE g_hInstance;
|
HINSTANCE g_hInstance;
|
||||||
|
@ -68,7 +69,7 @@ BOOL WINAPI _DllMainCRTStartup(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lp
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExecScript(BOOL log) {
|
void ExecScript(BOOL log) {
|
||||||
g_to = TIMEOUT;
|
g_to = INFINITE;
|
||||||
g_foundto = FALSE;
|
g_foundto = FALSE;
|
||||||
g_hwndDlg = FindWindowEx(g_hwndParent,NULL,"#32770",NULL);
|
g_hwndDlg = FindWindowEx(g_hwndParent,NULL,"#32770",NULL);
|
||||||
g_hwndList = FindWindowEx(g_hwndDlg,NULL,"SysListView32",NULL);
|
g_hwndList = FindWindowEx(g_hwndDlg,NULL,"SysListView32",NULL);
|
||||||
|
@ -78,7 +79,7 @@ void ExecScript(BOOL log) {
|
||||||
if (my_strstr(g_szto,"/TIMEOUT=")) {
|
if (my_strstr(g_szto,"/TIMEOUT=")) {
|
||||||
g_szto += 9;
|
g_szto += 9;
|
||||||
g_to = my_atoi(g_szto);
|
g_to = my_atoi(g_szto);
|
||||||
if (g_to<0) g_to = TIMEOUT;
|
if (g_to<0) g_to = log?TIMEOUT:NOLOG_TIMEOUT;
|
||||||
g_foundto = TRUE;
|
g_foundto = TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -112,20 +113,21 @@ void ExecScript(BOOL log) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
szUnusedBuf = (char *)GlobalLock(hUnusedBuf);
|
szUnusedBuf = (char *)GlobalLock(hUnusedBuf);
|
||||||
|
|
||||||
|
GetVersionEx(&osv);
|
||||||
|
if (osv.dwPlatformId == VER_PLATFORM_WIN32_NT) {
|
||||||
|
InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION);
|
||||||
|
SetSecurityDescriptorDacl(&sd,true,NULL,false);
|
||||||
|
sa.lpSecurityDescriptor = &sd;
|
||||||
|
}
|
||||||
|
else sa.lpSecurityDescriptor = NULL;
|
||||||
|
sa.bInheritHandle = true;
|
||||||
|
if (!CreatePipe(&read_stdout,&newstdout,&sa,0)) {
|
||||||
|
pushstring("error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GetVersionEx(&osv);
|
|
||||||
if (osv.dwPlatformId == VER_PLATFORM_WIN32_NT) {
|
|
||||||
InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION);
|
|
||||||
SetSecurityDescriptorDacl(&sd,true,NULL,false);
|
|
||||||
sa.lpSecurityDescriptor = &sd;
|
|
||||||
}
|
|
||||||
else sa.lpSecurityDescriptor = NULL;
|
|
||||||
sa.bInheritHandle = true;
|
|
||||||
if (!CreatePipe(&read_stdout,&newstdout,&sa,0)) {
|
|
||||||
pushstring("error");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
GetStartupInfo(&si);
|
GetStartupInfo(&si);
|
||||||
si.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;
|
si.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;
|
||||||
si.wShowWindow = SW_HIDE;
|
si.wShowWindow = SW_HIDE;
|
||||||
|
@ -138,51 +140,54 @@ void ExecScript(BOOL log) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (dwExit == STILL_ACTIVE || dwRead) {
|
if (log) {
|
||||||
PeekNamedPipe(read_stdout, 0, 0, 0, &dwRead, NULL);
|
while (dwExit == STILL_ACTIVE || dwRead) {
|
||||||
if (dwRead) {
|
PeekNamedPipe(read_stdout, 0, 0, 0, &dwRead, NULL);
|
||||||
ReadFile(read_stdout, szBuf, sizeof(szBuf)-1, &dwRead, NULL);
|
if (dwRead) {
|
||||||
szBuf[dwRead] = 0;
|
ReadFile(read_stdout, szBuf, sizeof(szBuf)-1, &dwRead, NULL);
|
||||||
if (log) {
|
szBuf[dwRead] = 0;
|
||||||
char *p, *lineBreak;
|
{
|
||||||
SIZE_T iReqLen = lstrlen(szBuf) + lstrlen(szUnusedBuf);
|
char *p, *lineBreak;
|
||||||
if (GlobalSize(hUnusedBuf) < iReqLen) {
|
SIZE_T iReqLen = lstrlen(szBuf) + lstrlen(szUnusedBuf);
|
||||||
GlobalUnlock(hUnusedBuf);
|
if (GlobalSize(hUnusedBuf) < iReqLen) {
|
||||||
hUnusedBuf = GlobalReAlloc(hUnusedBuf, iReqLen+sizeof(szBuf), GHND);
|
GlobalUnlock(hUnusedBuf);
|
||||||
if (!hUnusedBuf) {
|
hUnusedBuf = GlobalReAlloc(hUnusedBuf, iReqLen+sizeof(szBuf), GHND);
|
||||||
pushstring("error");
|
if (!hUnusedBuf) {
|
||||||
CloseHandle(pi.hThread);
|
pushstring("error");
|
||||||
CloseHandle(pi.hProcess);
|
CloseHandle(pi.hThread);
|
||||||
CloseHandle(newstdout);
|
CloseHandle(pi.hProcess);
|
||||||
CloseHandle(read_stdout);
|
CloseHandle(newstdout);
|
||||||
return;
|
CloseHandle(read_stdout);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
szUnusedBuf = (char *)GlobalLock(hUnusedBuf);
|
||||||
}
|
}
|
||||||
szUnusedBuf = (char *)GlobalLock(hUnusedBuf);
|
p = szUnusedBuf; // get the old left overs
|
||||||
}
|
lstrcat(p, szBuf);
|
||||||
p = szUnusedBuf; // get the old left overs
|
|
||||||
lstrcat(p, szBuf);
|
|
||||||
|
|
||||||
while (lineBreak = my_strstr(p, "\r\n")) {
|
while (lineBreak = my_strstr(p, "\r\n")) {
|
||||||
*lineBreak = 0;
|
*lineBreak = 0;
|
||||||
LogMessage(p);
|
LogMessage(p);
|
||||||
p = lineBreak + 2;
|
p = lineBreak + 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If data was taken out from the unused buffer, move p contents to the start of szUnusedBuf
|
// If data was taken out from the unused buffer, move p contents to the start of szUnusedBuf
|
||||||
if (p != szUnusedBuf) {
|
if (p != szUnusedBuf) {
|
||||||
char *p2 = szUnusedBuf;
|
char *p2 = szUnusedBuf;
|
||||||
while (*p) *p2++ = *p++;
|
while (*p) *p2++ = *p++;
|
||||||
*p2 = 0;
|
*p2 = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else Sleep(LOOPTIMEOUT);
|
||||||
|
GetExitCodeProcess(pi.hProcess, &dwExit);
|
||||||
|
if (dwExit != STILL_ACTIVE) {
|
||||||
|
PeekNamedPipe(read_stdout, 0, 0, 0, &dwRead, NULL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else Sleep(LOOPTIMEOUT);
|
if (*szUnusedBuf) LogMessage(szUnusedBuf);
|
||||||
GetExitCodeProcess(pi.hProcess, &dwExit);
|
|
||||||
if (dwExit != STILL_ACTIVE) {
|
|
||||||
PeekNamedPipe(read_stdout, 0, 0, 0, &dwRead, NULL);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (*szUnusedBuf) LogMessage(szUnusedBuf);
|
else WaitForSingleObject(pi.hProcess, g_to);
|
||||||
wsprintf(szRet,"%d",dwExit);
|
wsprintf(szRet,"%d",dwExit);
|
||||||
pushstring(szRet);
|
pushstring(szRet);
|
||||||
CloseHandle(pi.hThread);
|
CloseHandle(pi.hThread);
|
||||||
|
|
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue