hbabcockos1@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