[cffi-devel] Re: trapping C exit

Luís Oliveira luismbo at gmail.com
Tue Mar 21 12:28:38 UTC 2006


hbabcockos1 at mac.com writes:
> Is there a way to trap a call to exit made in a C library and prevent
> it from stopping the currently running Lisp process? I'm struggling
> with an annoying C library function that was written to call exit()
> if it didn't get the arguments that it expected (or sometimes to call
> exit() even if it did get the expected arguments).

This is quite annoying and I've run into this problem myself in cl-glut.
You have a couple of solutions:

  a) Try hard no to cause the library to call exit(). Eg: check the
     arguments in the lisp side before calling out to C, always try to
     be in a usable state. For instance, in cl-glut, I call glutInit()
     at load time and also right after returning from its event
     loop. This way the library is always initialized and won't exit()
     and kill the lisp because the user called some function without
     initializing it first.

  b) Avoid the library. :-) Again, this is pretty much what I did in
     cl-glut. GLUT always calls exit() instead of returning from the
     event loop so I'm using FreeGLUT.

  c) Override exit() using LD_PRELOAD. This one I have not tried and I
     don't if it'll work at all; probably not a good idea, but it might
     work for your specific function. See this Linux Journal article:

     "Modifying a Dynamic Library Without Changing the Source Code"
     http://www.linuxjournal.com/node/7795/print

HTH

-- 
Luís Oliveira
luismbo (@) gmail (.) com
Equipa Portuguesa do Translation Project
http://www.iro.umontreal.ca/translation/registry.cgi?team=pt




More information about the cffi-devel mailing list