[v6,4/6] eal: skip stdio on console logging

Message ID 20230629155858.75668-5-stephen@networkplumber.org (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series Logging related patches |

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

Stephen Hemminger June 29, 2023, 3:58 p.m. UTC
  There is no need to use stdio when logging to console.
Using the write system call directly avoids unnecessary copy
to stdio output buffer.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/eal/unix/eal_log.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Patch

diff --git a/lib/eal/unix/eal_log.c b/lib/eal/unix/eal_log.c
index 85d817c2d31e..151f30eb6071 100644
--- a/lib/eal/unix/eal_log.c
+++ b/lib/eal/unix/eal_log.c
@@ -5,6 +5,7 @@ 
 #include <stdio.h>
 #include <sys/types.h>
 #include <syslog.h>
+#include <unistd.h>
 
 #include <rte_log.h>
 
@@ -21,8 +22,7 @@  console_log_write(__rte_unused void *c, const char *buf, size_t size)
 	ssize_t ret;
 
 	/* write on stderr */
-	ret = fwrite(buf, 1, size, stderr);
-	fflush(stderr);
+	ret = write(STDERR_FILENO, buf, size);
 
 	/* Syslog error levels are from 0 to 7, so subtract 1 to convert */
 	syslog(rte_log_cur_msg_loglevel() - 1, "%.*s", (int)size, buf);