Changeset 6665

Show
Ignore:
Timestamp:
06/20/09 12:38:08 (15 months ago)
Author:
dbaelde
Message:

Add blocking sections around file_new and file_new_type.
Those calls can indeed be long, when the file is ill-formed (e.g., when
trying to decode a .wav as a .mp3).
But this fixes an even nastier bug in liquidsoap running in daemon mode.
In that mode, liquidsoap attaches stderr to a pipe and has a task reading
this pipe and logging its contents. Since file_new* can write to stderr,
they could create a deadlock: the caml global lock is taken so the reading
task cannot read, the pipe becomes full and blocks file_new*.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/ocaml-taglib/src/taglib_stubs.c

    r4954 r6665  
    4646#include <caml/fail.h> 
    4747#include <caml/memory.h> 
     48#include <caml/signals.h> 
    4849 
    4950CAMLprim value caml_taglib_init() 
     
    9192{ 
    9293  CAMLparam1(name); 
    93   TagLib_File *f = taglib_file_new((const char *)String_val(name)) ; 
     94 
     95  int len = caml_string_length(name); 
     96  char *filename = malloc(len); 
     97  memcpy(filename, String_val(name), len); 
     98 
     99  caml_enter_blocking_section(); 
     100  TagLib_File *f = taglib_file_new(filename) ; 
     101  caml_leave_blocking_section(); 
     102 
     103  free(filename); 
    94104 
    95105  if (f == NULL) 
     
    102112{ 
    103113  CAMLparam2(name,type); 
    104   TagLib_File *f = taglib_file_new_type((const char *)String_val(name),Int_val(type)) ; 
     114 
     115  int len = caml_string_length(name); 
     116  char *filename = malloc(len); 
     117  memcpy(filename, String_val(name), len); 
     118 
     119  caml_enter_blocking_section(); 
     120  TagLib_File *f = 
     121    taglib_file_new_type((const char *)String_val(name),Int_val(type)) ; 
     122  caml_leave_blocking_section(); 
     123 
     124  free(filename); 
    105125 
    106126  if (f == NULL)