candump: handle individual logfile name for stdout

Since commit ad250a68dc ("candump: add option to define individual
filename for logfile") the option "-f <fname>" allows to define an
individual filename for a logfile.

Usually the "-" is used as filename to represent stdout or stdin on
Linux/Posix systems to be able to concatenate several applications via
pipes. This patch handles this special case by detecting the filename
"-" to print the logfile format on stdout instead of creating a logfile
with the name "-".

Fixes: ad250a68dc ("candump: add option to define individual filename for logfile")
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
pull/354/head
Oliver Hartkopp 2022-03-25 15:15:57 +01:00
parent aa3f029925
commit c70d0a8e61
1 changed files with 6 additions and 0 deletions

View File

@ -442,6 +442,12 @@ int main(int argc, char **argv)
exit(0);
}
/* "-f -" is equal to "-L" (print logfile format on stdout) */
if (log && logname && strcmp("-", logname) == 0) {
log = 0; /* no logging into a file */
logfrmt = 1; /* print logformat output to stdout */
}
if (silent == SILENT_INI) {
if (log) {
fprintf(stderr, "Disabled standard output while logging.\n");