Module: wine Branch: master Commit: 6c8929f83fb4e6bb456bc6bcfb3e9a0f83f81474 URL: http://source.winehq.org/git/wine.git/?a=commit;h=6c8929f83fb4e6bb456bc6bcfb...
Author: Ken Thomases ken@codeweavers.com Date: Wed Nov 30 16:49:06 2011 -0600
gdi.exe16: Wait for and reap print spool child process.
---
dlls/gdi.exe16/printdrv.c | 28 +++++++++++++++++++++++----- 1 files changed, 23 insertions(+), 5 deletions(-)
diff --git a/dlls/gdi.exe16/printdrv.c b/dlls/gdi.exe16/printdrv.c index 3bd0605..c1665f5 100644 --- a/dlls/gdi.exe16/printdrv.c +++ b/dlls/gdi.exe16/printdrv.c @@ -34,6 +34,9 @@ #ifdef HAVE_IO_H # include <io.h> #endif +#ifdef HAVE_SYS_WAIT_H +# include <sys/wait.h> +#endif #ifdef HAVE_UNISTD_H # include <unistd.h> #endif @@ -205,6 +208,7 @@ typedef struct PRINTJOB HANDLE16 hHandle; int nIndex; int fd; + pid_t pid; } PRINTJOB, *PPRINTJOB;
#define MAX_PRINT_JOBS 1 @@ -218,7 +222,7 @@ static PPRINTJOB FindPrintJobFromHandle(HANDLE16 hHandle) return gPrintJobsTable[0]; }
-static int CreateSpoolFile(LPCSTR pszOutput) +static int CreateSpoolFile(LPCSTR pszOutput, pid_t *out_pid) { int fd=-1; char psCmd[1024]; @@ -227,9 +231,11 @@ static int CreateSpoolFile(LPCSTR pszOutput)
/* TTD convert the 'output device' into a spool file name */
- if (pszOutput == NULL || *pszOutput == '\0') + if (pszOutput == NULL || *pszOutput == '\0' || out_pid == NULL) return -1;
+ *out_pid = -1; + psCmd[0] = 0; /* @@ Wine registry key: HKCU\Software\Wine\Printing\Spooler */ if(!RegOpenKeyA(HKEY_CURRENT_USER, "Software\Wine\Printing\Spooler", &hkey)) @@ -263,7 +269,7 @@ static int CreateSpoolFile(LPCSTR pszOutput) ERR("pipe() failed!\n"); return -1; } - if (fork() == 0) + if ((*out_pid = fork()) == 0) { psCmdP++;
@@ -317,12 +323,22 @@ static int FreePrintJob(HANDLE16 hJob) pPrintJob = FindPrintJobFromHandle(hJob); if (pPrintJob != NULL) { + nRet = SP_OK; gPrintJobsTable[pPrintJob->nIndex] = NULL; HeapFree(GetProcessHeap(), 0, pPrintJob->pszOutput); HeapFree(GetProcessHeap(), 0, pPrintJob->pszTitle); if (pPrintJob->fd >= 0) close(pPrintJob->fd); + if (pPrintJob->pid > 0) + { + pid_t wret; + int status; + do { + wret = waitpid(pPrintJob->pid, &status, 0); + } while (wret < 0 && errno == EINTR); + if (wret < 0 || !WIFEXITED(status) || WEXITSTATUS(status)) + nRet = SP_ERROR; + } HeapFree(GetProcessHeap(), 0, pPrintJob); - nRet = SP_OK; } return nRet; } @@ -342,9 +358,10 @@ HPJOB16 WINAPI OpenJob16(LPCSTR lpOutput, LPCSTR lpTitle, HDC16 hDC) if (pPrintJob == NULL) { int fd; + pid_t pid;
/* Try and create a spool file */ - fd = CreateSpoolFile(lpOutput); + fd = CreateSpoolFile(lpOutput, &pid); if (fd >= 0) { pPrintJob = HeapAlloc(GetProcessHeap(), 0, sizeof(PRINTJOB)); @@ -364,6 +381,7 @@ HPJOB16 WINAPI OpenJob16(LPCSTR lpOutput, LPCSTR lpTitle, HDC16 hDC) } pPrintJob->hDC = hDC; pPrintJob->fd = fd; + pPrintJob->pid = pid; pPrintJob->nIndex = 0; pPrintJob->hHandle = hHandle; gPrintJobsTable[pPrintJob->nIndex] = pPrintJob;