Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
14 years ago

How to tidy up after client hangup with inetd?

Dear Forum,

My NiosII running uClinux is working as a motion server. I used inetd to listen on a port and launch my server application. Sometimes, the client will make a request that causes the server program to vfork

and execl another process to deal with the client's request. Normally, the client will end the session with sensible commands and the server program gracefully uses SIGTERM to kill the child processes it has produced. However, when the client severs the connection abruptly, inetd terminates the server program, but the child processes are still runnning. I've tried to fix this problem by catching SIGTERM from inetd in the server program and gracefully terminating the server's child processes. This fails to work when the client abruptly disconnects, yet it works if I kill the server from the terminal with kill <server pid>; I don't understand this failure because inetd.c seems to kill stuff by issuing SIGTERM. What am I missing?

Stephen

Edit: SIGTERM is not the problem, it seems that when a client disconnects abruptly an EOF appears in the the server's stdin stream. This can be used to gracefully reap the server's child processes.
No RepliesBe the first to reply