[Pythonmac-SIG] CGIHTTPServer problems on OS X

Jack Jansen Jack.Jansen@oratrix.com
Tue, 18 Jun 2002 14:16:08 +0200


Tony,
your analysis makes sense to me, but I assume someone (who may 
know better) put that fflush() in there. Could you post this fix 
to sourceforge as a bug report, so someone with a more intimate 
understanding of CGIhttpserver.py can look at it?
I have no idea who to assign it to, maybe Guido?

On maandag, juni 17, 2002, at 06:15 , Tony Lownds wrote:

> 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:
>
>
>
--
- Jack Jansen        <Jack.Jansen@oratrix.com>        
http://www.cwi.nl/~jack -
- If I can't dance I don't want to be part of your revolution -- 
Emma Goldman -