drop LPR support

neither the option nor the feature where properly exposed to the user so
there is no user-visible change. it can be done by writing to temporary
file and executing `lp` via QProcess, however that could potentially
leak private information

Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
This commit is contained in:
Ivailo Monev 2020-01-18 05:28:02 +00:00
parent 4e8305cb87
commit 5a3f09d4da
8 changed files with 5 additions and 247 deletions

View file

@ -527,7 +527,7 @@ else()
endif()
if(NOT WITH_CUPS OR NOT CUPS_FOUND)
katie_definition(-DQT_NO_CUPS -DQT_NO_LPR)
katie_definition(-DQT_NO_CUPS)
endif()
if(NOT WITH_RESOLV OR NOT RESOLV_FOUND)

View file

@ -90,6 +90,7 @@
#define QT_NO_IMAGE_TEXT
#define QT_NO_GLIB
#define QT_NO_ICONV
#define QT_NO_LPR
// Not supported, used to bootstrap
#cmakedefine QT_NO_QOBJECT
@ -213,7 +214,6 @@
#cmakedefine QT_NO_LOCALFILE_OPTIMIZED_QML
#cmakedefine QT_NO_LOCALSERVER
#cmakedefine QT_NO_LOCALSOCKET
#cmakedefine QT_NO_LPR
#cmakedefine QT_NO_MAINWINDOW
#cmakedefine QT_NO_MATRIX4X4
#cmakedefine QT_NO_MDIAREA

View file

@ -1419,9 +1419,6 @@ void QPdfBaseEngine::setProperty(PrintEnginePropertyKey key, const QVariant &val
case PPK_PrinterName:
d->printerName = value.toString();
break;
case PPK_PrinterProgram:
d->printProgram = value.toString();
break;
case PPK_Resolution:
d->resolution = value.toInt();
break;
@ -1524,9 +1521,6 @@ QVariant QPdfBaseEngine::property(PrintEnginePropertyKey key) const
case PPK_PrinterName:
ret = d->printerName;
break;
case PPK_PrinterProgram:
ret = d->printProgram;
break;
case PPK_Resolution:
ret = d->resolution;
break;
@ -1632,28 +1626,6 @@ bool QPdfBaseEngine::end()
return true;
}
#ifndef QT_NO_LPR
static void closeAllOpenFds()
{
// hack time... getting the maximum number of open
// files, if possible. if not we assume it's the
// larger of 256 and the fd we got
int i;
#if defined(_SC_OPEN_MAX)
i = (int)sysconf(_SC_OPEN_MAX);
#elif defined(_POSIX_OPEN_MAX)
i = (int)_POSIX_OPEN_MAX;
#elif defined(OPEN_MAX)
i = (int)OPEN_MAX;
#else
i = 256;
#endif
// leave stdin/out/err untouched
while(--i > 2)
QT_CLOSE(i);
}
#endif
bool QPdfBaseEnginePrivate::openPrintDevice()
{
if(outDevice)
@ -1678,118 +1650,6 @@ bool QPdfBaseEnginePrivate::openPrintDevice()
outDevice = new QFile();
static_cast<QFile *>(outDevice)->open(ret.first, QIODevice::WriteOnly);
fd = ret.first;
#endif
#ifndef QT_NO_LPR
} else {
QString pr;
if (!printerName.isEmpty())
pr = printerName;
int fds[2];
if (qt_safe_pipe(fds) != 0) {
qWarning("QPdfPrinter: Could not open pipe to print");
return false;
}
pid_t pid = fork();
if (pid == 0) { // child process
// if possible, exit quickly, so the actual lp/lpr
// becomes a child of init, and ::waitpid() is
// guaranteed not to wait.
if (fork() > 0) {
closeAllOpenFds();
// try to replace this process with "true" - this prevents
// global destructors from being called (that could possibly
// do wrong things to the parent process)
(void)execlp("true", "true", (char *)0);
(void)execl("/bin/true", "true", (char *)0);
(void)execl("/usr/bin/true", "true", (char *)0);
::_exit(0);
}
qt_safe_dup2(fds[0], 0, 0);
closeAllOpenFds();
if (!printProgram.isEmpty()) {
if (!selectionOption.isEmpty())
pr.prepend(selectionOption);
else
pr.prepend(QLatin1String("-P"));
(void)execlp(printProgram.toLocal8Bit().data(), printProgram.toLocal8Bit().data(),
pr.toLocal8Bit().data(), (char *)0);
} else {
// if no print program has been specified, be smart
// about the option string too.
QList<QByteArray> lprhack;
QList<QByteArray> lphack;
QByteArray media;
if (!pr.isEmpty() || !selectionOption.isEmpty()) {
if (!selectionOption.isEmpty()) {
QStringList list = selectionOption.split(QLatin1Char(' '));
for (int i = 0; i < list.size(); ++i)
lprhack.append(list.at(i).toLocal8Bit());
lphack = lprhack;
} else {
lprhack.append("-P");
lphack.append("-d");
}
lprhack.append(pr.toLocal8Bit());
lphack.append(pr.toLocal8Bit());
}
lphack.append("-s");
char ** lpargs = new char *[lphack.size()+6];
char lp[] = "lp";
lpargs[0] = lp;
int i;
for (i = 0; i < lphack.size(); ++i)
lpargs[i+1] = (char *)lphack.at(i).constData();
#ifndef Q_OS_OSF
char dash_o[] = "-o";
if (QPdf::paperSizeToString(paperSize)) {
lpargs[++i] = dash_o;
lpargs[++i] = const_cast<char *>(QPdf::paperSizeToString(paperSize));
lpargs[++i] = dash_o;
media = "media=";
media += QPdf::paperSizeToString(paperSize);
lpargs[++i] = media.data();
}
#endif
lpargs[++i] = 0;
char **lprargs = new char *[lprhack.size()+2];
char lpr[] = "lpr";
lprargs[0] = lpr;
for (int i = 0; i < lprhack.size(); ++i)
lprargs[i+1] = (char *)lprhack[i].constData();
lprargs[lprhack.size() + 1] = 0;
(void)execvp("lp", lpargs);
(void)execvp("lpr", lprargs);
(void)execv("/bin/lp", lpargs);
(void)execv("/bin/lpr", lprargs);
(void)execv("/usr/bin/lp", lpargs);
(void)execv("/usr/bin/lpr", lprargs);
delete []lpargs;
delete []lprargs;
}
// if we couldn't exec anything, close the fd,
// wait for a second so the parent process (the
// child of the GUI process) has exited. then
// exit.
QT_CLOSE(0);
(void)::sleep(1);
::_exit(0);
}
// parent process
QT_CLOSE(fds[0]);
fd = fds[1];
(void)qt_safe_waitpid(pid, 0, 0);
if (fd < 0)
return false;
outDevice = new QFile();
static_cast<QFile *>(outDevice)->open(fd, QIODevice::WriteOnly);
#endif
}

View file

@ -254,7 +254,6 @@ public:
// printer options
QString outputFileName;
QString printerName;
QString printProgram;
QString selectionOption;
QString title;
QString creator;

View file

@ -63,12 +63,10 @@ public:
PPK_PaperRect,
PPK_PaperSource,
PPK_PrinterName,
PPK_PrinterProgram,
PPK_Resolution,
PPK_SelectionOption,
PPK_SupportedResolutions,
PPK_WindowsPageSize,
PPK_FontEmbedding,
PPK_SuppressSystemPrintStatus,

View file

@ -646,49 +646,6 @@ QPSPrintEngine::QPSPrintEngine(QPrinter::PrinterMode m)
{
}
static void ignoreSigPipe(bool b)
{
#ifndef QT_NO_LPR
static struct sigaction *users_sigpipe_handler = 0;
static int lockCount = 0;
QMutexLocker locker(QMutexPool::globalInstanceGet(&users_sigpipe_handler));
if (b) {
if (lockCount++ > 0)
return;
if (users_sigpipe_handler != 0)
return; // already ignoring sigpipe
users_sigpipe_handler = new struct sigaction;
struct sigaction tmp_sigpipe_handler;
tmp_sigpipe_handler.sa_handler = SIG_IGN;
sigemptyset(&tmp_sigpipe_handler.sa_mask);
tmp_sigpipe_handler.sa_flags = 0;
if (sigaction(SIGPIPE, &tmp_sigpipe_handler, users_sigpipe_handler) == -1) {
delete users_sigpipe_handler;
users_sigpipe_handler = 0;
}
}
else {
if (--lockCount > 0)
return;
if (users_sigpipe_handler == 0)
return; // not ignoring sigpipe
if (sigaction(SIGPIPE, users_sigpipe_handler, 0) == -1)
qWarning("QPSPrintEngine: Could not restore SIGPIPE handler");
delete users_sigpipe_handler;
users_sigpipe_handler = 0;
}
#else
Q_UNUSED(b);
#endif
}
QPSPrintEngine::~QPSPrintEngine()
{
Q_D(QPSPrintEngine);
@ -745,9 +702,6 @@ bool QPSPrintEngine::end()
return true;
}
// we're writing to lp/lpr through a pipe, we don't want to crash with SIGPIPE
// if lp/lpr dies
ignoreSigPipe(true);
d->flushPage(true);
QByteArray trailer;
QPdf::ByteStream s(&trailer);
@ -758,7 +712,6 @@ bool QPSPrintEngine::end()
d->outDevice->write(trailer);
QPdfBaseEngine::end();
ignoreSigPipe(false);
d->firstPage = true;
d->headerDone = false;
@ -912,13 +865,9 @@ bool QPSPrintEngine::newPage()
if (!d->firstPage && d->useAlphaEngine)
flushAndInit();
// we're writing to lp/lpr through a pipe, we don't want to crash with SIGPIPE
// if lp/lpr dies
ignoreSigPipe(true);
if (!d->firstPage)
d->flushPage();
d->firstPage = false;
ignoreSigPipe(false);
delete d->currentPage;
d->currentPage = new QPdfPage;

View file

@ -217,10 +217,7 @@ void QPrinterPrivate::addToManualSetList(QPrintEngine::PrintEnginePropertyKey ke
When printing directly to a printer on Windows or Mac OS X, QPrinter uses
the built-in printer drivers. On X11, QPrinter uses the
\l{Common Unix Printing System (CUPS)} or the standard Unix \l lpr utility
to send PostScript or PDF output to the printer. As an alternative,
the printProgram() function can be used to specify the command or utility
to use instead of the system default.
\l{Common Unix Printing System (CUPS)}.
Note that setting parameters like paper size and resolution on an
invalid printer is undefined. You can use QPrinter::isValid() to
@ -451,8 +448,8 @@ void QPrinterPrivate::addToManualSetList(QPrintEngine::PrintEnginePropertyKey ke
/*!
\enum QPrinter::PageOrder
This enum type is used by QPrinter to tell the application program
how to print.
This enum type is used by QPrinter to tell the printer which page
it should print first.
\value FirstPageFirst the lowest-numbered page should be printed
first.
@ -890,42 +887,6 @@ void QPrinter::setOutputFileName(const QString &fileName)
}
/*!
Returns the name of the program that sends the print output to the
printer.
The default is to return an empty string; meaning that QPrinter will try to
be smart in a system-dependent way. On X11 only, you can set it to something
different to use a specific print program. On the other platforms, this
returns an empty string.
\sa setPrintProgram(), setPrinterSelectionOption()
*/
QString QPrinter::printProgram() const
{
Q_D(const QPrinter);
return d->printEngine->property(QPrintEngine::PPK_PrinterProgram).toString();
}
/*!
Sets the name of the program that should do the print job to \a
printProg.
On X11, this function sets the program to call with the PostScript
output. On other platforms, it has no effect.
\sa printProgram()
*/
void QPrinter::setPrintProgram(const QString &printProg)
{
Q_D(QPrinter);
ABORT_IF_ACTIVE("QPrinter::setPrintProgram");
d->printEngine->setProperty(QPrintEngine::PPK_PrinterProgram, printProg);
d->addToManualSetList(QPrintEngine::PPK_PrinterProgram);
}
/*!
Returns the document name.
@ -2048,9 +2009,6 @@ QPrinter::PrintRange QPrinter::printRange() const
\value PPK_PrinterName A string specifying the name of the printer.
\value PPK_PrinterProgram A string specifying the name of the
printer program used for printing,
\value PPK_Resolution An integer describing the dots per inch for
this printer.
@ -2063,9 +2021,6 @@ QPrinter::PrintRange QPrinter::printRange() const
printing progress. As of 4.1 this only has effect on Mac OS X where, by default,
a status dialog is shown.
\value PPK_WindowsPageSize An integer specifying a DM_PAPER entry
on Windows.
\value PPK_CustomPaperSize A QSizeF specifying a custom paper size
in the QPrinter::Point unit.

View file

@ -136,9 +136,6 @@ public:
void setOutputFileName(const QString &);
QString outputFileName()const;
void setPrintProgram(const QString &);
QString printProgram() const;
void setDocName(const QString &);
QString docName() const;