diff options
author | Brad King <brad.king@kitware.com> | 2003-12-14 13:47:39 -0500 |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2003-12-14 13:47:39 -0500 |
commit | 5dcbef7dfe7e365b1cb2f5881be07bc934df8df5 (patch) | |
tree | daa135c3208101aea95b4565f4434c6afa0ddd83 /Source/kwsys/ProcessWin32.c | |
parent | 8da78710bc24b39f39f586b76395fe14660099e0 (diff) | |
download | cmake-5dcbef7dfe7e365b1cb2f5881be07bc934df8df5.tar.gz |
ENH: Using CreateFile with FILE_FLAG_DELETE_ON_CLOSE to automatically delete the Win9x forwarding executable even if the parent process crashes.
Diffstat (limited to 'Source/kwsys/ProcessWin32.c')
-rw-r--r-- | Source/kwsys/ProcessWin32.c | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/Source/kwsys/ProcessWin32.c b/Source/kwsys/ProcessWin32.c index 90f54b60e7..d52a5d1922 100644 --- a/Source/kwsys/ProcessWin32.c +++ b/Source/kwsys/ProcessWin32.c @@ -187,6 +187,9 @@ struct kwsysProcess_s char* PipeFileSTDOUT; char* PipeFileSTDERR; + /* Handle to automatically delete the Win9x forwarding executable. */ + HANDLE Win9xHandle; + /* ------------- Data managed per call to Execute ------------- */ /* The exceptional behavior that terminated the process, if any. */ @@ -286,7 +289,8 @@ kwsysProcess* kwsysProcess_New() /* Construct the executable name from the process id and kwsysProcess instance. This should be unique. */ - sprintf(fwdName, "cmw9xfwd_%u_%p.exe", GetCurrentProcessId(), cp); + sprintf(fwdName, KWSYS_NAMESPACE_STRING "pew9xfwd_%u_%p.exe", + GetCurrentProcessId(), cp); /* If we have a temp directory, use it. */ if(length > 0 && length <= _MAX_PATH) @@ -315,6 +319,19 @@ kwsysProcess* kwsysProcess_New() kwsysProcess_Delete(cp); return 0; } + + /* Get a handle to the file that will delete it when closed. */ + cp->Win9xHandle = CreateFile(win9x, GENERIC_READ, FILE_SHARE_READ, 0, + OPEN_EXISTING, FILE_FLAG_DELETE_ON_CLOSE, 0); + if(cp->Win9xHandle == INVALID_HANDLE_VALUE) + { + /* We were not able to get a read handle for the forwarding + executable. It will not be deleted properly. Give up. */ + _unlink(win9x); + free(win9x); + kwsysProcess_Delete(cp); + return 0; + } } else { @@ -475,8 +492,9 @@ void kwsysProcess_Delete(kwsysProcess* cp) } if(cp->Win9x) { - _unlink(cp->Win9x); - free(cp->Win9x); + /* Close or handle to the forwarding executable file. This will + cause it to be deleted. */ + kwsysProcessCleanupHandle(&cp->Win9xHandle); } free(cp); } |