Hi All,
I'm new to this newsgroup, and have only used threads in a very basic
manner up to this point, but have been a C programmer for about 5-6 years.
I'm working on a project, its in C, on OpenBSD 4.3, using the system
pthread library and system compiler (gcc 3.3.5 propolice). The goal is
to create a daemon process that listens on both a TCP socket and a UNIX
socket eg. file and process incoming connections identically. The
thought was to, after daemonization to start two threads, each with
their own listen loop, one for TCP and one for the UNIX domain socket.
So I'm writing the TCP ****tion first and I get a strange condition.
When I call accept instead of blocking, it actually aborts the program,
no error message, gdb just returns and says "program terminated
normally". Having it just run not as a seperate thread, it works
correctly. Heres the code:
void init_sockets()
{
pthread_t tcp_pt;
if (get_config_int("tcp_listen_****t") > 0) {
/*pthread_create(&tcp_pt,NULL,tcp_socket_loop,NULL);*/ << aborts
tcp_socket_loop(NULL); << works
}
}
void *tcp_socket_loop(void *junk)
{
int sock = socket(AF_INET,SOCK_STREAM,0);
int ****t = get_config_int("tcp_listen_****t"); << verified is 5555,
which it is supposed to be
struct sockaddr_in sa,ca;
int cli_fd,cl;
char buf[128];
if (sock == -1) error_exit("socket() failed: %m");
memset(&sa,0,sizeof(struct sockaddr_in));
sa.sin_family = AF_INET;
sa.sin_addr.s_addr = htonl(INADDR_ANY);
sa.sin_****t = htons(****t);
if (bind(sock,(struct sockaddr *)&sa,sizeof(struct sockaddr_in)) <
0) error_exit("bind() failed: %m");
snprintf(buf,sizeof(buf),"Listening on TCP ****t %d",****t); << it
gets to this point, everything looks okay
status_message(buf);
listen(sock,10); << checked errno, was 0
cli_fd = accept(sock,(struct sockaddr *)&ca,&cl); << program ends
here?
return NULL; << never reaches this line in GDB
}
Is it a gdb problem? Is there some caveat to accept inside of a thread
that I dont know about? Any help would be greatly appreciated.


|