Windows %printer% IODevice needs a valid handle for waiting
"Russell Lang" <[email protected]> Tue, 06 Jul 2004 21:24:45 +1000
| Newsgroups | gmane.comp.printing.ghostscript.patches |
|---|---|
| Message-ID | <40EB189D.16366.A5995BD4@localhost> |
This is associated with the fixes for http://bugs.ghostscript.com/show_bug.cgi?id=687562 http://bugs.ghostscript.com/show_bug.cgi?id=687542 Log Message: In the Windows %printer% IODevice, the existing thread handle is closed automatically when the thread finishes. Duplicate the thread handle so we always have a valid handle for waiting and closing. Russell Lang [email protected] Ghostgum Software Pty Ltd http://www.ghostgum.com.au/ --- l:/cvs/gs/src/gp_msprn.c Thu Feb 28 22:50:41 2002 +++ src/gp_msprn.c Tue Jul 06 11:18:24 2004 @@ -151,6 +151,7 @@ HANDLE hprinter; int pipeh[2]; unsigned long tid; + HANDLE hthread; char pname[gp_file_name_sizeof]; unsigned long *ptid = &((tid_t *)(iodev->state))->tid; @@ -179,12 +180,23 @@ } /* start a thread to read the pipe */ - *ptid = _beginthread(&mswin_printer_thread, 32768, pipeh[0]); - if (*ptid == -1) { + tid = _beginthread(&mswin_printer_thread, 32768, pipeh[0]); + if (tid == -1) { fclose(*pfile); close(pipeh[0]); return_error(gs_error_invalidfileaccess); } + /* Duplicate thread handle so we can wait on it + * even if original handle is closed by CRTL + * when the thread finishes. + */ + if (!DuplicateHandle(GetCurrentProcess(), (HANDLE)tid, + GetCurrentProcess(), &hthread, + 0, FALSE, DUPLICATE_SAME_ACCESS)) { + fclose(*pfile); + return_error(gs_error_invalidfileaccess); + } + *ptid = (unsigned long)hthread; /* Give the name of the printer to the thread by writing * it to the pipe. This is avoids elaborate thread _______________________________________________ gs-code-review mailing list [email protected] http://www.ghostscript.com/mailman/listinfo/gs-code-review