Commit d9d69026 authored by Sam Lantinga's avatar Sam Lantinga

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.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403533
parent d2e9f851
...@@ -230,7 +230,7 @@ ALSA_WaitDevice(_THIS) ...@@ -230,7 +230,7 @@ ALSA_WaitDevice(_THIS)
*/ */
/* Check every 10 loops */ /* Check every 10 loops */
if (this->hidden->parent && (((++cnt) % 10) == 0)) { 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; this->enabled = 0;
} }
} }
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <signal.h> #include <signal.h>
#endif #endif
#include <unistd.h> #include <unistd.h>
#include <errno.h>
#include "SDL_timer.h" #include "SDL_timer.h"
#include "SDL_audio.h" #include "SDL_audio.h"
...@@ -149,7 +150,7 @@ ARTS_WaitDevice(_THIS) ...@@ -149,7 +150,7 @@ ARTS_WaitDevice(_THIS)
*/ */
/* Check every 10 loops */ /* Check every 10 loops */
if (this->hidden->parent && (((++cnt) % 10) == 0)) { 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; this->enabled = 0;
} }
} }
......
...@@ -417,7 +417,7 @@ DMA_WaitDevice(_THIS) ...@@ -417,7 +417,7 @@ DMA_WaitDevice(_THIS)
that use a different process id for each thread. that use a different process id for each thread.
*/ */
if (parent && (((++cnt) % 10) == 0)) { /* Check every 10 loops */ if (parent && (((++cnt) % 10) == 0)) { /* Check every 10 loops */
if (kill(parent, 0) < 0) { if (kill(parent, 0) < 0 && errno == ESRCH) {
this->enabled = 0; this->enabled = 0;
} }
} }
......
...@@ -128,7 +128,7 @@ ESD_WaitDevice(_THIS) ...@@ -128,7 +128,7 @@ ESD_WaitDevice(_THIS)
*/ */
/* Check every 10 loops */ /* Check every 10 loops */
if (this->hidden->parent && (((++cnt) % 10) == 0)) { 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; this->enabled = 0;
} }
} }
......
...@@ -165,7 +165,7 @@ PULSEAUDIO_WaitDevice(_THIS) ...@@ -165,7 +165,7 @@ PULSEAUDIO_WaitDevice(_THIS)
*/ */
/* Check every 10 loops */ /* Check every 10 loops */
if (this->hidden->parent && (((++cnt) % 10) == 0)) { 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; this->enabled = 0;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment