Fix: load: incomplete error handling for load_session_from_file
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Tue, 7 Apr 2020 20:27:05 +0000 (16:27 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 20 Apr 2020 19:34:30 +0000 (15:34 -0400)
Observed issue
==============
lttng-ivc test fails to fail.

test_save_load_blocking_timeout[lttng-tools-2.12-lttng-tools-2.11-False]

Here we load a xml created by lttng-tools-2.12 and try to load it using
lttng-tools 2.11. We expect this to fail on the load.

The command report an error on the stderr but the command return code
value is zero.

From lttng-ivc test runtime.log:
Command #0
  Return value: 0
  Command: lttng load --input-path=/home/joraj/lttng/lttng-ivc/.tox/py3/tmp/test_save_load_blocking_timeou0/save_load saved_trace
  STDOUT:
      Session saved_trace has been loaded successfully
  STDERR:
      XML Error: Element 'process_attr_trackers': This element is not expected.
      Error: Session configuration file validation failed

Cause
==============
The error coming from load_session_from_file is not handled correctly.

Solution
========

Rework error handling in load_session_from_path and
load_session_from_file.

LTTNG_ERR_LOAD_SESSION_NOENT is NOT an error when session_name is
specified in load_session_from_path. In this scenario, we are actively
looking for the configuration of the session.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I0fea474045b718664e70ffe169e4e4fa125791a8

src/common/config/session-config.c

index b1fa992fe0f65c02f922ea99d4d6d3c632d23b1c..86afc24394c701fd3a54bf7cf348b299d60b1312 100644 (file)
@@ -3309,10 +3309,24 @@ int load_session_from_file(const char *path, const char *session_name,
                        xmlNextElementSibling(session_node)) {
                ret = process_session_node(session_node,
                        session_name, overwrite, overrides);
-               if (session_name && ret == 0) {
-                       /* Target session found and loaded */
-                       session_found = 1;
-                       break;
+               if (!session_name && ret) {
+                       /* Loading error occurred. */
+                       goto end;
+               } else if (session_name) {
+                       if (ret == 0) {
+                               /* Target session found and loaded */
+                               session_found = 1;
+                               break;
+                       } else if (ret == -LTTNG_ERR_NO_SESSION) {
+                               /*
+                                * Ignore this error, we are looking for the
+                                * session.
+                                */
+                               ret = 0;
+                       } else {
+                               /* Loading error occurred. */
+                               goto end;
+                       }
                }
        }
 end:
@@ -3444,10 +3458,27 @@ int load_session_from_path(const char *path, const char *session_name,
 
                        ret = load_session_from_file(file_path.data, session_name,
                                validation_ctx, overwrite, overrides);
-                       if (session_name && !ret) {
-                               session_found = 1;
-                               break;
+                       if (!session_name && ret) {
+                               /* Loading error occured. */
+                               goto end;
+                       } else if (session_name) {
+                               if (ret == 0) {
+                                       /* Target session found and loaded */
+                                       session_found = 1;
+                                       break;
+                               } else if (ret ==
+                                               -LTTNG_ERR_LOAD_SESSION_NOENT) {
+                                       /*
+                                        * Ignore this error, we are looking for
+                                        * the session.
+                                        */
+                                       ret = 0;
+                               } else {
+                                       /* Loading error occured. */
+                                       goto end;
+                               }
                        }
+
                        /*
                         * Reset the buffer's size to the location of the
                         * path's trailing '/'.
This page took 0.029069 seconds and 4 git commands to generate.