<table><tr><td style="">jpalecek edited the summary of this revision. <a href="https://phabricator.kde.org/transactions/detail/PHID-XACT-DREV-5s6fbumatj5ljah/" rel="noreferrer">(Show Details)</a>
</td><a style="text-decoration: none; padding: 4px 8px; margin: 0 8px 8px; float: right; color: #464C5C; font-weight: bold; border-radius: 3px; background-color: #F7F7F9; background-image: linear-gradient(to bottom,#fff,#f1f0f1); display: inline-block; border: 1px solid rgba(71,87,120,.2);" href="https://phabricator.kde.org/D8673" rel="noreferrer">View Revision</a></tr></table><br /><div><strong>CHANGES TO REVISION SUMMARY</strong><div><div style="white-space: pre-wrap; color: #74777D;">The TERM signal handling in ksmserver invokes functions which are not async-signal safe, like Qt functions and <span style="padding: 0 2px; color: #333333; background: rgba(251, 175, 175, .7);">C++<br />
</span><span style="padding: 0 2px; color: #333333; background: rgba(151, 234, 151, .6);">C++ </span>destructors. Moreover, the signal handling can occur in other than the main thread, which leads to Qt complaining about<span style="padding: 0 2px; color: #333333; background: rgba(151, 234, 151, .6);"> </span> functions being invoked from the wrong thread. Such a crash can be seen in a report of [[ bug 384316 |https://bugs.kde.org/show_bug.cgi?id=384316 ]].<br />
<br />
To fix both of these issues, this change makes the signal handling use the self-pipe trick, which signals the need for termination to the main thread by writing to a special-purpose file descriptor. The main<span style="padding: 0 2px; color: #333333; background: rgba(251, 175, 175, .7);"><br />
</span><span style="padding: 0 2px; color: #333333; background: rgba(151, 234, 151, .6);"> </span>loop then takes care of the termination. This is mostly inspired by [[ http://doc.qt.io/qt-5/unix-signals.html ]].<br />
<br />
Note that `QApplication::quit` already does what we need when destroying<span style="padding: 0 2px; color: #333333; background: rgba(251, 175, 175, .7);"><br />
</span><span style="padding: 0 2px; color: #333333; background: rgba(151, 234, 151, .6);"> </span>the server, particularly deleting `the_server`/calling `cleanUp()`.<br />
<br />
BTW I noticed the code (here and in XIO error handler) makes quite<span style="padding: 0 2px; color: #333333; background: rgba(251, 175, 175, .7);"><br />
</span><span style="padding: 0 2px; color: #333333; background: rgba(151, 234, 151, .6);"> </span>sure the_server is zeroed. However, other code in ksmserver is not <span style="padding: 0 2px; color: #333333; background: rgba(251, 175, 175, .7);">so<br />
</span><span style="padding: 0 2px; color: #333333; background: rgba(151, 234, 151, .6);">so </span>keen on checking `the_server` is !0 when using it.</div></div></div><br /><div><strong>REPOSITORY</strong><div><div>R120 Plasma Workspace</div></div></div><br /><div><strong>REVISION DETAIL</strong><div><a href="https://phabricator.kde.org/D8673" rel="noreferrer">https://phabricator.kde.org/D8673</a></div></div><br /><div><strong>To: </strong>jpalecek, Plasma<br /><strong>Cc: </strong>plasma-devel, ZrenBot, progwolff, lesliezhai, ali-mohamed, jensreuterberg, abetts, sebas, apol, mart<br /></div>