Description: Let foomatic-rip actually error out if something goes wrong. It simply continued or closed silently (exit status 0) on several issues (LP: #570522). Also make string buffers bigger as many of them were too small. This patch contains the changes which are planned to be introduced in Foomatic 4.0.5, so this can be considered a test release for 4.0.5. Origin: upstream Author: Till Kamppeter Last-Update: 2010-06-08 Index: foomatic-filters/ChangeLog =================================================================== --- foomatic-filters.orig/ChangeLog 2010-07-19 16:40:10.000000000 +0200 +++ foomatic-filters/ChangeLog 2010-07-25 16:08:04.000000000 +0200 @@ -1,3 +1,32 @@ +2010-06-08 Till Kamppeter + + * USAGE: Documentation correction. + +2010-06-07 Till Kamppeter + + * USAGE: Finally completed the documentation update to reflect that + the Ghostscript library is not needed any more. + + * foomaticrip.c, foomaticrip.h, pdf.c: Let foomatic-rip actually + error out if something goes wrong. It simply continued or closed + silently (exit status 0) on the following events: Failure of + print_file() function call, failure of Ghostscript to determine + the number of pages of a PDF input file (causes Ubuntu bug + #570522), failure to start Ghostscript to render a PDF file, + failure to create a temporary file for extracting selected pages + from a PDF file, failure to run Ghostscript to extract pages from + a PDF file, page count result being a negative number. + + * foomaticrip.c: Use EXIT_PRINTED constant and not hard-coded "0" + as exit value when terminating successfully. + + * foomaticrip.h: Correct definition of EXIT_STARVED constant. + +2010-03-26 Till Kamppeter + + * options.c, options.h: Made some strings longer, to avoid space + problems. + 2010-02-15 Till Kamppeter * Tagged branch for release 4.0.4. Index: foomatic-filters/USAGE =================================================================== --- foomatic-filters.orig/USAGE 2010-07-19 16:40:10.000000000 +0200 +++ foomatic-filters/USAGE 2010-07-25 16:08:04.000000000 +0200 @@ -74,9 +74,8 @@ Foomatic runs on all systems where one can run the Perl interpreter and Ghostscript. -foomatic-filters needs the Ghostscript library for foomatic-rip and -the Perl interpreter for beh (Backend Error Handler) and the test -suite. +foomatic-filters needs the Perl interpreter for beh (Backend Error +Handler) and the test suite. To build foomatic-rip you need a C compiler and its standard libraries. @@ -138,9 +137,8 @@ a normal user. The "configure" script will auto-detect where the programs have to be -installed and where the Perl interpreter and the Ghostscript library -are located. If "configure" fails because of something not being -installed, do +installed and where the Perl interpreter is located. If "configure" +fails because of something not being installed, do rm -rf config.cache autom*.cache Index: foomatic-filters/foomaticrip.c =================================================================== --- foomatic-filters.orig/foomaticrip.c 2010-07-19 16:40:10.000000000 +0200 +++ foomatic-filters/foomaticrip.c 2010-07-25 16:08:04.000000000 +0200 @@ -1602,7 +1602,8 @@ PostScript file (all before the first page begins). */ optionset_copy_values(optionset("userval"), optionset("header")); - print_file(filename, 1); + if (!print_file(filename, 1)) + rip_die(EXIT_PRNERR_NORETRY, "Could not print file %s\n", filename); filename = strtok_r(NULL, " ", &p); } @@ -1639,6 +1640,6 @@ list_free(arglist); - return 0; + return EXIT_PRINTED; } Index: foomatic-filters/foomaticrip.h =================================================================== --- foomatic-filters.orig/foomaticrip.h 2010-07-19 16:40:10.000000000 +0200 +++ foomatic-filters/foomaticrip.h 2010-07-25 16:08:04.000000000 +0200 @@ -56,7 +56,7 @@ #define EXIT_JOBERR 3 /* job is defective */ #define EXIT_SIGNAL 4 /* terminated after catching signal */ #define EXIT_ENGAGED 5 /* printer is otherwise engaged (connection refused) */ -#define EXIT_STARVED = 6; /* starved for system resources */ +#define EXIT_STARVED 6 /* starved for system resources */ #define EXIT_PRNERR_NORETRY_ACCESS_DENIED 7 /* bad password? bad port permissions? */ #define EXIT_PRNERR_NOT_RESPONDING 8 /* just doesn't answer at all (turned off?) */ #define EXIT_PRNERR_NORETRY_BAD_SETTINGS 9 /* interface settings are invalid */ Index: foomatic-filters/options.c =================================================================== --- foomatic-filters.orig/options.c 2010-07-19 16:40:10.000000000 +0200 +++ foomatic-filters/options.c 2010-07-25 16:08:04.000000000 +0200 @@ -34,10 +34,10 @@ /* Values from foomatic keywords in the ppd file */ char printer_model [256]; -char printer_id [128]; +char printer_id [256]; char driver [128]; -char cmd [1024]; -char cmd_pdf [1024]; +char cmd [4096]; +char cmd_pdf [4096]; dstr_t *postpipe = NULL; /* command into which the output of this filter should be piped */ int ps_accounting = 1; @@ -751,7 +751,7 @@ { choice_t *choice = option_find_choice(opt, "Custom"); char ** paramvalues = paramvalues_from_string(opt, values); - char width[30], height[20]; + char width[30], height[30]; int pos; assert(choice); @@ -1215,7 +1215,7 @@ } if (!startswith(code, "%% FoomaticRIPOptionSetting")) - unhtmlify(choice->command, 1024, code); + unhtmlify(choice->command, 65536, code); } /* @@ -1529,10 +1529,10 @@ unhtmlify(postpipe->data, postpipe->alloc, value->data); } else if (strcmp(key, "FoomaticRIPCommandLine") == 0) { - unhtmlify(cmd, 1024, value->data); + unhtmlify(cmd, 4096, value->data); } else if (strcmp(key, "FoomaticRIPCommandLinePDF") == 0) { - unhtmlify(cmd_pdf, 1024, value->data); + unhtmlify(cmd_pdf, 4096, value->data); } else if (strcmp(key, "FoomaticRIPNoPageAccounting") == 0) { /* Boolean value */ @@ -1742,7 +1742,7 @@ * line */ if (startswith(cmd, "gs")) { - strncpy(cmd_pdf, cmd, 1024); + strncpy(cmd_pdf, cmd, 4096); return 1; } Index: foomatic-filters/options.h =================================================================== --- foomatic-filters.orig/options.h 2010-07-19 16:40:10.000000000 +0200 +++ foomatic-filters/options.h 2010-07-25 16:08:04.000000000 +0200 @@ -55,7 +55,7 @@ typedef struct choice_s { char value [128]; char text [128]; - char command[1024]; + char command[65536]; struct choice_s *next; } choice_t; @@ -125,8 +125,8 @@ extern char jclend[256]; extern char jclprefix[256]; -extern char cmd[1024]; -extern char cmd_pdf[1024]; +extern char cmd[4096]; +extern char cmd_pdf[4096]; extern int ps_accounting; Index: foomatic-filters/pdf.c =================================================================== --- foomatic-filters.orig/pdf.c 2010-07-19 16:40:10.000000000 +0200 +++ foomatic-filters/pdf.c 2010-07-25 16:08:04.000000000 +0200 @@ -52,10 +52,8 @@ gspath, filename); FILE *pd = popen(gscommand, "r"); - if (!pd) { - _log("Failed to execute ghostscript to determine number of input pages!\n"); - return 0; - } + if (!pd) + rip_die(EXIT_STARVED, "Failed to execute ghostscript to determine number of input pages!\n"); fread(output, 1, 31, pd); pclose(pd); @@ -77,7 +75,7 @@ _log("Starting renderer with command: %s\n", cmd); kid3 = start_process("kid3", exec_kid3, (void *)cmd, NULL, NULL); if (kid3 < 0) - return 0; + rip_die(EXIT_STARVED, "Could not start renderer\n"); return 1; } @@ -118,7 +116,7 @@ snprintf(filename, PATH_MAX, "%s/foomatic-XXXXXX", temp_dir()); mktemp(filename); if (!filename[0]) - return 0; + rip_die(EXIT_STARVED, "Unable to create temporary file!\n"); snprintf(filename_arg, PATH_MAX, "-sOutputFile=%s", filename); snprintf(first_arg, 50, "-dFirstPage=%d", first); @@ -132,10 +130,8 @@ gspath, filename_arg, first_arg, last_arg, pdffilename); FILE *pd = popen(gscommand, "r"); - if (!pd) { - _log("Could not run ghostscript to extract the pages!\n"); - return 0; - } + if (!pd) + rip_die(EXIT_STARVED, "Could not run ghostscript to extract the pages!\n"); pclose(pd); return 1; @@ -158,7 +154,7 @@ else { if (!pdf_extract_pages(tmpfile, filename, firstpage, lastpage)) - return 0; + rip_die(EXIT_STARVED, "Could not run ghostscript to extract the pages!\n"); dstrcatf(cmd, " < %s", tmpfile); } @@ -237,7 +233,7 @@ page_count = pdf_count_pages(filename); if (page_count <= 0) - return 0; + rip_die(EXIT_JOBERR, "Unable to determine number of pages, page count: %d\n", page_count); _log("File contains %d pages\n", page_count); optionset_copy_values(optionset("header"), optionset("currentpage"));