rt-utils.c: Fix write() return value check
PATCH 1/1 rt-utils.c: Fix write() return value check
The write() return value check in tracemark() is a copy-paste from the one in tracing_stop() which checks for 2 bytes to be written. As a result, tracemark() is almost always warning.
Check for the write() return value to be equal to the written length, which is the value returned if no error occurred.
While at it, add "\n" to the warn messages.
--- src/lib/rt-utils.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
src/lib/rt-utils.c +3 -3
@@ -437,8 +437,8 @@ void tracemark(char *fmt, ...)/* write the tracemark message */ ret =write (tracemark_fd, tracebuf, len); -if (ret !=2 ) -warn ("trace stop write failed" ); +if (ret != len) +warn ("trace mark write failed\n" ); }void tracing_stop (void )
@@ -449,7 +449,7 @@ void tracing_stop(void)return ; ret =write (trace_fd,"0\n" ,2 );if (ret !=2 ) -warn ("trace stop write failed" ); +warn ("trace stop write failed\n" ); }void enable_trace_mark (void )
base-commit: 4e68b52f0e0c9777c91088948374c6ee3d4a1f6b
Signature · 1 line
2.53.0
Quoted 39 lines · Gabriele Monaco
The
write()return value check intracemark()is a copy-paste from the one intracing_stop()which checks for 2 bytes to be written. As a result,tracemark()is almost always warning.Check for the
write()return value to be equal to the written length, which is the value returned if no error occurred.
While at it, add "\n" to the warn messages.Fixes 60d60540c009 ("rt-utils.c: Check return values of write()")Signed-off-by Gabriele Monaco <[email protected]>--- src/lib/rt-utils.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)src/lib/rt-utils.c +3
-3@@ -437,8 +437,8 @@ void tracemark(char *fmt, ...)/* write the tracemark message */ ret =write (tracemark_fd, tracebuf, len); -if (ret !=2 ) -warn ("trace stop write failed" ); +if (ret != len) +warn ("trace mark write failed\n" ); }void tracing_stop (void )@@ -449,7 +449,7 @@ void tracing_stop(void)return ; ret =write (trace_fd,"0\n" ,2 );if (ret !=2 ) -warn ("trace stop write failed" ); +warn ("trace stop write failed\n" ); }void enable_trace_mark (void )
Quoted 2 lines
base-commit:
4e68b52f0e0c9777c91088948374c6ee3d4a1f6b