Skip to content

Commit

Permalink
Fix usage of gzip_compression (#691)
Browse files Browse the repository at this point in the history
* Fix usage of gzip_compression

If dlt_daemon is compiled with gzip compression any use of GzipCompression
will turn it on. This is due to incorrect check of the flag where it
is checked as if it was a boolenan when it is an int where only the value
DLT_LOGSTORAGE_GZIP_ON means that it should be enabled.

* Fix bad copypaste
  • Loading branch information
averater authored Dec 6, 2024
1 parent 35fa48e commit 80371aa
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
7 changes: 3 additions & 4 deletions src/offlinelogstorage/dlt_offline_logstorage.c
Original file line number Diff line number Diff line change
Expand Up @@ -1340,14 +1340,13 @@ DLT_STATIC int dlt_logstorage_check_gzip_compression(DltLogStorageFilterConfig *
} else if (strcasestr(value, "OFF") != NULL) {
config->gzip_compression = DLT_LOGSTORAGE_GZIP_OFF;
} else {
dlt_log(LOG_WARNING,
"Unknown gzip compression flag. Set default OFF\n");
config->gzip_compression = DLT_LOGSTORAGE_GZIP_OFF;
dlt_log(LOG_WARNING, "Unknown gzip compression flag\n");
config->gzip_compression = DLT_LOGSTORAGE_GZIP_ERROR;
return 1;
}
#else
dlt_log(LOG_WARNING, "dlt-daemon not compiled with logstorage gzip support\n");
config->gzip_compression = 0;
config->gzip_compression = DLT_LOGSTORAGE_GZIP_OFF;
#endif
return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions src/offlinelogstorage/dlt_offline_logstorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@
/* Offline Logstorage disable network routing */
#define DLT_LOGSTORAGE_GZIP_ERROR -1 /* error case */
#define DLT_LOGSTORAGE_GZIP_UNSET 0 /* not set */
#define DLT_LOGSTORAGE_GZIP_OFF 1 /* default, enable network routing */
#define DLT_LOGSTORAGE_GZIP_ON (1 << 1) /* disable network routing */
#define DLT_LOGSTORAGE_GZIP_OFF 1 /* default, no compression */
#define DLT_LOGSTORAGE_GZIP_ON (1 << 1) /* enable gzip compression */

/* logstorage max cache */
extern unsigned int g_logstorage_cache_max;
Expand Down
36 changes: 21 additions & 15 deletions src/offlinelogstorage/dlt_offline_logstorage_behavior.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void dlt_logstorage_log_file_name(char *log_file_name,
}

dlt_logstorage_concat_logfile_name(log_file_name, ".dlt");
if (filter_config->gzip_compression) {
if (filter_config->gzip_compression == DLT_LOGSTORAGE_GZIP_ON) {
dlt_logstorage_concat_logfile_name(log_file_name, ".gz");
}
}
Expand Down Expand Up @@ -372,7 +372,7 @@ int dlt_logstorage_storage_dir_info(DltLogStorageUserConfig *file_config,
config->records = NULL;
}

char *suffix = config->gzip_compression ? ".dlt.gz" : ".dlt";
char *suffix = config->gzip_compression == DLT_LOGSTORAGE_GZIP_ON ? ".dlt.gz" : ".dlt";

for (i = 0; i < cnt; i++) {
int len = 0;
Expand Down Expand Up @@ -488,12 +488,13 @@ DLT_STATIC void dlt_logstorage_open_log_output_file(DltLogStorageFilterConfig *c
return;
}
config->fd = fileno(file);
if (config->gzip_compression) {
if (config->gzip_compression == DLT_LOGSTORAGE_GZIP_ON) {
#ifdef DLT_LOGSTORAGE_USE_GZIP
dlt_vlog(LOG_DEBUG, "%s: Opening GZIP log file\n", __func__);
config->gzlog = gzdopen(config->fd, mode);
#endif
} else {
}
else {
dlt_vlog(LOG_DEBUG, "%s: Opening log file\n", __func__);
config->log = file;
}
Expand Down Expand Up @@ -826,9 +827,10 @@ DLT_STATIC int dlt_logstorage_write_to_log(void *ptr, size_t size, size_t nmemb,
DltLogStorageFilterConfig *config)
{
#ifdef DLT_LOGSTORAGE_USE_GZIP
if (config->gzip_compression) {
if (config->gzip_compression == DLT_LOGSTORAGE_GZIP_ON) {
return gzfwrite(ptr, size, nmemb, config->gzlog);
} else {
}
else {
return fwrite(ptr, size, nmemb, config->log);
}
#else
Expand All @@ -853,26 +855,28 @@ DLT_STATIC void dlt_logstorage_check_write_ret(DltLogStorageFilterConfig *config
}

if (ret <= 0) {
if (config->gzip_compression) {
if (config->gzip_compression == DLT_LOGSTORAGE_GZIP_ON) {
#ifdef DLT_LOGSTORAGE_USE_GZIP
const char *msg = gzerror(config->gzlog, &ret);
if (msg != NULL) {
dlt_vlog(LOG_ERR, "%s: failed to write cache into log file: %s\n", __func__, msg);
}
#endif
} else {
}
else {
if (ferror(config->log) != 0)
dlt_vlog(LOG_ERR, "%s: failed to write cache into log file\n", __func__);
}
}
else {
/* force sync */
if (config->gzip_compression) {
if (config->gzip_compression == DLT_LOGSTORAGE_GZIP_ON) {
#ifdef DLT_LOGSTORAGE_USE_GZIP
if (gzflush(config->gzlog, Z_SYNC_FLUSH) != 0)
dlt_vlog(LOG_ERR, "%s: failed to gzflush log file\n", __func__);
#endif
} else {
}
else {
if (fflush(config->log) != 0)
dlt_vlog(LOG_ERR, "%s: failed to flush log file\n", __func__);
}
Expand Down Expand Up @@ -1103,7 +1107,7 @@ int dlt_logstorage_prepare_on_msg(DltLogStorageFilterConfig *config,
/* Sync only if on_msg */
if ((config->sync == DLT_LOGSTORAGE_SYNC_ON_MSG) ||
(config->sync == DLT_LOGSTORAGE_SYNC_UNSET)) {
if (config->gzip_compression) {
if (config->gzip_compression == DLT_LOGSTORAGE_GZIP_ON) {
if (fsync(fileno(config->gzlog)) != 0) {
if (errno != ENOSYS) {
dlt_vlog(LOG_ERR, "%s: failed to sync gzip log file\n", __func__);
Expand Down Expand Up @@ -1199,10 +1203,11 @@ int dlt_logstorage_write_on_msg(DltLogStorageFilterConfig *config,
dlt_log(LOG_WARNING, "Wrote less data than specified\n");

#ifdef DLT_LOGSTORAGE_USE_GZIP
if (config->gzip_compression) {
if (config->gzip_compression == DLT_LOGSTORAGE_GZIP_ON) {
gzerror(config->gzlog, &ret);
return ret;
} else {
}
else {
return ferror(config->log);
}
#else
Expand Down Expand Up @@ -1233,12 +1238,13 @@ int dlt_logstorage_sync_on_msg(DltLogStorageFilterConfig *config,
return -1;

if (status == DLT_LOGSTORAGE_SYNC_ON_MSG) { /* sync on every message */
if (config->gzip_compression) {
if (config->gzip_compression == DLT_LOGSTORAGE_GZIP_ON) {
#ifdef DLT_LOGSTORAGE_USE_GZIP
if (gzflush(config->gzlog, Z_SYNC_FLUSH) != 0)
dlt_vlog(LOG_ERR, "%s: failed to gzflush log file\n", __func__);
#endif
} else {
}
else {
if (fflush(config->log) != 0)
dlt_vlog(LOG_ERR, "%s: failed to flush log file\n", __func__);
}
Expand Down

0 comments on commit 80371aa

Please sign in to comment.