Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pdftops does not handle EINTR #2780

Closed
michaelrsweet opened this issue Apr 2, 2008 · 2 comments
Closed

pdftops does not handle EINTR #2780

michaelrsweet opened this issue Apr 2, 2008 · 2 comments

Comments

@michaelrsweet
Copy link
Collaborator

michaelrsweet commented Apr 2, 2008

Version: 1.4-current
CUPS.org User: martin.pitt.canonical

First, a big thanks for the much improved test suite in 1.3.7! By comparing expected number of errors it promptly caught a failure when I prepared 1.3.7 packages for Debian/Ubuntu:

E [02/Apr/2008:02:47:45 +0200] PID 20824 (/tmp/cups-martin/bin/filter/pdftops) stopped with status 1!

We use the pdftops filter from 1.4 svn head on 1.3.7.

I tracked this down to pdftops.c's wait() failing on EINTR (yay, my favourite of "ten things I hate about Unix" did it again). Attached patch handles this properly, similar to other parts in the code which run wait().

BTW, it took me quite some time to debug this. Calling the filter manually with identical arguments on the command line succeeded. Smuggling gdb in between cupsd and pdftops does not work easily due to stdin not being a console, and for race conditions like that it's probably quite useless anyway. The existing fprintf()s to stderr do not leave any trace in error_log or anywhere else, so I ended up cluttering the code with fprintf() to a newly created log file. Is there a better/easier method to debug a filter?

Thanks,

Martin

@michaelrsweet
Copy link
Collaborator Author

michaelrsweet commented Apr 9, 2008

CUPS.org User: mike

Actually, we do want to kill the child on SIGTERM (cancel job), so we need to pass that through. Updated patch attached, committed to CUPS trunk...

@michaelrsweet
Copy link
Collaborator Author

michaelrsweet commented Apr 9, 2008

"str2780.patch":

Index: pdftops.c

--- pdftops.c (revision 7441)
+++ pdftops.c (working copy)
@@ -28,6 +28,7 @@
#include <cups/i18n.h>
#include <signal.h>
#include <sys/wait.h>
+#include <errno.h>

/*
@@ -38,6 +39,13 @@

/*

  • * Local globals...
  • /
    +
    +static int job_canceled = 0;
    +
    +
    +/
    • 'main()' - Main entry for filter...
      */

@@ -57,6 +65,7 @@
ppd_file_t ppd; / PPD file /
ppd_size_t *size; /
Current page size /
int pdfpid, /
Process ID for pdftops */

  •   pdfwaitpid,     /* Process ID from wait() */
    pdfstatus,      /* Status from pdftops */
    pdfargc;        /* Number of args for pdftops */
    

    char pdfargv[100], / Arguments for pdftops */
    @@ -261,8 +270,18 @@

    • Parent comes here...
      */
  • if (wait(&pdfstatus) != pdfpid)

  • while ((pdfwaitpid = wait(&pdfstatus)) < 0 && errno == EINTR)
    {

  • /*
    
  •  \* Wait until we get a valid process ID or the job is canceled...
    
  •  */
    
  •  if (job_canceled)
    
  • break;

  • }

  • if (pdfwaitpid != pdfpid)
  • {
    kill(pdfpid, SIGTERM);
    pdfstatus = 1;
    }
    @@ -270,18 +289,18 @@
    {
    if (WIFEXITED(pdfstatus))
    {
  •    pdfstatus = WEXITSTATUS(pdfstatus);
    
  • pdfstatus = WEXITSTATUS(pdfstatus);
  •    _cupsLangPrintf(stderr,
    
  •               _("ERROR: pdftops filter exited with status %d!\n"),
    
  • _cupsLangPrintf(stderr,
  •       _("ERROR: pdftops filter exited with status %d!\n"),
        pdfstatus);
    
    }
    else
    {
  •    pdfstatus = WTERMSIG(pdfstatus);
    
  • pdfstatus = WTERMSIG(pdfstatus);
  •    _cupsLangPrintf(stderr,
    
  •               _("ERROR: pdftops filter crashed on signal %d!\n"),
    
  • _cupsLangPrintf(stderr,
  •       _("ERROR: pdftops filter crashed on signal %d!\n"),
        pdfstatus);
    
    }
    }
    @@ -306,6 +325,8 @@
    cancel_job(int sig) /* I - Signal number (unused) */
    {
    (void)sig;
    +
  • job_canceled = 1;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant