mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-22 09:58:09 +00:00
criu: fix log_keep_err signal deadlock
When using pr_err in signal handler, locking is used in an unsafe manner. If another signal happens while holding the lock, deadlock can happen. To fix this, we can introduce mutex_trylock similar to pthread_mutex_trylock that returns immediately. Due to the fact that lock is used only for writing first_err, this change garantees that deadlock cannot happen. Fixes: #358 Signed-off-by: Ivan Pravdin <ipravdin.official@gmail.com>
This commit is contained in:
parent
25f7185202
commit
2a428d20ce
@ -132,11 +132,12 @@ static void log_note_err(char *msg)
|
|||||||
* anyway, so it doesn't make much sense to try hard
|
* anyway, so it doesn't make much sense to try hard
|
||||||
* and optimize this out.
|
* and optimize this out.
|
||||||
*/
|
*/
|
||||||
mutex_lock(&first_err->l);
|
if (mutex_trylock(&first_err->l)) {
|
||||||
if (first_err->s[0] == '\0')
|
if (first_err->s[0] == '\0')
|
||||||
__strlcpy(first_err->s, msg, sizeof(first_err->s));
|
__strlcpy(first_err->s, msg, sizeof(first_err->s));
|
||||||
mutex_unlock(&first_err->l);
|
mutex_unlock(&first_err->l);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char *log_first_err(void)
|
char *log_first_err(void)
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#define __CR_COMMON_LOCK_H__
|
#define __CR_COMMON_LOCK_H__
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <linux/futex.h>
|
#include <linux/futex.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
@ -162,6 +163,11 @@ static inline void mutex_lock(mutex_t *m)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool mutex_trylock(mutex_t *m)
|
||||||
|
{
|
||||||
|
return atomic_inc_return(&m->raw) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
static inline void mutex_unlock(mutex_t *m)
|
static inline void mutex_unlock(mutex_t *m)
|
||||||
{
|
{
|
||||||
uint32_t c = 0;
|
uint32_t c = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user