Skip to content

Commit

Permalink
dlt: Fix compilation warning
Browse files Browse the repository at this point in the history
Signed-off-by: mluu <[email protected]>
  • Loading branch information
minminlittleshrimp committed May 21, 2024
1 parent 75f6c95 commit e41e1a2
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 55 deletions.
20 changes: 13 additions & 7 deletions src/daemon/dlt-daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,17 @@ int option_handling(DltDaemonLocal *daemon_local, int argc, char *argv[])
/* switch() */

#ifdef DLT_DAEMON_USE_FIFO_IPC
snprintf(daemon_local->flags.userPipesDir, DLT_PATH_MAX,
ssize_t n = snprintf(daemon_local->flags.userPipesDir, DLT_PATH_MAX,
"%s/dltpipes", dltFifoBaseDir);
snprintf(daemon_local->flags.daemonFifoName, DLT_PATH_MAX,
if (n < 0 || (size_t)n > DLT_PATH_MAX) {
dlt_vlog(LOG_WARNING, "%s: snprintf truncation/error(%ld) %s\n",
__func__, n, daemon_local->flags.userPipesDir);
}

n = snprintf(daemon_local->flags.daemonFifoName, DLT_PATH_MAX,
"%s/dlt", dltFifoBaseDir);
dlt_vlog(LOG_WARNING, "%s: snprintf truncation/error(%ld) %s\n",
__func__, n, daemon_local->flags.daemonFifoName);
#endif

#ifdef DLT_SHM_ENABLE
Expand Down Expand Up @@ -1935,7 +1942,7 @@ static char* file_read_everything(FILE* const file, const size_t sizeLimit)

/* Size limit includes NULL terminator. */
const off_t size = s_buf.st_size;
if (size < 0 || size >= sizeLimit) {
if (size < 0 || size >= (off_t)sizeLimit) {
dlt_log(LOG_WARNING, "file size invalid\n");
fclose(file);
return NULL;
Expand Down Expand Up @@ -1979,12 +1986,12 @@ static char* file_read_field(FILE* const file, const char* const fieldName)
}

const char* const kDelimiters = "\r\n\"\'=";
const size_t fieldNameLen = strlen(fieldName);
const ssize_t fieldNameLen = strlen(fieldName);

char* result = NULL;

char* buffer = NULL;
ssize_t bufferSize = 0;
size_t bufferSize = 0;

while (true) {
ssize_t lineSize = getline(&buffer, &bufferSize, file);
Expand Down Expand Up @@ -2125,8 +2132,7 @@ void dlt_daemon_exit_trigger()
#ifdef DLT_DAEMON_USE_FIFO_IPC
char tmp[DLT_PATH_MAX] = { 0 };

ssize_t n;
n = snprintf(tmp, DLT_PATH_MAX, "%s/dlt", dltFifoBaseDir);
ssize_t n = snprintf(tmp, DLT_PATH_MAX, "%s/dlt", dltFifoBaseDir);
if (n < 0 || (size_t)n > DLT_PATH_MAX) {
dlt_vlog(LOG_WARNING, "%s: snprintf truncation/error(%ld) %s\n",
__func__, n, tmp);
Expand Down
15 changes: 9 additions & 6 deletions src/daemon/dlt_daemon_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -635,12 +635,15 @@ DltDaemonApplication *dlt_daemon_application_add(DltDaemon *daemon,
#endif
#ifdef DLT_DAEMON_USE_FIFO_IPC
if (dlt_user_handle < DLT_FD_MINIMUM) {
snprintf(filename,
DLT_DAEMON_COMMON_TEXTBUFSIZE,
"%s/dltpipes/dlt%d",
dltFifoBaseDir,
pid);

ssize_t n = snprintf(filename,
DLT_DAEMON_COMMON_TEXTBUFSIZE,
"%s/dltpipes/dlt%d",
dltFifoBaseDir,
pid);
if (n < 0 || (size_t)n > DLT_DAEMON_COMMON_TEXTBUFSIZE) {
dlt_vlog(LOG_WARNING, "%s: snprintf truncation/error(%ld) %s\n",
__func__, n, filename);
}
dlt_user_handle = open(filename, O_WRONLY | O_NONBLOCK);

if (dlt_user_handle < 0) {
Expand Down
28 changes: 23 additions & 5 deletions src/lib/dlt_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,18 @@ static DltReturnValue dlt_initialize_fifo_connection(void)
char filename[DLT_PATH_MAX];
int ret;

snprintf(dlt_user_dir, DLT_PATH_MAX, "%s/dltpipes", dltFifoBaseDir);
snprintf(dlt_daemon_fifo, DLT_PATH_MAX, "%s/dlt", dltFifoBaseDir);
ssize_t n = snprintf(dlt_user_dir, DLT_PATH_MAX, "%s/dltpipes", dltFifoBaseDir);
if (n < 0 || (size_t)n > DLT_PATH_MAX) {
dlt_vlog(LOG_WARNING, "%s: snprintf truncation/error(%ld) %s\n",
__func__, n, dlt_user_dir);
}

n = snprintf(dlt_daemon_fifo, DLT_PATH_MAX, "%s/dlt", dltFifoBaseDir);
if (n < 0 || (size_t)n > DLT_PATH_MAX) {
dlt_vlog(LOG_WARNING, "%s: snprintf truncation/error(%ld) %s\n",
__func__, n, dlt_daemon_fifo);
}

ret = mkdir(dlt_user_dir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH | S_ISVTX);

if ((ret == -1) && (errno != EEXIST)) {
Expand All @@ -416,7 +426,11 @@ static DltReturnValue dlt_initialize_fifo_connection(void)
}

/* create and open DLT user FIFO */
snprintf(filename, DLT_PATH_MAX, "%s/dlt%d", dlt_user_dir, getpid());
n = snprintf(filename, DLT_PATH_MAX, "%s/dlt%d", dlt_user_dir, getpid());
if (n < 0 || (size_t)n > DLT_PATH_MAX) {
dlt_vlog(LOG_WARNING, "%s: snprintf truncation/error(%ld) %s\n",
__func__, n, filename);
}

/* Try to delete existing pipe, ignore result of unlink */
unlink(filename);
Expand Down Expand Up @@ -720,7 +734,7 @@ DltReturnValue dlt_init_common(void)
uint32_t header_size = 0;

/* Binary semaphore for threads */
if ((pthread_attr_init(&dlt_mutex_attr) != 0) ||
if ((pthread_mutexattr_init(&dlt_mutex_attr) != 0) ||
(pthread_mutexattr_settype(&dlt_mutex_attr, PTHREAD_MUTEX_ERRORCHECK) != 0) ||
(pthread_mutex_init(&dlt_mutex, &dlt_mutex_attr) != 0)) {
dlt_user_init_state = INIT_UNITIALIZED;
Expand Down Expand Up @@ -1030,7 +1044,11 @@ DltReturnValue dlt_free(void)
if (dlt_user.dlt_user_handle != DLT_FD_INIT) {
close(dlt_user.dlt_user_handle);
dlt_user.dlt_user_handle = DLT_FD_INIT;
snprintf(filename, DLT_PATH_MAX, "%s/dlt%d", dlt_user_dir, getpid());
ssize_t n = snprintf(filename, DLT_PATH_MAX, "%s/dlt%d", dlt_user_dir, getpid());
if (n < 0 || (size_t)n > DLT_PATH_MAX) {
dlt_vlog(LOG_WARNING, "%s: snprintf truncation/error(%ld) %s\n",
__func__, n, filename);
}
unlink(filename);
}

Expand Down
63 changes: 27 additions & 36 deletions src/offlinelogstorage/dlt_offline_logstorage.c
Original file line number Diff line number Diff line change
Expand Up @@ -681,9 +681,15 @@ DLT_STATIC void dlt_logstorage_create_keys_multi(char *ecuid, char *apid,
DLT_STATIC void dlt_logstorage_create_keys_only_ecu(char *ecuid, char *key)
{
char curr_str[DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN + 1] = { 0 };

strncpy(curr_str, ecuid, DLT_ID_SIZE);
strncat(curr_str, "::", 2);
const char *delimiter = "::";
if(!strncpy(curr_str, ecuid, DLT_ID_SIZE)) {
dlt_log(LOG_ERR, "Required inputs ecuid are NULL\n");
return;
}
if(!strncat(curr_str, delimiter, strlen(delimiter))) {
dlt_log(LOG_ERR, "Cannot prepare key\n");
return;
}

strncpy(key, curr_str, strlen(curr_str));
}
Expand Down Expand Up @@ -1186,22 +1192,6 @@ DLT_STATIC int dlt_logstorage_check_specificsize(DltLogStorageFilterConfig *conf
return dlt_logstorage_read_number(&config->specific_size, value);
}

DLT_STATIC int dlt_logstorage_set_sync_strategy(int *sync,
int value)
{
*sync = value;

if (value == 0)
{
dlt_log(LOG_WARNING,
"Unknown sync strategies. Set default ON_MSG\n");
*sync = DLT_LOGSTORAGE_SYNC_ON_MSG;
return 1;
}

return 0;
}

/**
* dlt_logstorage_check_sync_strategy
*
Expand Down Expand Up @@ -1331,10 +1321,10 @@ DLT_STATIC int dlt_logstorage_check_disable_network(DltLogStorageFilterConfig *c
DLT_STATIC int dlt_logstorage_check_gzip_compression(DltLogStorageFilterConfig *config,
char *value)
{
#ifdef DLT_LOGSTORAGE_USE_GZIP
if ((config == NULL) || (value == NULL))
return -1;

#ifdef DLT_LOGSTORAGE_USE_GZIP
if (strcasestr(value, "ON") != NULL) {
config->gzip_compression = DLT_LOGSTORAGE_GZIP_ON;
} else if (strcasestr(value, "OFF") != NULL) {
Expand Down Expand Up @@ -2268,6 +2258,7 @@ int dlt_logstorage_get_config(DltLogStorage *handle,
DltLogStorageFilterConfig **cur_config_ptr = NULL;
char key[DLT_CONFIG_FILE_SECTIONS_MAX][DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN] =
{ { '\0' }, { '\0' }, { '\0' } };
const char *delimiter = ":";
int i = 0;
int apid_len = 0;
int ctid_len = 0;
Expand Down Expand Up @@ -2300,8 +2291,8 @@ int dlt_logstorage_get_config(DltLogStorage *handle,
if ((apid == NULL) && (ctid == NULL)) {
/* ecu:: */
strncpy(key[0], ecuid, ecuid_len);
strncat(key[0], ":", 1);
strncat(key[0], ":", 1);
strncat(key[0], delimiter, strlen(delimiter));
strncat(key[0], delimiter, strlen(delimiter));

num_configs = dlt_logstorage_list_find(key[0], &(handle->config_list),
config);
Expand All @@ -2323,52 +2314,52 @@ int dlt_logstorage_get_config(DltLogStorage *handle,
}

/* :apid: */
strncpy(key[0], ":", 1);
strncpy(key[0], delimiter, strlen(delimiter));
if (apid != NULL)
strncat(key[0], apid, apid_len);
strncat(key[0], ":", 1);
strncat(key[0], delimiter, strlen(delimiter));

/* ::ctid */
strncpy(key[1], ":", 1);
strncat(key[1], ":", 1);
strncpy(key[1], delimiter, strlen(delimiter));
strncat(key[1], delimiter, strlen(delimiter));
if (ctid != NULL)
strncat(key[1], ctid, ctid_len);

/* :apid:ctid */
strncpy(key[2], ":", 1);
strncpy(key[2], delimiter, strlen(delimiter));
if (apid != NULL)
strncat(key[2], apid, apid_len);
strncat(key[2], ":", 1);
strncat(key[2], delimiter, strlen(delimiter));
if (ctid != NULL)
strncat(key[2], ctid, ctid_len);

/* ecu:apid:ctid */
strncpy(key[3], ecuid, ecuid_len);
strncat(key[3], ":", 1);
strncat(key[3], delimiter, strlen(delimiter));
if (apid != NULL)
strncat(key[3], apid, apid_len);
strncat(key[3], ":", 1);
strncat(key[3], delimiter, strlen(delimiter));
if (ctid != NULL)
strncat(key[3], ctid, ctid_len);

/* ecu:apid: */
strncpy(key[4], ecuid, ecuid_len);
strncat(key[4], ":", 1);
strncat(key[4], delimiter, strlen(delimiter));
if (apid != NULL)
strncat(key[4], apid, apid_len);
strncat(key[4], ":", 1);
strncat(key[4], delimiter, strlen(delimiter));

/* ecu::ctid */
strncpy(key[5], ecuid, ecuid_len);
strncat(key[5], ":", 1);
strncat(key[5], ":", 1);
strncat(key[5], delimiter, strlen(delimiter));
strncat(key[5], delimiter, strlen(delimiter));
if (ctid != NULL)
strncat(key[5], ctid, ctid_len);

/* ecu:: */
strncpy(key[6], ecuid, ecuid_len);
strncat(key[6], ":", 1);
strncat(key[6], ":", 1);
strncat(key[6], delimiter, strlen(delimiter));
strncat(key[6], delimiter, strlen(delimiter));

/* Search the list three times with keys as -apid: , :ctid and apid:ctid */
for (i = 0; i < DLT_OFFLINE_LOGSTORAGE_MAX_POSSIBLE_KEYS; i++)
Expand Down
2 changes: 1 addition & 1 deletion src/offlinelogstorage/dlt_offline_logstorage_behavior.c
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ int dlt_logstorage_prepare_on_msg(DltLogStorageFilterConfig *config,
if ((config->sync == DLT_LOGSTORAGE_SYNC_ON_MSG) ||
(config->sync == DLT_LOGSTORAGE_SYNC_UNSET)) {
if (config->gzip_compression) {
if (fsync(fileno(config->gzlog)) != 0) {
if (fsync(config->fd) != 0) {
if (errno != ENOSYS) {
dlt_vlog(LOG_ERR, "%s: failed to sync gzip log file\n", __func__);
}
Expand Down

0 comments on commit e41e1a2

Please sign in to comment.