Skip to contentSkip to conversation

gitweb: Return or exit after done serving request

PATCH In review Jakub Narebski 2 participants 4 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gitweb: Return or exit after done serving request

Check if there is a caller in top frame of gitweb, and either 'return' if gitweb code is wrapped in subroutine, or 'exit' if it is not.

This should avoid

gitweb.cgi: Subroutine git_SOMETHING redefined at gitweb.cgi line NNN

warnings in error_log when running gitweb with mod_perl (using ModPerl::Registry handler)

---
I have noticed bunch of

  [Sun Jun 13 11:58:02 2010] gitweb.cgi: Subroutine git_opml redefined
  at /var/www/perl/gitweb/gitweb.cgi line 6808.

warnings in /var/log/httpd/error_log, after running gitweb from mod_perl. This fixes it.

 gitweb/gitweb.perl |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
gitweb/gitweb.perl +9 -0
index e108bbc..02f366d 100755
@@ -987,7 +987,16 @@ if ($action !~ m/^(?:opml|project_list|project_index)$/ &&
 	die_error(400, "Project needed");
 }
 $actions{$action}->();
+
 DONE_GITWEB:
+if (defined caller) {
+	# wrapped in a subroutine processing requests,
+	# e.g. mod_perl with ModPerl::Registry, or PSGI with Plack::App::WrapCGI
+	return;
+} else {
+	# pure CGI script, serving single request
+	exit;
+}
 1;
 
 ## ======================================================================
#1 lore raw
Quoted 9 lines · Jakub Narebski
gitweb/gitweb.perl +1 -0
index e108bbc..02f366d 100755
@@ -987,7 +987,16 @@ if ($action !~ m/^(?:opml|project_list|project_index)$/ &&
 	die_error(400, "Project needed");
 }
 $actions{$action}->();
+

gitweb/gitweb.perl if ($action !~ m/^(?:opml|project_list|project_index)$/ && · line 1000

Quoted 10 lines
gitweb/gitweb.perl +8 -0
 DONE_GITWEB:
+if (defined caller) {
+	# wrapped in a subroutine processing requests,
+	# e.g. mod_perl with ModPerl::Registry, or PSGI with Plack::App::WrapCGI
+	return;
+} else {
+	# pure CGI script, serving single request
+	exit;
+}
 1;

Is the last "1;" still needed if we did this?

I am guessing that this new codeblock will go inside "sub run" when merging with your c2394fe (gitweb: Put all per-connection code in run() subroutine, 2010-05-07) and Sam's a0446e7 (gitweb: Add support for FastCGI, using CGI::Fast, 2010-05-07). If I am mistaken, please advise.

Thanks.

#2 lore raw
Quoted 15 lines · Junio C Hamano
Quoted 13 lines · Jakub Narebski
gitweb/gitweb.perl +4 -0
index e108bbc..02f366d 100755
@@ -987,7 +987,16 @@ if ($action !~ m/^(?:opml|project_list|project_index)$/ &&
 	die_error(400, "Project needed");
 }
 $actions{$action}->();
+
 DONE_GITWEB:
+if (defined caller) {
+	# wrapped in a subroutine processing requests,
+	# e.g. mod_perl with ModPerl::Registry, or PSGI with Plack::App::WrapCGI
Quoted 8 lines

gitweb/gitweb.perl if ($action !~ m/^(?:opml|project_list|project_index)$/ && · line 1000

Quoted 6 lines
gitweb/gitweb.perl +5 -0
+	return;
+} else {
+	# pure CGI script, serving single request
+	exit;
+}
 1;

Is the last "1;" still needed if we did this?

Probably not, and probably we never need this.

Quoted 5 lines

I am guessing that this new codeblock will go inside "sub run" when merging with your c2394fe (gitweb: Put all per-connection code in run() subroutine, 2010-05-07) and Sam's a0446e7 (gitweb: Add support for FastCGI, using CGI::Fast, 2010-05-07). If I am mistaken, please advise.

No, the code is meant to be after last code to be run in gitweb, in *top level* scope, otherwise it would always return.

So the patch merged with commits mentioned above ('jn/gitweb-fastcgi', old or new) would look like the following... but I am not sure if it is needed, as I tried to reproduce error / warning that I got to ensure that the patch really fixes it (as in new post "sub run" code there are subroutine definitions before end of 'main' code, i.e. run(); in new post "sub run" code, $actions{$action}->(); in pre "sub run" code) and I couldn't get again this:

/var/log/httpd/error_log:
...

  [Sun Jun 13 11:58:02 2010] gitweb.cgi: Subroutine git_atom redefined at /var/www/perl/gitweb/gitweb.cgi line 6804.
  [Sun Jun 13 11:58:02 2010] gitweb.cgi: Subroutine git_opml redefined at /var/www/perl/gitweb/gitweb.cgi line 6808.
  ...gi-bin

Lets table it now.

-- >8 --
Subject: [RFC/PATCH] gitweb: Return or exit after done serving request

Check if there is a caller in top frame of gitweb, and either 'return' if gitweb code is wrapped in subroutine, or 'exit' if it is not.

This should avoid

gitweb.cgi: Subroutine git_SOMETHING redefined at gitweb.cgi line NNN

warnings in error_log when running gitweb with mod_perl (using ModPerl::Registry handler)

---
 gitweb/gitweb.perl |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
gitweb/gitweb.perl +10 -0
index 14ef50c..43589b5 100755
@@ -1111,6 +1111,16 @@ sub run {
 
 run();
 
+if (defined caller) {
+	# wrapped in a subroutine processing requests,
+	# e.g. mod_perl with ModPerl::Registry, or PSGI with Plack::App::WrapCGI
+	return;
+} else {
+	# pure CGI script, serving single request
+	# or 'exit' hijacked appropriately
+	exit;
+}
+
 ## ======================================================================
 ## action links
 
Signature · 1 line
1.7.0.1
#3 lore raw
Quoted 6 lines · Jakub Narebski

On Mon, 14 June 2010, Junio C Hamano wrote:
...

Quoted 1 line

Is the last "1;" still needed if we did this?

Probably not, and probably we never need this.

Quoted 1 line
Quoted 7 lines
Quoted 4 lines

I am guessing that this new codeblock will go inside "sub run" when merging with your c2394fe (gitweb: Put all per-connection code in run() subroutine, 2010-05-07) and Sam's a0446e7 (gitweb: Add support for FastCGI, using CGI::Fast, 2010-05-07). If I am mistaken, please advise.

No, the code is meant to be after last code to be run in gitweb, in *top level* scope, otherwise it would always return.

Ok, tentatively I fixed the mismerge of 'pu' from the last night and pushed it out.