# HG changeset patch # User Sam Lantinga # Date 1234847871 0 # Node ID b21348d47cab912eb49ac37547cf02c7e2fa8ae2 # Parent bcd41b2690917cee95d30da0cc7a9e7b08a121cd 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. diff -r bcd41b269091 -r b21348d47cab src/audio/alsa/SDL_alsa_audio.c --- a/src/audio/alsa/SDL_alsa_audio.c Tue Feb 17 04:57:39 2009 +0000 +++ b/src/audio/alsa/SDL_alsa_audio.c Tue Feb 17 05:17:51 2009 +0000 @@ -230,7 +230,7 @@ */ /* 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 -r bcd41b269091 -r b21348d47cab src/audio/arts/SDL_artsaudio.c --- a/src/audio/arts/SDL_artsaudio.c Tue Feb 17 04:57:39 2009 +0000 +++ b/src/audio/arts/SDL_artsaudio.c Tue Feb 17 05:17:51 2009 +0000 @@ -27,6 +27,7 @@ #include #endif #include +#include #include "SDL_timer.h" #include "SDL_audio.h" @@ -149,7 +150,7 @@ */ /* 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 -r bcd41b269091 -r b21348d47cab src/audio/dma/SDL_dmaaudio.c --- a/src/audio/dma/SDL_dmaaudio.c Tue Feb 17 04:57:39 2009 +0000 +++ b/src/audio/dma/SDL_dmaaudio.c Tue Feb 17 05:17:51 2009 +0000 @@ -417,7 +417,7 @@ 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 -r bcd41b269091 -r b21348d47cab src/audio/esd/SDL_esdaudio.c --- a/src/audio/esd/SDL_esdaudio.c Tue Feb 17 04:57:39 2009 +0000 +++ b/src/audio/esd/SDL_esdaudio.c Tue Feb 17 05:17:51 2009 +0000 @@ -128,7 +128,7 @@ */ /* 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 -r bcd41b269091 -r b21348d47cab src/audio/pulseaudio/SDL_pulseaudio.c --- a/src/audio/pulseaudio/SDL_pulseaudio.c Tue Feb 17 04:57:39 2009 +0000 +++ b/src/audio/pulseaudio/SDL_pulseaudio.c Tue Feb 17 05:17:51 2009 +0000 @@ -165,7 +165,7 @@ */ /* 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; } }