r10376 - /man-cgi/man.cgi
Author: jfs
Date: Fri Feb 28 12:00:09 2014
New Revision: 10376
URL: http://svn.debian.org/wsvn/?sc=1&rev=10376
Log:
- Improve child process handling
- Fix how childs were being called (script was being executed twice)
- When a manpage is not found and it was a localised request, direct the user to the English version in the
error message
- Use the number of output lines for the MAN command as a measure of wether the program executed properly
or not (puts the error message *after* the PRE)
Modified:
man-cgi/man.cgi
Modified: man-cgi/man.cgi
URL: http://svn.debian.org/wsvn/man-cgi/man.cgi?rev=10376&op=diff
==============================================================================
--- man-cgi/man.cgi (original)
+++ man-cgi/man.cgi Fri Feb 28 12:00:09 2014
@@ -42,6 +42,7 @@
use File::stat;
use Time::localtime;
+use Error qw(:try);
$www{'title'} = 'Debian Hypertext Man Pages';
$www{'home'} = 'http://manpages.debian.org';
@@ -55,6 +56,12 @@
#$command{'man'} = '/home/wosch/bin/cgi-man'; # 8Bit clean man
$command{'man'} = '/usr/bin/man'; # 8Bit clean man
$exec_timeout = 20; # seconds to wait for the man command to execute
+
+
+$SIG{ALRM} = sub {
+ my $sig_name = shift;
+ die "Timeout by signal [$sig_name]\n";
+};
# Config Options
# map sections to their man command argument(s)
@@ -465,7 +472,7 @@
local($acounter) = 0;
while (<APROPOS>) {
- next if !/$q/oi; # Fast mach, but includes manpages which have a section in the description
+ next if !/$q/oi; # Fast match, but includes manpages which have a section in the description
$acounter++;
# matches whatis.db lines: name[, name ...] (sect) - msg
@@ -502,6 +509,7 @@
local($html_name, $html_section, $prefix);
local(@manargs);
local($query) = $name;
+ local($output_lines) = 0;
# $section =~ s/^([0-9ln]).*$/$1/;
$section =~ tr/A-Z/a-z/;
@@ -655,17 +663,6 @@
print "X Calling $command{'man'} ".join(" ",@manargs)." for $name ($section)\n" if $debug;
&proc(*MAN, $command{'man'}, @manargs, "--", $section, $name) ||
&mydie ("$0: open of $command{'man'} command failed: $!\n");
- if (eof(MAN)) {
- print "X $command{'man'} @manargs -- $section $name x\n" if $debug;
- print "Sorry, no data found for `$html_name" .
- ($html_section ? "($html_section)": '') . "'.\n";
- print ¬_found('section',$html_section);
- if ( $locale) {
- print "You might want to try the ".
- qq{<A HREF="$BASE?query=$name&sektion=$section&apropos=0&manpath=$manpath">original (english)</A> version.\n};
- }
- return;
- }
if ($format ne "html") {
if ($format eq "latin1" || $format eq "ascii") {
@@ -759,9 +756,21 @@
push(@sect, $1);
}
print;
+ $outputlines = $outputlines + 1;
}
close(MAN);
print qq{</PRE>\n<a name="end">\n<hr noshade>\n};
+ if ($outputlines == 0 ) {
+ print "X $command{'man'} @manargs -- $section $name x\n" if $debug;
+ print "Sorry, no data found for `$html_name" .
+ ($html_section ? "($html_section)": '') . "' in language ".$locales{$locale}.".\n";
+ print ¬_found('section',$html_section, $locale);
+ if ( $locale) {
+ print "You might want to try the ".
+ qq{<A HREF="$BASE?query=$name&sektion=$section&apropos=0&manpath=$manpath">original (english)</A> version.\n};
+ }
+ return;
+ }
for ($i = 0; $i <= $#sect; $i++) {
print qq{<a href="#} . &encode_url($sect[$i]) .
@@ -821,18 +830,32 @@
# die "Arguments @args are tainted\n" if is_tainted(@args);
if ($pid == 0) {
my $execpid = fork;
+ die "ERROR: cannot fork" unless defined $execpid;
if ($execpid > 0){
+ # Parent process
eval{
- local $SIG{ALRM} = sub {kill 9, -$PID; die "TIMEOUT!"};
+ local $SIG{ALRM} = sub {kill 9, -$execpid; die "Alarm signals timeout. Killing child process [$execpid]!\n"};
alarm $exec_timeout;
waitpid($execpid, 0);
alarm 0;
};
+ catch Error with {
+ my $err = shift;
+ print $err->{-text} . "\n";
+ print "Killing child process [$execpid] ...\n";
+ kill -9, $execpid;
+ print "Killed\n" if $debug;
+ alarm(0);
+ }
+ exit(0);
}
elsif ($execpid == 0){
+ # Child process
+ # set the child process to be a group leader, so that
+ # kill -9 will kill it and all its descendents
setpgrp(0,0);
exec $prog, @args;
- &mydie("exec $prog failed\n");
+ &mydie("failure executing $prog\n");
exit(0);
}
}
@@ -943,8 +966,10 @@
sub available_translations {
# Print translations available for a given manual page
local($name, $section) = @_;
+ print "X Checking available translations (name: $name, section: $section)\n" if $debug;
return if $section eq '';
local ($locald, $path, $found);
+ print "X Looking for available translations\n" if $debug;
$found = 0 ;
foreach $path (split(/:/, $manPath{$manpath}) ) {
# Remove the current locale from the path if there is one
@@ -1399,7 +1424,7 @@
}
sub not_found {
- local($type, $section) = @_;
+ local($type, $section, $locale) = @_;
my $text ="";
$text = qq{
<p>This might happen because:
@@ -1414,6 +1439,10 @@
if ( $section != 0 ) {
$text = $text. "<li>The manpage exists but not in the section you selected. Try searching in 'All sections'.</li>\n";
}
+ if ( $locale ne "en" ) {
+ $text = $text. "<li>The manpage exists in a locale, but could not be converted to your encoding. Try requesting the English version instead.</li>\n";
+ }
+
$text = $text.qq{
<li>There was an error in the archive extraction scripts and the package that provides this manpage was not handled properly.</li>
</ul>
Reply to: