From 696b8806fbbf4d83e1439f6e8d6613c6efd4fc8c Mon Sep 17 00:00:00 2001 From: Roberto Scolaro Date: Mon, 20 Jan 2025 08:54:54 +0000 Subject: [PATCH] fix(libsinsp): allow reading scap from stdin Signed-off-by: Roberto Scolaro --- userspace/libsinsp/sinsp.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/userspace/libsinsp/sinsp.cpp b/userspace/libsinsp/sinsp.cpp index a7f512276d..bb9f41028c 100644 --- a/userspace/libsinsp/sinsp.cpp +++ b/userspace/libsinsp/sinsp.cpp @@ -717,8 +717,19 @@ std::string sinsp::generate_gvisor_config(const std::string& socket_path) { } int64_t sinsp::get_file_size(const std::string& fname, char* error) { + std::filesystem::path p(fname); + auto s = std::filesystem::status(p); + + // scap files can be streamed and the source can be one + // of the following. In that case we return 0 as file size. + if(s.type() == std::filesystem::file_type::character || + s.type() == std::filesystem::file_type::fifo || + s.type() == std::filesystem::file_type::socket) { + return 0; + } + std::error_code ec; - auto sz = std::filesystem::file_size(fname, ec); + auto sz = std::filesystem::file_size(p, ec); if(ec) { strlcpy(error, ec.message().c_str(), SCAP_LASTERR_SIZE); return -1;