summaryrefslogtreecommitdiff
path: root/src/daemon
diff options
context:
space:
mode:
authorS. Hameed <shameed@jp.adit-jv.com>2015-08-05 15:22:20 +0900
committerLutz Helwing <lutz_helwing@mentor.com>2015-11-24 09:48:42 +0100
commit8ed28dc15429a736c8404d491ed73fd0b04235e2 (patch)
tree0c1c68a5a58c59c3936986a4495c467798b7964b /src/daemon
parentda4ac57d87108d8b2690979c273c000a798a59f5 (diff)
downloadDLT-daemon-8ed28dc15429a736c8404d491ed73fd0b04235e2.tar.gz
Offline logstorage: Offline logstorage feature
Features: 1. Offline log storage to internal and external devices (PATH based trigger) 2. File options configurable in dlt.conf a : Appends timestamp in log file name (OfflineLogstorageTimestamp) b : Appends delimiter in log file name (OfflineLogstorageDelimiter) c : Wrap around value for log file count in file name (OfflineLogstorageMaxCounter) 3. Common config file parser support Signed-off-by: S. Hameed <shameed@jp.adit-jv.com> Signed-off-by: Christoph Lipka <clipka@jp.adit-jv.com>
Diffstat (limited to 'src/daemon')
-rw-r--r--src/daemon/dlt-daemon.c48
-rw-r--r--src/daemon/dlt-daemon.h6
-rw-r--r--src/daemon/dlt.conf13
-rw-r--r--src/daemon/dlt_daemon_client.c63
-rw-r--r--src/daemon/dlt_daemon_offline_logstorage.c71
-rw-r--r--src/daemon/dlt_daemon_offline_logstorage.h17
6 files changed, 185 insertions, 33 deletions
diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c
index 20dda80..61aca56 100644
--- a/src/daemon/dlt-daemon.c
+++ b/src/daemon/dlt-daemon.c
@@ -63,6 +63,7 @@
#include "dlt_daemon_client.h"
#include "dlt_daemon_connection.h"
#include "dlt_daemon_event_handler.h"
+#include "dlt_daemon_offline_logstorage.h"
#if defined(DLT_SYSTEMD_WATCHDOG_ENABLE) || defined(DLT_SYSTEMD_ENABLE)
#include "sd-daemon.h"
@@ -231,6 +232,12 @@ int option_file_parser(DltDaemonLocal *daemon_local)
memset(daemon_local->flags.pathToECUSoftwareVersion, 0, sizeof(daemon_local->flags.pathToECUSoftwareVersion));
daemon_local->flags.sendTimezone = 0;
daemon_local->flags.offlineLogstorageMaxDevices = 0;
+ daemon_local->flags.offlineLogstorageDirPath[0] = 0;
+ daemon_local->flags.offlineLogstorageMaxDevices = 0;
+ daemon_local->flags.offlineLogstorageTimestamp = 1;
+ daemon_local->flags.offlineLogstorageDelimiter = '_';
+ daemon_local->flags.offlineLogstorageMaxCounter = UINT_MAX;
+ daemon_local->flags.offlineLogstorageMaxCounterIdx = 0;
strncpy(daemon_local->flags.ctrlSockPath,
DLT_DAEMON_DEFAULT_CTRL_SOCK_PATH,
sizeof(daemon_local->flags.ctrlSockPath) - 1);
@@ -421,11 +428,38 @@ int option_file_parser(DltDaemonLocal *daemon_local)
daemon_local->flags.sendTimezone = atoi(value);
//printf("Option: %s=%s\n",token,value);
}
- else if(strcmp(token, "OfflineLogstorageMaxDevices")==0)
+ else if(strcmp(token, "OfflineLogstorageMaxDevices") == 0)
{
daemon_local->flags.offlineLogstorageMaxDevices = atoi(value);
}
- else if(strcmp(token,"ControlSocketPath")==0)
+ else if(strcmp(token, "OfflineLogstorageDirPath") == 0)
+ {
+ strncpy(daemon_local->flags.offlineLogstorageDirPath,
+ value,
+ sizeof(daemon_local->flags.offlineLogstorageDirPath) - 1);
+ }
+ else if(strcmp(token, "OfflineLogstorageTimestamp") == 0)
+ {
+ /* Check if set to 0, default otherwise */
+ if(atoi(value) == 0)
+ {
+ daemon_local->flags.offlineLogstorageTimestamp = 0;
+ }
+ }
+ else if(strcmp(token, "OfflineLogstorageDelimiter") == 0)
+ {
+ /* Check if valid punctuation, default otherwise*/
+ if(ispunct((char)value[0]))
+ {
+ daemon_local->flags.offlineLogstorageDelimiter = (char)value[0];
+ }
+ }
+ else if(strcmp(token, "OfflineLogstorageMaxCounter") == 0)
+ {
+ daemon_local->flags.offlineLogstorageMaxCounter = atoi(value);
+ daemon_local->flags.offlineLogstorageMaxCounterIdx = strlen(value);
+ }
+ else if(strcmp(token,"ControlSocketPath") == 0)
{
memset(
daemon_local->flags.ctrlSockPath,
@@ -537,6 +571,16 @@ int main(int argc, char* argv[])
}
/* --- Daemon init phase 2 end --- */
+ if(daemon_local.flags.offlineLogstorageDirPath[0])
+ {
+ if(dlt_daemon_logstorage_setup_internal_storage(&daemon,
+ daemon_local.flags.offlineLogstorageDirPath,
+ daemon_local.flags.vflag)==-1)
+ {
+ dlt_log(LOG_INFO,"Setting up internal offline log storage failed!\n");
+ }
+ }
+
// create fd for watchdog
#ifdef DLT_SYSTEMD_WATCHDOG_ENABLE
{
diff --git a/src/daemon/dlt-daemon.h b/src/daemon/dlt-daemon.h
index ab18d1f..503a98f 100644
--- a/src/daemon/dlt-daemon.h
+++ b/src/daemon/dlt-daemon.h
@@ -79,7 +79,6 @@
#include <dlt_offline_trace.h>
#include <sys/time.h>
-#include "dlt_daemon_offline_logstorage.h"
#define DLT_DAEMON_FLAG_MAX 256
/**
@@ -114,6 +113,11 @@ typedef struct
char pathToECUSoftwareVersion[DLT_DAEMON_FLAG_MAX]; /**< (String: Filename) The file from which to read the ECU version from. */
int sendTimezone; /**< (Boolean) Send Timezone perdiodically */
int offlineLogstorageMaxDevices; /**< (int) Maximum devices to be used as offline logstorage devices */
+ char offlineLogstorageDirPath[DLT_MOUNT_PATH_MAX]; /**< (String: Directory) DIR path to store offline logs */
+ int offlineLogstorageTimestamp; /**< (int) Append timestamp in offline logstorage filename */
+ char offlineLogstorageDelimiter; /**< (char) Append delimeter character in offline logstorage filename */
+ unsigned int offlineLogstorageMaxCounter; /**< (int) Maximum offline logstorage file counter index until wraparound */
+ unsigned int offlineLogstorageMaxCounterIdx; /**< (int) String len of offlineLogstorageMaxCounter*/
char userPipesDir[NAME_MAX + 1]; /**< (String: Directory) directory where dltpipes reside (Default: /tmp/dltpipes) */
char daemonFifoName[NAME_MAX + 1]; /**< (String: Filename) name of local fifo (Default: /tmp/dlt) */
unsigned int port; /**< port number */
diff --git a/src/daemon/dlt.conf b/src/daemon/dlt.conf
index 23d40ec..72377e5 100644
--- a/src/daemon/dlt.conf
+++ b/src/daemon/dlt.conf
@@ -132,3 +132,16 @@ ControlSocketPath = /tmp/dlt-ctrl.sock
# Store DLT log messages, if not set offline logstorage is off (Default: off)
# Maximum devices to be used as offline logstorage devices
# OfflineLogstorageMaxDevices = 1
+
+# Path to store DLT offline log storage messages (Default: off)
+# OfflineLogstorageDirPath = /opt
+
+# File options
+# Appends timestamp in log file name, Disable by setting to 0 (Default: 1)
+# OfflineLogstorageTimestamp = 0
+
+# Appends delimiter in log file name, allowed punctutations only (Default: _)
+# OfflineLogstorageDelimiter = _
+
+# Wrap around value for log file count in file name (Default: UINT_MAX)
+# OfflineLogstorageMaxCounter = 999
diff --git a/src/daemon/dlt_daemon_client.c b/src/daemon/dlt_daemon_client.c
index 89b5489..7658787 100644
--- a/src/daemon/dlt_daemon_client.c
+++ b/src/daemon/dlt_daemon_client.c
@@ -264,7 +264,13 @@ int dlt_daemon_client_send(int sock,DltDaemon *daemon,DltDaemonLocal *daemon_loc
* newly introduced dlt_daemon_log_internal */
if(daemon_local->flags.offlineLogstorageMaxDevices > 0)
{
- dlt_daemon_logstorage_write(daemon, daemon_local->flags.offlineLogstorageMaxDevices, storage_header, storage_header_size, data1, size1, data2, size2);
+ dlt_daemon_logstorage_write(daemon, daemon_local->flags,
+ storage_header,
+ storage_header_size,
+ data1,
+ size1,
+ data2,
+ size2);
}
}
@@ -1937,18 +1943,43 @@ void dlt_daemon_control_service_logstorage(int sock, DltDaemon *daemon, DltDaemo
}
req = (DltServiceOfflineLogstorage*) (msg->databuffer);
+ int device_index=-1;
+ int i=0;
+ for(i=0; i < daemon_local->flags.offlineLogstorageMaxDevices; i++)
+ {
+ /* Check if the requested device path is already used as log storage device */
+ if(strcmp(daemon->storage_handle[i].device_mount_point,
+ req->mount_point) == 0)
+ {
+ device_index = i;
+ break;
+ }
+ /* Get first available device index here */
+ if((daemon->storage_handle[i].connection_type !=
+ DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) &&
+ (device_index == -1))
+ {
+ device_index = i;
+ }
+ }
+
+ if((device_index) == -1)
+ {
+ dlt_daemon_control_service_response(sock,
+ daemon,
+ daemon_local,
+ DLT_SERVICE_ID_OFFLINE_LOGSTORAGE,
+ DLT_SERVICE_RESPONSE_ERROR,
+ verbose);
+ dlt_log(LOG_WARNING, "MAX devices already in use \n");
+ return;
+ }
+
/* Check for device connection request from log storage ctrl app */
if (req->connection_type == DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED)
{
- if(req->dev_num > daemon_local->flags.offlineLogstorageMaxDevices)
- {
- dlt_daemon_control_service_response(sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, DLT_SERVICE_RESPONSE_ERROR, verbose);
- dlt_log(LOG_INFO, "Device number received is greater than MAX device configured \n");
- return;
- }
- /* Adding +1 to device number as ctrl app sends device number 1 less (to support indexing of storage_handle */
- ret = dlt_logstorage_device_connected(&(daemon->storage_handle[req->dev_num]), req->dev_num+1);
+ ret = dlt_logstorage_device_connected(&(daemon->storage_handle[device_index]), req->mount_point);
if(ret != 0)
{
dlt_daemon_control_service_response(sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, DLT_SERVICE_RESPONSE_ERROR, verbose);
@@ -1956,7 +1987,7 @@ void dlt_daemon_control_service_logstorage(int sock, DltDaemon *daemon, DltDaemo
}
/* Setup logstorage with config file settings */
- ret = dlt_logstorage_load_config(&(daemon->storage_handle[req->dev_num]));
+ ret = dlt_logstorage_load_config(&(daemon->storage_handle[device_index]));
if(ret != 0)
{
dlt_daemon_control_service_response(sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, DLT_SERVICE_RESPONSE_ERROR, verbose);
@@ -1966,22 +1997,16 @@ void dlt_daemon_control_service_logstorage(int sock, DltDaemon *daemon, DltDaemo
dlt_daemon_control_service_response(sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE,DLT_SERVICE_RESPONSE_OK, verbose);
/* Check if log level of running application needs an update */
- dlt_daemon_logstorage_update_application_loglevel(daemon, req->dev_num, verbose);
+ dlt_daemon_logstorage_update_application_loglevel(daemon, device_index, verbose);
}
/* Check for device disconnection request from log storage ctrl app */
else if(req->connection_type == DLT_OFFLINE_LOGSTORAGE_DEVICE_DISCONNECTED)
{
- if(req->dev_num > daemon_local->flags.offlineLogstorageMaxDevices)
- {
- dlt_log(LOG_INFO, "Device number received is greater than MAX device configured \n");
- return;
- }
-
/* Check if log level of running application needs to be reset */
- dlt_daemon_logstorage_reset_application_loglevel(daemon, req->dev_num, daemon_local->flags.offlineLogstorageMaxDevices, verbose);
+ dlt_daemon_logstorage_reset_application_loglevel(daemon, device_index, daemon_local->flags.offlineLogstorageMaxDevices, verbose);
- dlt_logstorage_device_disconnected(&(daemon->storage_handle[req->dev_num]));
+ dlt_logstorage_device_disconnected(&(daemon->storage_handle[device_index]));
dlt_daemon_control_service_response(sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, DLT_SERVICE_RESPONSE_OK, verbose);
}
diff --git a/src/daemon/dlt_daemon_offline_logstorage.c b/src/daemon/dlt_daemon_offline_logstorage.c
index 7410225..bc8817c 100644
--- a/src/daemon/dlt_daemon_offline_logstorage.c
+++ b/src/daemon/dlt_daemon_offline_logstorage.c
@@ -466,7 +466,7 @@ int dlt_daemon_logstorage_get_loglevel(DltDaemon *daemon, int max_device, char *
* to write to the device, DltDaemon will disconnect this device.
*
* @param daemon Pointer to Dlt Daemon structure
- * @param max_devices number of configured storage devices
+ * @param user_config User configurations for log file
* @param data1 message header buffer
* @param size1 message header buffer size
* @param data2 message extended header buffer
@@ -474,21 +474,26 @@ int dlt_daemon_logstorage_get_loglevel(DltDaemon *daemon, int max_device, char *
* @param data3 message data buffer
* @param size3 message data size
*/
-void dlt_daemon_logstorage_write(DltDaemon *daemon, int max_devices, unsigned char *data1, int size1, unsigned char *data2, int size2, unsigned char *data3, int size3)
+void dlt_daemon_logstorage_write(DltDaemon *daemon, DltDaemonFlags user_config,
+ unsigned char *data1, int size1, unsigned char *data2, int size2,
+ unsigned char *data3, int size3)
{
int i = 0;
/* data2 contains DltStandardHeader, DltStandardHeaderExtra and DltExtendedHeader. We are interested
* in last one, because it contains apid, ctid and loglevel */
DltExtendedHeader ext;
- char apid[4] = {0};
- char ctid[4] = {0};
+ DltLogStorageUserConfig file_config;
+ char apid[DLT_ID_SIZE] = {0};
+ char ctid[DLT_ID_SIZE] = {0};
int log_level = -1;
- if (daemon == NULL || max_devices <= 0 || data1 == NULL || data2 == NULL || data3 == NULL
- || ((unsigned int)size2 < (sizeof(DltStandardHeader) + sizeof(DltStandardHeaderExtra) + sizeof(DltExtendedHeader))))
+ if (daemon == NULL || user_config.offlineLogstorageMaxDevices <= 0
+ || data1 == NULL || data2 == NULL || data3 == NULL
+ || ((unsigned int)size2 < (sizeof(DltStandardHeader) +
+ sizeof(DltStandardHeaderExtra) + sizeof(DltExtendedHeader))))
{
- dlt_log(LOG_INFO, "dlt_daemon_logstorage_write: message type is not log. Skip storing.\n");
+ dlt_log(LOG_DEBUG, "dlt_daemon_logstorage_write: message type is not log. Skip storing.\n");
return;
}
@@ -499,11 +504,18 @@ void dlt_daemon_logstorage_write(DltDaemon *daemon, int max_devices, unsigned ch
dlt_set_id(ctid, ext.ctid);
log_level = DLT_GET_MSIN_MTIN(ext.msin);
- for (i = 0; i < max_devices; i++)
+ /* Copy user configuration */
+ file_config.logfile_timestamp = user_config.offlineLogstorageTimestamp;
+ file_config.logfile_delimiter = user_config.offlineLogstorageDelimiter;
+ file_config.logfile_maxcounter = user_config.offlineLogstorageMaxCounter;
+ file_config.logfile_counteridxlen = user_config.offlineLogstorageMaxCounterIdx;
+
+ for (i = 0; i < user_config.offlineLogstorageMaxDevices; i++)
{
if (daemon->storage_handle[i].config_status == DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE)
{
- if (dlt_logstorage_write(&(daemon->storage_handle[i]), apid, ctid, log_level, data1, size1, data2, size2, data3, size3) != 0)
+ if (dlt_logstorage_write(&(daemon->storage_handle[i]), file_config, apid, ctid,
+ log_level, data1, size1, data2, size2, data3, size3) != 0)
{
dlt_log(LOG_ERR,"dlt_daemon_logstorage_write: dlt_logstorage_write failed. Disable storage device\n");
/* DLT_OFFLINE_LOGSTORAGE_MAX_WRITE_ERRORS happened, therefore remove logstorage device */
@@ -512,3 +524,44 @@ void dlt_daemon_logstorage_write(DltDaemon *daemon, int max_devices, unsigned ch
}
}
}
+
+/**
+ * dlt_daemon_logstorage_setup_internal_storage
+ *
+ * Setup user defined path as offline log storage device
+ *
+ * @param daemon Pointer to Dlt Daemon structure
+ * @param path User configured internal storage path
+ * @param verbose If set to true verbose information is printed out
+ */
+int dlt_daemon_logstorage_setup_internal_storage(DltDaemon *daemon, char *path, int verbose)
+{
+ int ret = 0;
+
+ if((path == NULL) || (daemon == NULL))
+ {
+ return -1;
+ }
+
+ /* connect internal storage device */
+ /* Device index always used as 0 as it is setup on DLT daemon startup */
+ ret = dlt_logstorage_device_connected(&(daemon->storage_handle[0]), path);
+ if(ret != 0)
+ {
+ dlt_log(LOG_ERR,"dlt_daemon_logstorage_setup_emmc_support : Device connect failed\n");
+ return -1;
+ }
+
+ /* setup logstorage with config file settings */
+ ret = dlt_logstorage_load_config(&(daemon->storage_handle[0]));
+ if(ret != 0)
+ {
+ dlt_log(LOG_ERR,"dlt_daemon_logstorage_setup_emmc_support : Loading configuration file failed\n");
+ return -1;
+ }
+
+ /* check if log level of running application need an update */
+ dlt_daemon_logstorage_update_application_loglevel(daemon, 0, verbose);
+
+ return ret;
+}
diff --git a/src/daemon/dlt_daemon_offline_logstorage.h b/src/daemon/dlt_daemon_offline_logstorage.h
index 26e5686..621bd59 100644
--- a/src/daemon/dlt_daemon_offline_logstorage.h
+++ b/src/daemon/dlt_daemon_offline_logstorage.h
@@ -103,7 +103,7 @@ void dlt_daemon_logstorage_update_application_loglevel(DltDaemon *daemon, int de
* to write to the device, DltDaemon will disconnect this device.
*
* @param daemon Pointer to Dlt Daemon structure
- * @param max_devices number of configured storage devices
+ * @param user_config User configurations for log file
* @param apid application id
* @param ctid context id
* @param log_level log level
@@ -112,5 +112,18 @@ void dlt_daemon_logstorage_update_application_loglevel(DltDaemon *daemon, int de
* @param data2 message data buffer
* @param size2 message data size
*/
-void dlt_daemon_logstorage_write(DltDaemon *daemon, int max_devices, unsigned char *data1, int size1, unsigned char *data2, int size2, unsigned char *data3, int size3);
+void dlt_daemon_logstorage_write(DltDaemon *daemon, DltDaemonFlags user_config, unsigned char *data1,
+ int size1, unsigned char *data2, int size2,
+ unsigned char *data3, int size3);
+
+/**
+ * dlt_daemon_logstorage_setup_internal_storage
+ *
+ * Setup user defined path as offline log storage device
+ *
+ * @param daemon Pointer to Dlt Daemon structure
+ * @param path User configured internal storage path
+ * @param verbose If set to true verbose information is printed out
+ */
+int dlt_daemon_logstorage_setup_internal_storage(DltDaemon *daemon, char *path, int verbose);
#endif /* DLT_DAEMON_OFFLINE_LOGSTORAGE_H */