Subject: [PATCH 3/4] git-instaweb: Add checks that web server can be started and is started

From: Jakub Narebski <[email-masked]>
Date: Wed, 29 Dec 2010 17:49:14 +0100

Better to check that "$root/gitweb.cgi" exists, and that web server
started, rather than have (for example) the following error message

  $ git instaweb --httpd=plackup --browser=mozilla
  Waiting for 'plackup' to start .../usr/share/gitweb/gitweb.cgi:
  No such file or directory at <somewhere>/perl5/CGI/Compile.pm line 97.
  ........

and keep waiting in httpd_is_ready for gitweb.cgi which would not start.

Note that the first check is not strictly necessary, but checking
separately that gitweb.cgi script can be found at expected place leads
to better error message.

Signed-off-by: Jakub Narebski <[email-masked]>
---
It can be considered bugfix, or it can be considered hardening of
git-instaweb (making it more resilent).

 git-instaweb.sh |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/git-instaweb.sh b/git-instaweb.sh
index da569f2..94f8b07 100755
--- a/git-instaweb.sh
+++ b/git-instaweb.sh
@@ -41,6 +41,9 @@ test -z "$root" && root='@@GITWEBDIR@@'
 # any untaken local port will do...
 test -z "$port" && port=1234
 
+# Sanity check
+test -e "$root/gitweb.cgi" || die "gitweb.cgi not found at '$root'"
+
 resolve_full_httpd () {
 	case "$httpd" in
 	*apache2*|*lighttpd*|*httpd*)
@@ -617,7 +620,7 @@ webrick)
 	;;
 esac
 
-start_httpd
+start_httpd || die "Could not start '$httpd'"
 url=http://127.0.0.1:$port
 
 if test -n "$browser"; then
-- 
1.7.3