]> sipb.mit.edu Git - ikiwiki.git/blobdiff - ikiwiki
web commit by joey
[ikiwiki.git] / ikiwiki
diff --git a/ikiwiki b/ikiwiki
index 72b4ab77192cb4248739e1cadbc9775cdb03256c..cb90ef04f10b7cee9a81d2223df028feb98e8438 100755 (executable)
--- a/ikiwiki
+++ b/ikiwiki
@@ -10,7 +10,8 @@ use Getopt::Long;
 
 my (%links, %oldlinks, %oldpagemtime, %renderedfiles, %pagesources);
 
-my %config=( #{{{
+# Holds global config settings, also used by some modules.
+our %config=( #{{{
        wiki_file_prune_regexp => qr{((^|/).svn/|\.\.|^\.|\/\.|\.html?$)},
        wiki_link_regexp => qr/\[\[([^\s]+)\]\]/,
        wiki_file_regexp => qr/(^[-A-Za-z0-9_.:\/+]+$)/,
@@ -400,6 +401,25 @@ sub render ($) { #{{{
        }
 } #}}}
 
+sub lockwiki () { #{{{
+       # Take an exclusive lock on the wiki to prevent multiple concurrent
+       # run issues. The lock will be dropped on program exit.
+       if (! -d "$config{srcdir}/.ikiwiki") {
+               mkdir("$config{srcdir}/.ikiwiki");
+       }
+       open(WIKILOCK, ">$config{srcdir}/.ikiwiki/lockfile") || error ("cannot write to lockfile: $!");
+       if (! flock(WIKILOCK, 2 | 4)) {
+               debug("wiki seems to be locked, waiting for lock");
+               my $wait=600; # arbitrary, but don't hang forever to 
+                             # prevent process pileup
+               for (1..600) {
+                       return if flock(WIKILOCK, 2 | 4);
+                       sleep 1;
+               }
+               error("wiki is locked; waited $wait seconds without lock being freed (possible stuck process or stale lock?)");
+       }
+} #}}}
+
 sub loadindex () { #{{{
        open (IN, "$config{srcdir}/.ikiwiki/index") || return;
        while (<IN>) {
@@ -524,7 +544,7 @@ sub rcs_recentchanges ($) { #{{{
                                @pages=@message=();
                        }
                        elsif ($state eq 'body') {
-                               push @message, {line => $_},
+                               push @message, {line => escapeHTML($_)},
                        }
                }
        }
@@ -556,7 +576,7 @@ sub refresh () { #{{{
                                $File::Find::prune=1;
                                use warnings "all";
                        }
-                       elsif (! -d $_) {
+                       elsif (! -d $_ && ! -l $_) {
                                my ($f)=/$config{wiki_file_regexp}/; # untaint
                                if (! defined $f) {
                                        warn("skipping bad filename $_\n");
@@ -1165,25 +1185,13 @@ sub setup () { # {{{
        ($code)=$code=~/(.*)/s;
        close IN;
 
-       my (%setup);
        eval $code;
        error($@) if $@;
-       
-       gen_wrapper(%config, %setup, %{$setup{cgiwrapper}}) if $setup{cgiwrapper};
-       gen_wrapper(%config, %setup, %{$setup{svnwrapper}}) if $setup{svnwrapper};
-       
-       print "$setup{wikiname} setup complete, now forcing a rebuild\n";
-       foreach my $c (keys %setup) {
-               $config{$c}=possibly_foolish_untaint($setup{$c})
-                       if defined $setup{$c} && ! ref $setup{$c};
-       }
-       $config{rebuild}=1;
-       refresh();
-       saveindex();
        exit;
 } #}}}
 
 # main {{{
+lockwiki();
 setup() if $config{setup};
 if ($config{wrapper}) {
        gen_wrapper(%config);