aboutsummaryrefslogtreecommitdiff
path: root/IkiWiki/Wrapper.pm
diff options
context:
space:
mode:
authorjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>2006-03-23 07:37:16 +0000
committerjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>2006-03-23 07:37:16 +0000
commitb645dc5a4118feabd37d95fabbc6aaa803e3c45f (patch)
tree305ffea8613c8dce53e752d74ea3c07237cb6da2 /IkiWiki/Wrapper.pm
parent6c8cf5dd571662f981227489f7c4652a1a1f10cd (diff)
downloadikiwiki-b645dc5a4118feabd37d95fabbc6aaa803e3c45f.tar
ikiwiki-b645dc5a4118feabd37d95fabbc6aaa803e3c45f.tar.gz
Getopt::Long is a huge, heavy perl module. So why use it?
This {gross,amazing} hack makes all wrapped uses of ikiwiki forgo any option parsing at all. Options come in preparses via an env var from the wrapper. As a bonus, Wrapper.pm no longer needs to be updated when command line options are added to the program. Load time is sped up by around 10%. ikiwikiwrap --params is no longer supported by this change. You will need to rebuild your wrappers to take advantage of it.
Diffstat (limited to 'IkiWiki/Wrapper.pm')
-rw-r--r--IkiWiki/Wrapper.pm48
1 files changed, 16 insertions, 32 deletions
diff --git a/IkiWiki/Wrapper.pm b/IkiWiki/Wrapper.pm
index 8e513c1f6..62d284eb6 100644
--- a/IkiWiki/Wrapper.pm
+++ b/IkiWiki/Wrapper.pm
@@ -2,11 +2,12 @@
use warnings;
use strict;
+use Cwd q{abs_path};
+use Data::Dumper;
package IkiWiki;
sub gen_wrapper () { #{{{
- eval q{use Cwd 'abs_path'};
$config{srcdir}=abs_path($config{srcdir});
$config{destdir}=abs_path($config{destdir});
my $this=abs_path($0);
@@ -17,26 +18,8 @@ sub gen_wrapper () { #{{{
if ($config{setup}) {
error("cannot create a wrapper that uses a setup file");
}
-
- my @params=($config{srcdir}, $config{destdir},
- "--wikiname=$config{wikiname}",
- "--templatedir=$config{templatedir}");
- 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, "--diffurl=$config{diffurl}" if length $config{diffurl};
- push @params, "--anonok" if $config{anonok};
- push @params, "--adminuser=$_" foreach @{$config{adminuser}};
- my $params=join(" ", @params);
- my $call='';
- foreach my $p ($this, $this, @params) {
- $call.=qq{"$p", };
- }
- $call.="NULL";
+ my $wrapper=possibly_foolish_untaint($config{wrapper});
+ delete $config{wrapper};
my @envsave;
push @envsave, qw{REMOTE_ADDR QUERY_STRING REQUEST_METHOD REQUEST_URI
@@ -50,6 +33,11 @@ sub gen_wrapper () { #{{{
EOF
}
+ $Data::Dumper::Indent=0;
+ my $configstring=Data::Dumper->Dump([\%config], ['*config']);
+ $configstring=~s/\\/\\\\/g;
+ $configstring=~s/"/\\"/g;
+
open(OUT, ">ikiwiki-wrap.c") || error("failed to write ikiwiki-wrap.c: $!");;
print OUT <<"EOF";
/* A wrapper for ikiwiki, can be safely made suid. */
@@ -64,33 +52,29 @@ extern char **environ;
int main (int argc, char **argv) {
/* Sanitize environment. */
char *s;
- char *newenviron[$#envsave+3];
+ char *newenviron[$#envsave+4];
int i=0;
$envsave
newenviron[i++]="HOME=$ENV{HOME}";
+ newenviron[i++]="WRAPPED_OPTIONS=$configstring";
newenviron[i]=NULL;
environ=newenviron;
- if (argc == 2 && strcmp(argv[1], "--params") == 0) {
- printf("$params\\n");
- exit(0);
- }
-
- execl($call);
+ execl("$this", "$this", NULL);
perror("failed to run $this");
exit(1);
}
EOF
close OUT;
- if (system("gcc", "ikiwiki-wrap.c", "-o", possibly_foolish_untaint($config{wrapper})) != 0) {
+ if (system("gcc", "ikiwiki-wrap.c", "-o", $wrapper) != 0) {
error("failed to compile ikiwiki-wrap.c");
}
unlink("ikiwiki-wrap.c");
if (defined $config{wrappermode} &&
- ! chmod(oct($config{wrappermode}), possibly_foolish_untaint($config{wrapper}))) {
- error("chmod $config{wrapper}: $!");
+ ! chmod(oct($config{wrappermode}), $wrapper)) {
+ error("chmod $wrapper: $!");
}
- print "successfully generated $config{wrapper}\n";
+ print "successfully generated $wrapper\n";
} #}}}
1