diff options
author | Bui Nguyen Quoc Thanh <thanh.buinguyenquoc@vn.bosch.com> | 2020-09-23 10:30:07 +0700 |
---|---|---|
committer | Saya Sugiura <39760799+ssugiura@users.noreply.github.com> | 2021-01-06 09:27:28 +0900 |
commit | 1bbccc2bb07109007fecaf8007a6552d056edb66 (patch) | |
tree | 1af55bffa6705c45aeb3c81ac9816ac538d22f2e /src | |
parent | 2fa8b0d10a401aadab068015c0c08dd4d39e6c98 (diff) | |
download | DLT-daemon-1bbccc2bb07109007fecaf8007a6552d056edb66.tar.gz |
libdlt: Use SIGUSR1 for thread on Android
Since bionic does not support pthread_cancel(),
try to terminate housekeeper thread via SIGUSR1.
Signed-off-by: Bui Nguyen Quoc Thanh <thanh.buinguyenquoc@vn.bosch.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/dlt_user.c | 35 | ||||
-rw-r--r-- | src/lib/dlt_user_cfg.h | 6 |
2 files changed, 36 insertions, 5 deletions
diff --git a/src/lib/dlt_user.c b/src/lib/dlt_user.c index f1c1864..795bfbd 100644 --- a/src/lib/dlt_user.c +++ b/src/lib/dlt_user.c @@ -3621,13 +3621,31 @@ static void dlt_user_cleanup_handler(void *arg) void dlt_user_housekeeperthread_function(__attribute__((unused)) void *ptr) { struct timespec ts; + bool in_loop = true; + +#ifdef __ANDROID_API__ + sigset_t set; + sigset_t pset; + /* + * bionic is not supporting pthread_cancel so + * use SIGUSR1 to kill thread properly. + */ + sigemptyset(&set); + sigaddset(&set, SIGUSR1); + if (pthread_sigmask(SIG_BLOCK, &set, NULL) != 0) { + dlt_vlog(LOG_ERR, "Failed to block signal with error [%s]\n", + strerror(errno)); + in_loop = false; + } +#endif + #ifdef linux prctl(PR_SET_NAME, "dlt_housekeeper", 0, 0, 0); #endif pthread_cleanup_push(dlt_user_cleanup_handler, NULL); - while (1) { + while (in_loop) { /* Check for new messages from DLT daemon */ if (!dlt_user.disable_injection_msg) if (dlt_user_log_check_user_message() < DLT_RETURN_OK) @@ -3640,6 +3658,19 @@ void dlt_user_housekeeperthread_function(__attribute__((unused)) void *ptr) /* flush buffer to DLT daemon if possible */ if (dlt_user.dlt_log_handle != DLT_FD_INIT) dlt_user_log_resend_buffer(); + +#ifdef __ANDROID_API__ + if (sigpending(&pset)) { + dlt_vlog(LOG_ERR, "sigpending failed with error [%s]!\n", strerror(errno)); + break; + } + + if (sigismember(&pset, SIGUSR1)) { + dlt_log(LOG_NOTICE, "Received SIGUSR1! Stop thread\n"); + break; + } +#endif + /* delay */ ts.tv_sec = 0; ts.tv_nsec = DLT_USER_RECEIVE_NDELAY; @@ -4796,7 +4827,7 @@ void dlt_stop_threads() #ifdef DLT_NETWORK_TRACE_ENABLE dlt_lock_mutex(&mq_mutex); #endif /* DLT_NETWORK_TRACE_ENABLE */ - dlt_housekeeperthread_result = pthread_kill(dlt_housekeeperthread_handle, SIGKILL); + dlt_housekeeperthread_result = pthread_kill(dlt_housekeeperthread_handle, SIGUSR1); dlt_user_cleanup_handler(NULL); #endif diff --git a/src/lib/dlt_user_cfg.h b/src/lib/dlt_user_cfg.h index 93d3206..d394daa 100644 --- a/src/lib/dlt_user_cfg.h +++ b/src/lib/dlt_user_cfg.h @@ -123,12 +123,12 @@ /* default message id for non-verbose mode, if no message id was provided */ #define DLT_USER_DEFAULT_MSGID 0xffff -/* delay for housekeeper thread (nsec) while receiving messages*/ -#define DLT_USER_RECEIVE_NDELAY (500 * 1000 * 1000) - /* timeout for poll operations in milliseconds*/ #define DLT_USER_RECEIVE_MDELAY (500) +/* delay for housekeeper thread (nsec) while receiving messages*/ +#define DLT_USER_RECEIVE_NDELAY (DLT_USER_RECEIVE_MDELAY * 1000 * 1000) + /* Name of environment variable for local print mode */ #define DLT_USER_ENV_LOCAL_PRINT_MODE "DLT_LOCAL_PRINT_MODE" |