Question

I have a Rails application with a FFI binding to a custom RPC system. Unfortunately, the C code calls exit() when it is unable to connect to the RPC server, terminating the entire Rails application.

Is it possible to trap calls to exit() in Ruby? I'd rather not have to change the C code.

Was it helpful?

Solution

You cannot trap a function call. However maybe you can link the C code with a dummy exit() function that will not actually exit.

The cleaner solution is by far to change the C code to give it a proper library behaviour.

You could also fork in ruby before doing the RPC call, a bit on the expensive side performance wise but would solve the issue too...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top