From 1f498627b5ed6c8e8a7db96ff86af388fb37353e Mon Sep 17 00:00:00 2001 From: Till Kamppeter Date: Mon, 18 Oct 2021 23:45:59 +0200 Subject: [PATCH] Let pr_system_cb() set the CUPS_SERVERBIN env variable If CUPS_SERVERBIN is not set and FILTER_DIR is set to a path ending with "/filter", we set CUP_SERVERBIN to the value of FILTER_DIR minus the "/filter" at the end. This way CUPS filters in the FILTER_DIR, called by filterExternalCUPS() of cups-filters get an environment as close as to the one of CUPS as possible. --- pappl-retrofit/pappl-retrofit.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pappl-retrofit/pappl-retrofit.c b/pappl-retrofit/pappl-retrofit.c index 105dc16..6ac101c 100644 --- a/pappl-retrofit/pappl-retrofit.c +++ b/pappl-retrofit/pappl-retrofit.c @@ -4286,6 +4286,7 @@ pr_system_cb(int num_options, // I - Number of options pappl_loglevel_t loglevel; // Log level int port = 0; // Port number, if any char *ptr; + char buf[1024]; pappl_soptions_t soptions = PAPPL_SOPTIONS_MULTI_QUEUE | PAPPL_SOPTIONS_WEB_INTERFACE | PAPPL_SOPTIONS_WEB_LOG | @@ -4390,6 +4391,20 @@ pr_system_cb(int num_options, // I - Number of options snprintf(global_data->filter_dir, sizeof(global_data->filter_dir), "/usr/lib/%s/filter", global_data->config->system_package_name); + // Set CUPS_SERVERBIN (only if not already set and if FILTER_DIR ends + // with "/filter"). This gives the best possible environment to the + // CUPS filters when they are called out of the Printer Application. + if (getenv("CUPS_SERVERBIN") == NULL && strlen(global_data->filter_dir) > 7) + { + strncpy(buf, global_data->filter_dir, sizeof(buf)); + ptr = buf + strlen(buf) - 7; + if (strcmp(ptr, "/filter") == 0) + { + *ptr = '\0'; + setenv("CUPS_SERVERBIN", buf, 1); + } + } + // CUPS Backend dir if (global_data->config->components & PR_COPTIONS_CUPS_BACKENDS) {