diff --git a/TODO b/TODO index 2b017e7..29e83c6 100644 --- a/TODO +++ b/TODO @@ -28,5 +28,4 @@ rate limits (maybe not needed now that we have plugins?) misc ? periodic reaping of disconnected sockets (maybe autoping is doing this already) - ? export not dying on SIGPIPE, or not getting SIGPIPE ? why isn't the LMDB mapping CLOEXEC diff --git a/src/apps/dbutils/cmd_export.cpp b/src/apps/dbutils/cmd_export.cpp index 3cf2636..0b86de2 100644 --- a/src/apps/dbutils/cmd_export.cpp +++ b/src/apps/dbutils/cmd_export.cpp @@ -32,6 +32,8 @@ void cmd_export(const std::vector &subArgs) { uint64_t start = reverse ? until : since; uint64_t startDup = reverse ? MAX_U64 : 0; + exitOnSigPipe(); + env.generic_foreachFull(txn, env.dbi_Event__created_at, lmdb::to_sv(start), lmdb::to_sv(startDup), [&](auto k, auto v) { if (reverse) { if (lmdb::from_sv(k) < since) return false; diff --git a/src/apps/dbutils/cmd_monitor.cpp b/src/apps/dbutils/cmd_monitor.cpp index 6c7304f..0bde893 100644 --- a/src/apps/dbutils/cmd_monitor.cpp +++ b/src/apps/dbutils/cmd_monitor.cpp @@ -54,6 +54,8 @@ void cmd_monitor(const std::vector &subArgs) { } } + exitOnSigPipe(); + env.foreach_Event(txn, [&](auto &ev){ monitors.process(txn, ev, [&](RecipientList &&recipients, uint64_t levId){ for (auto &r : recipients) { diff --git a/src/apps/dbutils/cmd_scan.cpp b/src/apps/dbutils/cmd_scan.cpp index ecc053b..713c29d 100644 --- a/src/apps/dbutils/cmd_scan.cpp +++ b/src/apps/dbutils/cmd_scan.cpp @@ -34,6 +34,8 @@ void cmd_scan(const std::vector &subArgs) { uint64_t numEvents = 0; + exitOnSigPipe(); + while (1) { bool complete = query.process(txn, [&](const auto &sub, uint64_t levId, std::string_view eventPayload){ if (count) numEvents++; diff --git a/src/global.h b/src/global.h index dfd6b1e..989ee89 100644 --- a/src/global.h +++ b/src/global.h @@ -16,3 +16,4 @@ uint64_t parseUint64(const std::string &s); std::string parseIP(const std::string &ip); uint64_t getDBVersion(lmdb::txn &txn); std::string padBytes(std::string_view str, size_t n, char padChar); +void exitOnSigPipe(); diff --git a/src/misc.cpp b/src/misc.cpp index df13ff7..8ce9f23 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -109,3 +110,10 @@ std::string padBytes(std::string_view str, size_t n, char padChar) { if (str.size() > n) throw herr("unable to pad, string longer than expected"); return std::string(str) + std::string(n - str.size(), padChar); } + +void exitOnSigPipe() { + struct sigaction act; + memset(&act, 0, sizeof act); + act.sa_sigaction = [](int, siginfo_t*, void*){ ::exit(1); }; + if (sigaction(SIGPIPE, &act, nullptr)) throw herr("couldn't run sigaction(): ", strerror(errno)); +}