{"thread":{"id":"6216","subject":"[0/2 PATCH] FastCGI and nginx support for gitweb","startedAt":"2007-01-04T07:48:31Z","lastAt":"2007-01-09T12:28:50Z","messageCount":7,"participants":["Eric Wong","Jakub Narebski","Sam Vilain"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"30802","messageId":"11678969111362-git-send-email-normalperson@yhbt.net","threadId":"6216","inReplyTo":null,"subject":"[0/2 PATCH] FastCGI and nginx support for gitweb","fromName":"Eric Wong","fromEmail":"normalperson@yhbt.net","sentAt":"2007-01-04T07:48:31Z","receivedAt":"2007-01-04T07:48:31Z","isPatch":true,"sender":{"key":"e@80x24.org","avatar":null},"body":"I was looking at nginx for another project and got sidetracked\ninto writing instaweb support for it; so I ended up writing a\nsimple FCGI wrapper for gitweb as well.\n\n---\n .gitignore              |    1 +\n Makefile                |   11 ++++++-\n git-instaweb.sh         |   72 ++++++++++++++++++++++++++++++++++++++++++++++-\n gitweb/gitweb-fcgi.perl |   51 +++++++++++++++++++++++++++++++++\n gitweb/gitweb.perl      |    1 +\n 5 files changed, 134 insertions(+), 2 deletions(-)\n\n-- \nEric Wong\n"},{"id":"30803","messageId":"11678969781711-git-send-email-normalperson@yhbt.net","threadId":"6216","inReplyTo":"11678969111362-git-send-email-normalperson@yhbt.net","subject":"[PATCH 1/2] gitweb: add a simple wrapper for FCGI support","fromName":"Eric Wong","fromEmail":"normalperson@yhbt.net","sentAt":"2007-01-04T07:49:37Z","receivedAt":"2007-01-04T07:49:37Z","isPatch":true,"sender":{"key":"e@80x24.org","avatar":null},"body":"The FCGI wrapper is designed to be spawned from the\ncommand-line, and can be backgrounded there.  No\nFCGI-specific spawners are necessary.\n\nSince we re-eval gitweb.cgi on every request, I've\nquieted warnings for redefined functions.\n\nSigned-off-by: Eric Wong <normalperson@yhbt.net>\n---\n .gitignore              |    1 +\n Makefile                |    6 +++++\n gitweb/gitweb-fcgi.perl |   51 +++++++++++++++++++++++++++++++++++++++++++++++\n gitweb/gitweb.perl      |    1 +\n 4 files changed, 59 insertions(+), 0 deletions(-)\n\ndiff --git a/.gitignore b/.gitignore\nindex 2904f12..700ac4f 100644\n--- a/.gitignore\n+++ b/.gitignore\n@@ -137,6 +137,7 @@ git-whatchanged\n git-write-tree\n git-core-*/?*\n gitweb/gitweb.cgi\n+gitweb/gitweb.fcgi\n test-date\n test-delta\n test-dump-cache-tree\ndiff --git a/Makefile b/Makefile\nindex fa1a022..3e94def 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -684,6 +684,12 @@ gitweb/gitweb.cgi: gitweb/gitweb.perl\n \tchmod +x $@+\n \tmv $@+ $@\n \n+gitweb/gitweb.fcgi: gitweb/gitweb-fcgi.perl\n+\trm -f $@ $@+\n+\tsed -e '1s|#!.*perl|#!$(PERL_PATH_SQ)|' $< >$@+\n+\tchmod +x $@+\n+\tmv $@+ $@\n+\n git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/gitweb.css\n \trm -f $@ $@+\n \tsed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \\\ndiff --git a/gitweb/gitweb-fcgi.perl b/gitweb/gitweb-fcgi.perl\nnew file mode 100644\nindex 0000000..2b7d5bf\n--- /dev/null\n+++ b/gitweb/gitweb-fcgi.perl\n@@ -0,0 +1,51 @@\n+#!/usr/bin/perl -w\n+use strict;\n+use FCGI;\n+use CGI;\n+use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev/;\n+\n+sub usage {\n+\tprint STDERR \"$0 --fcgi-socket=(path|[host]:port) \",\n+\t             \"--cgi-bin=path\\n\";\n+\texit 1;\n+}\n+\n+my ($fcgi_sock, $cgi_bin);\n+GetOptions('fcgi-socket|s=s' => \\$fcgi_sock,\n+           'cgi-bin|c=s' => \\$cgi_bin) or usage();\n+\n+usage() unless ($fcgi_sock && $cgi_bin);\n+\n+die \"FastCGI socket: $fcgi_sock already exists!\\n\" if (-S $fcgi_sock);\n+die \"CGI executable: $cgi_bin does not exist!\\n\" if (!-f $cgi_bin);\n+\n+# gitweb will exit, make it throw an exception instead:\n+no warnings qw/once/;\n+*CORE::GLOBAL::exit = sub { die 'gitweb_exit' };\n+use warnings;\n+\n+# FCGI will erase the current %ENV; so make sure we save this:\n+my $gwcfg = $ENV{GITWEB_CONFIG};\n+\n+my $fcgi_req = FCGI::Request(\\*STDIN, \\*STDOUT, \\*STDERR, \\%ENV,\n+                             FCGI::OpenSocket($fcgi_sock, 128),\n+                             FCGI::FAIL_ACCEPT_ON_INTR);\n+while ($fcgi_req->Accept >= 0) {\n+\tunless ($ENV{PATH_INFO}) {\n+\t\t# nginx currently fails to set PATH_INFO,\n+\t\t# so we'll do it ourselves\n+\t\tmy $pi = $ENV{SCRIPT_NAME};\n+\t\t$pi =~ s!^/\\+!!;\n+\t\t$ENV{PATH_INFO} = $pi;\n+\t}\n+\t# clear CGI query parameters set inside gitweb so we can reparse\n+\t# the %ENV fed to us\n+\tCGI::initialize_globals();\n+\t$ENV{GITWEB_CONFIG} = $gwcfg if defined $gwcfg;\n+\tdo $cgi_bin;\n+\tdelete $ENV{PATH_INFO};\n+}\n+\n+END {\n+\tunlink $fcgi_sock if (defined $fcgi_sock && -S $fcgi_sock);\n+}\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 2179054..4a9189b 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -9,6 +9,7 @@\n \n use strict;\n use warnings;\n+no warnings qw(redefine); # for FCGI\n use CGI qw(:standard :escapeHTML -nosticky);\n use CGI::Util qw(unescape);\n use CGI::Carp qw(fatalsToBrowser);\n-- \n1.5.0.rc0.gcafca-dirty\n"},{"id":"30804","messageId":"1167896979262-git-send-email-normalperson@yhbt.net","threadId":"6216","inReplyTo":"11678969111362-git-send-email-normalperson@yhbt.net","subject":"[PATCH 2/2] instaweb: add support for nginx + FastCGI","fromName":"Eric Wong","fromEmail":"normalperson@yhbt.net","sentAt":"2007-01-04T07:49:38Z","receivedAt":"2007-01-04T07:49:38Z","isPatch":true,"sender":{"key":"e@80x24.org","avatar":null},"body":"nginx does not support regular CGI\n\nSigned-off-by: Eric Wong <normalperson@yhbt.net>\n---\n Makefile        |    5 +++-\n git-instaweb.sh |   72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-\n 2 files changed, 75 insertions(+), 2 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 3e94def..893c7f2 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -690,7 +690,8 @@ gitweb/gitweb.fcgi: gitweb/gitweb-fcgi.perl\n \tchmod +x $@+\n \tmv $@+ $@\n \n-git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/gitweb.css\n+git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/gitweb.css \\\n+              gitweb/gitweb.fcgi\n \trm -f $@ $@+\n \tsed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \\\n \t    -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \\\n@@ -699,6 +700,8 @@ git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/gitweb.css\n \t    -e '/@@GITWEB_CGI@@/d' \\\n \t    -e '/@@GITWEB_CSS@@/r gitweb/gitweb.css' \\\n \t    -e '/@@GITWEB_CSS@@/d' \\\n+\t    -e '/@@GITWEB_FCGI@@/r gitweb/gitweb.fcgi' \\\n+\t    -e '/@@GITWEB_FCGI@@/d' \\\n \t    $@.sh > $@+\n \tchmod +x $@+\n \tmv $@+ $@\ndiff --git a/git-instaweb.sh b/git-instaweb.sh\nindex 08362f4..dcd04fd 100755\n--- a/git-instaweb.sh\n+++ b/git-instaweb.sh\n@@ -20,7 +20,7 @@ httpd=\"`git repo-config --get instaweb.httpd`\"\n browser=\"`git repo-config --get instaweb.browser`\"\n port=`git repo-config --get instaweb.port`\n module_path=\"`git repo-config --get instaweb.modulepath`\"\n-\n+fcgi_pid_file=\"$fqgitdir\"/gitweb/fcgi.pid\n conf=$GIT_DIR/gitweb/httpd.conf\n \n # Defaults:\n@@ -34,7 +34,22 @@ test -z \"$browser\" && browser='firefox'\n # any untaken local port will do...\n test -z \"$port\" && port=1234\n \n+use_fcgi () {\n+\tcase \"$httpd\" in\n+\t*nginx*)\n+\t\treturn 0\n+\t\t;;\n+\tesac\n+\treturn -1\n+}\n+\n start_httpd () {\n+\tif use_fcgi; then\n+\t\t\"$fqgitdir\"/gitweb/gitweb.fcgi \\\n+\t\t           --fcgi-socket=\"$fcgi_sock\" \\\n+\t\t\t   --cgi-bin=\"$fqgitdir/gitweb/gitweb.cgi\" &\n+\t\techo $! > \"$fcgi_pid_file\"\n+\tfi\n \thttpd_only=\"`echo $httpd | cut -f1 -d' '`\"\n \tif test \"`expr index $httpd_only /`\" -eq '1' || \\\n \t\t\t\twhich $httpd_only >/dev/null\n@@ -61,6 +76,9 @@ start_httpd () {\n }\n \n stop_httpd () {\n+\tif use_fcgi; then\n+\t\ttest -f \"$fcgi_pid_file\" && kill `cat \"$fcgi_pid_file\"`\n+\tfi\n \ttest -f \"$fqgitdir/pid\" && kill `cat \"$fqgitdir/pid\"`\n }\n \n@@ -138,7 +156,48 @@ mkdir -p \"$GIT_DIR/gitweb/tmp\"\n GIT_EXEC_PATH=\"`git --exec-path`\"\n GIT_DIR=\"$fqgitdir\"\n export GIT_EXEC_PATH GIT_DIR\n+fcgi_sock=\"$fqgitdir/gitweb/fcgi.sock\"\n \n+nginx_conf () {\n+\tmkdir -p \"$fqgitdir\"/gitweb/logs\n+\tcat > \"$conf\" <<EOF\n+pid $fqgitdir/pid;\n+error_log $fqgitdir/gitweb/logs/error.log;\n+events {\n+\tworker_connections 1024;\n+}\n+http {\n+\taccess_log $fqgitdir/gitweb/logs/access.log;\n+\ttypes {\n+\t\ttext/css css;\n+\t}\n+\tserver {\n+\t\tlisten $port;\n+\t\troot $fqgitdir/gitweb;\n+\t\tlocation = / {\n+\t\t\tfastcgi_pass unix:$fcgi_sock;\n+\t\t\tfastcgi_index gitweb.fcgi;\n+\t\t\tfastcgi_param QUERY_STRING \\$query_string;\n+\t\t\tfastcgi_param REQUEST_METHOD \\$request_method;\n+\t\t\tfastcgi_param CONTENT_TYPE \\$content_type;\n+\t\t\tfastcgi_param CONTENT_LENGTH \\$content_length;\n+\t\t\tfastcgi_param SCRIPT_NAME \\$fastcgi_script_name;\n+\t\t\tfastcgi_param REQUEST_URI \\$request_uri;\n+\t\t\tfastcgi_param DOCUMENT_URI \\$document_uri;\n+\t\t\tfastcgi_param DOCUMENT_ROOT \\$document_root;\n+\t\t\tfastcgi_param SERVER_PROTOCOL \\$server_protocol;\n+\t\t\tfastcgi_param GATEWAY_INTERFACE CGI/1.1;\n+\t\t\tfastcgi_param SERVER_SOFTWARE nginx;\n+\t\t\tfastcgi_param REMOTE_ADDR \\$remote_addr;\n+\t\t\tfastcgi_param REMOTE_PORT \\$remote_port;\n+\t\t\tfastcgi_param SERVER_ADDR \\$server_addr;\n+\t\t\tfastcgi_param SERVER_PORT \\$server_port;\n+\t\t\tfastcgi_param SERVER_NAME \\$server_name;\n+\t\t}\n+\t}\n+}\n+EOF\n+}\n \n lighttpd_conf () {\n \tcat > \"$conf\" <<EOF\n@@ -230,8 +289,16 @@ gitweb_css () {\n EOFGITWEB\n }\n \n+gitweb_fcgi () {\n+\tcat > \"$1\" <<\\EOFGITWEB\n+@@GITWEB_FCGI@@\n+EOFGITWEB\n+\tchmod +x \"$1\"\n+}\n+\n gitweb_cgi $GIT_DIR/gitweb/gitweb.cgi\n gitweb_css $GIT_DIR/gitweb/gitweb.css\n+gitweb_fcgi $GIT_DIR/gitweb/gitweb.fcgi\n \n case \"$httpd\" in\n *lighttpd*)\n@@ -240,6 +307,9 @@ case \"$httpd\" in\n *apache2*)\n \tapache2_conf\n \t;;\n+*nginx*)\n+\tnginx_conf\n+\t;;\n *)\n \techo \"Unknown httpd specified: $httpd\"\n \texit 1\n-- \n1.5.0.rc0.gcafca-dirty\n"},{"id":"30806","messageId":"enif9a$9ve$1@sea.gmane.org","threadId":"6216","inReplyTo":"11678969111362-git-send-email-normalperson@yhbt.net","subject":"Re: [0/2 PATCH] FastCGI and nginx support for gitweb","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2007-01-04T08:56:09Z","receivedAt":"2007-01-04T08:56:09Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Eric Wong wrote:\n\n> I was looking at nginx for another project and got sidetracked\n> into writing instaweb support for it; so I ended up writing a\n> simple FCGI wrapper for gitweb as well.\n\nFCGI, not CGI::Fast?\n-- \nJakub Narebski\nWarsaw, Poland\nShadeHawk on #git\n"},{"id":"30808","messageId":"20070104092559.GA17473@localdomain","threadId":"6216","inReplyTo":"enif9a$9ve$1@sea.gmane.org","subject":"Re: [0/2 PATCH] FastCGI and nginx support for gitweb","fromName":"Eric Wong","fromEmail":"normalperson@yhbt.net","sentAt":"2007-01-04T09:25:59Z","receivedAt":"2007-01-04T09:25:59Z","isPatch":true,"sender":{"key":"e@80x24.org","avatar":null},"body":"Jakub Narebski <jnareb@gmail.com> wrote:\n> Eric Wong wrote:\n> \n> > I was looking at nginx for another project and got sidetracked\n> > into writing instaweb support for it; so I ended up writing a\n> > simple FCGI wrapper for gitweb as well.\n> \n> FCGI, not CGI::Fast?\n\nCGI::Fast is just a wrapper on top of FCGI but gives access to functions\nin the CGI module.  We already use the CGI module explicitly in gitweb;\nand I didn't want to make deeper changes in gitweb nor introduce extra\ndependencies.\n\n-- \nEric Wong\n"},{"id":"31003","messageId":"20070107021814.GA21370@mayonaise.dyndns.org","threadId":"6216","inReplyTo":"1167896979262-git-send-email-normalperson@yhbt.net","subject":"[PATCH 2/2 (fixed)] instaweb: add support for nginx + FastCGI","fromName":"Eric Wong","fromEmail":"normalperson@yhbt.net","sentAt":"2007-01-07T02:18:14Z","receivedAt":"2007-01-07T02:18:14Z","isPatch":true,"sender":{"key":"e@80x24.org","avatar":null},"body":"nginx does not support regular CGI\n\nSigned-off-by: Eric Wong <normalperson@yhbt.net>\n---\n\nOops, the original patch returned -1 in use_fcgi() instead of 1,\nwhich shells don't like :x\n\n Makefile        |    5 +++-\n git-instaweb.sh |   72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-\n 2 files changed, 75 insertions(+), 2 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 2b33a2a..05848f1 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -690,7 +690,8 @@ gitweb/gitweb.fcgi: gitweb/gitweb-fcgi.perl\n \tchmod +x $@+\n \tmv $@+ $@\n \n-git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/gitweb.css\n+git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/gitweb.css \\\n+              gitweb/gitweb.fcgi\n \trm -f $@ $@+\n \tsed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \\\n \t    -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \\\n@@ -699,6 +700,8 @@ git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/gitweb.css\n \t    -e '/@@GITWEB_CGI@@/d' \\\n \t    -e '/@@GITWEB_CSS@@/r gitweb/gitweb.css' \\\n \t    -e '/@@GITWEB_CSS@@/d' \\\n+\t    -e '/@@GITWEB_FCGI@@/r gitweb/gitweb.fcgi' \\\n+\t    -e '/@@GITWEB_FCGI@@/d' \\\n \t    $@.sh > $@+\n \tchmod +x $@+\n \tmv $@+ $@\ndiff --git a/git-instaweb.sh b/git-instaweb.sh\nindex 08362f4..d712c0c 100755\n--- a/git-instaweb.sh\n+++ b/git-instaweb.sh\n@@ -20,7 +20,7 @@ httpd=\"`git repo-config --get instaweb.httpd`\"\n browser=\"`git repo-config --get instaweb.browser`\"\n port=`git repo-config --get instaweb.port`\n module_path=\"`git repo-config --get instaweb.modulepath`\"\n-\n+fcgi_pid_file=\"$fqgitdir\"/gitweb/fcgi.pid\n conf=$GIT_DIR/gitweb/httpd.conf\n \n # Defaults:\n@@ -34,7 +34,22 @@ test -z \"$browser\" && browser='firefox'\n # any untaken local port will do...\n test -z \"$port\" && port=1234\n \n+use_fcgi () {\n+\tcase \"$httpd\" in\n+\t*nginx*)\n+\t\treturn 0\n+\t\t;;\n+\tesac\n+\treturn 1\n+}\n+\n start_httpd () {\n+\tif use_fcgi; then\n+\t\t\"$fqgitdir\"/gitweb/gitweb.fcgi \\\n+\t\t           --fcgi-socket=\"$fcgi_sock\" \\\n+\t\t\t   --cgi-bin=\"$fqgitdir/gitweb/gitweb.cgi\" &\n+\t\techo $! > \"$fcgi_pid_file\"\n+\tfi\n \thttpd_only=\"`echo $httpd | cut -f1 -d' '`\"\n \tif test \"`expr index $httpd_only /`\" -eq '1' || \\\n \t\t\t\twhich $httpd_only >/dev/null\n@@ -61,6 +76,9 @@ start_httpd () {\n }\n \n stop_httpd () {\n+\tif use_fcgi; then\n+\t\ttest -f \"$fcgi_pid_file\" && kill `cat \"$fcgi_pid_file\"`\n+\tfi\n \ttest -f \"$fqgitdir/pid\" && kill `cat \"$fqgitdir/pid\"`\n }\n \n@@ -138,7 +156,48 @@ mkdir -p \"$GIT_DIR/gitweb/tmp\"\n GIT_EXEC_PATH=\"`git --exec-path`\"\n GIT_DIR=\"$fqgitdir\"\n export GIT_EXEC_PATH GIT_DIR\n+fcgi_sock=\"$fqgitdir/gitweb/fcgi.sock\"\n \n+nginx_conf () {\n+\tmkdir -p \"$fqgitdir\"/gitweb/logs\n+\tcat > \"$conf\" <<EOF\n+pid $fqgitdir/pid;\n+error_log $fqgitdir/gitweb/logs/error.log;\n+events {\n+\tworker_connections 1024;\n+}\n+http {\n+\taccess_log $fqgitdir/gitweb/logs/access.log;\n+\ttypes {\n+\t\ttext/css css;\n+\t}\n+\tserver {\n+\t\tlisten $port;\n+\t\troot $fqgitdir/gitweb;\n+\t\tlocation = / {\n+\t\t\tfastcgi_pass unix:$fcgi_sock;\n+\t\t\tfastcgi_index gitweb.fcgi;\n+\t\t\tfastcgi_param QUERY_STRING \\$query_string;\n+\t\t\tfastcgi_param REQUEST_METHOD \\$request_method;\n+\t\t\tfastcgi_param CONTENT_TYPE \\$content_type;\n+\t\t\tfastcgi_param CONTENT_LENGTH \\$content_length;\n+\t\t\tfastcgi_param SCRIPT_NAME \\$fastcgi_script_name;\n+\t\t\tfastcgi_param REQUEST_URI \\$request_uri;\n+\t\t\tfastcgi_param DOCUMENT_URI \\$document_uri;\n+\t\t\tfastcgi_param DOCUMENT_ROOT \\$document_root;\n+\t\t\tfastcgi_param SERVER_PROTOCOL \\$server_protocol;\n+\t\t\tfastcgi_param GATEWAY_INTERFACE CGI/1.1;\n+\t\t\tfastcgi_param SERVER_SOFTWARE nginx;\n+\t\t\tfastcgi_param REMOTE_ADDR \\$remote_addr;\n+\t\t\tfastcgi_param REMOTE_PORT \\$remote_port;\n+\t\t\tfastcgi_param SERVER_ADDR \\$server_addr;\n+\t\t\tfastcgi_param SERVER_PORT \\$server_port;\n+\t\t\tfastcgi_param SERVER_NAME \\$server_name;\n+\t\t}\n+\t}\n+}\n+EOF\n+}\n \n lighttpd_conf () {\n \tcat > \"$conf\" <<EOF\n@@ -230,8 +289,16 @@ gitweb_css () {\n EOFGITWEB\n }\n \n+gitweb_fcgi () {\n+\tcat > \"$1\" <<\\EOFGITWEB\n+@@GITWEB_FCGI@@\n+EOFGITWEB\n+\tchmod +x \"$1\"\n+}\n+\n gitweb_cgi $GIT_DIR/gitweb/gitweb.cgi\n gitweb_css $GIT_DIR/gitweb/gitweb.css\n+gitweb_fcgi $GIT_DIR/gitweb/gitweb.fcgi\n \n case \"$httpd\" in\n *lighttpd*)\n@@ -240,6 +307,9 @@ case \"$httpd\" in\n *apache2*)\n \tapache2_conf\n \t;;\n+*nginx*)\n+\tnginx_conf\n+\t;;\n *)\n \techo \"Unknown httpd specified: $httpd\"\n \texit 1\n-- \n1.5.0.rc0.gc26c8\n"},{"id":"31238","messageId":"45A38A82.2060307@vilain.net","threadId":"6216","inReplyTo":"11678969781711-git-send-email-normalperson@yhbt.net","subject":"Re: [PATCH 1/2] gitweb: add a simple wrapper for FCGI support","fromName":"Sam Vilain","fromEmail":"sam@vilain.net","sentAt":"2007-01-09T12:28:50Z","receivedAt":"2007-01-09T12:28:50Z","isPatch":true,"sender":{"key":"sam@vilain.net","avatar":"https://gravatar.com/avatar/8fc840ca854dbf6f7065b4335e3b934951c1dca3b11db688e95e471901f8f4a8?d=mp&s=160"},"body":"Eric Wong wrote:\n> The FCGI wrapper is designed to be spawned from the\n> command-line, and can be backgrounded there.  No\n> FCGI-specific spawners are necessary.\n> \n> Since we re-eval gitweb.cgi on every request, I've\n> quieted warnings for redefined functions.\n> \n\nI never did submit this; perhaps I should've...\n\nhttp://utsl.gen.nz/gitweb/?p=gitweb;a=commitdiff;h=56d7d436;hp=2326acfa\n\nSam.\n\n> Signed-off-by: Eric Wong <normalperson@yhbt.net>\n> ---\n>  .gitignore              |    1 +\n>  Makefile                |    6 +++++\n>  gitweb/gitweb-fcgi.perl |   51 +++++++++++++++++++++++++++++++++++++++++++++++\n>  gitweb/gitweb.perl      |    1 +\n>  4 files changed, 59 insertions(+), 0 deletions(-)\n> \n> diff --git a/.gitignore b/.gitignore\n> index 2904f12..700ac4f 100644\n> --- a/.gitignore\n> +++ b/.gitignore\n> @@ -137,6 +137,7 @@ git-whatchanged\n>  git-write-tree\n>  git-core-*/?*\n>  gitweb/gitweb.cgi\n> +gitweb/gitweb.fcgi\n>  test-date\n>  test-delta\n>  test-dump-cache-tree\n> diff --git a/Makefile b/Makefile\n> index fa1a022..3e94def 100644\n> --- a/Makefile\n> +++ b/Makefile\n> @@ -684,6 +684,12 @@ gitweb/gitweb.cgi: gitweb/gitweb.perl\n>  \tchmod +x $@+\n>  \tmv $@+ $@\n>  \n> +gitweb/gitweb.fcgi: gitweb/gitweb-fcgi.perl\n> +\trm -f $@ $@+\n> +\tsed -e '1s|#!.*perl|#!$(PERL_PATH_SQ)|' $< >$@+\n> +\tchmod +x $@+\n> +\tmv $@+ $@\n> +\n>  git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/gitweb.css\n>  \trm -f $@ $@+\n>  \tsed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \\\n> diff --git a/gitweb/gitweb-fcgi.perl b/gitweb/gitweb-fcgi.perl\n> new file mode 100644\n> index 0000000..2b7d5bf\n> --- /dev/null\n> +++ b/gitweb/gitweb-fcgi.perl\n> @@ -0,0 +1,51 @@\n> +#!/usr/bin/perl -w\n> +use strict;\n> +use FCGI;\n> +use CGI;\n> +use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev/;\n> +\n> +sub usage {\n> +\tprint STDERR \"$0 --fcgi-socket=(path|[host]:port) \",\n> +\t             \"--cgi-bin=path\\n\";\n> +\texit 1;\n> +}\n> +\n> +my ($fcgi_sock, $cgi_bin);\n> +GetOptions('fcgi-socket|s=s' => \\$fcgi_sock,\n> +           'cgi-bin|c=s' => \\$cgi_bin) or usage();\n> +\n> +usage() unless ($fcgi_sock && $cgi_bin);\n> +\n> +die \"FastCGI socket: $fcgi_sock already exists!\\n\" if (-S $fcgi_sock);\n> +die \"CGI executable: $cgi_bin does not exist!\\n\" if (!-f $cgi_bin);\n> +\n> +# gitweb will exit, make it throw an exception instead:\n> +no warnings qw/once/;\n> +*CORE::GLOBAL::exit = sub { die 'gitweb_exit' };\n> +use warnings;\n> +\n> +# FCGI will erase the current %ENV; so make sure we save this:\n> +my $gwcfg = $ENV{GITWEB_CONFIG};\n> +\n> +my $fcgi_req = FCGI::Request(\\*STDIN, \\*STDOUT, \\*STDERR, \\%ENV,\n> +                             FCGI::OpenSocket($fcgi_sock, 128),\n> +                             FCGI::FAIL_ACCEPT_ON_INTR);\n> +while ($fcgi_req->Accept >= 0) {\n> +\tunless ($ENV{PATH_INFO}) {\n> +\t\t# nginx currently fails to set PATH_INFO,\n> +\t\t# so we'll do it ourselves\n> +\t\tmy $pi = $ENV{SCRIPT_NAME};\n> +\t\t$pi =~ s!^/\\+!!;\n> +\t\t$ENV{PATH_INFO} = $pi;\n> +\t}\n> +\t# clear CGI query parameters set inside gitweb so we can reparse\n> +\t# the %ENV fed to us\n> +\tCGI::initialize_globals();\n> +\t$ENV{GITWEB_CONFIG} = $gwcfg if defined $gwcfg;\n> +\tdo $cgi_bin;\n> +\tdelete $ENV{PATH_INFO};\n> +}\n> +\n> +END {\n> +\tunlink $fcgi_sock if (defined $fcgi_sock && -S $fcgi_sock);\n> +}\n> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\n> index 2179054..4a9189b 100755\n> --- a/gitweb/gitweb.perl\n> +++ b/gitweb/gitweb.perl\n> @@ -9,6 +9,7 @@\n>  \n>  use strict;\n>  use warnings;\n> +no warnings qw(redefine); # for FCGI\n>  use CGI qw(:standard :escapeHTML -nosticky);\n>  use CGI::Util qw(unescape);\n>  use CGI::Carp qw(fatalsToBrowser);\n"}]}