On Fri, May 28, 2004 at 12:26:15PM +0200, Bruno.Verlyck@inria.fr wrote: > # open Cash;; > # run_with_strings (fun () -> exec_path "ls" []);; > Exception: Sys_error "Bad file descriptor". > # Exception: Sys_error "Bad file descriptor". > I can't make any of the run_with_* that I've tried work, whether in > my programs or with cashtop. > > Ideas? (Cash 0.20) > Not a lot with so little info (of course it works here). Would you > mind sending me more OS details ? A backtrace would be very useful, > and/or the result of trace/truss/strace -f ? This is on Debian sid, Linux 2.6.6. I couldn't figure out how to get a backtrace. However, from the forked child, I see: [pid 9461] close(4) = 0 [pid 9461] close(4) = -1 EBADF (Bad file descriptor) (Full strace attached) Will try the patch. How does the CVS version rank in terms of stability? > That said, what comes to mind is that the behavior of close_{in,out} > has changed in Pervasives over the last versions of Caml. I wrote > some (too many) lines of code to make Cash.close_{in,out} work anyway. > I see in the CVS log that there was a change related to that, some > time after 3.07 (see the attached patch). You could try it, or even > try the entire CVS version of Cash. > > Bruno. > Index: io_3_2.ml > =================================================================== > RCS file: /net/pauillac/caml/repository/cash/io_3_2.ml,v > retrieving revision 1.47 > retrieving revision 1.48 > diff -c -a -r1.47 -r1.48 > *** io_3_2.ml 2002/08/05 17:07:37 1.47 > --- io_3_2.ml 2002/12/05 17:37:52 1.48 > *************** > *** 116,126 **** > Some fd -> > let res = low_close_fd fd in (* low_close_fd will tell it. *) > do { > ! close_any any_chan; (* Never raise exception in the current implementation. *) > res > } ] > in > (fun ichan -> close (anychan_of_ichan ichan), > fun ochan -> do { flush ochan; close (anychan_of_ochan ochan) }) > ; > > --- 116,129 ---- > Some fd -> > let res = low_close_fd fd in (* low_close_fd will tell it. *) > do { > ! (* Used to raise no exception, but this varies between implementations... *) > ! try close_any any_chan with [ Sys_error "Bad file descriptor" -> () ]; > res > } ] > in > (fun ichan -> close (anychan_of_ichan ichan), > + (* Current religion says: flush do nothing on a closed channel. *) > + (* Current implication is: if an unflushed channel's fd is closed, it's an error. *) > fun ochan -> do { flush ochan; close (anychan_of_ochan ochan) }) > ;