Skip to content

Commit

Permalink
Merge pull request #26 from m-kress/ignore_invalid_commmand
Browse files Browse the repository at this point in the history
Ignore invalid commmand
  • Loading branch information
m-kress authored Jul 6, 2023
2 parents 402dfce + 2121831 commit 5dd3073
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
* Version (not released, yet)
- m-kress:
-- add missing brackets to harmonize code
-- check (stat) the program path given as command and ignore the command, if not existing
- auouymous:
-- fix behavior of (program_)?regex and (program_)?neg_regex conditions
- LonEox78:
Expand Down
3 changes: 3 additions & 0 deletions man/metalog.conf.5.in
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ Set to \fI0\fR to filter out repeat log messages.
Run the specified program as soon as something is logged in a given section.

The program is passed the date, the matching program name, and the log message.

In case the program doesn't exist at metalog startup, metalog will not exit and
just ignore that config line.
.TP
\fBstamp_fmt\fR = \fI"%b %e %T"\fR
Format of the human readable timestamp prepended to all log messages.
Expand Down
19 changes: 19 additions & 0 deletions src/metalog.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,25 @@ static int parseLine(char * const line, ConfigBlock **cur_block,
(void) 0;
}
else if (strcasecmp(keyword, "command") == 0) {
char *command = NULL;
struct stat st;
char *p = NULL;

if ((command = wstrdup(value)) == NULL) {
return -3;
}

p = strchr(command, (int) ' ');
if (p != NULL) {
*p = '\0';
}
if (stat(command, &st) < 0) {
warnp("Ignoring command \"%s\"", command);
free(command);
return 0;
}
free(command);

if (((*cur_block)->command = wstrdup(value)) == NULL) {
return -3;
}
Expand Down

0 comments on commit 5dd3073

Please sign in to comment.