[cffi-devel] CFFI and wait (2)

Martin Simmons martin at lispworks.com
Tue Jun 1 14:55:32 UTC 2010


>>>>> On Tue, 1 Jun 2010 12:03:54 +0200, Lorenzo Villani said:
> 
> I'm trying to use CFFI in order to wrap execve (2). The wrapper also
> uses fork (2) and wait (2). While I have absolutely no problems with
> execve or fork I'm stumbling on a problem with wait.
> 
> Wait takes a pointer to an int to store child process' status. The
> problem is: after the call to wait the value stored in the pointer is
> the same as before the call.
> 
> I am using CFFI  0.10.5 and GNU CLISP 2.47 on Fedora 13.

Check the value returned by c-wait, because it sounds like it is getting an
error.  If it returns -1, then you need to check errno.

You should also use unwind-protect to ensure that foreign-free is called (or
use with-foreign-pointer instead of foreign-alloc and foreign-free).

I don't know about CLISP, but your code will not work reliably if the Lisp
implementation calls wait itself (e.g. in response to SIGCHLD).  If possible,
I would use a implementation-supplied function instead of trying to implement
execute-program yourself.

__Martin




More information about the cffi-devel mailing list