* [0/2 PATCH] FastCGI and nginx support for gitweb
@ 2007-01-04 7:48 Eric Wong
2007-01-04 7:49 ` [PATCH 1/2] gitweb: add a simple wrapper for FCGI support Eric Wong
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Eric Wong @ 2007-01-04 7:48 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
I was looking at nginx for another project and got sidetracked
into writing instaweb support for it; so I ended up writing a
simple FCGI wrapper for gitweb as well.
---
.gitignore | 1 +
Makefile | 11 ++++++-
git-instaweb.sh | 72 ++++++++++++++++++++++++++++++++++++++++++++++-
gitweb/gitweb-fcgi.perl | 51 +++++++++++++++++++++++++++++++++
gitweb/gitweb.perl | 1 +
5 files changed, 134 insertions(+), 2 deletions(-)
--
Eric Wong
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/2] gitweb: add a simple wrapper for FCGI support
2007-01-04 7:48 [0/2 PATCH] FastCGI and nginx support for gitweb Eric Wong
@ 2007-01-04 7:49 ` Eric Wong
2007-01-09 12:28 ` Sam Vilain
2007-01-04 7:49 ` [PATCH 2/2] instaweb: add support for nginx + FastCGI Eric Wong
2007-01-04 8:56 ` [0/2 PATCH] FastCGI and nginx support for gitweb Jakub Narebski
2 siblings, 1 reply; 7+ messages in thread
From: Eric Wong @ 2007-01-04 7:49 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, Eric Wong
The FCGI wrapper is designed to be spawned from the
command-line, and can be backgrounded there. No
FCGI-specific spawners are necessary.
Since we re-eval gitweb.cgi on every request, I've
quieted warnings for redefined functions.
Signed-off-by: Eric Wong <normalperson@yhbt.net>
---
.gitignore | 1 +
Makefile | 6 +++++
gitweb/gitweb-fcgi.perl | 51 +++++++++++++++++++++++++++++++++++++++++++++++
gitweb/gitweb.perl | 1 +
4 files changed, 59 insertions(+), 0 deletions(-)
diff --git a/.gitignore b/.gitignore
index 2904f12..700ac4f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -137,6 +137,7 @@ git-whatchanged
git-write-tree
git-core-*/?*
gitweb/gitweb.cgi
+gitweb/gitweb.fcgi
test-date
test-delta
test-dump-cache-tree
diff --git a/Makefile b/Makefile
index fa1a022..3e94def 100644
--- a/Makefile
+++ b/Makefile
@@ -684,6 +684,12 @@ gitweb/gitweb.cgi: gitweb/gitweb.perl
chmod +x $@+
mv $@+ $@
+gitweb/gitweb.fcgi: gitweb/gitweb-fcgi.perl
+ rm -f $@ $@+
+ sed -e '1s|#!.*perl|#!$(PERL_PATH_SQ)|' $< >$@+
+ chmod +x $@+
+ mv $@+ $@
+
git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/gitweb.css
rm -f $@ $@+
sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
diff --git a/gitweb/gitweb-fcgi.perl b/gitweb/gitweb-fcgi.perl
new file mode 100644
index 0000000..2b7d5bf
--- /dev/null
+++ b/gitweb/gitweb-fcgi.perl
@@ -0,0 +1,51 @@
+#!/usr/bin/perl -w
+use strict;
+use FCGI;
+use CGI;
+use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev/;
+
+sub usage {
+ print STDERR "$0 --fcgi-socket=(path|[host]:port) ",
+ "--cgi-bin=path\n";
+ exit 1;
+}
+
+my ($fcgi_sock, $cgi_bin);
+GetOptions('fcgi-socket|s=s' => \$fcgi_sock,
+ 'cgi-bin|c=s' => \$cgi_bin) or usage();
+
+usage() unless ($fcgi_sock && $cgi_bin);
+
+die "FastCGI socket: $fcgi_sock already exists!\n" if (-S $fcgi_sock);
+die "CGI executable: $cgi_bin does not exist!\n" if (!-f $cgi_bin);
+
+# gitweb will exit, make it throw an exception instead:
+no warnings qw/once/;
+*CORE::GLOBAL::exit = sub { die 'gitweb_exit' };
+use warnings;
+
+# FCGI will erase the current %ENV; so make sure we save this:
+my $gwcfg = $ENV{GITWEB_CONFIG};
+
+my $fcgi_req = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV,
+ FCGI::OpenSocket($fcgi_sock, 128),
+ FCGI::FAIL_ACCEPT_ON_INTR);
+while ($fcgi_req->Accept >= 0) {
+ unless ($ENV{PATH_INFO}) {
+ # nginx currently fails to set PATH_INFO,
+ # so we'll do it ourselves
+ my $pi = $ENV{SCRIPT_NAME};
+ $pi =~ s!^/\+!!;
+ $ENV{PATH_INFO} = $pi;
+ }
+ # clear CGI query parameters set inside gitweb so we can reparse
+ # the %ENV fed to us
+ CGI::initialize_globals();
+ $ENV{GITWEB_CONFIG} = $gwcfg if defined $gwcfg;
+ do $cgi_bin;
+ delete $ENV{PATH_INFO};
+}
+
+END {
+ unlink $fcgi_sock if (defined $fcgi_sock && -S $fcgi_sock);
+}
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 2179054..4a9189b 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -9,6 +9,7 @@
use strict;
use warnings;
+no warnings qw(redefine); # for FCGI
use CGI qw(:standard :escapeHTML -nosticky);
use CGI::Util qw(unescape);
use CGI::Carp qw(fatalsToBrowser);
--
1.5.0.rc0.gcafca-dirty
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/2] instaweb: add support for nginx + FastCGI
2007-01-04 7:48 [0/2 PATCH] FastCGI and nginx support for gitweb Eric Wong
2007-01-04 7:49 ` [PATCH 1/2] gitweb: add a simple wrapper for FCGI support Eric Wong
@ 2007-01-04 7:49 ` Eric Wong
2007-01-07 2:18 ` [PATCH 2/2 (fixed)] " Eric Wong
2007-01-04 8:56 ` [0/2 PATCH] FastCGI and nginx support for gitweb Jakub Narebski
2 siblings, 1 reply; 7+ messages in thread
From: Eric Wong @ 2007-01-04 7:49 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, Eric Wong
nginx does not support regular CGI
Signed-off-by: Eric Wong <normalperson@yhbt.net>
---
Makefile | 5 +++-
git-instaweb.sh | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 75 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile
index 3e94def..893c7f2 100644
--- a/Makefile
+++ b/Makefile
@@ -690,7 +690,8 @@ gitweb/gitweb.fcgi: gitweb/gitweb-fcgi.perl
chmod +x $@+
mv $@+ $@
-git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/gitweb.css
+git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/gitweb.css \
+ gitweb/gitweb.fcgi
rm -f $@ $@+
sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
-e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
@@ -699,6 +700,8 @@ git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/gitweb.css
-e '/@@GITWEB_CGI@@/d' \
-e '/@@GITWEB_CSS@@/r gitweb/gitweb.css' \
-e '/@@GITWEB_CSS@@/d' \
+ -e '/@@GITWEB_FCGI@@/r gitweb/gitweb.fcgi' \
+ -e '/@@GITWEB_FCGI@@/d' \
$@.sh > $@+
chmod +x $@+
mv $@+ $@
diff --git a/git-instaweb.sh b/git-instaweb.sh
index 08362f4..dcd04fd 100755
--- a/git-instaweb.sh
+++ b/git-instaweb.sh
@@ -20,7 +20,7 @@ httpd="`git repo-config --get instaweb.httpd`"
browser="`git repo-config --get instaweb.browser`"
port=`git repo-config --get instaweb.port`
module_path="`git repo-config --get instaweb.modulepath`"
-
+fcgi_pid_file="$fqgitdir"/gitweb/fcgi.pid
conf=$GIT_DIR/gitweb/httpd.conf
# Defaults:
@@ -34,7 +34,22 @@ test -z "$browser" && browser='firefox'
# any untaken local port will do...
test -z "$port" && port=1234
+use_fcgi () {
+ case "$httpd" in
+ *nginx*)
+ return 0
+ ;;
+ esac
+ return -1
+}
+
start_httpd () {
+ if use_fcgi; then
+ "$fqgitdir"/gitweb/gitweb.fcgi \
+ --fcgi-socket="$fcgi_sock" \
+ --cgi-bin="$fqgitdir/gitweb/gitweb.cgi" &
+ echo $! > "$fcgi_pid_file"
+ fi
httpd_only="`echo $httpd | cut -f1 -d' '`"
if test "`expr index $httpd_only /`" -eq '1' || \
which $httpd_only >/dev/null
@@ -61,6 +76,9 @@ start_httpd () {
}
stop_httpd () {
+ if use_fcgi; then
+ test -f "$fcgi_pid_file" && kill `cat "$fcgi_pid_file"`
+ fi
test -f "$fqgitdir/pid" && kill `cat "$fqgitdir/pid"`
}
@@ -138,7 +156,48 @@ mkdir -p "$GIT_DIR/gitweb/tmp"
GIT_EXEC_PATH="`git --exec-path`"
GIT_DIR="$fqgitdir"
export GIT_EXEC_PATH GIT_DIR
+fcgi_sock="$fqgitdir/gitweb/fcgi.sock"
+nginx_conf () {
+ mkdir -p "$fqgitdir"/gitweb/logs
+ cat > "$conf" <<EOF
+pid $fqgitdir/pid;
+error_log $fqgitdir/gitweb/logs/error.log;
+events {
+ worker_connections 1024;
+}
+http {
+ access_log $fqgitdir/gitweb/logs/access.log;
+ types {
+ text/css css;
+ }
+ server {
+ listen $port;
+ root $fqgitdir/gitweb;
+ location = / {
+ fastcgi_pass unix:$fcgi_sock;
+ fastcgi_index gitweb.fcgi;
+ fastcgi_param QUERY_STRING \$query_string;
+ fastcgi_param REQUEST_METHOD \$request_method;
+ fastcgi_param CONTENT_TYPE \$content_type;
+ fastcgi_param CONTENT_LENGTH \$content_length;
+ fastcgi_param SCRIPT_NAME \$fastcgi_script_name;
+ fastcgi_param REQUEST_URI \$request_uri;
+ fastcgi_param DOCUMENT_URI \$document_uri;
+ fastcgi_param DOCUMENT_ROOT \$document_root;
+ fastcgi_param SERVER_PROTOCOL \$server_protocol;
+ fastcgi_param GATEWAY_INTERFACE CGI/1.1;
+ fastcgi_param SERVER_SOFTWARE nginx;
+ fastcgi_param REMOTE_ADDR \$remote_addr;
+ fastcgi_param REMOTE_PORT \$remote_port;
+ fastcgi_param SERVER_ADDR \$server_addr;
+ fastcgi_param SERVER_PORT \$server_port;
+ fastcgi_param SERVER_NAME \$server_name;
+ }
+ }
+}
+EOF
+}
lighttpd_conf () {
cat > "$conf" <<EOF
@@ -230,8 +289,16 @@ gitweb_css () {
EOFGITWEB
}
+gitweb_fcgi () {
+ cat > "$1" <<\EOFGITWEB
+@@GITWEB_FCGI@@
+EOFGITWEB
+ chmod +x "$1"
+}
+
gitweb_cgi $GIT_DIR/gitweb/gitweb.cgi
gitweb_css $GIT_DIR/gitweb/gitweb.css
+gitweb_fcgi $GIT_DIR/gitweb/gitweb.fcgi
case "$httpd" in
*lighttpd*)
@@ -240,6 +307,9 @@ case "$httpd" in
*apache2*)
apache2_conf
;;
+*nginx*)
+ nginx_conf
+ ;;
*)
echo "Unknown httpd specified: $httpd"
exit 1
--
1.5.0.rc0.gcafca-dirty
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [0/2 PATCH] FastCGI and nginx support for gitweb
2007-01-04 7:48 [0/2 PATCH] FastCGI and nginx support for gitweb Eric Wong
2007-01-04 7:49 ` [PATCH 1/2] gitweb: add a simple wrapper for FCGI support Eric Wong
2007-01-04 7:49 ` [PATCH 2/2] instaweb: add support for nginx + FastCGI Eric Wong
@ 2007-01-04 8:56 ` Jakub Narebski
2007-01-04 9:25 ` Eric Wong
2 siblings, 1 reply; 7+ messages in thread
From: Jakub Narebski @ 2007-01-04 8:56 UTC (permalink / raw)
To: git
Eric Wong wrote:
> I was looking at nginx for another project and got sidetracked
> into writing instaweb support for it; so I ended up writing a
> simple FCGI wrapper for gitweb as well.
FCGI, not CGI::Fast?
--
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [0/2 PATCH] FastCGI and nginx support for gitweb
2007-01-04 8:56 ` [0/2 PATCH] FastCGI and nginx support for gitweb Jakub Narebski
@ 2007-01-04 9:25 ` Eric Wong
0 siblings, 0 replies; 7+ messages in thread
From: Eric Wong @ 2007-01-04 9:25 UTC (permalink / raw)
To: Jakub Narebski; +Cc: git
Jakub Narebski <jnareb@gmail.com> wrote:
> Eric Wong wrote:
>
> > I was looking at nginx for another project and got sidetracked
> > into writing instaweb support for it; so I ended up writing a
> > simple FCGI wrapper for gitweb as well.
>
> FCGI, not CGI::Fast?
CGI::Fast is just a wrapper on top of FCGI but gives access to functions
in the CGI module. We already use the CGI module explicitly in gitweb;
and I didn't want to make deeper changes in gitweb nor introduce extra
dependencies.
--
Eric Wong
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/2 (fixed)] instaweb: add support for nginx + FastCGI
2007-01-04 7:49 ` [PATCH 2/2] instaweb: add support for nginx + FastCGI Eric Wong
@ 2007-01-07 2:18 ` Eric Wong
0 siblings, 0 replies; 7+ messages in thread
From: Eric Wong @ 2007-01-07 2:18 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
nginx does not support regular CGI
Signed-off-by: Eric Wong <normalperson@yhbt.net>
---
Oops, the original patch returned -1 in use_fcgi() instead of 1,
which shells don't like :x
Makefile | 5 +++-
git-instaweb.sh | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 75 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile
index 2b33a2a..05848f1 100644
--- a/Makefile
+++ b/Makefile
@@ -690,7 +690,8 @@ gitweb/gitweb.fcgi: gitweb/gitweb-fcgi.perl
chmod +x $@+
mv $@+ $@
-git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/gitweb.css
+git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/gitweb.css \
+ gitweb/gitweb.fcgi
rm -f $@ $@+
sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
-e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
@@ -699,6 +700,8 @@ git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/gitweb.css
-e '/@@GITWEB_CGI@@/d' \
-e '/@@GITWEB_CSS@@/r gitweb/gitweb.css' \
-e '/@@GITWEB_CSS@@/d' \
+ -e '/@@GITWEB_FCGI@@/r gitweb/gitweb.fcgi' \
+ -e '/@@GITWEB_FCGI@@/d' \
$@.sh > $@+
chmod +x $@+
mv $@+ $@
diff --git a/git-instaweb.sh b/git-instaweb.sh
index 08362f4..d712c0c 100755
--- a/git-instaweb.sh
+++ b/git-instaweb.sh
@@ -20,7 +20,7 @@ httpd="`git repo-config --get instaweb.httpd`"
browser="`git repo-config --get instaweb.browser`"
port=`git repo-config --get instaweb.port`
module_path="`git repo-config --get instaweb.modulepath`"
-
+fcgi_pid_file="$fqgitdir"/gitweb/fcgi.pid
conf=$GIT_DIR/gitweb/httpd.conf
# Defaults:
@@ -34,7 +34,22 @@ test -z "$browser" && browser='firefox'
# any untaken local port will do...
test -z "$port" && port=1234
+use_fcgi () {
+ case "$httpd" in
+ *nginx*)
+ return 0
+ ;;
+ esac
+ return 1
+}
+
start_httpd () {
+ if use_fcgi; then
+ "$fqgitdir"/gitweb/gitweb.fcgi \
+ --fcgi-socket="$fcgi_sock" \
+ --cgi-bin="$fqgitdir/gitweb/gitweb.cgi" &
+ echo $! > "$fcgi_pid_file"
+ fi
httpd_only="`echo $httpd | cut -f1 -d' '`"
if test "`expr index $httpd_only /`" -eq '1' || \
which $httpd_only >/dev/null
@@ -61,6 +76,9 @@ start_httpd () {
}
stop_httpd () {
+ if use_fcgi; then
+ test -f "$fcgi_pid_file" && kill `cat "$fcgi_pid_file"`
+ fi
test -f "$fqgitdir/pid" && kill `cat "$fqgitdir/pid"`
}
@@ -138,7 +156,48 @@ mkdir -p "$GIT_DIR/gitweb/tmp"
GIT_EXEC_PATH="`git --exec-path`"
GIT_DIR="$fqgitdir"
export GIT_EXEC_PATH GIT_DIR
+fcgi_sock="$fqgitdir/gitweb/fcgi.sock"
+nginx_conf () {
+ mkdir -p "$fqgitdir"/gitweb/logs
+ cat > "$conf" <<EOF
+pid $fqgitdir/pid;
+error_log $fqgitdir/gitweb/logs/error.log;
+events {
+ worker_connections 1024;
+}
+http {
+ access_log $fqgitdir/gitweb/logs/access.log;
+ types {
+ text/css css;
+ }
+ server {
+ listen $port;
+ root $fqgitdir/gitweb;
+ location = / {
+ fastcgi_pass unix:$fcgi_sock;
+ fastcgi_index gitweb.fcgi;
+ fastcgi_param QUERY_STRING \$query_string;
+ fastcgi_param REQUEST_METHOD \$request_method;
+ fastcgi_param CONTENT_TYPE \$content_type;
+ fastcgi_param CONTENT_LENGTH \$content_length;
+ fastcgi_param SCRIPT_NAME \$fastcgi_script_name;
+ fastcgi_param REQUEST_URI \$request_uri;
+ fastcgi_param DOCUMENT_URI \$document_uri;
+ fastcgi_param DOCUMENT_ROOT \$document_root;
+ fastcgi_param SERVER_PROTOCOL \$server_protocol;
+ fastcgi_param GATEWAY_INTERFACE CGI/1.1;
+ fastcgi_param SERVER_SOFTWARE nginx;
+ fastcgi_param REMOTE_ADDR \$remote_addr;
+ fastcgi_param REMOTE_PORT \$remote_port;
+ fastcgi_param SERVER_ADDR \$server_addr;
+ fastcgi_param SERVER_PORT \$server_port;
+ fastcgi_param SERVER_NAME \$server_name;
+ }
+ }
+}
+EOF
+}
lighttpd_conf () {
cat > "$conf" <<EOF
@@ -230,8 +289,16 @@ gitweb_css () {
EOFGITWEB
}
+gitweb_fcgi () {
+ cat > "$1" <<\EOFGITWEB
+@@GITWEB_FCGI@@
+EOFGITWEB
+ chmod +x "$1"
+}
+
gitweb_cgi $GIT_DIR/gitweb/gitweb.cgi
gitweb_css $GIT_DIR/gitweb/gitweb.css
+gitweb_fcgi $GIT_DIR/gitweb/gitweb.fcgi
case "$httpd" in
*lighttpd*)
@@ -240,6 +307,9 @@ case "$httpd" in
*apache2*)
apache2_conf
;;
+*nginx*)
+ nginx_conf
+ ;;
*)
echo "Unknown httpd specified: $httpd"
exit 1
--
1.5.0.rc0.gc26c8
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] gitweb: add a simple wrapper for FCGI support
2007-01-04 7:49 ` [PATCH 1/2] gitweb: add a simple wrapper for FCGI support Eric Wong
@ 2007-01-09 12:28 ` Sam Vilain
0 siblings, 0 replies; 7+ messages in thread
From: Sam Vilain @ 2007-01-09 12:28 UTC (permalink / raw)
To: Eric Wong; +Cc: git
Eric Wong wrote:
> The FCGI wrapper is designed to be spawned from the
> command-line, and can be backgrounded there. No
> FCGI-specific spawners are necessary.
>
> Since we re-eval gitweb.cgi on every request, I've
> quieted warnings for redefined functions.
>
I never did submit this; perhaps I should've...
http://utsl.gen.nz/gitweb/?p=gitweb;a=commitdiff;h=56d7d436;hp=2326acfa
Sam.
> Signed-off-by: Eric Wong <normalperson@yhbt.net>
> ---
> .gitignore | 1 +
> Makefile | 6 +++++
> gitweb/gitweb-fcgi.perl | 51 +++++++++++++++++++++++++++++++++++++++++++++++
> gitweb/gitweb.perl | 1 +
> 4 files changed, 59 insertions(+), 0 deletions(-)
>
> diff --git a/.gitignore b/.gitignore
> index 2904f12..700ac4f 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -137,6 +137,7 @@ git-whatchanged
> git-write-tree
> git-core-*/?*
> gitweb/gitweb.cgi
> +gitweb/gitweb.fcgi
> test-date
> test-delta
> test-dump-cache-tree
> diff --git a/Makefile b/Makefile
> index fa1a022..3e94def 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -684,6 +684,12 @@ gitweb/gitweb.cgi: gitweb/gitweb.perl
> chmod +x $@+
> mv $@+ $@
>
> +gitweb/gitweb.fcgi: gitweb/gitweb-fcgi.perl
> + rm -f $@ $@+
> + sed -e '1s|#!.*perl|#!$(PERL_PATH_SQ)|' $< >$@+
> + chmod +x $@+
> + mv $@+ $@
> +
> git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/gitweb.css
> rm -f $@ $@+
> sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
> diff --git a/gitweb/gitweb-fcgi.perl b/gitweb/gitweb-fcgi.perl
> new file mode 100644
> index 0000000..2b7d5bf
> --- /dev/null
> +++ b/gitweb/gitweb-fcgi.perl
> @@ -0,0 +1,51 @@
> +#!/usr/bin/perl -w
> +use strict;
> +use FCGI;
> +use CGI;
> +use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev/;
> +
> +sub usage {
> + print STDERR "$0 --fcgi-socket=(path|[host]:port) ",
> + "--cgi-bin=path\n";
> + exit 1;
> +}
> +
> +my ($fcgi_sock, $cgi_bin);
> +GetOptions('fcgi-socket|s=s' => \$fcgi_sock,
> + 'cgi-bin|c=s' => \$cgi_bin) or usage();
> +
> +usage() unless ($fcgi_sock && $cgi_bin);
> +
> +die "FastCGI socket: $fcgi_sock already exists!\n" if (-S $fcgi_sock);
> +die "CGI executable: $cgi_bin does not exist!\n" if (!-f $cgi_bin);
> +
> +# gitweb will exit, make it throw an exception instead:
> +no warnings qw/once/;
> +*CORE::GLOBAL::exit = sub { die 'gitweb_exit' };
> +use warnings;
> +
> +# FCGI will erase the current %ENV; so make sure we save this:
> +my $gwcfg = $ENV{GITWEB_CONFIG};
> +
> +my $fcgi_req = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV,
> + FCGI::OpenSocket($fcgi_sock, 128),
> + FCGI::FAIL_ACCEPT_ON_INTR);
> +while ($fcgi_req->Accept >= 0) {
> + unless ($ENV{PATH_INFO}) {
> + # nginx currently fails to set PATH_INFO,
> + # so we'll do it ourselves
> + my $pi = $ENV{SCRIPT_NAME};
> + $pi =~ s!^/\+!!;
> + $ENV{PATH_INFO} = $pi;
> + }
> + # clear CGI query parameters set inside gitweb so we can reparse
> + # the %ENV fed to us
> + CGI::initialize_globals();
> + $ENV{GITWEB_CONFIG} = $gwcfg if defined $gwcfg;
> + do $cgi_bin;
> + delete $ENV{PATH_INFO};
> +}
> +
> +END {
> + unlink $fcgi_sock if (defined $fcgi_sock && -S $fcgi_sock);
> +}
> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
> index 2179054..4a9189b 100755
> --- a/gitweb/gitweb.perl
> +++ b/gitweb/gitweb.perl
> @@ -9,6 +9,7 @@
>
> use strict;
> use warnings;
> +no warnings qw(redefine); # for FCGI
> use CGI qw(:standard :escapeHTML -nosticky);
> use CGI::Util qw(unescape);
> use CGI::Carp qw(fatalsToBrowser);
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2007-01-09 12:29 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-01-04 7:48 [0/2 PATCH] FastCGI and nginx support for gitweb Eric Wong
2007-01-04 7:49 ` [PATCH 1/2] gitweb: add a simple wrapper for FCGI support Eric Wong
2007-01-09 12:28 ` Sam Vilain
2007-01-04 7:49 ` [PATCH 2/2] instaweb: add support for nginx + FastCGI Eric Wong
2007-01-07 2:18 ` [PATCH 2/2 (fixed)] " Eric Wong
2007-01-04 8:56 ` [0/2 PATCH] FastCGI and nginx support for gitweb Jakub Narebski
2007-01-04 9:25 ` Eric Wong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).