Skip to content

Commit c95aa47

Browse files
committed
fix(Mutex_POSIX): prevent deadlocks when logging inside signal handlers
Fixes #4939.
1 parent ee4f89f commit c95aa47

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

Foundation/include/Poco/Mutex_POSIX.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "Poco/Exception.h"
2323
#include <pthread.h>
2424
#include <errno.h>
25+
#include <signal.h>
2526

2627

2728
namespace Poco {
@@ -40,6 +41,7 @@ class Foundation_API MutexImpl
4041

4142
private:
4243
pthread_mutex_t _mutex;
44+
sigset_t set, oldset;
4345
};
4446

4547

@@ -56,6 +58,8 @@ class Foundation_API FastMutexImpl: public MutexImpl
5658
//
5759
inline void MutexImpl::lockImpl()
5860
{
61+
sigfillset(&set);
62+
pthread_sigmask(SIG_BLOCK, &set, &oldset);
5963
if (pthread_mutex_lock(&_mutex))
6064
throw SystemException("cannot lock mutex");
6165
}
@@ -77,6 +81,7 @@ inline void MutexImpl::unlockImpl()
7781
{
7882
if (pthread_mutex_unlock(&_mutex))
7983
throw SystemException("cannot unlock mutex");
84+
pthread_sigmask(SIG_SETMASK, &oldset, NULL);
8085
}
8186

8287

0 commit comments

Comments
 (0)