如何处理共享库调用exit()并意外销毁全局对象?

huangapple go评论100阅读模式
英文:

How to handle a shared lib calling exit() and unexpectedly destroying global objects?

问题

一个应用程序使用librpm.so,它通过调用exit()来处理一些错误,例如当它接收到SIGPIPE信号时。这导致glibc在其他线程正在访问它们时销毁本地静态对象,从而导致崩溃。

在glibc开始销毁静态实例之前,是否有一种方法可以让应用程序进行清理(取消初始化使用线程的模块)?这些模块是从编译后的共享库中启动的。

英文:

An application uses librpm.so, which handles some errors by calling exit(), for example when it receives a SIGPIPE. This results in glibc destroying local static objects while other threads are accessing them, resulting in a crash.

Is there a way for the application to clean up (uninitialize modules that use threads) before glibc starts destroying static instances ? These modules are started from compiled shared libraries.

答案1

得分: 1

你可以主动捕获 SIGPIPE 信号,然后再库处理之前。

示例:https://www.thegeekstuff.com/2012/03/catch-signals-sample-c-code/

英文:

You can be proactive a catch SIGPIPE before the library takes it.

Example: https://www.thegeekstuff.com/2012/03/catch-signals-sample-c-code/

huangapple
  • 本文由 发表于 2023年8月5日 02:09:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76838274.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定