+ 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 && 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.'"';
+ }