]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Mirror 1.1.x changes.
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Wed, 25 Feb 2004 16:22:01 +0000 (16:22 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Wed, 25 Feb 2004 16:22:01 +0000 (16:22 +0000)
git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/branches/branch-1.2@4079 7a7537e8-13f0-0310-91df-b6672ffda945

CHANGES-1.1.txt
scheduler/client.c
scheduler/client.h
scheduler/main.c

index 87155c09d90c2e60a68396ac0357f2ef9e4c493a..856e175d11037daf72948fc523d50f0eec731689 100644 (file)
@@ -3,6 +3,9 @@ CHANGES-1.1.txt
 
 CHANGES IN CUPS V1.1.21rc1
 
+       - The scheduler could use excess amounts of CPU if a CGI
+         program was sending data faster than the client could
+         take it (STR #595)
        - Updated the Ghostscript 8.x integration stuff (STR
          #484)
        - The lpd backend used a source port of 732 by default,
index 06aaf1049fc053aaa5f93adea11dbca2139c53b6..9bf53adb2a311323510d718c10a39360da4ab964 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: client.c,v 1.91.2.75 2004/02/05 20:54:44 mike Exp $"
+ * "$Id: client.c,v 1.91.2.76 2004/02/25 16:22:01 mike Exp $"
  *
  *   Client routines for the Common UNIX Printing System (CUPS) scheduler.
  *
@@ -92,7 +92,7 @@ AcceptClient(listener_t *lis) /* I - Listener socket */
                                /* Time of last DoS attack */
 
 
-  LogMessage(L_DEBUG2, "AcceptClient(%p) %d NumClients = %d",
+  LogMessage(L_DEBUG2, "AcceptClient(lis=%p) %d NumClients = %d",
              lis, lis->fd, NumClients);
 
  /*
@@ -471,34 +471,22 @@ CloseClient(client_t *con)        /* I - Client to close */
     LogMessage(L_DEBUG2, "CloseClient: %d Killing process ID %d...",
                con->http.fd, con->pipe_pid);
     kill(con->pipe_pid, SIGKILL);
-
-    LogMessage(L_DEBUG2, "CloseClient: %d Removing fd %d from InputSet...",
-               con->http.fd, con->file);
-    FD_CLR(con->file, InputSet);
-
-    LogMessage(L_DEBUG2, "CloseClient: %d Closing data file %d.",
-               con->http.fd, con->file);
-
-    close(con->file);
-    con->file = 0;
   }
-  else if (con->file)
-  {
-   /*
-    * Close the open data file...
-    */
 
-
-    LogMessage(L_DEBUG2, "CloseClient: %d Removing fd %d from InputSet.",
-               con->http.fd, con->file);
-
-    FD_CLR(con->file, InputSet);
+  if (con->file >= 0)
+  {
+    if (FD_ISSET(con->file, InputSet))
+    {
+      LogMessage(L_DEBUG2, "CloseClient: %d Removing fd %d from InputSet...",
+                con->http.fd, con->file);
+      FD_CLR(con->file, InputSet);
+    }
 
     LogMessage(L_DEBUG2, "CloseClient: %d Closing data file %d.",
                con->http.fd, con->file);
 
     close(con->file);
-    con->file = 0;
+    con->file = -1;
   }
 
   if (!partial)
@@ -930,7 +918,8 @@ ReadClient(client_t *con)           /* I - Client to read from */
        con->http.data_remaining = 0;
        con->operation           = HTTP_WAITING;
        con->bytes               = 0;
-       con->file                = 0;
+       con->file                = -1;
+       con->file_ready          = 0;
        con->pipe_pid            = 0;
        con->username[0]         = '\0';
        con->password[0]         = '\0';
@@ -1806,7 +1795,7 @@ ReadClient(client_t *con)         /* I - Client to read from */
                       con->file);
 
            close(con->file);
-           con->file = 0;
+           con->file = -1;
            unlink(con->filename);
            ClearString(&con->filename);
 
@@ -1830,7 +1819,7 @@ ReadClient(client_t *con)         /* I - Client to read from */
                      con->http.fd, con->file, (int)filestats.st_size);
 
          close(con->file);
-         con->file = 0;
+         con->file = -1;
 
           if (filestats.st_size > MaxRequestSize &&
              MaxRequestSize > 0)
@@ -1901,7 +1890,7 @@ ReadClient(client_t *con)         /* I - Client to read from */
            con->bytes += ippLength(con->request);
        }
 
-        if (con->file == 0 && con->http.state != HTTP_POST_SEND)
+        if (con->file < 0 && con->http.state != HTTP_POST_SEND)
        {
          /*
          * Create a file as needed for the request data...
@@ -1948,7 +1937,7 @@ ReadClient(client_t *con)         /* I - Client to read from */
                         con->file);
 
              close(con->file);
-             con->file = 0;
+             con->file = -1;
              unlink(con->filename);
              ClearString(&con->filename);
 
@@ -1972,7 +1961,7 @@ ReadClient(client_t *con)         /* I - Client to read from */
 
        if (con->http.state == HTTP_POST_SEND)
        {
-         if (con->file)
+         if (con->file >= 0)
          {
            fstat(con->file, &filestats);
 
@@ -1980,7 +1969,7 @@ ReadClient(client_t *con)         /* I - Client to read from */
                        con->http.fd, con->file, (int)filestats.st_size);
 
            close(con->file);
-           con->file = 0;
+           con->file = -1;
 
             if (filestats.st_size > MaxRequestSize &&
                MaxRequestSize > 0)
@@ -2068,7 +2057,7 @@ SendCommand(client_t      *con,
 
   LogMessage(L_INFO, "Started \"%s\" (pid=%d)", command, con->pipe_pid);
 
-  LogMessage(L_DEBUG, "SendCommand() %d file=%d", con->http.fd, con->file);
+  LogMessage(L_DEBUG, "SendCommand: %d file=%d", con->http.fd, con->file);
 
   if (con->pipe_pid == 0)
     return (0);
@@ -2093,6 +2082,7 @@ SendCommand(client_t      *con,
       return (0);
   }
 
+  con->file_ready = 0;
   con->got_fields = 0;
   con->field_col  = 0;
 
@@ -2443,6 +2433,11 @@ WriteClient(client_t *con)               /* I - Client connection */
   ipp_state_t  ipp_state;              /* IPP state value */
 
 
+#ifdef DEBUG
+  LogMessage(L_DEBUG2, "WriteClient(con=%p) %d response=%p, file=%d pipe_pid=%d",
+             con, con->http.fd, con->response, con->file, con->pipe_pid);
+#endif /* DEBUG */
+
   if (con->http.state != HTTP_GET_SEND &&
       con->http.state != HTTP_POST_SEND)
     return (1);
@@ -2454,6 +2449,11 @@ WriteClient(client_t *con)               /* I - Client connection */
   }
   else if ((bytes = read(con->file, buf, HTTP_MAX_BUFFER)) > 0)
   {
+#ifdef DEBUG
+    LogMessage(L_DEBUG2, "WriteClient: Read %d bytes from file %d...",
+               bytes, con->file);
+#endif /* DEBUG */
+
     if (con->pipe_pid && !con->got_fields)
     {
      /*
@@ -2474,14 +2474,14 @@ WriteClient(client_t *con)              /* I - Client connection */
          *bufptr++ = '\0';
 
          httpPrintf(HTTP(con), "%s\r\n", buf);
-         LogMessage(L_DEBUG2, "WriteClient() %d %s", con->http.fd, buf);
+         LogMessage(L_DEBUG2, "WriteClient: %d %s", con->http.fd, buf);
 
          /*
          * Update buffer...
          */
 
          bytes -= (bufptr - buf);
-         memcpy(buf, bufptr, bytes + 1);
+         memmove(buf, bufptr, bytes + 1);
          bufptr = buf - 1;
 
          /*
@@ -2538,17 +2538,20 @@ WriteClient(client_t *con)              /* I - Client connection */
 
     con->http.state = HTTP_WAITING;
 
-    LogMessage(L_DEBUG2, "WriteClient() Removing fd %d from OutputSet...",
+    LogMessage(L_DEBUG2, "WriteClient: Removing fd %d from OutputSet...",
                con->http.fd);
 
     FD_CLR(con->http.fd, OutputSet);
 
-    if (con->file)
+    if (con->file >= 0)
     {
-      LogMessage(L_DEBUG2, "WriteClient() Removing fd %d from InputSet...",
-                 con->file);
-      FD_CLR(con->file, InputSet);
-
+      if (FD_ISSET(con->file, InputSet))
+      {
+       LogMessage(L_DEBUG2, "WriteClient: Removing fd %d from InputSet...",
+                   con->file);
+       FD_CLR(con->file, InputSet);
+      }
+  
       if (con->pipe_pid)
        kill(con->pipe_pid, SIGTERM);
 
@@ -2556,7 +2559,7 @@ WriteClient(client_t *con)                /* I - Client connection */
                  con->http.fd, con->file);
 
       close(con->file);
-      con->file     = 0;
+      con->file     = -1;
       con->pipe_pid = 0;
     }
 
@@ -2589,9 +2592,19 @@ WriteClient(client_t *con)               /* I - Client connection */
       return (0);
     }
   }
+  else
+  {
+    con->file_ready = 0;
+
+    if (con->pipe_pid && !FD_ISSET(con->file, InputSet))
+    {
+      LogMessage(L_DEBUG2, "WriteClient: Adding fd %d to InputSet...", con->file);
+      FD_SET(con->file, InputSet);
+    }
+  }
 
   if (bytes >= 1024)
-    LogMessage(L_DEBUG2, "WriteClient() %d %d bytes", con->http.fd, bytes);
+    LogMessage(L_DEBUG2, "WriteClient: %d %d bytes", con->http.fd, bytes);
 
   con->http.activity = time(NULL);
 
@@ -3508,5 +3521,5 @@ CDSAWriteFunc(SSLConnectionRef connection,        /* I  - SSL/TLS connection */
 
 
 /*
- * End of "$Id: client.c,v 1.91.2.75 2004/02/05 20:54:44 mike Exp $".
+ * End of "$Id: client.c,v 1.91.2.76 2004/02/25 16:22:01 mike Exp $".
  */
index c91ba4c86cd9391bd8d84ae8a6fab3988ac656b3..912b85125165e28309b5591c2e46995455be62ca 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: client.h,v 1.17.2.10 2003/07/20 03:13:09 mike Exp $"
+ * "$Id: client.h,v 1.17.2.11 2004/02/25 16:22:01 mike Exp $"
  *
  *   Client definitions for the Common UNIX Printing System (CUPS) scheduler.
  *
@@ -41,6 +41,7 @@ typedef struct
                *command,               /* Command to run */
                *options;               /* Options for command */
   int          file;                   /* Input/output file */
+  int          file_ready;             /* Input ready on file/pipe? */
   int          pipe_pid;               /* Pipe process ID (or 0 if not a pipe) */
   int          got_fields,             /* Non-zero if all fields seen */
                field_col;              /* Column within line */
@@ -110,5 +111,5 @@ extern int  WriteClient(client_t *con);
 
 
 /*
- * End of "$Id: client.h,v 1.17.2.10 2003/07/20 03:13:09 mike Exp $".
+ * End of "$Id: client.h,v 1.17.2.11 2004/02/25 16:22:01 mike Exp $".
  */
index f2a46b2fe741dbcc256359cbcfdd0f4e9b1fc3c2..9655283d9d80e38cab45b424f07f8618bbb9fc5e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: main.c,v 1.57.2.54 2003/11/19 16:54:07 mike Exp $"
+ * "$Id: main.c,v 1.57.2.55 2004/02/25 16:22:01 mike Exp $"
  *
  *   Scheduler main loop for the Common UNIX Printing System (CUPS).
  *
@@ -430,6 +430,11 @@ main(int  argc,                            /* I - Number of command-line arguments */
 
   while (!stop_scheduler)
   {
+#ifdef DEBUG
+    LogMessage(L_DEBUG2, "main: Top of loop, dead_children=%d, NeedReload=%d",
+               dead_children, NeedReload);
+#endif /* DEBUG */
+
    /*
     * Check if there are dead children to handle...
     */
@@ -606,8 +611,29 @@ main(int  argc,                            /* I - Number of command-line arguments */
       * Write data as needed...
       */
 
+      if (con->pipe_pid && FD_ISSET(con->file, input))
+      {
+       /*
+        * Keep track of pending input from the file/pipe separately
+       * so that we don't needlessly spin on select() when the web
+       * client is not ready to receive data...
+       */
+
+        con->file_ready = 1;
+
+#ifdef DEBUG
+        LogMessage(L_DEBUG2, "main: Data ready file %d!", con->file);
+#endif /* DEBUG */
+
+       if (!FD_ISSET(con->http.fd, output))
+       {
+         LogMessage(L_DEBUG2, "main: Removing fd %d from InputSet...", con->file);
+         FD_CLR(con->file, InputSet);
+       }
+      }
+
       if (FD_ISSET(con->http.fd, output) &&
-          (!con->pipe_pid || FD_ISSET(con->file, input)))
+          (!con->pipe_pid || con->file_ready))
         if (!WriteClient(con))
        {
          con --;
@@ -1134,5 +1160,5 @@ usage(void)
 
 
 /*
- * End of "$Id: main.c,v 1.57.2.54 2003/11/19 16:54:07 mike Exp $".
+ * End of "$Id: main.c,v 1.57.2.55 2004/02/25 16:22:01 mike Exp $".
  */