[Pythonmac-SIG] CGIHTTPServer problems on OS X

Tony Lownds tony@lownds.com
Mon, 17 Jun 2002 09:15:21 -0700


At 12:20 AM +0200 6/16/02, Jack Jansen wrote:
>On vrijdag, juni 14, 2002, at 09:14 , Kevin Altis wrote:
>
>>Serving files works fine, but I can't get CGIs to work. The error I'm
>>getting is (partial traceback)
>
>Have you tried this on another Unix or Linux system? I would be 
>surprised if it was an OSX-specific issue (but then, I'm surprised 
>easily;-).
>

It's probably a BSD-specific issue... it doesn't affect Linux (I just 
tried both). CGIHTTPServer.py calls the flush method on a file 
descriptor open for reading. That in turn does a fflush(3) call, 
which is documented to cause an error in this case:

man fflush:

ERRORS
      [EBADF]            Stream is not an open stream, or, in the case of
                         fflush(), not a stream open for writing.

On my Linux box, fflush is also documented to cause an error on files 
not open for writing, so I guess in practice the C library doesn't 
act that way.

I think the correct fix is to remove the self.rfile.flush() line from 
CGIHTTPServer.py

-Tony


Index: CGIHTTPServer.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/CGIHTTPServer.py,v
retrieving revision 1.25
diff -u -r1.25 CGIHTTPServer.py
--- CGIHTTPServer.py    1 Jun 2002 19:51:15 -0000       1.25
+++ CGIHTTPServer.py    17 Jun 2002 16:09:22 -0000
@@ -193,7 +193,6 @@
              if '=' not in decoded_query:
                  args.append(decoded_query)
              nobody = nobody_uid()
-            self.rfile.flush() # Always flush before forking
              self.wfile.flush() # Always flush before forking
              pid = os.fork()
              if pid != 0: