diff options
author | Saya Sugiura <ssugiura@jp.adit-jv.com> | 2018-06-28 11:15:47 +0900 |
---|---|---|
committer | Christoph Lipka <clipka@users.noreply.github.com> | 2018-12-21 10:16:46 +0100 |
commit | 037d33d0c1bc83ca79812340ea9120d13fd1c705 (patch) | |
tree | bf51eabc6ae30e17ab650dbc4ecfb9127b4da6d8 /src/lib/dlt_user.c | |
parent | 88b6b69f313f35267fb0bde533f8e1d2a742f771 (diff) | |
download | DLT-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>
Diffstat (limited to 'src/lib/dlt_user.c')
-rw-r--r-- | src/lib/dlt_user.c | 36 |
1 files changed, 35 insertions, 1 deletions
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 */ |