summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKHANH LUONG HONG DUY <khanh.luonghongduy@vn.bosch.com>2020-10-28 18:04:51 +0700
committerSaya Sugiura <39760799+ssugiura@users.noreply.github.com>2021-01-06 09:27:28 +0900
commitc50f2a7c8edb13e1373515e78193af94d4d8d9c9 (patch)
tree32da8520db4ca1eb5f97a0f6ef8b2f43c214d598
parent83c35bf15337caf335c429d12da1136a3d0c05ab (diff)
downloadDLT-daemon-c50f2a7c8edb13e1373515e78193af94d4d8d9c9.tar.gz
dlt-receive: flush stdout buffer by signal
When dlt-receive logs is redirecting to file then a terminating signal is sent to dlt-receive, it will stop without flushing all logs from stdout to file, due to the default size of stdout is 4096 byte. When dlt-receive receive the SIGTERM or SIGINT, it flushes stdout buffer to stdout before terminating. Signed-off-by: KHANH LUONG HONG DUY <khanh.luonghongduy@vn.bosch.com>
-rw-r--r--src/console/dlt-receive.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/console/dlt-receive.c b/src/console/dlt-receive.c
index cdfa274..1b5c112 100644
--- a/src/console/dlt-receive.c
+++ b/src/console/dlt-receive.c
@@ -75,6 +75,8 @@
#include <string.h>
#include <glob.h>
#include <syslog.h>
+#include <signal.h>
+#include <sys/socket.h>
#ifdef __linux__
# include <linux/limits.h>
#else
@@ -86,6 +88,24 @@
#define DLT_RECEIVE_ECU_ID "RECV"
+DltClient dltclient;
+
+void signal_handler(int signal)
+{
+ switch (signal) {
+ case SIGHUP:
+ case SIGTERM:
+ case SIGINT:
+ case SIGQUIT:
+ /* stop main loop */
+ shutdown(dltclient.receiver.fd, SHUT_RD);
+ break;
+ default:
+ /* This case should never happen! */
+ break;
+ } /* switch */
+}
+
/* Function prototypes */
int dlt_receive_message_callback(DltMessage *message, void *data);
@@ -290,7 +310,6 @@ void dlt_receive_close_output_file(DltReceiveData *dltdata)
*/
int main(int argc, char *argv[])
{
- DltClient dltclient;
DltReceiveData dltdata;
int c;
int index;
@@ -313,6 +332,15 @@ int main(int argc, char *argv[])
dltdata.totalbytes = 0;
dltdata.part_num = -1;
+ /* Config signal handler */
+ struct sigaction act;
+ act.sa_handler = signal_handler;
+ sigemptyset(&act.sa_mask);
+ sigaction(SIGHUP, &act, 0);
+ sigaction(SIGTERM, &act, 0);
+ sigaction(SIGINT, &act, 0);
+ sigaction(SIGQUIT, &act, 0);
+
/* Fetch command line arguments */
opterr = 0;