diff options
-rw-r--r-- | src/pwgui/main.cpp | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/src/pwgui/main.cpp b/src/pwgui/main.cpp index 65fd469..25771c1 100644 --- a/src/pwgui/main.cpp +++ b/src/pwgui/main.cpp @@ -65,7 +65,7 @@ int main(int argc, char *argv[]) // First check parameter count if (argc != 6 && argc != 7) { ERROR("Invalid number of arguments passed.\n"); - return CUPS_BACKEND_FAILED; + return CUPS_BACKEND_CANCEL; } // Determine device uri @@ -76,7 +76,7 @@ int main(int argc, char *argv[]) snprintf(device, NAMELEN, "%s", argv[0]); } else { ERROR("No device URI given.\n"); - return CUPS_BACKEND_FAILED; + return CUPS_BACKEND_CANCEL; } // Get backend from uri @@ -89,7 +89,7 @@ int main(int argc, char *argv[]) helper_getpiduid(argv[2], argv[3]); helper_messageBox("PrinterGUI", "Kein Backend für den gewählten Drucker vorhanden."); ERROR("Backend %s is not executable. Over and out.\n", backend); - return CUPS_BACKEND_FAILED; + return CUPS_BACKEND_CANCEL; } // argv[3] is title, get printergui pid from it @@ -110,12 +110,14 @@ int main(int argc, char *argv[]) // Get document to print if (argc == 6) { // Data comes from stdin, save... - snprintf(tmpfile, NAMELEN, "/tmp/print-%s-%d-%s-%d", argv[1], (int)time(NULL), argv[2], (int)getpid()); + if (cupsTempFile2(tmpfile, NAMELEN) == NULL) { + snprintf(tmpfile, NAMELEN, "/tmp/print-%s-%d-%s-%d", argv[1], (int)time(NULL), argv[2], (int)getpid()); + } int fh = open(tmpfile, O_CREAT | O_WRONLY | O_TRUNC, 0600); if (fh < 0) { helper_messageBox("PrinterGUI", "Konnte temporäre Datei für den Druckjob nicht anlegen."); - ERROR("Could not open %s for writing. Over and out.\n", tmpfile); - return CUPS_BACKEND_FAILED; + ERROR("Could not open %s for writing (err:%d). Over and out.\n", tmpfile, errno); + return CUPS_BACKEND_CANCEL; } char buffer[BUFLEN]; int bytes, ret; @@ -127,17 +129,17 @@ int main(int argc, char *argv[]) } if (bytes < 0) { helper_messageBox("PrinterGUI", "Konnte den Druckjob nicht auf STDIN empfangen."); - ERROR("Could not read print job from STDIN. Over and out.\n"); + ERROR("Could not read print job from STDIN (err:%d). Over and out.\n", errno); close(fh); remove(tmpfile); - return CUPS_BACKEND_FAILED; + return CUPS_BACKEND_CANCEL; } if ((ret = write(fh, buffer, bytes)) != bytes) { helper_messageBox("PrinterGUI", "Konnte Druckjob nicht in temporäre Datei schreiben."); - ERROR("Could not write %d bytes to %s (wrote %d). Over and out.\n", (int)bytes, tmpfile, (int)ret); + ERROR("Could not write %d bytes to %s (wrote %d, err:%d). Over and out.\n", (int)bytes, tmpfile, (int)ret, errno); close(fh); remove(tmpfile); - return CUPS_BACKEND_FAILED; + return CUPS_BACKEND_CANCEL; } total += bytes; } @@ -151,7 +153,7 @@ int main(int argc, char *argv[]) if (fh < 0) { helper_messageBox("PrinterGUI", "Konnte den Druckjob nicht vom Dateisystem lesen."); ERROR("Could not open %s for reading. Over and out.\n", tmpfile); - return CUPS_BACKEND_FAILED; + return CUPS_BACKEND_CANCEL; } close(fh); // @@ -175,7 +177,7 @@ int main(int argc, char *argv[]) if (pipe(pfd) != 0) { helper_messageBox("PrinterGUI", "Konnte pipe für die GUI nicht anlegen. Druckvorgang fehlgeschlagen."); ERROR("Could not create pipe for GUI. Over and out.\n"); - return CUPS_BACKEND_FAILED; + return CUPS_BACKEND_CANCEL; } const pid_t pid = fork(); if (pid == 0) { @@ -193,7 +195,7 @@ int main(int argc, char *argv[]) bg->setMainWindow(w); w->show(); exit(a.exec()); - return CUPS_BACKEND_FAILED; + return CUPS_BACKEND_CANCEL; } // Main (Parent) close(pfd[1]); @@ -301,6 +303,8 @@ static int run_backend(char *backend, char *uri, char *jobid, char *user, char * args[3] = strchr(title, ' '); if (args[3] == NULL) { args[3] = title; + } else { + args[3]++; } } else { args[3] = title; @@ -360,7 +364,7 @@ static int run_backend(char *backend, char *uri, char *jobid, char *user, char * } if (!WIFEXITED(status)) { ERROR("Running backend %s failed!\n", backend); - return CUPS_BACKEND_FAILED; + return CUPS_BACKEND_CANCEL; } status = WEXITSTATUS(status); if (status != CUPS_BACKEND_OK) { @@ -464,7 +468,7 @@ static void helper_dropprivs() chdir("/"); if (setuid(0) != -1) { ERROR("setuid-fu!?\n"); - exit(CUPS_BACKEND_FAILED); + exit(CUPS_BACKEND_CANCEL); } } |