Author: jfs
Date: Sat Feb  8 16:51:19 2014
New Revision: 10371

URL: http://svn.debian.org/wsvn/?sc=1&rev=10371
Log:

Added code to control the exec() and timeout if it does not finish in time.

Under some calls, man does not seem to return cleanly. It happens when 
accessing 
http://manpages.debian.org/cgi-bin/man.cgi?query=apt_preferences&apropos=0&sektion=0&manpath=Debian+unstable+sid&format=html&locale=ja

Which spawns the following process group that never finishes:

www-data 12988  0.0  0.0  20272  1632 ?        S    16:44   0:00 /usr/bin/man 
-M /srv/manpages.debian.org/extractor/manpages-dists/sid/usr/share/man/ja -L 
ja_JP.eucJP --  apt_preferences
www-data 13000  0.0  0.0   4180   576 ?        S    16:44   0:00  \_ /bin/sh 
/usr/bin/nroff -mandoc -Tutf8
www-data 13004  0.0  0.0  11972  1176 ?        S    16:44   0:00  |   \_ groff 
-mtty-char -Tutf8 -mandoc
www-data 13005 15.8  0.0  14920  3516 ?        R    16:44   0:41  |       \_ 
troff -mtty-char -mandoc -Tutf8
www-data 13006  2.7  0.0  13256  1800 ?        S    16:44   0:07  |       \_ 
grotty
www-data 13001  0.0  0.0  14836  6136 ?        S    16:44   0:00  \_ iconv -c 
-f UTF-8 -t EUC-JP//TRANSLIT
www-data 13002  0.0  0.0   8848   640 ?        S    16:44   0:00  \_ col -b -p 
-x




Modified:
    man-cgi/man.cgi

Modified: man-cgi/man.cgi
URL: http://svn.debian.org/wsvn/man-cgi/man.cgi?rev=10371&op=diff
==============================================================================
--- man-cgi/man.cgi     (original)
+++ man-cgi/man.cgi     Sat Feb  8 16:51:19 2014
@@ -54,7 +54,7 @@
 #$command{'man'} =     'man'; # 8Bit clean man
 #$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
 
 # Config Options
 # map sections to their man command argument(s)
@@ -820,8 +820,21 @@
 #    die "Program $prog is tainted\n" if is_tainted($prog);
 #    die "Arguments @args are tainted\n" if is_tainted(@args);
     if ($pid == 0) {
-       exec $prog, @args;
-       &mydie("exec $prog failed\n");
+       my $execpid = fork;
+       if ($execpid > 0){
+               eval{
+                       local $SIG{ALRM} = sub {kill 9, -$PID; die "TIMEOUT!"};
+                       alarm $exec_timeout;
+                       waitpid($execpid, 0);
+                       alarm 0;
+               };
+       }
+       elsif ($execpid == 0){
+               setpgrp(0,0);
+               exec $prog, @args;
+               &mydie("exec $prog failed\n");
+               exit(0);
+       }
     }
     1;
 }


-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]
Archive: http://lists.debian.org/[email protected]

Reply via email to