A bit unsure where to look for this one...
Context:
- HTML5 web page, that uses HTML5 EventSource / server-side events to get refresh notifications
- OpenWrt BarrierBreaker server, running uHTTPd as the web server
- a two-level CGI script that provides the server-side events:
- the CGI is a shell script (ash, not bash), that parses QUERY_STRING, and calls...
- a C application that do the true data extraction (from an SQLite database) and pushes the data to the web page
Everything works, except for a little detail: when the web page is closed, the C application keeps running. Since it doesn't expect any user input, its current structure is a simple while(1). So after some time, the openwrt box has dozens of copies of the app running.
So the question: how can the application be changed to detect that the client isn't there anymore, and that it should quits?
Thanks
[Edit]
Since posting this a few hours ago, i investigated if the information was somehow available in the script's input stream. It appears it isn't.
I also found http://html5doctor.com/server-sent-events/ that describes a strategy to do exactly this in a Node.js environment, but I have no idea how to translate this in a script-based one.
[/Edit]