mirror of
git://source.winehq.org/git/wine.git
synced 2024-10-14 19:47:27 +00:00
winspool.drv: Rewrite the lpr scheduler to use the pipe scheduler.
This commit is contained in:
parent
5bdcd79c2e
commit
052cfad067
|
@ -7361,32 +7361,83 @@ BOOL WINAPI GetJobW(HANDLE hPrinter, DWORD JobId, DWORD Level, LPBYTE pJob,
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* schedule_lpr
|
* schedule_pipe
|
||||||
*/
|
*/
|
||||||
static BOOL schedule_lpr(LPCWSTR printer_name, LPCWSTR filename)
|
static BOOL schedule_pipe(LPCWSTR cmd, LPCWSTR filename)
|
||||||
{
|
{
|
||||||
char *unixname, *queue, *cmd;
|
#ifdef HAVE_FORK
|
||||||
char fmt[] = "lpr -P'%s' '%s'";
|
char *unixname, *cmdA;
|
||||||
DWORD len;
|
DWORD len;
|
||||||
int r;
|
int fds[2] = {-1, -1}, file_fd = -1, no_read;
|
||||||
|
BOOL ret = FALSE;
|
||||||
|
char buf[1024];
|
||||||
|
|
||||||
if(!(unixname = wine_get_unix_file_name(filename)))
|
if(!(unixname = wine_get_unix_file_name(filename)))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
len = WideCharToMultiByte(CP_ACP, 0, printer_name, -1, NULL, 0, NULL, NULL);
|
len = WideCharToMultiByte(CP_UNIXCP, 0, cmd, -1, NULL, 0, NULL, NULL);
|
||||||
queue = HeapAlloc(GetProcessHeap(), 0, len);
|
cmdA = HeapAlloc(GetProcessHeap(), 0, len);
|
||||||
WideCharToMultiByte(CP_ACP, 0, printer_name, -1, queue, len, NULL, NULL);
|
WideCharToMultiByte(CP_UNIXCP, 0, cmd, -1, cmdA, len, NULL, NULL);
|
||||||
|
|
||||||
cmd = HeapAlloc(GetProcessHeap(), 0, strlen(unixname) + len + sizeof(fmt) - 5);
|
TRACE("printing with: %s\n", cmdA);
|
||||||
sprintf(cmd, fmt, queue, unixname);
|
|
||||||
|
|
||||||
TRACE("printing with: %s\n", cmd);
|
if((file_fd = open(unixname, O_RDONLY)) == -1)
|
||||||
r = system(cmd);
|
goto end;
|
||||||
|
|
||||||
|
if (pipe(fds))
|
||||||
|
{
|
||||||
|
ERR("pipe() failed!\n");
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fork() == 0)
|
||||||
|
{
|
||||||
|
close(0);
|
||||||
|
dup2(fds[0], 0);
|
||||||
|
close(fds[1]);
|
||||||
|
|
||||||
|
/* reset signals that we previously set to SIG_IGN */
|
||||||
|
signal(SIGPIPE, SIG_DFL);
|
||||||
|
signal(SIGCHLD, SIG_DFL);
|
||||||
|
|
||||||
|
execl("/bin/sh", "/bin/sh", "-c", cmdA, NULL);
|
||||||
|
_exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
while((no_read = read(file_fd, buf, sizeof(buf))) > 0)
|
||||||
|
write(fds[1], buf, no_read);
|
||||||
|
|
||||||
|
ret = TRUE;
|
||||||
|
|
||||||
|
end:
|
||||||
|
if(file_fd != -1) close(file_fd);
|
||||||
|
if(fds[0] != -1) close(fds[0]);
|
||||||
|
if(fds[1] != -1) close(fds[1]);
|
||||||
|
|
||||||
|
HeapFree(GetProcessHeap(), 0, cmdA);
|
||||||
|
HeapFree(GetProcessHeap(), 0, unixname);
|
||||||
|
return ret;
|
||||||
|
#else
|
||||||
|
return FALSE;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************
|
||||||
|
* schedule_lpr
|
||||||
|
*/
|
||||||
|
static BOOL schedule_lpr(LPCWSTR printer_name, LPCWSTR filename)
|
||||||
|
{
|
||||||
|
WCHAR *cmd;
|
||||||
|
const WCHAR fmtW[] = {'l','p','r',' ','-','P','\'','%','s','\'',0};
|
||||||
|
BOOL r;
|
||||||
|
|
||||||
|
cmd = HeapAlloc(GetProcessHeap(), 0, strlenW(printer_name) * sizeof(WCHAR) + sizeof(fmtW));
|
||||||
|
sprintfW(cmd, fmtW, printer_name);
|
||||||
|
|
||||||
|
r = schedule_pipe(cmd, filename);
|
||||||
|
|
||||||
HeapFree(GetProcessHeap(), 0, cmd);
|
HeapFree(GetProcessHeap(), 0, cmd);
|
||||||
HeapFree(GetProcessHeap(), 0, queue);
|
return r;
|
||||||
HeapFree(GetProcessHeap(), 0, unixname);
|
|
||||||
return (r == 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
|
@ -7518,68 +7569,6 @@ static BOOL schedule_file(LPCWSTR filename)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* schedule_pipe
|
|
||||||
*/
|
|
||||||
static BOOL schedule_pipe(LPCWSTR cmd, LPCWSTR filename)
|
|
||||||
{
|
|
||||||
#ifdef HAVE_FORK
|
|
||||||
char *unixname, *cmdA;
|
|
||||||
DWORD len;
|
|
||||||
int fds[2] = {-1, -1}, file_fd = -1, no_read;
|
|
||||||
BOOL ret = FALSE;
|
|
||||||
char buf[1024];
|
|
||||||
|
|
||||||
if(!(unixname = wine_get_unix_file_name(filename)))
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
len = WideCharToMultiByte(CP_UNIXCP, 0, cmd, -1, NULL, 0, NULL, NULL);
|
|
||||||
cmdA = HeapAlloc(GetProcessHeap(), 0, len);
|
|
||||||
WideCharToMultiByte(CP_UNIXCP, 0, cmd, -1, cmdA, len, NULL, NULL);
|
|
||||||
|
|
||||||
TRACE("printing with: %s\n", cmdA);
|
|
||||||
|
|
||||||
if((file_fd = open(unixname, O_RDONLY)) == -1)
|
|
||||||
goto end;
|
|
||||||
|
|
||||||
if (pipe(fds))
|
|
||||||
{
|
|
||||||
ERR("pipe() failed!\n");
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fork() == 0)
|
|
||||||
{
|
|
||||||
close(0);
|
|
||||||
dup2(fds[0], 0);
|
|
||||||
close(fds[1]);
|
|
||||||
|
|
||||||
/* reset signals that we previously set to SIG_IGN */
|
|
||||||
signal(SIGPIPE, SIG_DFL);
|
|
||||||
signal(SIGCHLD, SIG_DFL);
|
|
||||||
|
|
||||||
execl("/bin/sh", "/bin/sh", "-c", cmdA, NULL);
|
|
||||||
_exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
while((no_read = read(file_fd, buf, sizeof(buf))) > 0)
|
|
||||||
write(fds[1], buf, no_read);
|
|
||||||
|
|
||||||
ret = TRUE;
|
|
||||||
|
|
||||||
end:
|
|
||||||
if(file_fd != -1) close(file_fd);
|
|
||||||
if(fds[0] != -1) close(fds[0]);
|
|
||||||
if(fds[1] != -1) close(fds[1]);
|
|
||||||
|
|
||||||
HeapFree(GetProcessHeap(), 0, cmdA);
|
|
||||||
HeapFree(GetProcessHeap(), 0, unixname);
|
|
||||||
return ret;
|
|
||||||
#else
|
|
||||||
return FALSE;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* schedule_unixfile
|
* schedule_unixfile
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue