diff options
author | Simon Rettberg | 2015-10-22 15:22:00 +0200 |
---|---|---|
committer | Simon Rettberg | 2015-10-22 15:22:00 +0200 |
commit | d9a2182d992fe8ea0670e6110b33bb4becf4e8d5 (patch) | |
tree | 8489d4754c7ec7c57e2adc66ef243ef0391a3cfd | |
parent | [pwgui] Revert using cupsTempFile2 - has issues when running backend (diff) | |
download | printergui-d9a2182d992fe8ea0670e6110b33bb4becf4e8d5.tar.gz printergui-d9a2182d992fe8ea0670e6110b33bb4becf4e8d5.tar.xz printergui-d9a2182d992fe8ea0670e6110b33bb4becf4e8d5.zip |
[pwgui] Break backend messages by \n, feed backend through stdin
-rw-r--r-- | src/pwgui/main.cpp | 43 |
1 files changed, 31 insertions, 12 deletions
diff --git a/src/pwgui/main.cpp b/src/pwgui/main.cpp index 256dca3..99459d2 100644 --- a/src/pwgui/main.cpp +++ b/src/pwgui/main.cpp @@ -21,7 +21,7 @@ #include <errno.h> #define NAMELEN 400 -#define BUFLEN 1000 +#define BUFLEN 9000 #define ENVLEN 20000 #define DEBUG(...) fprintf(stderr, "DEBUG: [pwgui] " __VA_ARGS__) @@ -234,6 +234,16 @@ static int run_backend(char *backend, char *uri, char *jobid, char *user, char * close(pipefd[0]); // close reading end dup2(pipefd[1], 2); // send stderr to pipe close(pipefd[1]); // no longer needed after dup + // Write tmpfile to stdin to mimic what cups usually does + int tfd = open(file, O_RDONLY); + if (tfd == -1) { + fprintf(stderr, "Could not open tmpfile as stdin for backend!\n"); + exit(1); + } + if (dup2(tfd, 0) == -1) { + fprintf(stderr, "Could not dup infile to stin of backend\n"); + exit(1); + } // Newer backend can read credentials from environment if (user != NULL) { setenv("AUTH_USERNAME", user, 1); @@ -310,7 +320,7 @@ static int run_backend(char *backend, char *uri, char *jobid, char *user, char * } args[4] = copies; args[5] = options; - args[6] = file; + args[6] = NULL; // file; args[7] = NULL; // Priv dropping struct stat st; @@ -331,19 +341,28 @@ static int run_backend(char *backend, char *uri, char *jobid, char *user, char * int readlen = 0; while ((readlen = read(pipefd[0], buffer, BUFLEN-1)) > 0) { buffer[readlen] = '\0'; - ERROR("BACKEND: %s\n", buffer); - if (strstr(buffer, "Unable to get printer status (Unauthorized)") != NULL) { - needAuth = true; - if (kill(pid, SIGTERM) < 0) { - ERROR("Sending SIGTERM to backend %d failed: %d\n", (int)pid, (int)errno); + char *ptr = buffer, *nl; + while (nl = strchr(ptr, '\n')) { + *nl = '\0'; + ERROR("BACKEND: %s\n", buffer); + if (strstr(buffer, "Unable to get printer status (Unauthorized)") != NULL) { + needAuth = true; + if (kill(pid, SIGTERM) < 0) { + ERROR("Sending SIGTERM to backend %d failed: %d\n", (int)pid, (int)errno); + } + goto loopend; + } else if (strstr(buffer, "Destination printer does not exist") != NULL) { + nonexistent = true; + kill(pid, SIGTERM); + goto loopend; } - break; - } else if (strstr(buffer, "Destination printer does not exist") != NULL) { - nonexistent = true; - kill(pid, SIGTERM); - break; + ptr = nl + 1; + } + if (*ptr != '\0') { + ERROR("LINEWRAP: Ignoring cutoff line!\n"); } } +loopend:; close(pipefd[0]); int status; if (waitpid(pid, &status, WNOHANG) == 0) { |