#include "include/types.h"
#include "include/compat.h"
#include "include/inline_memory.h"
+#include "include/scope_guard.h"
#if defined(HAVE_XIO)
#include "msg/xio/XioMsg.h"
#endif
return 0;
}
- void close_pipe(int *fds) {
+ static void close_pipe(const int *fds) {
if (fds[0] >= 0)
VOID_TEMP_FAILURE_RETRY(::close(fds[0]));
if (fds[1] >= 0)
<< bendl;
throw error_code(r);
}
+ auto sg = make_scope_guard([=] { close_pipe(tmpfd); });
r = set_nonblocking(tmpfd);
if (r < 0) {
bdout << "raw_pipe: error setting nonblocking flag on temp pipe: "
r = errno;
bdout << "raw_pipe: error tee'ing into temp pipe: " << cpp_strerror(r)
<< bendl;
- close_pipe(tmpfd);
throw error_code(r);
}
data = (char *)malloc(len);
if (!data) {
- close_pipe(tmpfd);
throw bad_alloc();
}
r = safe_read(tmpfd[0], data, len);
<< bendl;
free(data);
data = NULL;
- close_pipe(tmpfd);
throw error_code(r);
}
- close_pipe(tmpfd);
return data;
}
bool source_consumed;