From 3ebd4e0b45a8a6bd4c12604a3bb683dcb3a60eb8 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 10 Sep 2009 14:04:46 -0400 Subject: [PATCH 1/6] Add genwrapper hook, that can be used to add code into the C wrapper. --- IkiWiki/Plugin/skeleton.pm.example | 5 +++++ IkiWiki/Wrapper.pm | 8 ++++---- debian/changelog | 1 + doc/plugins/write.mdwn | 7 +++++++ 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/IkiWiki/Plugin/skeleton.pm.example b/IkiWiki/Plugin/skeleton.pm.example index 573510191..ddf2996d6 100644 --- a/IkiWiki/Plugin/skeleton.pm.example +++ b/IkiWiki/Plugin/skeleton.pm.example @@ -39,6 +39,7 @@ sub import { hook(type => "renamepage", id => "skeleton", call => \&renamepage); hook(type => "rename", id => "skeleton", call => \&rename); hook(type => "savestate", id => "skeleton", call => \&savestate); + hook(type => "genwrapper", id => "skeleton", call => \&genwrapper); } sub getopt () { @@ -239,4 +240,8 @@ sub savestate () { debug("skeleton plugin running in savestate"); } +sub genwrapper () { + debug("skeleton plugin running in genwrapper"); +} + 1 diff --git a/IkiWiki/Wrapper.pm b/IkiWiki/Wrapper.pm index 6555fe625..cf85738d6 100644 --- a/IkiWiki/Wrapper.pm +++ b/IkiWiki/Wrapper.pm @@ -38,11 +38,12 @@ sub gen_wrapper () { EOF } - my $test_receive=""; if ($config{test_receive}) { require IkiWiki::Receive; - $test_receive=IkiWiki::Receive::gen_wrapper(); } + + my @wrapper_hooks; + run_hooks(genwrapper => sub { push @wrapper_hooks, shift->() }); my $check_commit_hook=""; my $pre_exec=""; @@ -120,7 +121,7 @@ int main (int argc, char **argv) { char *s; $check_commit_hook -$test_receive +@wrapper_hooks $envsave newenviron[i++]="HOME=$ENV{HOME}"; newenviron[i++]="WRAPPED_OPTIONS=$configstring"; @@ -144,7 +145,6 @@ $pre_exec exit(1); } EOF - close OUT; my $cc=exists $ENV{CC} ? possibly_foolish_untaint($ENV{CC}) : 'cc'; if (system($cc, "$wrapper.c", "-o", "$wrapper.new") != 0) { diff --git a/debian/changelog b/debian/changelog index 2e1781713..488aef866 100644 --- a/debian/changelog +++ b/debian/changelog @@ -7,6 +7,7 @@ ikiwiki (3.14159265) UNRELEASED; urgency=low * underlay: Also allow configuring additional directories to search for template files in. * Fix parsing web commits from ipv6 addresses. + * Add genwrapper hook, that can be used to add code into the C wrapper. -- Joey Hess Wed, 02 Sep 2009 15:01:27 -0400 diff --git a/doc/plugins/write.mdwn b/doc/plugins/write.mdwn index 3976f9adf..668f8d8b6 100644 --- a/doc/plugins/write.mdwn +++ b/doc/plugins/write.mdwn @@ -496,6 +496,13 @@ describes the plugin as a whole. For example: and undef if a rebuild could be needed in some circumstances, but is not strictly required. +### genwrapper + + hook(type => "genwrapper", id => "foo", call => \&genwrapper); + +This hook is used to inject C code (which it returns) into the `main` +function of the ikiwiki wrapper when it is being generated. + ## Plugin interface To import the ikiwiki plugin interface: From 525d4cd037b1da19f4d54cf113212cbe452be417 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 10 Sep 2009 14:06:30 -0400 Subject: [PATCH 2/6] new hook --- doc/plugins/contrib/cvs/discussion.mdwn | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/plugins/contrib/cvs/discussion.mdwn b/doc/plugins/contrib/cvs/discussion.mdwn index 155a2289d..ace455d06 100644 --- a/doc/plugins/contrib/cvs/discussion.mdwn +++ b/doc/plugins/contrib/cvs/discussion.mdwn @@ -141,3 +141,7 @@ general-purpose way to do so. If and when some other problem thinks it wants to be solved by a new wrapper hook, it's easy enough to add one. Until then, I'd say it's more important to keep the wrapper as short and clear as possible. --[[schmonz]] + +> I've committed a slightly different hook, which should be general enough +> that `IkiWiki::Receive` can also use it, so please adapt your code to +> that. --[[Joey]] From 5ee980d77a614865747101615a6a795bec6f272f Mon Sep 17 00:00:00 2001 From: Amitai Schlair Date: Thu, 10 Sep 2009 15:17:28 -0400 Subject: [PATCH 3/6] catch up to genwrapper --- doc/plugins/contrib/cvs.mdwn | 3 --- doc/plugins/contrib/cvs/discussion.mdwn | 2 ++ 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/doc/plugins/contrib/cvs.mdwn b/doc/plugins/contrib/cvs.mdwn index d45992300..b75929139 100644 --- a/doc/plugins/contrib/cvs.mdwn +++ b/doc/plugins/contrib/cvs.mdwn @@ -22,9 +22,6 @@ Consider creating `$HOME/.cvsrc` if you don't have one already; the plugin doesn * `cvs.pm` started life as a copy of [[3.14159|news/version_3.14159]]'s `svn.pm`. * `IkiWiki.pm:wiki_file_prune_regexps` avoids copying CVS metadata into `$DESTDIR`. -* `IkiWiki/Wrapper.pm` provides a new "wrapperargcheck" hook, which -the plugin implements to avoid calling ikiwiki from post-commit -(and locking against itself) if it's a directory being `cvs add`ed. * [[ikiwiki-makerepo]]: * creates a repository, * imports `$SRCDIR` into top-level module `ikiwiki` (vendor tag IKIWIKI, release tag PRE_CVS), diff --git a/doc/plugins/contrib/cvs/discussion.mdwn b/doc/plugins/contrib/cvs/discussion.mdwn index ace455d06..645b2388b 100644 --- a/doc/plugins/contrib/cvs/discussion.mdwn +++ b/doc/plugins/contrib/cvs/discussion.mdwn @@ -145,3 +145,5 @@ short and clear as possible. --[[schmonz]] > I've committed a slightly different hook, which should be general enough > that `IkiWiki::Receive` can also use it, so please adapt your code to > that. --[[Joey]] + +>> Done. --[[schmonz]]. From 078f76d7fd3f53389a3dba47338c2d32b4dbba4a Mon Sep 17 00:00:00 2001 From: "http://joey.kitenet.net/" Date: Thu, 10 Sep 2009 16:14:29 -0400 Subject: [PATCH 4/6] testing --- doc/sandbox.mdwn | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/sandbox.mdwn b/doc/sandbox.mdwn index 8b594043e..7b56c6803 100644 --- a/doc/sandbox.mdwn +++ b/doc/sandbox.mdwn @@ -4,6 +4,8 @@ Here's a paragraph. Here's another one with *emphasised* text. +test + # Header ## Subheader From 26dae8f04955915f4203fab4bd5301c959f7771a Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 10 Sep 2009 16:09:19 -0400 Subject: [PATCH 5/6] clean up use of IkiWiki::Receive Loading and use of IkiWiki::Receive can all be pushed into the git plugin, rather than scattered around. I had at first wanted to make a receive plugin and move it there, but a plugin was not a good fit; you don't want users to have to manually load it, and making the git plugin load the receive plugin at the right times would need more, and ugly code. --- IkiWiki/Plugin/git.pm | 19 +++++++++++++++++++ IkiWiki/Receive.pm | 7 ++++--- IkiWiki/Wrapper.pm | 4 ---- ikiwiki.in | 4 ---- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/IkiWiki/Plugin/git.pm b/IkiWiki/Plugin/git.pm index 68b114a73..ad58231e0 100644 --- a/IkiWiki/Plugin/git.pm +++ b/IkiWiki/Plugin/git.pm @@ -14,6 +14,7 @@ my $no_chdir=0; sub import { hook(type => "checkconfig", id => "git", call => \&checkconfig); hook(type => "getsetup", id => "git", call => \&getsetup); + hook(type => "genwrapper", id => "git", call => \&genwrapper); hook(type => "rcs", id => "rcs_update", call => \&rcs_update); hook(type => "rcs", id => "rcs_prepedit", call => \&rcs_prepedit); hook(type => "rcs", id => "rcs_commit", call => \&rcs_commit); @@ -41,6 +42,7 @@ sub checkconfig () { wrappermode => (defined $config{git_wrappermode} ? $config{git_wrappermode} : "06755"), }; } + if (defined $config{git_test_receive_wrapper} && length $config{git_test_receive_wrapper}) { push @{$config{wrappers}}, { @@ -49,6 +51,13 @@ sub checkconfig () { wrappermode => (defined $config{git_wrappermode} ? $config{git_wrappermode} : "06755"), }; } + + # Run receive test only if being called by the wrapper, and not + # when generating same. + if ($config{test_receive} && ! exists $config{wrapper}) { + require IkiWiki::Receive; + IkiWiki::Receive::test(); + } } sub getsetup () { @@ -115,6 +124,16 @@ sub getsetup () { }, } +sub genwrapper { + if ($config{test_receive}) { + require IkiWiki::Receive; + return IkiWiki::Receive::genwrapper(); + } + else { + return ""; + } +} + sub safe_git (&@) { # Start a child process safely without resorting /bin/sh. # Return command output or success state (in scalar context). diff --git a/IkiWiki/Receive.pm b/IkiWiki/Receive.pm index 37b6f2a62..101c13ee5 100644 --- a/IkiWiki/Receive.pm +++ b/IkiWiki/Receive.pm @@ -1,5 +1,4 @@ #!/usr/bin/perl - package IkiWiki::Receive; use warnings; @@ -20,9 +19,9 @@ sub trusted () { ! grep { $_ eq $user } @{$config{untrusted_committers}}; } -sub gen_wrapper () { +sub genwrapper () { # Test for commits from untrusted committers in the wrapper, to - # avoid loading ikiwiki at all for trusted commits. + # avoid starting ikiwiki proper at all for trusted commits. my $ret=<<"EOF"; { @@ -37,6 +36,8 @@ EOF "u != $uid"; } @{$config{untrusted_committers}}). ") exit(0);\n"; + + $ret.=<<"EOF"; asprintf(&s, "CALLER_UID=%i", u); newenviron[i++]=s; diff --git a/IkiWiki/Wrapper.pm b/IkiWiki/Wrapper.pm index cf85738d6..ff110b5ff 100644 --- a/IkiWiki/Wrapper.pm +++ b/IkiWiki/Wrapper.pm @@ -37,10 +37,6 @@ sub gen_wrapper () { addenv("$var", s); EOF } - - if ($config{test_receive}) { - require IkiWiki::Receive; - } my @wrapper_hooks; run_hooks(genwrapper => sub { push @wrapper_hooks, shift->() }); diff --git a/ikiwiki.in b/ikiwiki.in index 4e9b812f8..b8581d880 100755 --- a/ikiwiki.in +++ b/ikiwiki.in @@ -190,10 +190,6 @@ sub main () { elsif ($config{post_commit} && ! commit_hook_enabled()) { # do nothing } - elsif ($config{test_receive}) { - require IkiWiki::Receive; - IkiWiki::Receive::test(); - } else { if ($config{rebuild}) { debug(gettext("rebuilding wiki..")); From fa2486c5648e751d561244faec38d261cbd01b36 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 10 Sep 2009 16:16:56 -0400 Subject: [PATCH 6/6] test from anon git --- doc/sandbox.mdwn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/sandbox.mdwn b/doc/sandbox.mdwn index 7b56c6803..22a5642da 100644 --- a/doc/sandbox.mdwn +++ b/doc/sandbox.mdwn @@ -4,7 +4,7 @@ Here's a paragraph. Here's another one with *emphasised* text. -test +test 2 # Header