concearning STUN server version 0.96
When running the stun server with the -b option the
child process created is killed after a few seconds.
Reason of this is that a child process is created and
the parent stopped after that.
In Linux when a parent is killed (or stopped) all its
child processes are killed as wel.
This has as result that the child process to run in
background is terminated a few seconds after it is
created.
To fix this the child should be daemonized.
this can be done by adding the following code in
server.cxx:
#ifndef WIN32
...
/* adding following includes after line 12 in server.cxx*/
#include <fcntl.h>
...
#endif
...
/* in the main function (line 214 file server.cxx) */
if (pid == 0) //child or not using background
{
if(background)
{
pid_t sid;
/* Create a new SID for the
child process */
sid = setsid();
if (sid < 0)
{
exit(-1);
}
verbose = false;
/* close standard file
descriptors and redirect them to /dev/null */
close(0);
close(1);
close(2);
int si = open("/dev/null",
O_RDWR);
dup(si);
dup(si);
}
}
StunServerInfo info;
bool ok = stunInitServer(info, myAddr, altAddr,
myMediaPort, verbose);
...
With this it can be used in a script in the /etc/init.d
directory to automatically start it up when the linux
server is restarted.