MCPcopy Create free account
hub / github.com/Kitware/CMake / kwsysProcessCleanup

Function kwsysProcessCleanup

Source/kwsys/ProcessWin32.c:1855–1936  ·  view source on GitHub ↗

Close all handles created by kwsysProcess_Execute. */

Source from the content-addressed store, hash-verified

1853
1854/* Close all handles created by kwsysProcess_Execute. */
1855void kwsysProcessCleanup(kwsysProcess* cp, DWORD error)
1856{
1857 int i;
1858 /* If this is an error case, report the error. */
1859 if (error) {
1860 /* Construct an error message if one has not been provided already. */
1861 if (cp->ErrorMessage[0] == 0) {
1862 /* Format the error message. */
1863 wchar_t err_msg[KWSYSPE_PIPE_BUFFER_SIZE];
1864 DWORD length = FormatMessageW(
1865 FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0, error,
1866 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), err_msg,
1867 KWSYSPE_PIPE_BUFFER_SIZE, 0);
1868 if (length < 1) {
1869 /* FormatMessage failed. Use a default message. */
1870 snprintf(cp->ErrorMessage, KWSYSPE_PIPE_BUFFER_SIZE,
1871 "Process execution failed with error 0x%lX. "
1872 "FormatMessage failed with error 0x%lX",
1873 error, GetLastError());
1874 }
1875 if (!WideCharToMultiByte(CP_UTF8, 0, err_msg, -1, cp->ErrorMessage,
1876 KWSYSPE_PIPE_BUFFER_SIZE, NULL, NULL)) {
1877 /* WideCharToMultiByte failed. Use a default message. */
1878 snprintf(cp->ErrorMessage, KWSYSPE_PIPE_BUFFER_SIZE,
1879 "Process execution failed with error 0x%lX. "
1880 "WideCharToMultiByte failed with error 0x%lX",
1881 error, GetLastError());
1882 }
1883 }
1884
1885 /* Remove trailing period and newline, if any. */
1886 kwsysProcessCleanErrorMessage(cp);
1887
1888 /* Set the error state. */
1889 cp->State = kwsysProcess_State_Error;
1890
1891 /* Cleanup any processes already started in a suspended state. */
1892 if (cp->ProcessInformation) {
1893 for (i = 0; i < cp->NumberOfCommands; ++i) {
1894 if (cp->ProcessInformation[i].hProcess) {
1895 TerminateProcess(cp->ProcessInformation[i].hProcess, 255);
1896 WaitForSingleObject(cp->ProcessInformation[i].hProcess, INFINITE);
1897 }
1898 }
1899 for (i = 0; i < cp->NumberOfCommands; ++i) {
1900 /* Remove from global list of processes and close handles. */
1901 kwsysProcessesRemove(cp->ProcessInformation[i].hProcess);
1902 kwsysProcessCleanupHandle(&cp->ProcessInformation[i].hThread);
1903 kwsysProcessCleanupHandle(&cp->ProcessInformation[i].hProcess);
1904 }
1905 }
1906
1907 /* Restore the working directory. */
1908 if (cp->RealWorkingDirectory) {
1909 SetCurrentDirectoryW(cp->RealWorkingDirectory);
1910 }
1911 }
1912

Callers 3

kwsysProcess_ExecuteFunction · 0.70
kwsysProcess_DisownFunction · 0.70
kwsysProcess_WaitForExitFunction · 0.70

Calls 4

kwsysProcessesRemoveFunction · 0.70
snprintfFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…