]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Wrapper.pm
avoid multiple ikiwiki cgi processes piling up, eating all memory, and thrashing
[ikiwiki.git] / IkiWiki / Wrapper.pm
index 99237d3b5c5b46b6b5afb85436938b1cbbd329c4..d7d7f65b823e7ca06c90dc457bfb49490d59fe92 100644 (file)
@@ -44,6 +44,7 @@ EOF
        }
 
        my $check_commit_hook="";
+       my $pre_exec="";
        if ($config{post_commit}) {
                # Optimise checking !commit_hook_enabled() , 
                # so that ikiwiki does not have to be started if the
@@ -67,6 +68,19 @@ EOF
        }
 EOF
        }
+       elsif ($config{cgi}) {
+               # Avoid more than one ikiwiki cgi running at a time by
+               # taking a cgi lock. Since ikiwiki uses several MB of
+               # memory, a pile up of processes could cause thrashing
+               # otherwise.
+               $pre_exec=<<"EOF";
+       {
+               int fd=open("$config{wikistatedir}/cgilock", O_CREAT | O_RDWR);
+               if (fd != -1)
+                       flock(fd, LOCK_EX);
+       }
+EOF
+       }
 
        $Data::Dumper::Indent=0; # no newlines
        my $configstring=Data::Dumper->Dump([\%config], ['*config']);
@@ -122,6 +136,7 @@ $envsave
                exit(1);
        }
 
+$pre_exec
        execl("$this", "$this", NULL);
        perror("exec $this");
        exit(1);