Skip to content
Advertisement

python xinetd client disconnection handling

This may or may not being a coding issue. It may also be an xinetd deamon issue, i do not know.

I have a python script which is triggered from a linux server running xinetd. Xinetd has been setup to only allow one instance as I only want one machine to be able to connect to the service, which is therefore also limited by IP.

Currently when the client connects to xinetd the service works correctly and the script begins sending its output to the client machine. However, when the client disconnects (i.e: due to reboot), the process is still alive on the server, and this blocks the ability for the client to connect once its finished rebooting or so on.

Q: How can i detect in python that the client has disconnected. Perhaps i can test if stdout is no longer being read from by the client (and then exit the script), or is there a much eaiser way in xinetd to have the child process be killed when the client disconnects ?

(I’m using python 2.4.3 on RHEL5 linux – solutions for 2.4 are needed, but 3.1 solutions would be useful to know also.)

Advertisement

Answer

Add a signal handler for SIGHUP. (x)inetd sends this upon the socket disconnecting.

Advertisement