mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-03 05:18:29 +03:00
libdaemon: Fix a subtle race in worker thread creation.
This commit is contained in:
parent
cb613d4c10
commit
7d299ecbb3
@ -381,6 +381,7 @@ static void *client_thread(void *baton)
|
|||||||
request req;
|
request req;
|
||||||
response res;
|
response res;
|
||||||
|
|
||||||
|
b->client.thread_id = pthread_self();
|
||||||
buffer_init(&req.buffer);
|
buffer_init(&req.buffer);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
@ -431,6 +432,7 @@ static int handle_connect(daemon_state s)
|
|||||||
struct sockaddr_un sockaddr;
|
struct sockaddr_un sockaddr;
|
||||||
client_handle client = { .thread_id = 0 };
|
client_handle client = { .thread_id = 0 };
|
||||||
socklen_t sl = sizeof(sockaddr);
|
socklen_t sl = sizeof(sockaddr);
|
||||||
|
pthread_t tid;
|
||||||
|
|
||||||
client.socket_fd = accept(s.socket_fd, (struct sockaddr *) &sockaddr, &sl);
|
client.socket_fd = accept(s.socket_fd, (struct sockaddr *) &sockaddr, &sl);
|
||||||
if (client.socket_fd < 0)
|
if (client.socket_fd < 0)
|
||||||
@ -446,10 +448,10 @@ static int handle_connect(daemon_state s)
|
|||||||
baton->s = s;
|
baton->s = s;
|
||||||
baton->client = client;
|
baton->client = client;
|
||||||
|
|
||||||
if (pthread_create(&baton->client.thread_id, NULL, client_thread, baton))
|
if (pthread_create(&tid, NULL, client_thread, baton))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
pthread_detach(baton->client.thread_id);
|
pthread_detach(tid);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user