How to deal with errno and signal handler in Linux?

六月ゝ 毕业季﹏ 提交于 2019-12-05 22:54:32

The glibc documentation says:

signal handlers that call functions that may set errno or modify the floating-point environment must save their original values, and restore them before returning.

So go ahead and do that.

To those reading this who can't rewrite their signal handlers, there may be a workaround. If you're writing a multi-threaded program using pthreads, errno will be in thread-local storage. So you can possibly dedicate one thread to handle a signal and block the signal in all other threads.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!