From 317ea246af2890928a75913db461ff2f417e518c Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Fri, 17 Apr 2020 15:49:52 -0400 Subject: [PATCH] Fix: load: incomplete error handling for load_session_from_file MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This fix is adapted from a fix against the stable-2.11 branch. The commit message of the stable-2.11 branch follows. An equivalent fix was already in place in `load_session_from_path()`, but the same problem as the stable-2.11 branch is present in `load_session_from_file()`. Original message: 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: Jérémie Galarneau Signed-off-by: Jonathan Rajotte Change-Id: Ic68c253aa194bf8ab72c3c271f10d443118bdeee --- src/common/config/session-config.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/common/config/session-config.c b/src/common/config/session-config.c index a8ea68eda..e893c1298 100644 --- a/src/common/config/session-config.c +++ b/src/common/config/session-config.c @@ -3767,10 +3767,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 a + * specific session. + */ + ret = 0; + } else { + /* Loading error occurred. */ + goto end; + } } } end: @@ -3778,9 +3792,6 @@ end: if (!ret) { ret = session_found ? 0 : -LTTNG_ERR_LOAD_SESSION_NOENT; } - if (ret == -LTTNG_ERR_NO_SESSION) { - ret = -LTTNG_ERR_LOAD_SESSION_NOENT; - } return ret; } -- 2.34.1