From 6df7adfff1a344ab7983b49e4ccb8f1d133b9171 Mon Sep 17 00:00:00 2001 From: Ken Thomases Date: Wed, 30 Nov 2011 16:49:14 -0600 Subject: [PATCH] winspool: Wait for and reap print spool child process. --- dlls/winspool.drv/info.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/dlls/winspool.drv/info.c b/dlls/winspool.drv/info.c index 7bf9149ca0a..68ab5d7d4c5 100644 --- a/dlls/winspool.drv/info.c +++ b/dlls/winspool.drv/info.c @@ -33,6 +33,12 @@ #include #include #include +#ifdef HAVE_SYS_ERRNO_H +#include +#endif +#ifdef HAVE_SYS_WAIT_H +#include +#endif #ifdef HAVE_UNISTD_H # include #endif @@ -7408,6 +7414,8 @@ static BOOL schedule_pipe(LPCWSTR cmd, LPCWSTR filename) int fds[2] = {-1, -1}, file_fd = -1, no_read; BOOL ret = FALSE; char buf[1024]; + pid_t pid, wret; + int status; if(!(unixname = wine_get_unix_file_name(filename))) return FALSE; @@ -7427,7 +7435,7 @@ static BOOL schedule_pipe(LPCWSTR cmd, LPCWSTR filename) goto end; } - if (fork() == 0) + if ((pid = fork()) == 0) { close(0); dup2(fds[0], 0); @@ -7439,10 +7447,33 @@ static BOOL schedule_pipe(LPCWSTR cmd, LPCWSTR filename) execl("/bin/sh", "/bin/sh", "-c", cmdA, NULL); _exit(1); } + else if (pid == -1) + { + ERR("fork() failed!\n"); + goto end; + } while((no_read = read(file_fd, buf, sizeof(buf))) > 0) write(fds[1], buf, no_read); + close(fds[1]); + fds[1] = -1; + + /* reap child */ + do { + wret = waitpid(pid, &status, 0); + } while (wret < 0 && errno == EINTR); + if (wret < 0) + { + ERR("waitpid() failed!\n"); + goto end; + } + if (!WIFEXITED(status) || WEXITSTATUS(status)) + { + ERR("child process failed! %d\n", status); + goto end; + } + ret = TRUE; end: