开发者

Ruby FFI - trapping C calls to exit()

开发者 https://www.devze.com 2023-02-16 14:26 出处:网络
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

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.


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...

0

精彩评论

暂无评论...
验证码 换一张
取 消