Fixed bug #633
authorSam Lantinga <slouken@libsdl.org>
Tue, 17 Feb 2009 05:17:51 +0000
changeset 3068b21348d47cab
parent 3067 bcd41b269091
child 3069 caefe2344f65
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 <signal.h>
#include <errno.h>
kill(pid, 0) < 0 && errno == ESRCH

not just

#include <signal.h>
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
src/audio/arts/SDL_artsaudio.c
src/audio/dma/SDL_dmaaudio.c
src/audio/esd/SDL_esdaudio.c
src/audio/pulseaudio/SDL_pulseaudio.c
     1.1 --- a/src/audio/alsa/SDL_alsa_audio.c	Tue Feb 17 04:57:39 2009 +0000
     1.2 +++ b/src/audio/alsa/SDL_alsa_audio.c	Tue Feb 17 05:17:51 2009 +0000
     1.3 @@ -230,7 +230,7 @@
     1.4           */
     1.5          /* Check every 10 loops */
     1.6          if (this->hidden->parent && (((++cnt) % 10) == 0)) {
     1.7 -            if (kill(this->hidden->parent, 0) < 0) {
     1.8 +            if (kill(this->hidden->parent, 0) < 0 && errno == ESRCH) {
     1.9                  this->enabled = 0;
    1.10              }
    1.11          }
     2.1 --- a/src/audio/arts/SDL_artsaudio.c	Tue Feb 17 04:57:39 2009 +0000
     2.2 +++ b/src/audio/arts/SDL_artsaudio.c	Tue Feb 17 05:17:51 2009 +0000
     2.3 @@ -27,6 +27,7 @@
     2.4  #include <signal.h>
     2.5  #endif
     2.6  #include <unistd.h>
     2.7 +#include <errno.h>
     2.8  
     2.9  #include "SDL_timer.h"
    2.10  #include "SDL_audio.h"
    2.11 @@ -149,7 +150,7 @@
    2.12           */
    2.13          /* Check every 10 loops */
    2.14          if (this->hidden->parent && (((++cnt) % 10) == 0)) {
    2.15 -            if (kill(this->hidden->parent, 0) < 0) {
    2.16 +            if (kill(this->hidden->parent, 0) < 0 && errno == ESRCH) {
    2.17                  this->enabled = 0;
    2.18              }
    2.19          }
     3.1 --- a/src/audio/dma/SDL_dmaaudio.c	Tue Feb 17 04:57:39 2009 +0000
     3.2 +++ b/src/audio/dma/SDL_dmaaudio.c	Tue Feb 17 05:17:51 2009 +0000
     3.3 @@ -417,7 +417,7 @@
     3.4             that use a different process id for each thread.
     3.5           */
     3.6          if (parent && (((++cnt) % 10) == 0)) {  /* Check every 10 loops */
     3.7 -            if (kill(parent, 0) < 0) {
     3.8 +            if (kill(parent, 0) < 0 && errno == ESRCH) {
     3.9                  this->enabled = 0;
    3.10              }
    3.11          }
     4.1 --- a/src/audio/esd/SDL_esdaudio.c	Tue Feb 17 04:57:39 2009 +0000
     4.2 +++ b/src/audio/esd/SDL_esdaudio.c	Tue Feb 17 05:17:51 2009 +0000
     4.3 @@ -128,7 +128,7 @@
     4.4           */
     4.5          /* Check every 10 loops */
     4.6          if (this->hidden->parent && (((++cnt) % 10) == 0)) {
     4.7 -            if (kill(this->hidden->parent, 0) < 0) {
     4.8 +            if (kill(this->hidden->parent, 0) < 0 && errno == ESRCH) {
     4.9                  this->enabled = 0;
    4.10              }
    4.11          }
     5.1 --- a/src/audio/pulseaudio/SDL_pulseaudio.c	Tue Feb 17 04:57:39 2009 +0000
     5.2 +++ b/src/audio/pulseaudio/SDL_pulseaudio.c	Tue Feb 17 05:17:51 2009 +0000
     5.3 @@ -165,7 +165,7 @@
     5.4           */
     5.5          /* Check every 10 loops */
     5.6          if (this->hidden->parent && (((++cnt) % 10) == 0)) {
     5.7 -            if (kill(this->hidden->parent, 0) < 0) {
     5.8 +            if (kill(this->hidden->parent, 0) < 0 && errno == ESRCH) {
     5.9                  this->enabled = 0;
    5.10              }
    5.11          }