|
|
652065 |
diff --git a/backend/beh.c b/backend/beh.c
|
|
|
652065 |
index 225fd27..5e9cee0 100644
|
|
|
652065 |
--- a/backend/beh.c
|
|
|
652065 |
+++ b/backend/beh.c
|
|
|
652065 |
@@ -22,6 +22,7 @@
|
|
|
652065 |
#include "backend-private.h"
|
|
|
652065 |
#include <cups/array.h>
|
|
|
652065 |
#include <ctype.h>
|
|
|
652065 |
+#include <sys/wait.h>
|
|
|
652065 |
|
|
|
652065 |
/*
|
|
|
652065 |
* Local globals...
|
|
|
652065 |
@@ -213,10 +214,14 @@ call_backend(char *uri, /* I - URI of final destination */
|
|
|
652065 |
char **argv, /* I - Command-line arguments */
|
|
|
652065 |
char *filename) { /* I - File name of input data */
|
|
|
652065 |
const char *cups_serverbin; /* Location of programs */
|
|
|
652065 |
+ char *backend_argv[8]; // Arguments for called CUPS backend
|
|
|
652065 |
char scheme[1024], /* Scheme from URI */
|
|
|
652065 |
*ptr, /* Pointer into scheme */
|
|
|
652065 |
- cmdline[65536]; /* Backend command line */
|
|
|
652065 |
- int retval;
|
|
|
652065 |
+ backend_path[2048]; // Backend path
|
|
|
652065 |
+ int pid,
|
|
|
652065 |
+ wait_pid,
|
|
|
652065 |
+ wait_status,
|
|
|
652065 |
+ retval = 0;
|
|
|
652065 |
|
|
|
652065 |
/*
|
|
|
652065 |
* Build the backend command line...
|
|
|
652065 |
@@ -235,16 +240,19 @@ call_backend(char *uri, /* I - URI of final destination */
|
|
|
652065 |
fprintf(stderr,
|
|
|
652065 |
"ERROR: beh: Direct output into a file not supported.\n");
|
|
|
652065 |
exit (CUPS_BACKEND_FAILED);
|
|
|
652065 |
- } else
|
|
|
652065 |
- snprintf(cmdline, sizeof(cmdline),
|
|
|
652065 |
- "%s/backend/%s '%s' '%s' '%s' '%s' '%s' %s",
|
|
|
652065 |
- cups_serverbin, scheme, argv[1], argv[2], argv[3],
|
|
|
652065 |
- /* Apply number of copies only if beh was called with a
|
|
|
652065 |
- file name and not with the print data in stdin, as
|
|
|
652065 |
- backends should handle copies only if they are called
|
|
|
652065 |
- with a file name */
|
|
|
652065 |
- (argc == 6 ? "1" : argv[4]),
|
|
|
652065 |
- argv[5], filename);
|
|
|
652065 |
+ }
|
|
|
652065 |
+
|
|
|
652065 |
+ backend_argv[0] = uri;
|
|
|
652065 |
+ backend_argv[1] = argv[1];
|
|
|
652065 |
+ backend_argv[2] = argv[2];
|
|
|
652065 |
+ backend_argv[3] = argv[3];
|
|
|
652065 |
+ backend_argv[4] = (argc == 6 ? "1" : argv[4]);
|
|
|
652065 |
+ backend_argv[5] = argv[5];
|
|
|
652065 |
+ backend_argv[6] = filename;
|
|
|
652065 |
+ backend_argv[7] = NULL;
|
|
|
652065 |
+
|
|
|
652065 |
+ snprintf(backend_path, sizeof(backend_path),
|
|
|
652065 |
+ "%s/backend/%s", cups_serverbin, scheme);
|
|
|
652065 |
|
|
|
652065 |
/*
|
|
|
652065 |
* Overwrite the device URI and run the actual backend...
|
|
|
652065 |
@@ -253,17 +261,41 @@ call_backend(char *uri, /* I - URI of final destination */
|
|
|
652065 |
setenv("DEVICE_URI", uri, 1);
|
|
|
652065 |
|
|
|
652065 |
fprintf(stderr,
|
|
|
652065 |
- "DEBUG: beh: Executing backend command line \"%s\"...\n",
|
|
|
652065 |
- cmdline);
|
|
|
652065 |
+ "DEBUG: beh: Executing backend command line \"%s '%s' '%s' '%s' '%s' '%s'%s%s\"...\n",
|
|
|
652065 |
+ backend_path, backend_argv[1], backend_argv[2], backend_argv[3],
|
|
|
652065 |
+ backend_argv[4], backend_argv[5],
|
|
|
652065 |
+ (backend_argv[6] && backend_argv[6][0] ? " " : ""),
|
|
|
652065 |
+ (backend_argv[6] && backend_argv[6][0] ? backend_argv[6] : ""));
|
|
|
652065 |
fprintf(stderr,
|
|
|
652065 |
"DEBUG: beh: Using device URI: %s\n",
|
|
|
652065 |
uri);
|
|
|
652065 |
|
|
|
652065 |
- retval = system(cmdline) >> 8;
|
|
|
652065 |
+ if ((pid = fork()) == 0)
|
|
|
652065 |
+ {
|
|
|
652065 |
+ retval = execv(backend_path, backend_argv);
|
|
|
652065 |
+
|
|
|
652065 |
+ if (retval == -1)
|
|
|
652065 |
+ fprintf(stderr, "ERROR: Unable to execute backend: %s\n",
|
|
|
652065 |
+ strerror(errno));
|
|
|
652065 |
+ exit (CUPS_BACKEND_FAILED);
|
|
|
652065 |
+ }
|
|
|
652065 |
+ else if (pid < 0)
|
|
|
652065 |
+ {
|
|
|
652065 |
+ fprintf(stderr, "ERROR: Unable to fork for backend\n");
|
|
|
652065 |
+ return (CUPS_BACKEND_FAILED);
|
|
|
652065 |
+ }
|
|
|
652065 |
+
|
|
|
652065 |
+ while ((wait_pid = wait(&wait_status)) < 0 && errno == EINTR);
|
|
|
652065 |
|
|
|
652065 |
- if (retval == -1)
|
|
|
652065 |
- fprintf(stderr, "ERROR: Unable to execute backend command line: %s\n",
|
|
|
652065 |
- strerror(errno));
|
|
|
652065 |
+ if (wait_pid >= 0 && wait_status)
|
|
|
652065 |
+ {
|
|
|
652065 |
+ if (WIFEXITED(wait_status))
|
|
|
652065 |
+ retval = WEXITSTATUS(wait_status);
|
|
|
652065 |
+ else if (WTERMSIG(wait_status) != SIGTERM)
|
|
|
652065 |
+ retval = WTERMSIG(wait_status);
|
|
|
652065 |
+ else
|
|
|
652065 |
+ retval = 0;
|
|
|
652065 |
+ }
|
|
|
652065 |
|
|
|
652065 |
return (retval);
|
|
|
652065 |
}
|