From: Francis Deslauriers Date: Mon, 26 Apr 2021 22:18:11 +0000 (-0400) Subject: run-as: reduce verbosity of fd sending error paths X-Git-Tag: v2.13.0-rc2~46 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=d4ea8de50ab6bfd348ac19828ac696d34287f895;p=lttng-tools.git run-as: reduce verbosity of fd sending error paths Issue ===== A testcase in `tests/regression/tools/save-load/test_save` tests that saving a session on an already existing configuration file fails. The test case fails as expected but it is a bit noisy in terms of error reporting: ok 9 - Enable channel chan-save for session save-42 ok 10 - Enable ust event tp:tptest for session save-42 Error: Attempt to send invalid file descriptor to master (fd = -1) PERROR - 09:57:10.893683118 [Client management]: Could not create configuration file: File exists (in save_session() at save.c:2706) PERROR - 09:57:10.893714862 [Main]: Failed to close result file descriptor: Bad file descriptor (in send_fds_to_master() at runas.c:824) ok 11 - Session failed to be saved. Expected! We see that 3 error statements are printed by the sessiond but only the second is really relevant. Fix === This commit: - changes the first `ERR()` statement to a `DBG()` statement, and - only call `close()` on seemingly valid FDs. Notes ===== This commit also removes the mention of "master" in the first `DBG()` statement as this function is used by both the master and the runas process. Signed-off-by: Francis Deslauriers Signed-off-by: Jérémie Galarneau Change-Id: Ie77d44233a770610f8a3f4412b84c0fd70c0812e --- diff --git a/src/common/runas.c b/src/common/runas.c index fc7b02be7..04aedc3e6 100644 --- a/src/common/runas.c +++ b/src/common/runas.c @@ -730,7 +730,7 @@ int do_send_fds(int sock, const int *fds, unsigned int fd_count) for (i = 0; i < fd_count; i++) { if (fds[i] < 0) { - ERR("Attempt to send invalid file descriptor to master (fd = %i)", + DBG("Attempt to send invalid file descriptor (fd = %i)", fds[i]); /* Return 0 as this is not a fatal error. */ return 0; @@ -818,10 +818,14 @@ int send_fds_to_master(struct run_as_worker *worker, enum run_as_cmd cmd, } for (i = 0; i < COMMAND_OUT_FD_COUNT(cmd); i++) { - int ret_close = close(COMMAND_OUT_FDS(cmd, run_as_ret)[i]); + int fd = COMMAND_OUT_FDS(cmd, run_as_ret)[i]; + if (fd >= 0) { + int ret_close = close(fd); - if (ret_close < 0) { - PERROR("Failed to close result file descriptor"); + if (ret_close < 0) { + PERROR("Failed to close result file descriptor (fd = %i)", + fd); + } } } end: