From 524de4db2639d37aa7049de4363c5d482cd34a0e Mon Sep 17 00:00:00 2001 From: Amitai Schlair Date: Sat, 22 Aug 2009 01:25:41 -0400 Subject: Pass along wrapper args to ikiwiki, then handle the "cvs add dir" case with a getopt hook directly in my plugin. If the wrapper change is safe, we won't need a wrapper wrapper. --- IkiWiki/Wrapper.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'IkiWiki/Wrapper.pm') diff --git a/IkiWiki/Wrapper.pm b/IkiWiki/Wrapper.pm index 6555fe625..4d92716ff 100644 --- a/IkiWiki/Wrapper.pm +++ b/IkiWiki/Wrapper.pm @@ -139,7 +139,7 @@ $envsave } $pre_exec - execl("$this", "$this", NULL); + execv("$this", argv); perror("exec $this"); exit(1); } -- cgit v1.2.3 From 5da229aa51adcec27b109ebe2e696f7426cbd781 Mon Sep 17 00:00:00 2001 From: Amitai Schlair Date: Sun, 23 Aug 2009 18:25:02 -0400 Subject: Instead of passing the args through the wrapper so the CVS plugin can evaluate them, check them in the wrapper right off the bat. This doesn't prevent the deadlock in web commits that need to cvs add directories, but I'm committing so Joey can take a look if he wants. --- IkiWiki/Wrapper.pm | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'IkiWiki/Wrapper.pm') diff --git a/IkiWiki/Wrapper.pm b/IkiWiki/Wrapper.pm index 4d92716ff..2354717c3 100644 --- a/IkiWiki/Wrapper.pm +++ b/IkiWiki/Wrapper.pm @@ -44,6 +44,17 @@ EOF $test_receive=IkiWiki::Receive::gen_wrapper(); } + my $check_cvs_add_dir=""; + # XXX conditionalize on $config{rcs} eq 'cvs' + $check_cvs_add_dir=<<"EOF"; + { + int j; + for (j = 1; j < argc; j++) + if (strcmp(argv[j], "New directory") == 0) + exit(0); + } +EOF + my $check_commit_hook=""; my $pre_exec=""; if ($config{post_commit}) { @@ -119,6 +130,7 @@ addenv(char *var, char *val) { int main (int argc, char **argv) { char *s; +$check_cvs_add_dir $check_commit_hook $test_receive $envsave @@ -139,7 +151,7 @@ $envsave } $pre_exec - execv("$this", argv); + execl("$this", "$this", NULL); perror("exec $this"); exit(1); } -- cgit v1.2.3 From 992d0aac09a3e3e81d7ad999910a4a026984f804 Mon Sep 17 00:00:00 2001 From: Amitai Schlair Date: Sun, 30 Aug 2009 00:05:23 -0400 Subject: The string to match might not be "New directory" exactly, so match that substring instead. --- IkiWiki/Wrapper.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'IkiWiki/Wrapper.pm') diff --git a/IkiWiki/Wrapper.pm b/IkiWiki/Wrapper.pm index 2354717c3..87c2ffc89 100644 --- a/IkiWiki/Wrapper.pm +++ b/IkiWiki/Wrapper.pm @@ -50,7 +50,7 @@ EOF { int j; for (j = 1; j < argc; j++) - if (strcmp(argv[j], "New directory") == 0) + if (strstr(argv[j], "New directory") != NULL) exit(0); } EOF -- cgit v1.2.3 From 5e94e973eeb4ba75d9c37bd801278f686f0977c3 Mon Sep 17 00:00:00 2001 From: Amitai Schlair Date: Sun, 30 Aug 2009 02:00:49 -0400 Subject: Only examine argv if the VCS is cvs. --- IkiWiki/Wrapper.pm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'IkiWiki/Wrapper.pm') diff --git a/IkiWiki/Wrapper.pm b/IkiWiki/Wrapper.pm index 87c2ffc89..cc2223d7a 100644 --- a/IkiWiki/Wrapper.pm +++ b/IkiWiki/Wrapper.pm @@ -45,8 +45,8 @@ EOF } my $check_cvs_add_dir=""; - # XXX conditionalize on $config{rcs} eq 'cvs' - $check_cvs_add_dir=<<"EOF"; + if ($config{rcs} eq 'cvs') { + $check_cvs_add_dir=<<"EOF"; { int j; for (j = 1; j < argc; j++) @@ -54,6 +54,7 @@ EOF exit(0); } EOF + } my $check_commit_hook=""; my $pre_exec=""; -- cgit v1.2.3 From aafd267ee099ddb8ff4129a0e4d46964be866f6d Mon Sep 17 00:00:00 2001 From: Amitai Schlair Date: Wed, 9 Sep 2009 21:58:42 -0400 Subject: Abstract out CVS's involvement in the wrapper: * In Wrapper.pm, add a new hook "wrapperargcheck" to examine argc/argv and return success or failure. In the failure case, the wrapper terminates. * In cvs.pm, implement the new hook to return failure if a directory is being cvs added. --- IkiWiki/Plugin/cvs.pm | 12 ++++++++++++ IkiWiki/Wrapper.pm | 21 +++++++++------------ 2 files changed, 21 insertions(+), 12 deletions(-) (limited to 'IkiWiki/Wrapper.pm') diff --git a/IkiWiki/Plugin/cvs.pm b/IkiWiki/Plugin/cvs.pm index 8409bebed..ff9d578e2 100644 --- a/IkiWiki/Plugin/cvs.pm +++ b/IkiWiki/Plugin/cvs.pm @@ -6,6 +6,7 @@ use strict; use IkiWiki; sub import { + hook(type => "wrapperargcheck", id => "cvs", call => \&wrapperargcheck); hook(type => "checkconfig", id => "cvs", call => \&checkconfig); hook(type => "getsetup", id => "cvs", call => \&getsetup); hook(type => "rcs", id => "rcs_update", call => \&rcs_update); @@ -20,6 +21,17 @@ sub import { hook(type => "rcs", id => "rcs_getctime", call => \&rcs_getctime); } +sub wrapperargcheck () { + my $check_args=<<"EOF"; + int j; + for (j = 1; j < argc; j++) + if (strstr(argv[j], "New directory") != NULL) + return 0; + return 1; +EOF + return $check_args; +} + sub checkconfig () { if (! defined $config{cvspath}) { $config{cvspath}="ikiwiki"; diff --git a/IkiWiki/Wrapper.pm b/IkiWiki/Wrapper.pm index cc2223d7a..0baf112ff 100644 --- a/IkiWiki/Wrapper.pm +++ b/IkiWiki/Wrapper.pm @@ -44,17 +44,8 @@ EOF $test_receive=IkiWiki::Receive::gen_wrapper(); } - my $check_cvs_add_dir=""; - if ($config{rcs} eq 'cvs') { - $check_cvs_add_dir=<<"EOF"; - { - int j; - for (j = 1; j < argc; j++) - if (strstr(argv[j], "New directory") != NULL) - exit(0); - } -EOF - } + my $check_args=" return 0;"; + run_hooks(wrapperargcheck => sub { $check_args = shift->(); }); my $check_commit_hook=""; my $pre_exec=""; @@ -128,10 +119,16 @@ addenv(char *var, char *val) { newenviron[i++]=s; } +int checkargs(int argc, char **argv) { +$check_args +} + int main (int argc, char **argv) { char *s; -$check_cvs_add_dir + if (!checkargs(argc, argv)) + exit(0); + $check_commit_hook $test_receive $envsave -- cgit v1.2.3 From 3ebd4e0b45a8a6bd4c12604a3bb683dcb3a60eb8 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 10 Sep 2009 14:04:46 -0400 Subject: 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(-) (limited to 'IkiWiki/Wrapper.pm') 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: -- cgit v1.2.3 From 8063bc3402bb1beab8ed85ecc25d19204e892060 Mon Sep 17 00:00:00 2001 From: Amitai Schlair Date: Thu, 10 Sep 2009 15:12:45 -0400 Subject: Catch up to the new genwrapper hook. --- IkiWiki/Plugin/cvs.pm | 15 ++++++++------- IkiWiki/Wrapper.pm | 10 ---------- 2 files changed, 8 insertions(+), 17 deletions(-) (limited to 'IkiWiki/Wrapper.pm') diff --git a/IkiWiki/Plugin/cvs.pm b/IkiWiki/Plugin/cvs.pm index e926425f2..3ce22203b 100644 --- a/IkiWiki/Plugin/cvs.pm +++ b/IkiWiki/Plugin/cvs.pm @@ -8,7 +8,7 @@ use IkiWiki; use File::chdir; sub import { - hook(type => "wrapperargcheck", id => "cvs", call => \&wrapperargcheck); + hook(type => "genwrapper", id => "cvs", call => \&genwrapper); hook(type => "checkconfig", id => "cvs", call => \&checkconfig); hook(type => "getsetup", id => "cvs", call => \&getsetup); hook(type => "rcs", id => "rcs_update", call => \&rcs_update); @@ -23,13 +23,14 @@ sub import { hook(type => "rcs", id => "rcs_getctime", call => \&rcs_getctime); } -sub wrapperargcheck () { +sub genwrapper () { my $check_args=<<"EOF"; - int j; - for (j = 1; j < argc; j++) - if (strstr(argv[j], "New directory") != NULL) - return 0; - return 1; + { + int j; + for (j = 1; j < argc; j++) + if (strstr(argv[j], "New directory") != NULL) + exit(0); + } EOF return $check_args; } diff --git a/IkiWiki/Wrapper.pm b/IkiWiki/Wrapper.pm index 57896e262..cf85738d6 100644 --- a/IkiWiki/Wrapper.pm +++ b/IkiWiki/Wrapper.pm @@ -45,9 +45,6 @@ EOF my @wrapper_hooks; run_hooks(genwrapper => sub { push @wrapper_hooks, shift->() }); - my $check_args=" return 0;"; - run_hooks(wrapperargcheck => sub { $check_args = shift->(); }); - my $check_commit_hook=""; my $pre_exec=""; if ($config{post_commit}) { @@ -120,16 +117,9 @@ addenv(char *var, char *val) { newenviron[i++]=s; } -int checkargs(int argc, char **argv) { -$check_args -} - int main (int argc, char **argv) { char *s; - if (!checkargs(argc, argv)) - exit(0); - $check_commit_hook @wrapper_hooks $envsave -- cgit v1.2.3 From 26dae8f04955915f4203fab4bd5301c959f7771a Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 10 Sep 2009 16:09:19 -0400 Subject: 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(-) (limited to 'IkiWiki/Wrapper.pm') 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..")); -- cgit v1.2.3 From 990a4b99b00c162da218f951041fed50c4259049 Mon Sep 17 00:00:00 2001 From: Giulio Eulisse Date: Mon, 19 Oct 2009 09:40:45 +0200 Subject: Pick up user specified CFLAGS when compiling the wrapper. (cherry picked from commit 13e9383b48857daa206387f3486eb00e3b171a68) --- IkiWiki/Wrapper.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'IkiWiki/Wrapper.pm') diff --git a/IkiWiki/Wrapper.pm b/IkiWiki/Wrapper.pm index ff110b5ff..7a1529119 100644 --- a/IkiWiki/Wrapper.pm +++ b/IkiWiki/Wrapper.pm @@ -143,7 +143,8 @@ $pre_exec EOF my $cc=exists $ENV{CC} ? possibly_foolish_untaint($ENV{CC}) : 'cc'; - if (system($cc, "$wrapper.c", "-o", "$wrapper.new") != 0) { + my $cflags=exists $ENV{CFLAGS} ? possibly_foolish_untaint($ENV{CFLAGS}) : '-O'; + if (system($cc, $cflags, "$wrapper.c", "-o", "$wrapper.new") != 0) { #translators: The parameter is a C filename. error(sprintf(gettext("failed to compile %s"), "$wrapper.c")); } -- cgit v1.2.3 From b6f6f126d0e3fa23687f2d8c537de207e2c7b5d3 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 21 Oct 2009 16:27:44 -0400 Subject: avoid -O default for CFLAGS, and document --- IkiWiki/Wrapper.pm | 6 +++--- debian/changelog | 1 + doc/usage.mdwn | 4 ++++ 3 files changed, 8 insertions(+), 3 deletions(-) (limited to 'IkiWiki/Wrapper.pm') diff --git a/IkiWiki/Wrapper.pm b/IkiWiki/Wrapper.pm index 7a1529119..5427a5c80 100644 --- a/IkiWiki/Wrapper.pm +++ b/IkiWiki/Wrapper.pm @@ -142,9 +142,9 @@ $pre_exec } EOF - my $cc=exists $ENV{CC} ? possibly_foolish_untaint($ENV{CC}) : 'cc'; - my $cflags=exists $ENV{CFLAGS} ? possibly_foolish_untaint($ENV{CFLAGS}) : '-O'; - if (system($cc, $cflags, "$wrapper.c", "-o", "$wrapper.new") != 0) { + my @cc=exists $ENV{CC} ? possibly_foolish_untaint($ENV{CC}) : 'cc'; + push @cc, possibly_foolish_untaint($ENV{CFLAGS}) if exists $ENV{CFLAGS}; + if (system(@cc, "$wrapper.c", "-o", "$wrapper.new") != 0) { #translators: The parameter is a C filename. error(sprintf(gettext("failed to compile %s"), "$wrapper.c")); } diff --git a/debian/changelog b/debian/changelog index f6739952e..0ff7a0d13 100644 --- a/debian/changelog +++ b/debian/changelog @@ -5,6 +5,7 @@ ikiwiki (3.20091018) UNRELEASED; urgency=low * edittemplate: Work around bug #551499 in CGI::FormBuilder. * Fix a bug introduced in the last version that caused ikiwiki to skip all files if a sourcedir of "./" was specified. + * Support CFLAGS when building wrapper. -- Joey Hess Sun, 18 Oct 2009 13:44:09 -0400 diff --git a/doc/usage.mdwn b/doc/usage.mdwn index 0c618de5c..4ee935f73 100644 --- a/doc/usage.mdwn +++ b/doc/usage.mdwn @@ -345,6 +345,10 @@ also be configured using a setup file. This controls what C compiler is used to build wrappers. Default is 'cc'. +* CFLAGS + + This can be used to pass options to the C compiler when building wrappers. + # SEE ALSO * [[ikiwiki-mass-rebuild]](8) -- cgit v1.2.3 From b4ab74e722aaca406922fe614d9e6541dd87c3bf Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 18 Mar 2010 17:35:59 -0400 Subject: C warning cleanup --- IkiWiki/Wrapper.pm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'IkiWiki/Wrapper.pm') diff --git a/IkiWiki/Wrapper.pm b/IkiWiki/Wrapper.pm index 5427a5c80..830b04877 100644 --- a/IkiWiki/Wrapper.pm +++ b/IkiWiki/Wrapper.pm @@ -76,8 +76,8 @@ EOF { int fd=open("$config{wikistatedir}/cgilock", O_CREAT | O_RDWR, 0666); if (fd != -1 && flock(fd, LOCK_EX) == 0) { - char *fd_s; - asprintf(&fd_s, "%i", fd); + char *fd_s=malloc(8); + sprintf(fd_s, "%i", fd); setenv("IKIWIKI_CGILOCK_FD", fd_s, 1); } } @@ -105,7 +105,7 @@ extern char **environ; char *newenviron[$#envsave+6]; int i=0; -addenv(char *var, char *val) { +void addenv(char *var, char *val) { char *s=malloc(strlen(var)+1+strlen(val)+1); if (!s) perror("malloc"); -- cgit v1.2.3 From dddd6aa99055d8505f73e39b12f049633d9cb4c3 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 18 Mar 2010 17:44:46 -0400 Subject: Allow wrappers to be built using tcc. --- IkiWiki/Wrapper.pm | 10 +++++++--- debian/changelog | 1 + .../post-update_hook_can__39__t_be_compiled_with_tcc.mdwn | 11 ++++++++--- 3 files changed, 16 insertions(+), 6 deletions(-) (limited to 'IkiWiki/Wrapper.pm') diff --git a/IkiWiki/Wrapper.pm b/IkiWiki/Wrapper.pm index 830b04877..f175b4a0b 100644 --- a/IkiWiki/Wrapper.pm +++ b/IkiWiki/Wrapper.pm @@ -101,7 +101,6 @@ EOF #include #include -extern char **environ; char *newenviron[$#envsave+6]; int i=0; @@ -121,8 +120,13 @@ $check_commit_hook $envsave newenviron[i++]="HOME=$ENV{HOME}"; newenviron[i++]="WRAPPED_OPTIONS=$configstring"; - newenviron[i]=NULL; - environ=newenviron; + + if (clearenv() != 0) { + perror("clearenv"); + exit(1); + } + for (; i>0; i--) + putenv(newenviron[i-1]); if (setregid(getegid(), -1) != 0 && setregid(getegid(), -1) != 0) { diff --git a/debian/changelog b/debian/changelog index e5347e2a1..73f6fcff8 100644 --- a/debian/changelog +++ b/debian/changelog @@ -12,6 +12,7 @@ ikiwiki (3.20100313) UNRELEASED; urgency=low wiki source files, such as .htaccess, that would normally be skipped for security or other reasons. Closes: #447267 (Thanks to Aaron Wilson for the original patch.) + * Allow wrappers to be built using tcc. -- Joey Hess Sat, 13 Mar 2010 14:48:10 -0500 diff --git a/doc/bugs/post-update_hook_can__39__t_be_compiled_with_tcc.mdwn b/doc/bugs/post-update_hook_can__39__t_be_compiled_with_tcc.mdwn index 4226c026a..a8fb19888 100644 --- a/doc/bugs/post-update_hook_can__39__t_be_compiled_with_tcc.mdwn +++ b/doc/bugs/post-update_hook_can__39__t_be_compiled_with_tcc.mdwn @@ -9,6 +9,11 @@ Everything works fine with gcc. versions: Debian lenny + backports - - - +> Seems that tcc does not respect changing where `environ` points as a way +> to change the environment seen after `exec` +> +> Given that the man page for `clearenv` suggests using `environ=NULL` +> if `clearenv` is not available, I would be lerry or using tcc to compile +> stuff, since that could easily lead to a security compromise of code that +> expects that to work. However, I have fixed ikiwiki to use `clearenv`. +> --[[Joey]] [[done]] -- cgit v1.2.3 From 0c6e467aa6931ec6bd7720ecaea5e33aeca4d1be Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 28 Mar 2010 18:27:23 -0400 Subject: use __TINYC__ define to avoid tinyc compat fixes breaking FreeBSD To review, tcc does not really use environ, so you have to use clearenv there. But POSIX, in their wisdom, didn't standardise clearenv yet, so on FreeBSD, one still needs to manipulate environ on their own. (If you use tcc on FreeBSD, this may leave you unsatisfied.) --- IkiWiki/Wrapper.pm | 6 ++++++ doc/bugs/clearenv_not_present_at_FreeBSD_.mdwn | 3 +++ 2 files changed, 9 insertions(+) (limited to 'IkiWiki/Wrapper.pm') diff --git a/IkiWiki/Wrapper.pm b/IkiWiki/Wrapper.pm index f175b4a0b..3f3e63ca6 100644 --- a/IkiWiki/Wrapper.pm +++ b/IkiWiki/Wrapper.pm @@ -101,6 +101,7 @@ EOF #include #include +extern char **environ; char *newenviron[$#envsave+6]; int i=0; @@ -121,12 +122,17 @@ $envsave newenviron[i++]="HOME=$ENV{HOME}"; newenviron[i++]="WRAPPED_OPTIONS=$configstring"; +#ifdef __TINYC__ if (clearenv() != 0) { perror("clearenv"); exit(1); } for (; i>0; i--) putenv(newenviron[i-1]); +#else + newenviron[i]=NULL; + environ=newenviron; +#endif if (setregid(getegid(), -1) != 0 && setregid(getegid(), -1) != 0) { diff --git a/doc/bugs/clearenv_not_present_at_FreeBSD_.mdwn b/doc/bugs/clearenv_not_present_at_FreeBSD_.mdwn index 6ad7975eb..c2355d6aa 100644 --- a/doc/bugs/clearenv_not_present_at_FreeBSD_.mdwn +++ b/doc/bugs/clearenv_not_present_at_FreeBSD_.mdwn @@ -1,2 +1,5 @@ When build wrapper on FreeBSD system, is error occured with clearenv reference. clearenv() das not exists at FreeBSD system, use workaround environ[0]=NULL; P.S. new git instalation, FreeBSD 7.x + +> #include fixed with nasty ifdefs to handle tcc w/o +> breaking everything else. ||done]] --[[Joey]] -- cgit v1.2.3 From 76a5dbe7cbc4e1f016752e4aa1445052c0b4a3ef Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 4 May 2010 18:41:55 -0400 Subject: note that tcc workaround is for bug fixed in tcc now --- IkiWiki/Wrapper.pm | 1 + 1 file changed, 1 insertion(+) (limited to 'IkiWiki/Wrapper.pm') diff --git a/IkiWiki/Wrapper.pm b/IkiWiki/Wrapper.pm index 3f3e63ca6..73f0896e8 100644 --- a/IkiWiki/Wrapper.pm +++ b/IkiWiki/Wrapper.pm @@ -123,6 +123,7 @@ $envsave newenviron[i++]="WRAPPED_OPTIONS=$configstring"; #ifdef __TINYC__ + /* old tcc versions do not support modifying environ directly */ if (clearenv() != 0) { perror("clearenv"); exit(1); -- cgit v1.2.3 From 0eabe6f79498e3339205aeff2c79ae1e85498ab4 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 1 Jul 2010 16:20:03 -0400 Subject: git: Added git_wrapper_background_command option. Can be used to eg, make the git wrapper push to github in the background after ikiwiki runs. --- IkiWiki.pm | 7 +++++++ IkiWiki/Plugin/git.pm | 8 ++++++++ IkiWiki/Wrapper.pm | 52 ++++++++++++++++++++++++++++++++++++++++++++------- debian/changelog | 3 +++ 4 files changed, 63 insertions(+), 7 deletions(-) (limited to 'IkiWiki/Wrapper.pm') diff --git a/IkiWiki.pm b/IkiWiki.pm index 35b38df46..701f7137d 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -441,6 +441,13 @@ sub getsetup () { safe => 0, rebuild => 0, }, + wrapper_background_command => { + type => "internal", + default => '', + description => "background shell command to run", + safe => 0, + rebuild => 0, + }, gettime => { type => "internal", description => "running in gettime mode", diff --git a/IkiWiki/Plugin/git.pm b/IkiWiki/Plugin/git.pm index 992c6226b..0f92476c9 100644 --- a/IkiWiki/Plugin/git.pm +++ b/IkiWiki/Plugin/git.pm @@ -41,6 +41,7 @@ sub checkconfig () { push @{$config{wrappers}}, { wrapper => $config{git_wrapper}, wrappermode => (defined $config{git_wrappermode} ? $config{git_wrappermode} : "06755"), + wrapper_background_command => $config{git_wrapper_background_command}, }; } @@ -78,6 +79,13 @@ sub getsetup () { safe => 0, # file rebuild => 0, }, + git_wrapper_background_command => { + type => "string", + example => "git push github", + description => "shell command for git_wrapper to run, in the background", + safe => 0, # command + rebuild => 0, + }, git_wrappermode => { type => "string", example => '06755', diff --git a/IkiWiki/Wrapper.pm b/IkiWiki/Wrapper.pm index 73f0896e8..bd134c9a3 100644 --- a/IkiWiki/Wrapper.pm +++ b/IkiWiki/Wrapper.pm @@ -73,17 +73,23 @@ EOF # otherwise. The fd of the lock is stored in # IKIWIKI_CGILOCK_FD so unlockwiki can close it. $pre_exec=<<"EOF"; - { - int fd=open("$config{wikistatedir}/cgilock", O_CREAT | O_RDWR, 0666); - if (fd != -1 && flock(fd, LOCK_EX) == 0) { - char *fd_s=malloc(8); - sprintf(fd_s, "%i", fd); - setenv("IKIWIKI_CGILOCK_FD", fd_s, 1); - } + lockfd=open("$config{wikistatedir}/cgilock", O_CREAT | O_RDWR, 0666); + if (lockfd != -1 && flock(lockfd, LOCK_EX) == 0) { + char *fd_s=malloc(8); + sprintf(fd_s, "%i", lockfd); + setenv("IKIWIKI_CGILOCK_FD", fd_s, 1); } EOF } + my $set_background_command=''; + if (defined $config{wrapper_background_command} && + length $config{wrapper_background_command}) { + my $background_command=delete $config{wrapper_background_command}; + $set_background_command=~s/"/\\"/g; + $set_background_command='#define BACKGROUND_COMMAND "'.$background_command.'"'; + } + $Data::Dumper::Indent=0; # no newlines my $configstring=Data::Dumper->Dump([\%config], ['*config']); $configstring=~s/\\/\\\\/g; @@ -114,6 +120,7 @@ void addenv(char *var, char *val) { } int main (int argc, char **argv) { + int lockfd=-1; char *s; $check_commit_hook @@ -147,9 +154,40 @@ $envsave } $pre_exec + +$set_background_command +#ifdef BACKGROUND_COMMAND + if (lockfd != -1) { + close(lockfd); + } + + pid_t pid=fork(); + if (pid == -1) { + perror("fork"); + exit(1); + } + else if (pid == 0) { + execl("$this", "$this", NULL); + perror("exec $this"); + exit(1); + } + else { + waitpid(pid, NULL, 0); + + if (daemon(1, 0) == 0) { + system(BACKGROUND_COMMAND); + exit(0); + } + else { + perror("daemon"); + exit(1); + } + } +#else execl("$this", "$this", NULL); perror("exec $this"); exit(1); +#endif } EOF diff --git a/debian/changelog b/debian/changelog index 4ce720ab6..7d857d9c0 100644 --- a/debian/changelog +++ b/debian/changelog @@ -17,6 +17,9 @@ ikiwiki (3.20100624) UNRELEASED; urgency=low * Use comment template on comments page of example blog. * comment.tmpl: Fix up display when inline uses it to display a non-comment page. (Such as a discussion page.) + * git: Added git_wrapper_background_command option. Can be used to eg, + make the git wrapper push to github in the background after ikiwiki + runs. -- Joey Hess Wed, 23 Jun 2010 15:30:04 -0400 -- cgit v1.2.3 From 0aa621a833930795fd10c5a701b33b6a1705d03f Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 24 Jul 2010 17:33:59 -0400 Subject: move wrapper building loop into Wrapper.pm --- IkiWiki/Wrapper.pm | 20 ++++++++++++++++++++ ikiwiki.in | 18 +----------------- 2 files changed, 21 insertions(+), 17 deletions(-) (limited to 'IkiWiki/Wrapper.pm') diff --git a/IkiWiki/Wrapper.pm b/IkiWiki/Wrapper.pm index bd134c9a3..927368fae 100644 --- a/IkiWiki/Wrapper.pm +++ b/IkiWiki/Wrapper.pm @@ -8,6 +8,26 @@ use File::Spec; use Data::Dumper; use IkiWiki; +sub gen_wrappers () { + debug(gettext("generating wrappers..")); + my %origconfig=(%config); + foreach my $wrapper (@{$config{wrappers}}) { + %config=(%origconfig, %{$wrapper}); + $config{verbose}=$config{setupverbose} + if exists $config{setupverbose}; + $config{syslog}=$config{setupsyslog} + if exists $config{setupsyslog}; + delete @config{qw(setupsyslog setupverbose wrappers genwrappers rebuild)}; + checkconfig(); + if (! $config{cgi} && ! $config{post_commit} && + ! $config{test_receive}) { + $config{post_commit}=1; + } + gen_wrapper(); + } + %config=(%origconfig); +} + sub gen_wrapper () { $config{srcdir}=File::Spec->rel2abs($config{srcdir}); $config{destdir}=File::Spec->rel2abs($config{destdir}); diff --git a/ikiwiki.in b/ikiwiki.in index aa3337938..bcda2469b 100755 --- a/ikiwiki.in +++ b/ikiwiki.in @@ -163,24 +163,8 @@ sub main () { ! $config{clean} && ((! $config{refresh} && ! $config{post_commit}) || $config{genwrappers})) { - debug(gettext("generating wrappers..")); require IkiWiki::Wrapper; - my %origconfig=(%config); - foreach my $wrapper (@{$config{wrappers}}) { - %config=(%origconfig, %{$wrapper}); - $config{verbose}=$config{setupverbose} - if exists $config{setupverbose}; - $config{syslog}=$config{setupsyslog} - if exists $config{setupsyslog}; - delete @config{qw(setupsyslog setupverbose wrappers genwrappers rebuild)}; - checkconfig(); - if (! $config{cgi} && ! $config{post_commit} && - ! $config{test_receive}) { - $config{post_commit}=1; - } - gen_wrapper(); - } - %config=(%origconfig); + gen_wrappers(); } # setup implies a wiki rebuild by default -- cgit v1.2.3