Fixed bug #877 release-1.2.9a
authorSam Lantinga <slouken@libsdl.org>
Fri, 06 Nov 2009 03:37:57 +0000
changeset 4674b52401dda92
parent 466 d3d060cb94a6
child 468 391babf75293
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
music.c
music_cmd.c
music_cmd.h
     1.1 --- a/configure.in	Thu Nov 05 00:02:50 2009 +0000
     1.2 +++ b/configure.in	Fri Nov 06 03:37:57 2009 +0000
     1.3 @@ -180,10 +180,22 @@
     1.4  
     1.5  AC_ARG_ENABLE([music-cmd],
     1.6  AC_HELP_STRING([--enable-music-cmd], [support an external music player [[default=yes]]]),
     1.7 -              [], [enable_music_cmd=yes])
     1.8 -if test x$enable_music_cmd = xyes; then
     1.9 -    SOURCES="$SOURCES $srcdir/music_cmd.c"
    1.10 -    EXTRA_CFLAGS="$EXTRA_CFLAGS -DCMD_MUSIC"
    1.11 +              [], [enable_music_cmd=detect])
    1.12 +if test "x$enable_music_cmd" != xno; then
    1.13 +    AC_CHECK_FUNCS([fork vfork])
    1.14 +    if test "x$ac_cv_func_fork" = "xyes"; then
    1.15 +        EXTRA_CFLAGS="$EXTRA_CFLAGS -DHAVE_FORK"
    1.16 +    elif test "x$ac_cv_func_vfork" = "xyes"; then
    1.17 +        EXTRA_CFLAGS="$EXTRA_CFLAGS -DHAVE_VFORK"
    1.18 +    elif test "x$enable_music_cmd" = "xyes"; then
    1.19 +        AC_MSG_ERROR([external music player not available on your platform])
    1.20 +    else
    1.21 +        enable_music_cmd=no
    1.22 +    fi
    1.23 +    if test "x$enable_music_cmd" != xno; then
    1.24 +        SOURCES="$SOURCES $srcdir/music_cmd.c"
    1.25 +        EXTRA_CFLAGS="$EXTRA_CFLAGS -DCMD_MUSIC"
    1.26 +    fi
    1.27  fi
    1.28  
    1.29  AC_ARG_ENABLE([music-wave],
     2.1 --- a/music.c	Thu Nov 05 00:02:50 2009 +0000
     2.2 +++ b/music.c	Fri Nov 06 03:37:57 2009 +0000
     2.3 @@ -32,11 +32,6 @@
     2.4  
     2.5  #include "SDL_mixer.h"
     2.6  
     2.7 -/* The music command hack is UNIX specific */
     2.8 -#ifndef unix
     2.9 -#undef CMD_MUSIC
    2.10 -#endif
    2.11 -
    2.12  #ifdef CMD_MUSIC
    2.13  #include "music_cmd.h"
    2.14  #endif
     3.1 --- a/music_cmd.c	Thu Nov 05 00:02:50 2009 +0000
     3.2 +++ b/music_cmd.c	Fri Nov 06 03:37:57 2009 +0000
     3.3 @@ -23,7 +23,7 @@
     3.4  
     3.5  /* This file supports an external command for playing music */
     3.6  
     3.7 -#if defined(unix) || defined(__MACOSX__) /* This is a UNIX-specific hack */
     3.8 +#ifdef CMD_MUSIC
     3.9  
    3.10  #include <sys/types.h>
    3.11  #include <sys/wait.h>
    3.12 @@ -143,7 +143,11 @@
    3.13  /* Start playback of a given music stream */
    3.14  void MusicCMD_Start(MusicCMD *music)
    3.15  {
    3.16 +#ifdef HAVE_FORK
    3.17  	music->pid = fork();
    3.18 +#else
    3.19 +	music->pid = vfork();
    3.20 +#endif
    3.21  	switch(music->pid) {
    3.22  	    /* Failed fork() system call */
    3.23  	    case -1:
    3.24 @@ -235,4 +239,4 @@
    3.25  	return(active);
    3.26  }
    3.27  
    3.28 -#endif /* unix */
    3.29 +#endif /* CMD_MUSIC */
     4.1 --- a/music_cmd.h	Thu Nov 05 00:02:50 2009 +0000
     4.2 +++ b/music_cmd.h	Fri Nov 06 03:37:57 2009 +0000
     4.3 @@ -22,7 +22,7 @@
     4.4  
     4.5  /* This file supports an external command for playing music */
     4.6  
     4.7 -#if defined(unix) || defined(__MACOSX__) /* This is a UNIX-specific hack */
     4.8 +#ifdef CMD_MUSIC
     4.9  
    4.10  #include <sys/types.h>
    4.11  #include <limits.h>
    4.12 @@ -60,4 +60,4 @@
    4.13  /* Return non-zero if a stream is currently playing */
    4.14  extern int MusicCMD_Active(MusicCMD *music);
    4.15  
    4.16 -#endif /* unix */
    4.17 +#endif /* CMD_MUSIC */