mirror of https://github.com/OpenVPN/openvpn-gui
Add logging to RunConnectScript()
parent
3fb55cba60
commit
c9becbf1ec
21
scripts.c
21
scripts.c
|
@ -116,16 +116,31 @@ RunConnectScript(connection_t *c, int run_as_service)
|
||||||
if (!run_as_service)
|
if (!run_as_service)
|
||||||
SetDlgItemText(c->hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_CONN_SCRIPT));
|
SetDlgItemText(c->hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_CONN_SCRIPT));
|
||||||
|
|
||||||
|
// Create the filename of the logfile
|
||||||
|
TCHAR script_log_filename[MAX_PATH];
|
||||||
|
_sntprintf_0(script_log_filename, _T("%s\\%s_up.log"), o.log_dir, c->config_name);
|
||||||
|
|
||||||
|
// Create the log file
|
||||||
|
SECURITY_ATTRIBUTES sa;
|
||||||
|
CLEAR(sa);
|
||||||
|
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
|
||||||
|
sa.lpSecurityDescriptor = NULL;
|
||||||
|
sa.bInheritHandle = TRUE;
|
||||||
|
|
||||||
|
HANDLE logfile_handle = CreateFile(script_log_filename, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||||
|
&sa, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||||
|
|
||||||
CLEAR(si);
|
CLEAR(si);
|
||||||
CLEAR(pi);
|
CLEAR(pi);
|
||||||
|
|
||||||
/* fill in STARTUPINFO struct */
|
/* fill in STARTUPINFO struct */
|
||||||
GetStartupInfo(&si);
|
GetStartupInfo(&si);
|
||||||
si.cb = sizeof(si);
|
si.cb = sizeof(si);
|
||||||
si.dwFlags = 0;
|
si.dwFlags = STARTF_USESTDHANDLES;
|
||||||
si.wShowWindow = SW_SHOWDEFAULT;
|
si.wShowWindow = SW_SHOWDEFAULT;
|
||||||
si.hStdInput = NULL;
|
si.hStdInput = NULL;
|
||||||
si.hStdOutput = NULL;
|
si.hStdOutput = logfile_handle;
|
||||||
|
si.hStdError = logfile_handle;
|
||||||
|
|
||||||
/* make an env array with confg specific env appended to the process's env */
|
/* make an env array with confg specific env appended to the process's env */
|
||||||
WCHAR *env = c->es ? merge_env_block(c->es) : NULL;
|
WCHAR *env = c->es ? merge_env_block(c->es) : NULL;
|
||||||
|
@ -168,6 +183,8 @@ out:
|
||||||
free(env);
|
free(env);
|
||||||
CloseHandle(pi.hThread);
|
CloseHandle(pi.hThread);
|
||||||
CloseHandle(pi.hProcess);
|
CloseHandle(pi.hProcess);
|
||||||
|
if (logfile_handle != NULL)
|
||||||
|
CloseHandle(logfile_handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue