summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaya Sugiura <ssugiura@jp.adit-jv.com>2018-06-28 11:15:47 +0900
committerChristoph Lipka <clipka@users.noreply.github.com>2018-12-21 10:16:46 +0100
commit037d33d0c1bc83ca79812340ea9120d13fd1c705 (patch)
treebf51eabc6ae30e17ab650dbc4ecfb9127b4da6d8
parent88b6b69f313f35267fb0bde533f8e1d2a742f771 (diff)
downloadDLT-daemon-037d33d0c1bc83ca79812340ea9120d13fd1c705.tar.gz
lib: socket: Flush all data before closing socket
Sometimes socket will be closed even not all of the data is flushed to daemon. So before closing, following will be handled: 1. Use shutdown() to shut down further transmissions 2. Subsequent read() to resend_buffer Also socket fd is reset in child fork handler since the socket itself will not be duplicated in the child process. Solves JIRA: SWGIII-28702 Signed-off-by: Saya Sugiura <ssugiura@jp.adit-jv.com>
-rw-r--r--src/lib/dlt_env_ll.c7
-rw-r--r--src/lib/dlt_user.c36
2 files changed, 40 insertions, 3 deletions
diff --git a/src/lib/dlt_env_ll.c b/src/lib/dlt_env_ll.c
index a3e3a16..aeaa1d3 100644
--- a/src/lib/dlt_env_ll.c
+++ b/src/lib/dlt_env_ll.c
@@ -354,8 +354,11 @@ void dlt_env_free_ll_set(dlt_env_ll_set * const ll_set)
return;
}
- free(ll_set->item);
- ll_set->item = NULL;
+ if (!ll_set->item)
+ {
+ free(ll_set->item);
+ ll_set->item = NULL;
+ }
ll_set->array_size = 0u;
ll_set->num_elem = 0u;
}
diff --git a/src/lib/dlt_user.c b/src/lib/dlt_user.c
index 34a5a3f..19bde1b 100644
--- a/src/lib/dlt_user.c
+++ b/src/lib/dlt_user.c
@@ -808,6 +808,7 @@ static void dlt_user_free_buffer(unsigned char **buffer)
DltReturnValue dlt_free(void)
{
uint32_t i;
+ int ret = 0;
#ifndef DLT_USE_UNIX_SOCKET_IPC
char filename[DLT_USER_MAX_FILENAME_LENGTH];
#endif
@@ -846,7 +847,39 @@ DltReturnValue dlt_free(void)
if (dlt_user.dlt_log_handle!=-1)
{
/* close log file/output fifo to daemon */
- close(dlt_user.dlt_log_handle);
+#ifdef DLT_USE_UNIX_SOCKET_IPC
+ ret = shutdown(dlt_user.dlt_log_handle, SHUT_WR);
+ if (ret < 0)
+ {
+ dlt_vlog(LOG_WARNING, "%s: shutdown failed: %s\n", __func__, strerror(errno));
+ }
+ else
+ {
+ while (1)
+ {
+ ssize_t bytes_read;
+
+ bytes_read = read(dlt_user.dlt_log_handle, dlt_user.resend_buffer, dlt_user.log_buf_len);
+ if (bytes_read < 0)
+ {
+ dlt_vlog(LOG_DEBUG, "%s - %d: Reading...\n", __func__, __LINE__);
+ break;
+ }
+ else
+ {
+ dlt_vlog(LOG_DEBUG, "%s - %d: %d bytes read from resend buffer\n", __func__, __LINE__);
+ if (!bytes_read)
+ break;
+ }
+ }
+ }
+#endif
+ ret = close(dlt_user.dlt_log_handle);
+ if (ret < 0)
+ {
+ dlt_vlog(LOG_WARNING, "%s: close failed: %s\n", __func__, strerror(errno));
+ }
+
dlt_user.dlt_log_handle = -1;
}
@@ -5019,6 +5052,7 @@ static void dlt_fork_child_fork_handler()
if (dlt_user_initialised)
{
/* don't start anything else but cleanup everything and avoid blow-out of buffers*/
+ dlt_user.dlt_log_handle = -1;
dlt_log_free();
dlt_free();
/* the only thing that remains is the atexit-handler */