From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from localhost (mandoc.bsd.lv [local]) by mandoc.bsd.lv (OpenSMTPD) with ESMTPA id e89c2341 for ; Wed, 13 Nov 2019 04:13:17 -0500 (EST) Date: Wed, 13 Nov 2019 04:13:17 -0500 (EST) X-Mailinglist: mandoc-source Reply-To: source@mandoc.bsd.lv MIME-Version: 1.0 From: schwarze@mandoc.bsd.lv To: source@mandoc.bsd.lv Subject: cvsweb: better error handling when reading the configuration file X-Mailer: activitymail 1.26, http://search.cpan.org/dist/activitymail/ Content-Type: text/plain; charset=utf-8 Message-ID: <8d077bd3b8f59ad0@mandoc.bsd.lv> Log Message: ----------- better error handling when reading the configuration file Modified Files: -------------- cvsweb: cvsweb.cgi Revision Data ------------- Index: cvsweb.cgi =================================================================== RCS file: /home/cvs/mandoc/cvsweb/cvsweb.cgi,v retrieving revision 4.21 retrieving revision 4.22 diff -Lcvsweb.cgi -Lcvsweb.cgi -u -p -r4.21 -r4.22 --- cvsweb.cgi +++ cvsweb.cgi @@ -144,7 +144,6 @@ sub spacedHtmlText($;$); sub link($$); sub revcmp($$); sub fatal($$@); -sub config_error($$); sub redirect($;$); sub safeglob($); sub search_path($); @@ -316,14 +315,18 @@ $maycompress = ( qw(cvsroot hideattic ignorecase sortby logsort f only_with_tag ln hidecvsroot hidenonreadable); -# # Load configuration. -# -if (-f $config) { - do "$config" or config_error($config, $@); -} else { - fatal("500 Internal Error", - 'Configuration not found. Set the parameter $config in cvsweb.cgi to your cvsweb.conf configuration file first.'); +{ + $config =~ m|^/| or fatal '500 Internal Error', + 'Configuration file name "%s" is not an absolute path.', + $config; + defined do $config and last; + $@ and fatal '500 Internal Error', + 'Error loading configuration file "%s":
%s
', + $config, $@; + fatal '500 Internal Error', + 'Cannot read configuration file "%s": %s', + $config, $! || 'unknown error'; } # Try to find a readable dir where we can cd into. Some abs_path() @@ -1542,17 +1545,6 @@ sub fatal($$@) sprintf($format, map(htmlquote($_), @args)), "\n"; html_footer(); exit(1); -} - - -# -# Signal a (fatal) configuration error. -# -sub config_error($$) -{ - fatal('500 Internal Error', - 'Error loading configuration file "%s":

' . - '%s
', @_); } -- To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv