summaryrefslogtreecommitdiff
path: root/pcsound
diff options
context:
space:
mode:
authorSimon Howard2007-09-03 00:43:29 +0000
committerSimon Howard2007-09-03 00:43:29 +0000
commit604e09624e22148458ddb12526f2646e600f29bd (patch)
tree56b5a4d399b87199c78220ed5adf31e8094ff82b /pcsound
parent0517fad3f4e89304dc7a4ad18c5785e02173ca6c (diff)
downloadchocolate-doom-604e09624e22148458ddb12526f2646e600f29bd.tar.gz
chocolate-doom-604e09624e22148458ddb12526f2646e600f29bd.tar.bz2
chocolate-doom-604e09624e22148458ddb12526f2646e600f29bd.zip
Try to open /dev/speaker in the parent process, so that we can tell if
we don't have permission to open it before we fork. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 966
Diffstat (limited to 'pcsound')
-rw-r--r--pcsound/pcsound_bsd.c39
1 files changed, 19 insertions, 20 deletions
diff --git a/pcsound/pcsound_bsd.c b/pcsound/pcsound_bsd.c
index 00367d1f..68884e0e 100644
--- a/pcsound/pcsound_bsd.c
+++ b/pcsound/pcsound_bsd.c
@@ -142,25 +142,11 @@ static void AdjustedBeep(int speaker_handle, int ms, int freq)
sleep_adjust = actual_time - ms;
}
-static void SoundServer(void)
+static void SoundServer(int speaker_handle)
{
- int speaker_handle;
tone_t tone;
int result;
- // Try to open the speaker device
-
- speaker_handle = open(SPEAKER_DEVICE, O_WRONLY);
-
- if (speaker_handle == -1)
- {
- // Don't have permissions for the console device?
-
- fprintf(stderr, "PCSound_BSD_Init: Failed to open '%s': %s\n",
- SPEAKER_DEVICE, strerror(errno));
- return;
- }
-
// Run in a loop, invoking the callback
for (;;)
@@ -181,10 +167,6 @@ static void SoundServer(void)
AdjustedBeep(speaker_handle, tone.duration, tone.frequency);
}
-
- // Finished, close the handle
-
- close(speaker_handle);
}
// Start up the sound server. Returns non-zero if successful.
@@ -192,12 +174,27 @@ static void SoundServer(void)
static int StartSoundServer(void)
{
int result;
+ int speaker_handle;
+
+ // Try to open the speaker device
+
+ speaker_handle = open(SPEAKER_DEVICE, O_WRONLY);
+
+ if (speaker_handle == -1)
+ {
+ // Don't have permissions for the console device?
+
+ fprintf(stderr, "StartSoundServer: Failed to open '%s': %s\n",
+ SPEAKER_DEVICE, strerror(errno));
+ return 0;
+ }
// Create a pipe for communications
if (socketpair(AF_UNIX, SOCK_STREAM, 0, sound_server_pipe) < 0)
{
perror("socketpair");
+ close(speaker_handle);
return 0;
}
@@ -210,13 +207,15 @@ static int StartSoundServer(void)
if (result < 0)
{
fprintf(stderr, "Failed to fork sound server!\n");
+ close(speaker_handle);
return 0;
}
else if (result == 0)
{
// This is the child (sound server)
- SoundServer();
+ SoundServer(speaker_handle);
+ close(speaker_handle);
exit(0);
}