+ my @wrapper_hooks;
+ run_hooks(genwrapper => sub { push @wrapper_hooks, shift->() });
+
+ my $check_commit_hook="";
+ my $pre_exec="";
+ if ($config{post_commit}) {
+ # Optimise checking !commit_hook_enabled() ,
+ # so that ikiwiki does not have to be started if the
+ # hook is disabled.
+ #
+ # Note that perl's flock may be implemented using fcntl
+ # or lockf on some systems. If so, and if there is no
+ # interop between the locking systems, the true C flock will
+ # always succeed, and this optimisation won't work.
+ # The perl code will later correctly check the lock,
+ # so the right thing will still happen, though without
+ # the benefit of this optimisation.
+ $check_commit_hook=<<"EOF";
+ {
+ int fd=open("$config{wikistatedir}/commitlock", O_CREAT | O_RDWR, 0666);
+ if (fd != -1) {
+ if (flock(fd, LOCK_SH | LOCK_NB) != 0)
+ exit(0);
+ close(fd);
+ }
+ }
+EOF
+ }
+ elsif ($config{cgi}) {
+ # Avoid more than one ikiwiki cgi running at a time by
+ # taking a cgi lock. Since ikiwiki uses several MB of
+ # memory, a pile up of processes could cause thrashing
+ # otherwise. The fd of the lock is stored in
+ # IKIWIKI_CGILOCK_FD so unlockwiki can close it.
+ $pre_exec=<<"EOF";
+ lockfd=open("$config{wikistatedir}/cgilock", O_CREAT | O_RDWR, 0666);
+ if (lockfd != -1 && lockf(lockfd, F_LOCK, 0) == 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.'"';
+ }
+