Bug in signalmodule.c + FIX (probably a hack :-)

scharf@EMBL-Heidelberg.DE
Tue, 6 Sep 1994 16:28:55 +0100

Hi,

I got a problem with the signal module on IRIX5. I created the server below
(which is based on the example in the python manual). When the parent gets the
signal SIGCLD then the signal module enters an infinite recursion...

I fixed it, but I did it blindly - I mean without understanding what's going
on. But this fix seems to solve the problem - at least for me :-)

BTW: on SUNOS-4.13 this error didn't occur.

Michael

#############################################################################
# a simple server, that forks and the child which serves the requests while
# the parent is waiting for new requests.
#############################################################################

#!/usr/pub/bin/python
# Echo server program
import socket,signal,posix,sys

def WaitChild(sig,frame):
# let's not produce zombies ....
posix.wait()

signal.signal(signal.SIGCLD,WaitChild)

HOST = '' # Symbolic name meaning the local host
PORT = 50007 # Arbitrary non-privileged server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(HOST, PORT)
# let's allow for 16 pending requests
s.listen(16)
while 1:
while 1:
# we get an interrupted system call,if the signal
# comes while s.accept....
try:
conn, addr = s.accept()
break
except socket.error:
pass
childid=posix.fork()
if childid==0:
# the child
data = conn.recv(1024)
# do something which takes a looooong time
# else it would'nt be worth to fork :-)
conn.send(data)
conn.close()
break
else:
# the parent
conn.close()

#############################################################################
# gdb stack trace - infinite recursion .....
#############################################################################
#0 0xfad7414 in _getpid () at flush.c:414
#1 0x4178bc in signal_handler () at ./signalmodule.c:95
#2 <signal handler called>
#3 0xfad5e14 in ksigaction () at flush.c:414
#4 0xfad3dd0 in _sigaction () at flush.c:414
#5 0xfad2a68 in _ssig () at flush.c:414
#6 0xfad0b48 in signal () at flush.c:414
#7 0x417914 in signal_handler () at ./signalmodule.c:105
#8 <signal handler called>
#9 0xfad5e14 in ksigaction () at flush.c:414
#10 0xfad3dd0 in _sigaction () at flush.c:414
#11 0xfad2a68 in _ssig () at flush.c:414
#12 0xfad0b48 in signal () at flush.c:414
#13 0x417914 in signal_handler () at ./signalmodule.c:105
#14 <signal handler called>
#15 0xfad5e14 in ksigaction () at flush.c:414
#16 0xfad3dd0 in _sigaction () at flush.c:414
#17 0xfad2a68 in _ssig () at flush.c:414
#18 0xfad0b48 in signal () at flush.c:414
#19 0x417914 in signal_handler () at ./signalmodule.c:105
....

#############################################################################
# a (blind) patch to break this recursion....
#############################################################################
----------------------- snip snip --------------------------------------------
--- signalmodule.c.~1~ Tue Aug 23 14:49:37 1994
+++ signalmodule.c Tue Sep 6 16:00:03 1994
@@ -88,11 +88,14 @@
err_set(KeyboardInterrupt);
return NULL;
}
-
static RETSIGTYPE
signal_handler(sig_num)
int sig_num;
{
+ static sig_level=0;
+ if (sig_level>0)
+ return;
+ sig_level++;
#ifdef WITH_THREAD
/* See NOTES section above */
if (getpid() == main_pid) {
@@ -103,6 +106,7 @@
}
#endif
(void *)signal(sig_num, &signal_handler);
+ sig_level--;
}

static object *

-- 
         __________________________________________________________
   ****    ___   _  _   ___   _    
  ******  | __) | \/ | |   ) | |   Michael Scharf
 ******** | _)  |    | | -<  | |_  Tel: +49 6221 387 305 Fax: 517
  * ****  |___) |_||_| |___) |___) EMail: scharf@EMBL-Heidelberg.de
   ****   __________________________________________________________