From c70d0a8e61140942447ef75b0afc2662551a4fad Mon Sep 17 00:00:00 2001 From: Oliver Hartkopp Date: Fri, 25 Mar 2022 15:15:57 +0100 Subject: [PATCH] candump: handle individual logfile name for stdout Since commit ad250a68dc83 ("candump: add option to define individual filename for logfile") the option "-f " 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: ad250a68dc83 ("candump: add option to define individual filename for logfile") Signed-off-by: Oliver Hartkopp --- candump.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/candump.c b/candump.c index eaa3c2f..6fe30bb 100644 --- a/candump.c +++ b/candump.c @@ -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");