Skip to content

Commit

Permalink
Merge pull request #27 from m-kress/trailing_newline
Browse files Browse the repository at this point in the history
Trailing newline
  • Loading branch information
m-kress authored Jul 18, 2023
2 parents 5dd3073 + 49322f1 commit 5753f62
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
5 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
* Version (not released, yet)
- m-kress:
-- Do not substitute trailing control characters of a log line, but eliminate them completelly.
Be aware, that this change will break existing filters that rely on the trailing underscore!

* Version 20230707
- m-kress:
-- add missing brackets to harmonize code
-- check (stat) the program path given as command and ignore the command, if not existing
Expand Down
19 changes: 10 additions & 9 deletions src/metalog.c
Original file line number Diff line number Diff line change
Expand Up @@ -1229,13 +1229,6 @@ static int get_stamp_fmt_timestamp(const char *stamp_fmt, char *datebuf, int dat
return 0;
}

static int log_stdout(const char * const date,
const char * const prg, const char * const info)
{
printf("%s [%s] %s\n", date, prg, info);
return 0;
}

static int processLogLine(const int logcode,
const char * const prg, char * const info)
{
Expand Down Expand Up @@ -1356,7 +1349,7 @@ static int processLogLine(const int logcode,
writeLogLine(block->output, datebuf, prg, info);

/* write to stdout */
log_stdout(datebuf, prg, info);
printf("%s [%s] %s\n", datebuf, prg, info);

/* send the log entry to the remote host */
if (remote_host.hostname != NULL && block->remote_log) {
Expand Down Expand Up @@ -1402,8 +1395,16 @@ static void sanitize(char * const line_)
register unsigned char *line = (unsigned char *) line_;

while (*line != 0U) {
/* replace control characters of the line */
if (ISCTRLCODE(*line)) {
*line = NONPRINTABLE_SUSTITUTE_CHAR;
/* eliminate a trailing control character (even '\n'), if it is the last one in this line */
if (*(line + 1) == 0U) {
*line = 0U;
}
else {
/* substitude a control character if it is in the middle of the line */
*line = NONPRINTABLE_SUSTITUTE_CHAR;
}
}
line++;
}
Expand Down
4 changes: 3 additions & 1 deletion src/metalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,10 @@ typedef enum LogLineType_ {
#define DEFAULT_DNS_LOOKUP_INTERVERVAL 120 /* seconds, after that a DNS lookup should be repeated */

#ifdef ACCEPT_UNICODE_CONTROL_CHARS
# define ISCTRLCODE(X) ((X) == 0x7f || ((unsigned char) (X)) < 32U)
/* "DEL" (0x7f) character or all characters < "SPACE" (0x20) */
# define ISCTRLCODE(X) ((X) == 0x7f || ((unsigned char) (X)) < 0x20)
#else
/* "DEL" (0x7f) character or all characters in (extended) ASCII character control groups C0 and C1 */
# define ISCTRLCODE(X) ((X) == 0x7f || !(((unsigned char) (X)) & 0x60))
#endif

Expand Down

0 comments on commit 5753f62

Please sign in to comment.