music_cmd.c
branchSDL-1.2
changeset 892 9dd046cb6cd7
parent 573 23d69b6621d0
child 893 3d9130c0136d
equal deleted inserted replaced
890:ae9b46ccd5ab 892:9dd046cb6cd7
    51 	music = (MusicCMD *)SDL_malloc(sizeof *music);
    51 	music = (MusicCMD *)SDL_malloc(sizeof *music);
    52 	if ( music == NULL ) {
    52 	if ( music == NULL ) {
    53 		Mix_SetError("Out of memory");
    53 		Mix_SetError("Out of memory");
    54 		return(NULL);
    54 		return(NULL);
    55 	}
    55 	}
    56 	music->file = SDL_strdup(file);
    56 	strncpy(music->file, file, (sizeof music->file)-1);
    57 	music->cmd = SDL_strdup(cmd);
    57 	music->file[(sizeof music->file)-1] = '\0';
       
    58 	strncpy(music->cmd, cmd, (sizeof music->cmd)-1);
       
    59 	music->cmd[(sizeof music->cmd)-1] = '\0';
    58 	music->pid = 0;
    60 	music->pid = 0;
    59 
    61 
    60 	/* We're done */
    62 	/* We're done */
    61 	return(music);
    63 	return(music);
    62 }
    64 }
   151 		Mix_SetError("fork() failed");
   153 		Mix_SetError("fork() failed");
   152 		return;
   154 		return;
   153 
   155 
   154 	    /* Child process - executes here */
   156 	    /* Child process - executes here */
   155 	    case 0: {
   157 	    case 0: {
   156 		    char *command;
   158 		    char command[PATH_MAX];
   157 		    char **argv;
   159 		    char **argv;
   158 
   160 
   159 		    /* Unblock signals in case we're called from a thread */
   161 		    /* Unblock signals in case we're called from a thread */
   160 		    {
   162 		    {
   161 			sigset_t mask;
   163 			sigset_t mask;
   162 			sigemptyset(&mask);
   164 			sigemptyset(&mask);
   163 			sigprocmask(SIG_SETMASK, &mask, NULL);
   165 			sigprocmask(SIG_SETMASK, &mask, NULL);
   164 		    }
   166 		    }
   165 
   167 
   166 		    /* Execute the command */
   168 		    /* Execute the command */
   167 		    command = SDL_strdup(music->cmd);
   169 		    strcpy(command, music->cmd);
   168 		    argv = parse_args(command, music->file);
   170 		    argv = parse_args(command, music->file);
   169 		    if ( argv != NULL ) {
   171 		    if ( argv != NULL ) {
   170 			execvp(argv[0], argv);
   172 			execvp(argv[0], argv);
   171 		    }
   173 		    }
   172 		    SDL_free(command);
       
   173 
   174 
   174 		    /* exec() failed */
   175 		    /* exec() failed */
   175 		    perror(argv[0]);
   176 		    perror(argv[0]);
   176 		    _exit(-1);
   177 		    _exit(-1);
   177 		}
   178 		}
   216 }
   217 }
   217 
   218 
   218 /* Close the given music stream */
   219 /* Close the given music stream */
   219 void MusicCMD_FreeSong(MusicCMD *music)
   220 void MusicCMD_FreeSong(MusicCMD *music)
   220 {
   221 {
   221 	SDL_free(music->file);
       
   222 	SDL_free(music->cmd);
       
   223 	SDL_free(music);
   222 	SDL_free(music);
   224 }
   223 }
   225 
   224 
   226 /* Return non-zero if a stream is currently playing */
   225 /* Return non-zero if a stream is currently playing */
   227 int MusicCMD_Active(MusicCMD *music)
   226 int MusicCMD_Active(MusicCMD *music)