Skip to content

Commit

Permalink
dlt-common: add new config to remove date and time in storage header
Browse files Browse the repository at this point in the history
Add a new OfflineTraceUseUptimeOnly toggle in dlt.conf
With this toggle you can supress real date and time from
the dlt message storage header and from offline trace filenames
This toogle is for data protection purposes.

Signed-off-by: Ahmet Findikci <[email protected]>
  • Loading branch information
ahmetfindi committed May 16, 2024
1 parent 9e28c5e commit 5e77dae
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 17 deletions.
6 changes: 6 additions & 0 deletions doc/dlt.conf.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,12 @@ Filename timestamp based or index based. 1 = timestamp based, 0 = index based

Default: Function is disabled

## OfflineTraceUseUptimeOnly

Use uptime in DLT storage header and filename instead of real-time

Default: Function is disabled

# LOCAL CONSOLE OUTPUT OPTIONS

## PrintASCII
Expand Down
8 changes: 8 additions & 0 deletions include/dlt/dlt_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -1299,6 +1299,14 @@ int dlt_receiver_check_and_get(DltReceiver *receiver,
* @return negative value if there was an error
*/
DltReturnValue dlt_set_storageheader(DltStorageHeader *storageheader, const char *ecu);
/**
* Fill the storage header of a DLT message with either the real-time clock or the monotonic clock.
* @param storageheader Pointer to the storage header of a DLT message.
* @param ecu Name of the ECU to be set in the storage header.
* @param useUptime If true, the monotonic clock is used as the timestamp; if false, the real-time clock is used.
* @return negative value if there was an error
*/
DltReturnValue dlt_set_storageheader_with_timestamp_option(DltStorageHeader *storageheader, const char *ecu, bool useUptime);
/**
* Check if a storage header contains its marker
* @param storageheader pointer to storage header of a dlt message
Expand Down
28 changes: 28 additions & 0 deletions include/dlt/dlt_multiple_files.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ typedef struct
char filenameBase[NAME_MAX + 1];/**< (String) Prefix of file name */
char filenameExt[NAME_MAX + 1];/**< (String) Extension of file name */
int ohandle; /**< (int) file handle to current output file */
bool fileNameUptimeBased; /**< (bool) is filename uptime stamp based? false = realtime based (Default: false) */
} MultipleFilesRingBuffer;

/**
Expand Down Expand Up @@ -78,6 +79,33 @@ extern DltReturnValue multiple_files_buffer_init(MultipleFilesRingBuffer *files_
const char *filename_base,
const char *filename_ext);

/**
* Initialise the multiple files buffer with an uptime option.
* This function call opens the currently used log file.
* A check of the complete size of the files is done during startup.
* Old files are deleted, if there is not enough space left to create new file.
* This function must be called before using further multiple files functions.
* @param files_buffer pointer to MultipleFilesRingBuffer struct.
* @param directory directory where to store multiple files.
* @param file_size maximum size of one files.
* @param max_size maximum size of complete multiple files in bytes.
* @param filename_timestamp_based filename to be created on timestamp-based or index-based.
* @param append Indicates whether the current log files is used or a new file should be be created
* @param filename_base Base name.
* @param filename_ext File extension.
* @param use_uptime_in_filename Indicates whether filename to be created with realtime- or uptime-stamp.
* @return negative value if there was an error.
*/
extern DltReturnValue multiple_files_buffer_init_with_uptime_option(MultipleFilesRingBuffer *files_buffer,
const char *directory,
int file_size,
int max_size,
bool filename_timestamp_based,
bool append,
const char *filename_base,
const char *filename_ext,
bool use_uptime_in_filename);

/**
* Uninitialise the multiple files buffer.
* This function call closes currently used log file.
Expand Down
11 changes: 8 additions & 3 deletions src/daemon/dlt-daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,10 @@ int option_file_parser(DltDaemonLocal *daemon_local)
daemon_local->flags.offlineTraceFilenameTimestampBased = (bool)atoi(value);
/*printf("Option: %s=%s\n",token,value); */
}
else if (strcmp(token, "OfflineTraceUseUptimeOnly") == 0)
{
daemon_local->flags.offlineTraceUseUptimeOnly = (bool)atoi(value);
}
else if (strcmp(token, "SendECUSoftwareVersion") == 0)
{
daemon_local->flags.sendECUSoftwareVersion = atoi(value);
Expand Down Expand Up @@ -1443,14 +1447,15 @@ int dlt_daemon_local_init_p2(DltDaemon *daemon, DltDaemonLocal *daemon_local, in
/* init offline trace */
if (((daemon->mode == DLT_USER_MODE_INTERNAL) || (daemon->mode == DLT_USER_MODE_BOTH)) &&
daemon_local->flags.offlineTraceDirectory[0]) {
if (multiple_files_buffer_init(&(daemon_local->offlineTrace),
if (multiple_files_buffer_init_with_uptime_option(&(daemon_local->offlineTrace),
daemon_local->flags.offlineTraceDirectory,
daemon_local->flags.offlineTraceFileSize,
daemon_local->flags.offlineTraceMaxSize,
daemon_local->flags.offlineTraceFilenameTimestampBased,
false,
DLT_OFFLINETRACE_FILENAME_BASE,
DLT_OFFLINETRACE_FILENAME_EXT) == -1) {
DLT_OFFLINETRACE_FILENAME_EXT,
daemon_local->flags.offlineTraceUseUptimeOnly) == -1) {
dlt_log(LOG_ERR, "Could not initialize offline trace\n");
return -1;
}
Expand Down Expand Up @@ -2273,7 +2278,7 @@ int dlt_daemon_log_internal(DltDaemon *daemon, DltDaemonLocal *daemon_local, cha

/* Set storageheader */
msg.storageheader = (DltStorageHeader *)(msg.headerbuffer);
dlt_set_storageheader(msg.storageheader, daemon->ecuid);
dlt_set_storageheader_with_timestamp_option(msg.storageheader, daemon->ecuid, daemon_local->flags.offlineTraceUseUptimeOnly);

/* Set standardheader */
msg.standardheader = (DltStandardHeader *)(msg.headerbuffer + sizeof(DltStorageHeader));
Expand Down
1 change: 1 addition & 0 deletions src/daemon/dlt-daemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ typedef struct
int offlineTraceFileSize; /**< (int) Maximum size in bytes of one trace file (Default: 1000000) */
int offlineTraceMaxSize; /**< (int) Maximum size of all trace files (Default: 4000000) */
bool offlineTraceFilenameTimestampBased; /**< (Boolean) timestamp based or index based (Default: true=Timestamp based) */
bool offlineTraceUseUptimeOnly; /**< (Boolean) use uptime in storage header and filename instead realtime (Default: false) */
DltLoggingMode loggingMode; /**< (int) The logging console for internal logging of dlt-daemon (Default: 0) */
int loggingLevel; /**< (int) The logging level for internal logging of dlt-daemon (Default: 6) */
char loggingFilename[DLT_DAEMON_FLAG_MAX]; /**< (String: Filename) The logging filename if internal logging mode is log to file (Default: /tmp/log) */
Expand Down
3 changes: 3 additions & 0 deletions src/daemon/dlt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ ControlSocketPath = /tmp/dlt-ctrl.sock
# Filename timestamp based or index based (Default:1) (timestamp based=1, index based =0)
# OfflineTraceFileNameTimestampBased = 1

# use uptime in DLT storage header and filename instead realtime (Default: 0)
# OfflineTraceUseUptimeOnly = 0

########################################################################
# Local console output configuration #
########################################################################
Expand Down
9 changes: 4 additions & 5 deletions src/daemon/dlt_daemon_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@ int dlt_daemon_client_send_message_to_all_client(DltDaemon *daemon,
} else {
ecu_ptr = daemon->ecuid;
}

if (dlt_set_storageheader(daemon_local->msg.storageheader, ecu_ptr)) {
if (dlt_set_storageheader_with_timestamp_option(daemon_local->msg.storageheader, ecu_ptr, daemon_local->flags.offlineTraceUseUptimeOnly)) {
dlt_vlog(LOG_WARNING,
"%s: failed to set storage header with header type: 0x%x\n",
__func__, daemon_local->msg.standardheader->htyp);
Expand Down Expand Up @@ -404,8 +404,7 @@ int dlt_daemon_client_send_control_message(int sock,

/* prepare storage header */
msg->storageheader = (DltStorageHeader *)msg->headerbuffer;

if (dlt_set_storageheader(msg->storageheader, daemon->ecuid) == DLT_RETURN_ERROR)
if (dlt_set_storageheader_with_timestamp_option(msg->storageheader, daemon->ecuid, daemon_local->flags.offlineTraceUseUptimeOnly) == DLT_RETURN_ERROR)
return DLT_DAEMON_ERROR_UNKNOWN;

/* prepare standard header */
Expand Down Expand Up @@ -2205,7 +2204,7 @@ void dlt_daemon_control_message_time(int sock, DltDaemon *daemon, DltDaemonLocal

/* prepare storage header */
msg.storageheader = (DltStorageHeader *)msg.headerbuffer;
dlt_set_storageheader(msg.storageheader, daemon->ecuid);
dlt_set_storageheader_with_timestamp_option(msg.storageheader, daemon->ecuid, daemon_local->flags.offlineTraceUseUptimeOnly);

/* prepare standard header */
msg.standardheader = (DltStandardHeader *)(msg.headerbuffer + sizeof(DltStorageHeader));
Expand Down
4 changes: 2 additions & 2 deletions src/gateway/dlt_gateway.c
Original file line number Diff line number Diff line change
Expand Up @@ -1413,8 +1413,8 @@ DltReturnValue dlt_gateway_process_passive_node_messages(DltDaemon *daemon,
}

/* prepare storage header */
if (dlt_set_storageheader(msg.storageheader,
msg.headerextra.ecu) == DLT_RETURN_ERROR) {
if (dlt_set_storageheader_with_timestamp_option(msg.storageheader,
msg.headerextra.ecu, daemon_local->flags.offlineTraceUseUptimeOnly) == DLT_RETURN_ERROR) {
dlt_vlog(LOG_ERR, "%s: Can't set storage header\n", __func__);
return DLT_RETURN_ERROR;
}
Expand Down
16 changes: 12 additions & 4 deletions src/shared/dlt_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -2317,10 +2317,15 @@ int dlt_receiver_check_and_get(DltReceiver *receiver,
}

DltReturnValue dlt_set_storageheader(DltStorageHeader *storageheader, const char *ecu)
{
return dlt_set_storageheader_with_timestamp_option(storageheader, ecu, false);
}

DltReturnValue dlt_set_storageheader_with_timestamp_option(DltStorageHeader *storageheader, const char *ecu, const bool useUptime)
{

#if !defined(_MSC_VER)
struct timeval tv;
struct timespec ts;
#endif

if ((storageheader == NULL) || (ecu == NULL))
Expand All @@ -2330,7 +2335,10 @@ DltReturnValue dlt_set_storageheader(DltStorageHeader *storageheader, const char
#if defined(_MSC_VER)
time(&(storageheader->seconds));
#else
gettimeofday(&tv, NULL);
if (useUptime)
clock_gettime(CLOCK_MONOTONIC, &ts);
else
clock_gettime(CLOCK_REALTIME, &ts);
#endif

/* prepare storage header */
Expand All @@ -2345,8 +2353,8 @@ DltReturnValue dlt_set_storageheader(DltStorageHeader *storageheader, const char
#if defined(_MSC_VER)
storageheader->microseconds = 0;
#else
storageheader->seconds = (uint32_t) tv.tv_sec; /* value is long */
storageheader->microseconds = (int32_t) tv.tv_usec; /* value is long */
storageheader->seconds = (uint32_t) ts.tv_sec; /* value is long */
storageheader->microseconds = (int32_t) (ts.tv_nsec / 1000); /* value is long */
#endif

return DLT_RETURN_OK;
Expand Down
29 changes: 26 additions & 3 deletions src/shared/dlt_multiple_files.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,18 @@ DltReturnValue multiple_files_buffer_create_new_file(MultipleFilesRingBuffer *fi
if (files_buffer->filenameTimestampBased) {
/* timestamp format: "yyyymmdd_hhmmss" */
char timestamp[16];
t = time(NULL);
tzset();
localtime_r(&t, &tmp);
if (files_buffer->fileNameUptimeBased) {
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);

t = ts.tv_sec;
gmtime_r(&t, &tmp);
}
else {
t = time(NULL);
tzset();
localtime_r(&t, &tmp);
}

strftime(timestamp, sizeof(timestamp), "%Y%m%d_%H%M%S", &tmp);

Expand Down Expand Up @@ -412,6 +421,19 @@ DltReturnValue multiple_files_buffer_init(MultipleFilesRingBuffer *files_buffer,
const bool append,
const char *filename_base,
const char *filename_ext)
{
return multiple_files_buffer_init_with_uptime_option(files_buffer, directory, file_size, max_size, filename_timestamp_based, append, filename_base, filename_ext, false);
}

DltReturnValue multiple_files_buffer_init_with_uptime_option(MultipleFilesRingBuffer *files_buffer,
const char *directory,
const int file_size,
const int max_size,
const bool filename_timestamp_based,
const bool append,
const char *filename_base,
const char *filename_ext,
const bool use_uptime_in_filename)
{
if (files_buffer == NULL) {
fprintf(stderr, "multiple files buffer not set\n");
Expand All @@ -428,6 +450,7 @@ DltReturnValue multiple_files_buffer_init(MultipleFilesRingBuffer *files_buffer,
files_buffer->filenameBase[NAME_MAX] = 0;
strncpy(files_buffer->filenameExt, filename_ext, NAME_MAX);
files_buffer->filenameExt[NAME_MAX] = 0;
files_buffer->fileNameUptimeBased = use_uptime_in_filename;

if (DLT_RETURN_ERROR == multiple_files_buffer_check_size(files_buffer)) return DLT_RETURN_ERROR;

Expand Down

0 comments on commit 5e77dae

Please sign in to comment.