danielhozac
Programmer
I am currently working a server which [tt]fork[/tt]s processes to handle incoming connections. However, since the sockets are [tt]accept[/tt]ed in the main server loop, I can't seem to close it in the child. I thought that I could handle it in a signal handler, but since the file which does the [tt]fork[/tt]ing is built as a shared library and I [tt]dlopen[/tt] it in the server, I get segmentation faults every time I use the [tt]siginfo_t[/tt] structure in the signal handler.
Here is some code:
I ran [tt]gdb[/tt] on my program, and it receives the [tt]SIGSEGV[/tt] as it enters the [tt]signalHandler[/tt] function.
Environment: Linux 2.4.21, glibc 2.2.93 and gcc 3.2
//Daniel
Here is some code:
Code:
int sockets[MAX_SOCKETS];
int initialize()
{
struct sigaction sa;
sa.sa_flags = SA_RESTART;
sigfillset(&sa.sa_mask);
sa.sa_sigaction = signalHandler;
if (sigaction(SIGCHLD, &sa, NULL) == -1)
return -1;
return 0;
}
void signalHandler(int signal, siginfo_t *info, void *context)
{
if (sockets[info->si_pid] != 0)
close(sockets[info->si_pid]);
}
I ran [tt]gdb[/tt] on my program, and it receives the [tt]SIGSEGV[/tt] as it enters the [tt]signalHandler[/tt] function.
Environment: Linux 2.4.21, glibc 2.2.93 and gcc 3.2
//Daniel