From 53a42a43d3478a8459dfffaca45d5cf9c9dbbc31 Mon Sep 17 00:00:00 2001 From: Jonathan Rajotte Date: Tue, 9 Jul 2019 15:57:52 -0400 Subject: [PATCH] Fix: use return of bt_localtime_r as success criteria Encountered error: jenkins@ci-node-bionic-amd64-05-10:~/babeltrace/tests/cli$ TZ=EST4 ./../utils/../../src/cli/babeltrace2 ./../utils/../data/ctf-traces/succeed/wk-heartbeat-u/ --begin 12:48:17.587029529 07-09 15:31:04.183 1224375 1224375 E PLUGIN/FLT.UTILS.TRIMMER Cannot convert timestamp to date and time: No such file or directory[trimmer] ts=1351532897 07-09 15:31:04.183 1224375 1224375 W LIB/MSG-ITER @iterator.c:865 Component input port message iterator's "next" method failed: iter-addr=0x55705c7ee870, iter-type=BT_MESSAGE_ITERATOR_TYPE_SELF_COMPONENT_PORT_INPUT, iter-upstream-comp-name="trimmer", iter-upstream-comp-log-level=BT_LOGGING_LEVEL_WARN, iter-upstream-comp-class-type=BT_COMPONENT_CLASS_TYPE_FILTER, iter-upstream-comp-class-name="trimmer", iter-upstream-comp-class-partial-descr="Keep messages that occur within ", iter-upstream-port-type=BT_PORT_TYPE_OUTPUT, iter-upstream-port-name="out", status=ERROR 07-09 15:31:04.183 1224375 1224375 W LIB/GRAPH @graph.c:580 Component's "consume" method failed: status=ERROR, comp-addr=0x55705c7ec4a0, comp-name="pretty", comp-log-level=BT_LOGGING_LEVEL_WARN, comp-class-type=BT_COMPONENT_CLASS_TYPE_SINK, comp-class-name="pretty", comp-class-partial-descr="Pretty-print messages (`text` fo", comp-class-is-frozen=0, comp-class-so-handle-addr=0x55705c808840, comp-class-so-handle-path="/home/jenkins/babeltrace/src/plugins/text/babeltrace-plugin-text.la", comp-input-port-count=1, comp-output-port-count=0 07-09 15:31:04.183 1224375 1224375 E CLI Graph failed to complete successfully But the same use of TZ=EST4 works fine on date. bt_localtime_r behave the same as localtime_r. The success criteria of localtime_r is that the returned pointer is not null. Checking the value of errno as a success criteria is never a good idea. man errno: The value in errno is significant only when the return value of the call indicated an error (i.e., -1 from most system calls; -1 or NULL from most library functions); a function that succeeds is allowed to change errno. The value of errno is never set to zero by any system call or library function. Signed-off-by: Jonathan Rajotte Change-Id: I1454ed1d5f8fe2aa095c8fcbb7b315bcb3c83871 Reviewed-on: https://review.lttng.org/c/babeltrace/+/1664 Reviewed-by: Michael Jeanson Reviewed-by: Philippe Proulx Tested-by: jenkins --- src/plugins/utils/trimmer/trimmer.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/plugins/utils/trimmer/trimmer.c b/src/plugins/utils/trimmer/trimmer.c index c1c0f692..720b4f81 100644 --- a/src/plugins/utils/trimmer/trimmer.c +++ b/src/plugins/utils/trimmer/trimmer.c @@ -866,6 +866,7 @@ int set_trimmer_iterator_bound(struct trimmer_iterator *trimmer_it, { struct trimmer_comp *trimmer_comp = trimmer_it->trimmer_comp; struct tm tm; + struct tm *res; time_t time_seconds = (time_t) (ns_from_origin / NS_PER_S); int ret = 0; @@ -874,12 +875,12 @@ int set_trimmer_iterator_bound(struct trimmer_iterator *trimmer_it, /* We only need to extract the date from this time */ if (is_gmt) { - bt_gmtime_r(&time_seconds, &tm); + res = bt_gmtime_r(&time_seconds, &tm); } else { - bt_localtime_r(&time_seconds, &tm); + res = bt_localtime_r(&time_seconds, &tm); } - if (errno) { + if (!res) { BT_COMP_LOGE_ERRNO("Cannot convert timestamp to date and time", "ts=%" PRId64, (int64_t) time_seconds); ret = -1; -- 2.34.1