From fe18ede121e5782676ccec4f29b29e1a1fc7b48f Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 6 Nov 2009 03:37:57 +0000 Subject: [PATCH] Fixed bug #877 Mike Frysinger 2009-11-05 09:11:43 PST the current code assumes "unix" means fork() exists. this doesnt work for no-mmu linux systems as fork() cant be implemented. simple enough to add fork/vfork tests to configure and let the rest of the code key off of CMD_MUSIC like normal -- no more needing to hardcode unix/mac-os-x defines in the source. --- configure.in | 20 ++++++++++++++++---- music.c | 5 ----- music_cmd.c | 8 ++++++-- music_cmd.h | 4 ++-- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/configure.in b/configure.in index fad60238..7a91c3e9 100644 --- a/configure.in +++ b/configure.in @@ -180,10 +180,22 @@ dnl Check command-line options AC_ARG_ENABLE([music-cmd], AC_HELP_STRING([--enable-music-cmd], [support an external music player [[default=yes]]]), - [], [enable_music_cmd=yes]) -if test x$enable_music_cmd = xyes; then - SOURCES="$SOURCES $srcdir/music_cmd.c" - EXTRA_CFLAGS="$EXTRA_CFLAGS -DCMD_MUSIC" + [], [enable_music_cmd=detect]) +if test "x$enable_music_cmd" != xno; then + AC_CHECK_FUNCS([fork vfork]) + if test "x$ac_cv_func_fork" = "xyes"; then + EXTRA_CFLAGS="$EXTRA_CFLAGS -DHAVE_FORK" + elif test "x$ac_cv_func_vfork" = "xyes"; then + EXTRA_CFLAGS="$EXTRA_CFLAGS -DHAVE_VFORK" + elif test "x$enable_music_cmd" = "xyes"; then + AC_MSG_ERROR([external music player not available on your platform]) + else + enable_music_cmd=no + fi + if test "x$enable_music_cmd" != xno; then + SOURCES="$SOURCES $srcdir/music_cmd.c" + EXTRA_CFLAGS="$EXTRA_CFLAGS -DCMD_MUSIC" + fi fi AC_ARG_ENABLE([music-wave], diff --git a/music.c b/music.c index dbd5737e..03d55817 100644 --- a/music.c +++ b/music.c @@ -32,11 +32,6 @@ #include "SDL_mixer.h" -/* The music command hack is UNIX specific */ -#ifndef unix -#undef CMD_MUSIC -#endif - #ifdef CMD_MUSIC #include "music_cmd.h" #endif diff --git a/music_cmd.c b/music_cmd.c index c3e694b7..5a43ddcd 100644 --- a/music_cmd.c +++ b/music_cmd.c @@ -23,7 +23,7 @@ /* This file supports an external command for playing music */ -#if defined(unix) || defined(__MACOSX__) /* This is a UNIX-specific hack */ +#ifdef CMD_MUSIC #include #include @@ -143,7 +143,11 @@ static char **parse_args(char *command, char *last_arg) /* Start playback of a given music stream */ void MusicCMD_Start(MusicCMD *music) { +#ifdef HAVE_FORK music->pid = fork(); +#else + music->pid = vfork(); +#endif switch(music->pid) { /* Failed fork() system call */ case -1: @@ -235,4 +239,4 @@ int MusicCMD_Active(MusicCMD *music) return(active); } -#endif /* unix */ +#endif /* CMD_MUSIC */ diff --git a/music_cmd.h b/music_cmd.h index 2a1b8da4..41757a86 100644 --- a/music_cmd.h +++ b/music_cmd.h @@ -22,7 +22,7 @@ /* This file supports an external command for playing music */ -#if defined(unix) || defined(__MACOSX__) /* This is a UNIX-specific hack */ +#ifdef CMD_MUSIC #include #include @@ -60,4 +60,4 @@ extern void MusicCMD_FreeSong(MusicCMD *music); /* Return non-zero if a stream is currently playing */ extern int MusicCMD_Active(MusicCMD *music); -#endif /* unix */ +#endif /* CMD_MUSIC */