From 854f5a4812f15b43fe270726ad95a5b75a3848ad Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 17 Feb 2009 05:17:51 +0000 Subject: [PATCH] Fixed bug #633 Description From Michael Stone 2008-09-25 19:27:29 (-) [reply] To determine whether a pid is occupied with the kill(pid, 0) idiom, you have to test #include #include kill(pid, 0) < 0 && errno == ESRCH not just #include kill(pid, 0) < 0 otherwise you get incorrect results when pid is running as a different user (causing kill(pid, 0) to return -1 + EPERM). src/audio/alsa/SDL_alsa_audio.c is certainly affected by this bug in both 1.2.13 and 1.3-trunk. It probably occurs in other places as well. --- src/audio/alsa/SDL_alsa_audio.c | 2 +- src/audio/arts/SDL_artsaudio.c | 3 ++- src/audio/dma/SDL_dmaaudio.c | 2 +- src/audio/esd/SDL_esdaudio.c | 2 +- src/audio/pulseaudio/SDL_pulseaudio.c | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/audio/alsa/SDL_alsa_audio.c b/src/audio/alsa/SDL_alsa_audio.c index 4854fb115..98f89ed72 100644 --- a/src/audio/alsa/SDL_alsa_audio.c +++ b/src/audio/alsa/SDL_alsa_audio.c @@ -230,7 +230,7 @@ ALSA_WaitDevice(_THIS) */ /* Check every 10 loops */ if (this->hidden->parent && (((++cnt) % 10) == 0)) { - if (kill(this->hidden->parent, 0) < 0) { + if (kill(this->hidden->parent, 0) < 0 && errno == ESRCH) { this->enabled = 0; } } diff --git a/src/audio/arts/SDL_artsaudio.c b/src/audio/arts/SDL_artsaudio.c index 64b1c69d4..b2b79bc6f 100644 --- a/src/audio/arts/SDL_artsaudio.c +++ b/src/audio/arts/SDL_artsaudio.c @@ -27,6 +27,7 @@ #include #endif #include +#include #include "SDL_timer.h" #include "SDL_audio.h" @@ -149,7 +150,7 @@ ARTS_WaitDevice(_THIS) */ /* Check every 10 loops */ if (this->hidden->parent && (((++cnt) % 10) == 0)) { - if (kill(this->hidden->parent, 0) < 0) { + if (kill(this->hidden->parent, 0) < 0 && errno == ESRCH) { this->enabled = 0; } } diff --git a/src/audio/dma/SDL_dmaaudio.c b/src/audio/dma/SDL_dmaaudio.c index 62a72dc26..6ab6c1a28 100644 --- a/src/audio/dma/SDL_dmaaudio.c +++ b/src/audio/dma/SDL_dmaaudio.c @@ -417,7 +417,7 @@ DMA_WaitDevice(_THIS) that use a different process id for each thread. */ if (parent && (((++cnt) % 10) == 0)) { /* Check every 10 loops */ - if (kill(parent, 0) < 0) { + if (kill(parent, 0) < 0 && errno == ESRCH) { this->enabled = 0; } } diff --git a/src/audio/esd/SDL_esdaudio.c b/src/audio/esd/SDL_esdaudio.c index 0a9078ee2..515cd61bd 100644 --- a/src/audio/esd/SDL_esdaudio.c +++ b/src/audio/esd/SDL_esdaudio.c @@ -128,7 +128,7 @@ ESD_WaitDevice(_THIS) */ /* Check every 10 loops */ if (this->hidden->parent && (((++cnt) % 10) == 0)) { - if (kill(this->hidden->parent, 0) < 0) { + if (kill(this->hidden->parent, 0) < 0 && errno == ESRCH) { this->enabled = 0; } } diff --git a/src/audio/pulseaudio/SDL_pulseaudio.c b/src/audio/pulseaudio/SDL_pulseaudio.c index 0521331ee..445ef0486 100644 --- a/src/audio/pulseaudio/SDL_pulseaudio.c +++ b/src/audio/pulseaudio/SDL_pulseaudio.c @@ -165,7 +165,7 @@ PULSEAUDIO_WaitDevice(_THIS) */ /* Check every 10 loops */ if (this->hidden->parent && (((++cnt) % 10) == 0)) { - if (kill(this->hidden->parent, 0) < 0) { + if (kill(this->hidden->parent, 0) < 0 && errno == ESRCH) { this->enabled = 0; } }