cupsd hangs on reading pipe with recycled file descriptor #1068

Closed
michaelrsweet opened this Issue Jan 28, 2005 · 3 comments

Comments

Projects
None yet
1 participant
Collaborator

michaelrsweet commented Jan 28, 2005

Version: 1.1.17
CUPS.org User: twaugh.redhat

File descriptors opened after the last select() call may collide with file descriptors that are newly closed and are listed in the 'input' fd_set.

(Hopefully the patch can explain it more clearly!)

[Originally RH bug #146236]

Collaborator

michaelrsweet commented Feb 6, 2005

CUPS.org User: mike

I think your patch could be more easily implemented simply by us clearing the input bits as we process them, i.e. like we do inside the job status loop, instead of adding another set.

Also, your patch doesn't apply cleanly against the current release, since we now allocate the fd_set to support more than 1024 file descriptors...

I've attached a patch against 1.1 CVS which should have the same effect without the global changes.

Collaborator

michaelrsweet commented Sep 18, 2005

"cups-recycled_fd.patch":

diff -Nur cups-1.1.17/scheduler/cupsd.h cups-1.1.17-fix/scheduler/cupsd.h
--- cups-1.1.17/scheduler/cupsd.h 2005-01-19 21:42:17.000000000 +0900
+++ cups-1.1.17-fix/scheduler/cupsd.h 2005-01-19 21:46:55.000000000 +0900
@@ -147,7 +147,8 @@

VAR int MaxFDs; /* Maximum number of files /
VAR fd_set InputSet, /
Input files for select() */

  •       OutputSet;  /\* Output files for select() */
    
  •       OutputSet,  /\* Output files for select() */
    
  •       IgnoreSet;  /* Opend files after select() */
    

    VAR int NeedReload VALUE(TRUE);
    /* Need to load configuration? */
    diff -Nur cups-1.1.17/scheduler/job.c cups-1.1.17-fix/scheduler/job.c
    --- cups-1.1.17/scheduler/job.c 2002-11-23 10:04:13.000000000 +0900
    +++ cups-1.1.17-fix/scheduler/job.c 2005-01-19 23:07:35.000000000 +0900
    @@ -1680,6 +1680,8 @@
    current->status = 0;
    memset(current->procs, 0, sizeof(current->procs));

  • FD_SET(current->pipe, &IgnoreSet); /* Protect this fd until next select... */

filterfds[1][0] = open("/dev/null", O_RDONLY);
filterfds[1][1] = -1;

diff -Nur cups-1.1.17/scheduler/main.c cups-1.1.17-fix/scheduler/main.c
--- cups-1.1.17/scheduler/main.c 2004-12-24 23:23:13.000000000 +0900
+++ cups-1.1.17-fix/scheduler/main.c 2005-01-19 23:54:36.000000000 +0900
@@ -454,6 +454,8 @@
sigchld_handler (0);
#endif

  • FD_ZERO(&IgnoreSet);

if ((i = select(MaxFDs, &input, &output, NULL, &timeout)) < 0)
{
char s[16384], /* String buffer */
@@ -577,6 +579,12 @@
FD_CLR(job->pipe, &input);

/*
  •    \* Do not read pipe created after last select().
    
  •    \* It should be checked after next select().
    
  •    */
    
  •    if (FD_ISSET(job->pipe, &IgnoreSet)) continue;
    
  •   /*
     \* Read any status messages from the filters...
    
    */
Collaborator

michaelrsweet commented Sep 18, 2005

"str1068.patch":

Index: main.c

RCS file: /development/cvs/cups/scheduler/main.c,v
retrieving revision 1.128
diff -u -r1.128 main.c
--- main.c 3 Jan 2005 19:29:59 -0000 1.128
+++ main.c 6 Feb 2005 23:53:25 -0000
@@ -585,7 +585,10 @@

 for (i = NumListeners, lis = Listeners; i > 0; i --, lis ++)
   if (FD_ISSET(lis->fd, input))
  •  {
    
  •    FD_CLR(lis->fd, input);
     AcceptClient(lis);
    
  •  }
    

    for (i = NumClients, con = Clients; i > 0; i --, con ++)
    {
    @@ -594,11 +597,15 @@
    */

    if (FD_ISSET(con->http.fd, input) || con->http.used)

  •  {
    
  •    FD_CLR(con->http.fd, input);
    
    • if (!ReadClient(con))
      {
      con --;
      continue;
      }
  •  }
    

    /*

    • Write data as needed...
      @@ -612,6 +619,7 @@
      • client is not ready to receive data...
        */
  • FD_CLR(con->file, input);
    con->file_ready = 1;

#ifdef DEBUG

michaelrsweet added this to the Stable milestone Mar 17, 2016

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