-
- # handle backlinks; if a page has added/removed links, update the
- # pages it links to
- # TODO: inefficient; pages may get rendered above and again here;
- # problem is the backlinks could be wrong in the first pass render
- # above
- if (%rendered) {
- my %linkchanged;
- foreach my $file (keys %rendered, @del) {
- my $page=pagename($file);
- if (exists $links{$page}) {
- foreach my $link (map { bestlink($page, $_) } @{$links{$page}}) {
- if (length $link &&
- ! exists $oldlinks{$page} ||
- ! grep { $_ eq $link } @{$oldlinks{$page}}) {
- $linkchanged{$link}=1;
- }
- }
- }
- if (exists $oldlinks{$page}) {
- foreach my $link (map { bestlink($page, $_) } @{$oldlinks{$page}}) {
- if (length $link &&
- ! exists $links{$page} ||
- ! grep { $_ eq $link } @{$links{$page}}) {
- $linkchanged{$link}=1;
- }
- }
- }
- }
- foreach my $link (keys %linkchanged) {
- my $linkfile=$pagesources{$link};
- if (defined $linkfile) {
- debug("rendering $linkfile, to update its backlinks");
- render($linkfile);
- }
- }
- }
-} #}}}
-
-sub gen_wrapper (@) { #{{{
- my %config=(@_);
- eval q{use Cwd 'abs_path'};
- $config{srcdir}=abs_path($config{srcdir});
- $config{destdir}=abs_path($config{destdir});
- my $this=abs_path($0);
- if (! -x $this) {
- error("$this doesn't seem to be executable");
- }
-
- if ($config{setup}) {
- error("cannot create a wrapper that uses a setup file");
- }
-
- my @params=($config{srcdir}, $config{templatedir}, $config{destdir},
- "--wikiname=$config{wikiname}");
- push @params, "--verbose" if $config{verbose};
- push @params, "--rebuild" if $config{rebuild};
- push @params, "--nosvn" if !$config{svn};
- push @params, "--cgi" if $config{cgi};
- push @params, "--url=$config{url}" if length $config{url};
- push @params, "--cgiurl=$config{cgiurl}" if length $config{cgiurl};
- push @params, "--historyurl=$config{historyurl}" if length $config{historyurl};
- push @params, "--anonok" if $config{anonok};
- my $params=join(" ", @params);
- my $call='';
- foreach my $p ($this, $this, @params) {
- $call.=qq{"$p", };
- }
- $call.="NULL";
-
- my @envsave;
- push @envsave, qw{REMOTE_ADDR QUERY_STRING REQUEST_METHOD REQUEST_URI
- CONTENT_TYPE CONTENT_LENGTH GATEWAY_INTERFACE
- HTTP_COOKIE} if $config{cgi};
- my $envsave="";
- foreach my $var (@envsave) {
- $envsave.=<<"EOF"
- if ((s=getenv("$var")))
- asprintf(&newenviron[i++], "%s=%s", "$var", s);
-EOF
- }
-
- open(OUT, ">ikiwiki-wrap.c") || error("failed to write ikiwiki-wrap.c: $!");;
- print OUT <<"EOF";
-/* A wrapper for ikiwiki, can be safely made suid. */
-#define _GNU_SOURCE
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-
-extern char **environ;
-
-int main (int argc, char **argv) {
- /* Sanitize environment. */
- char *s;
- char *newenviron[$#envsave+3];
- int i=0;
-$envsave
- newenviron[i++]="HOME=$ENV{HOME}";
- newenviron[i]=NULL;
- environ=newenviron;
-
- if (argc == 2 && strcmp(argv[1], "--params") == 0) {
- printf("$params\\n");
- exit(0);
- }
-
- execl($call);
- perror("failed to run $this");
- exit(1);
-}
-EOF