]> sourceware.org Git - lvm2.git/commitdiff
libdaemon: Fix a subtle race in worker thread creation.
authorPetr Rockai <prockai@redhat.com>
Wed, 9 Oct 2013 20:20:36 +0000 (22:20 +0200)
committerPetr Rockai <prockai@redhat.com>
Wed, 9 Oct 2013 22:34:35 +0000 (00:34 +0200)
libdaemon/server/daemon-server.c

index df2c852ff6beac10fe3fc57f3aebddea124c1c6d..b114b9f307d74a78097b4095771fe96e4072897b 100644 (file)
@@ -381,6 +381,7 @@ static void *client_thread(void *baton)
        request req;
        response res;
 
+       b->client.thread_id = pthread_self();
        buffer_init(&req.buffer);
 
        while (1) {
@@ -431,6 +432,7 @@ static int handle_connect(daemon_state s)
        struct sockaddr_un sockaddr;
        client_handle client = { .thread_id = 0 };
        socklen_t sl = sizeof(sockaddr);
+       pthread_t tid;
 
        client.socket_fd = accept(s.socket_fd, (struct sockaddr *) &sockaddr, &sl);
        if (client.socket_fd < 0)
@@ -446,10 +448,10 @@ static int handle_connect(daemon_state s)
        baton->s = s;
        baton->client = client;
 
-       if (pthread_create(&baton->client.thread_id, NULL, client_thread, baton))
+       if (pthread_create(&tid, NULL, client_thread, baton))
                return 0;
 
-       pthread_detach(baton->client.thread_id);
+       pthread_detach(tid);
 
        return 1;
 }
This page took 0.038616 seconds and 5 git commands to generate.