char *pseudo_argv[2];
const char *uri;
int fd1, fd2;
+ char *save_device_uri_var;
/* Eliminate any output to stderr, to get rid of the CUPS-backend-specific
output of the cupsBackendDeviceURI() function */
dup2(fd2, 2);
close(fd2);
+ /* If set, save the DEVICE_URI environment and then unset it, so that
+ if we are running under CUPS (as filter or backend) our raw_uri gets
+ resolved and not whatever URI is set in DEVICE_URI */
+ if ((save_device_uri_var = getenv("DEVICE_URI")) != NULL)
+ {
+ save_device_uri_var = strdup(save_device_uri_var);
+ unsetenv("DEVICE_URI");
+ }
+
/* Use the URI resolver of libcups to support DNS-SD-service-name-based
URIs. The function returns the corresponding host-name-based URI */
pseudo_argv[0] = (char *)raw_uri;
pseudo_argv[1] = NULL;
uri = cupsBackendDeviceURI(pseudo_argv);
+ /* Restore DEVICE_URI envidonment variable if we had unset it */
+ if (save_device_uri_var)
+ {
+ setenv("DEVICE_URI", save_device_uri_var, 1);
+ free(save_device_uri_var);
+ }
+
/* Re-activate stderr output */
dup2(fd1, 2);
close(fd1);
goto error;
}
- dup2(post_proc_pipe[0], 0);
- close(post_proc_pipe[0]);
close(post_proc_pipe[1]);
- fp = cupsFileStdin();
+ fp = cupsFileOpenFd(post_proc_pipe[0], "r");
buffer = (char*)malloc(MAX_OUTPUT_LEN * sizeof(char));
if (buffer == NULL) {
memset(buffer, 0, MAX_OUTPUT_LEN);
}
+ cupsFileClose(fp);
+
if (buffer != NULL)
free(buffer);