run-as: reduce verbosity of fd sending error paths
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Mon, 26 Apr 2021 22:18:11 +0000 (18:18 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 28 Apr 2021 21:33:50 +0000 (17:33 -0400)
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 <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Ie77d44233a770610f8a3f4412b84c0fd70c0812e

src/common/runas.c

index fc7b02be740d3636d0f25c514e58a6afc2c6c95d..04aedc3e69a00b14a5ffa0d24798d51d0d0c602e 100644 (file)
@@ -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:
This page took 0.026902 seconds and 5 git commands to generate.