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
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;
}
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: