From 1348d1c07dbda69c32317738b8e9c69734f181c3 Mon Sep 17 00:00:00 2001 From: Saya Sugiura Date: Tue, 22 May 2018 20:40:51 +0900 Subject: lib: daemon: Fix sem lock potential issue sem_wait may return an error if a signal is received while waiting for the lock,and therefore not take the lock before returning. Changed to have a while loop. Signed-off-by: Saya Sugiura --- include/dlt/dlt_user.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/dlt/dlt_user.h b/include/dlt/dlt_user.h index d736032..b885eaf 100644 --- a/include/dlt/dlt_user.h +++ b/include/dlt/dlt_user.h @@ -94,8 +94,11 @@ extern "C" { # define DLT_USER_RESENDBUF_MAX_SIZE (DLT_USER_BUF_MAX_SIZE + 100) /**< Size of resend buffer; Max DLT message size is 1390 bytes plus some extra header space */ /* Use a semaphore or mutex from your OS to prevent concurrent access to the DLT buffer. */ -# define DLT_SEM_LOCK() { sem_wait(&dlt_mutex); } -# define DLT_SEM_FREE() { sem_post(&dlt_mutex); } +#define DLT_SEM_LOCK() do{\ + while ((sem_wait(&dlt_mutex) == -1) && (errno == EINTR)) \ + continue; /* Restart if interrupted */ \ + } while(0) +#define DLT_SEM_FREE() { sem_post(&dlt_mutex); } /** * This structure is used for every context used in an application. -- cgit v1.2.1