]> git.alsa-project.org Git - alsa-lib.git/commitdiff
pcm: Fix shm initialization race-condition
authorIsmael Luceno <ismael@iodev.co.uk>
Mon, 22 Aug 2016 16:04:33 +0000 (13:04 -0300)
committerTakashi Iwai <tiwai@suse.de>
Mon, 22 Aug 2016 16:10:40 +0000 (18:10 +0200)
Easily seen when two threads try at the same time, one of them will fail.

The bug was identified by using apulse with Skype.

Fixes: dec428c35221 ("pcm: fix 'unable to create IPC shm instance' caused by fork from a thread")
Fixes: https://github.com/i-rinat/apulse/issues/38
Signed-off-by: Ismael Luceno <ismael@iodev.co.uk>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
src/pcm/pcm_direct.c

index c3925cc20fd37d49e2c6b6f03dc3f791dd15da25..643498375b3424625c629ae2d75554b95e098940 100644 (file)
@@ -96,11 +96,12 @@ int snd_pcm_direct_shm_create_or_connect(snd_pcm_direct_t *dmix)
 retryget:
        dmix->shmid = shmget(dmix->ipc_key, sizeof(snd_pcm_direct_share_t),
                             dmix->ipc_perm);
-       if (dmix->shmid < 0) {
-               if (errno == ENOENT)
+       if (dmix->shmid < 0 && errno == ENOENT) {
                if ((dmix->shmid = shmget(dmix->ipc_key, sizeof(snd_pcm_direct_share_t),
                                             IPC_CREAT | IPC_EXCL | dmix->ipc_perm)) != -1)
                        first_instance = 1;
+               else if (errno == EEXIST)
+                       goto retryget;
        }
        err = -errno;
        if (dmix->shmid < 0) {