fork a child to run dumpsetup
authorJoey Hess <joey@kitenet.net>
Thu, 8 Jul 2010 17:55:30 +0000 (13:55 -0400)
committerJoey Hess <joey@kitenet.net>
Thu, 8 Jul 2010 17:55:30 +0000 (13:55 -0400)
IkiWiki/Setup.pm

index 2b0259e2ac0e9b258d6537c48399547dba921e1d..5b77a6471111d28a0090a769d1c3cbac804e6792 100644 (file)
@@ -50,10 +50,8 @@ sub load ($;$) {
 
 sub dump ($) {
        my $file=IkiWiki::possibly_foolish_untaint(shift);
-       
-       eval qq{require IkiWiki::Setup::$config{setuptype}};
-       error $@ if $@;
-       my @dump="IkiWiki::Setup::$config{setuptype}"->gendump(
+
+       my @header=(
                "Setup file for ikiwiki.",
                "",
                "Passing this to ikiwiki --setup will make ikiwiki generate",
@@ -62,9 +60,23 @@ sub dump ($) {
                "Remember to re-run ikiwiki --setup any time you edit this file.",
        );
 
-       open (OUT, ">", $file) || die "$file: $!";
-       print OUT "$_\n" foreach @dump;
-       close OUT;
+       # Fork because dumping setup requires loading all plugins.
+       my $pid=fork();
+       if ($pid == 0) {
+               eval qq{require IkiWiki::Setup::$config{setuptype}};
+               error $@ if $@;
+               my @dump="IkiWiki::Setup::$config{setuptype}"->gendump(@header);
+       
+               open (OUT, ">", $file) || die "$file: $!";
+               print OUT "$_\n" foreach @dump;
+               close OUT;
+
+               exit 0;
+       }
+       else {
+               waitpid $pid, 0;
+               exit $? if $?;
+       }
 }
 
 sub merge ($) {