<p>Pau Espin Pedrol has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/10739">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">Logger: Disable pthread cancel point inside Logger destructor<br><br>pthread_cancel is implemented in c++ using exception handlers. In<br>destructor of Log object, the log function is called which will<br>eventually call fputs() to write to a file. Since that function is<br>considered a cancelation point, if pthread_cancel has been called the<br>exception handler will start unstacking frames and calling destructors<br>in the process. At some point this will cause a runtime exception in c++<br>which will call std::terminate() to abort the process.<br><br>The solution is thus to avoid starting the cancellation process inside the<br>destructor.<br><br>This behavior was spotted while calling the destructor of Transceiver<br>object in forthcoming patches.<br><br>See a more detailed example here:<br>https://skaark.wordpress.com/2010/08/26/pthread_cancel-considered-harmful/<br><br>Change-Id: I71ca90f3fbc73df58b878a03361f7b7831d838b4<br>---<br>M CommonLibs/Logger.cpp<br>1 file changed, 3 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/39/10739/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/CommonLibs/Logger.cpp b/CommonLibs/Logger.cpp</span><br><span>index 393d882..171c635 100644</span><br><span>--- a/CommonLibs/Logger.cpp</span><br><span>+++ b/CommonLibs/Logger.cpp</span><br><span>@@ -44,6 +44,8 @@</span><br><span> </span><br><span> Log::~Log()</span><br><span> {</span><br><span style="color: hsl(120, 100%, 40%);">+      int old_state;</span><br><span style="color: hsl(120, 100%, 40%);">+        pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &old_state);</span><br><span>      int mlen = mStream.str().size();</span><br><span>     int neednl = (mlen==0 || mStream.str()[mlen-1] != '\n');</span><br><span>     const char *fmt = neednl ? "%s\n" : "%s";</span><br><span>@@ -51,6 +53,7 @@</span><br><span>    // The COUT() macro prevents messages from stomping each other but adds uninteresting thread numbers,</span><br><span>        // so just use std::cout.</span><br><span>    LOGPSRC(mCategory, mPriority, filename, line, fmt, mStream.str().c_str());</span><br><span style="color: hsl(120, 100%, 40%);">+    pthread_setcancelstate(old_state, NULL);</span><br><span> }</span><br><span> </span><br><span> ostringstream& Log::get()</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/10739">change 10739</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/10739"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: osmo-trx </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I71ca90f3fbc73df58b878a03361f7b7831d838b4 </div>
<div style="display:none"> Gerrit-Change-Number: 10739 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Pau Espin Pedrol <pespin@sysmocom.de> </div>