[darcs-devel] Race in darcs.cgi

Davide Dente davidedente at fastmail.fm
Mon Sep 27 03:14:48 PDT 2004


Hello darcs-developers.

I'm testing Darcs and I think I've found a race condition in darcs.cgi,
the new CGI script for querying via web a Darcs repository.

darcs.cgi call the command "darcs", to create an XML output, and then
"xsltproc" to create an HTML page out of it. For the intermediate output
file  the library function File::Temp::tempfile is used.

The problem is that I have xsltproc trying to read the tempfile *after*
it has been created but *before* anything has been written to it. This
is because perl invoked by CGI does not autoflush the files, and my
server is probably to slow (SUN Ultra 60, Solaris 2.6, Perl 5.6.1).

I did solve this problem using this patch:

======
--- darcs.cgi   2004-09-24 19:18:04.803338000 +0200
+++ darcs.cgi.dd        2004-09-27 12:13:13.483883000 +0200
@@ -36,6 +36,7 @@
 use File::Basename;
 use File::stat;
 use File::Temp;
+use IO::Handle;
 use POSIX;
 
 ## the following variables can be customized to reflect your system
@@ -110,6 +111,7 @@
 sub make_xml {
     my ($repo, $target) = @_;
     my ($fh, $fname) = File::Temp::tempfile();
+    $fh->autoflush;
     
     # eliminate any slashes in the repository name
     $repo =~ s|/||g;
=====

that is, I did just force autoflush on.

Hope this helps.


dd




More information about the darcs-devel mailing list