mirror of
https://github.com/hoytech/strfry.git
synced 2025-06-17 08:48:51 +00:00
make bulk export commands gracefully exit on SIGPIPE (for example, if piped to head)
This commit is contained in:
1
TODO
1
TODO
@ -28,5 +28,4 @@ rate limits (maybe not needed now that we have plugins?)
|
|||||||
|
|
||||||
misc
|
misc
|
||||||
? periodic reaping of disconnected sockets (maybe autoping is doing this already)
|
? 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
|
? why isn't the LMDB mapping CLOEXEC
|
||||||
|
@ -32,6 +32,8 @@ void cmd_export(const std::vector<std::string> &subArgs) {
|
|||||||
uint64_t start = reverse ? until : since;
|
uint64_t start = reverse ? until : since;
|
||||||
uint64_t startDup = reverse ? MAX_U64 : 0;
|
uint64_t startDup = reverse ? MAX_U64 : 0;
|
||||||
|
|
||||||
|
exitOnSigPipe();
|
||||||
|
|
||||||
env.generic_foreachFull(txn, env.dbi_Event__created_at, lmdb::to_sv<uint64_t>(start), lmdb::to_sv<uint64_t>(startDup), [&](auto k, auto v) {
|
env.generic_foreachFull(txn, env.dbi_Event__created_at, lmdb::to_sv<uint64_t>(start), lmdb::to_sv<uint64_t>(startDup), [&](auto k, auto v) {
|
||||||
if (reverse) {
|
if (reverse) {
|
||||||
if (lmdb::from_sv<uint64_t>(k) < since) return false;
|
if (lmdb::from_sv<uint64_t>(k) < since) return false;
|
||||||
|
@ -54,6 +54,8 @@ void cmd_monitor(const std::vector<std::string> &subArgs) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exitOnSigPipe();
|
||||||
|
|
||||||
env.foreach_Event(txn, [&](auto &ev){
|
env.foreach_Event(txn, [&](auto &ev){
|
||||||
monitors.process(txn, ev, [&](RecipientList &&recipients, uint64_t levId){
|
monitors.process(txn, ev, [&](RecipientList &&recipients, uint64_t levId){
|
||||||
for (auto &r : recipients) {
|
for (auto &r : recipients) {
|
||||||
|
@ -34,6 +34,8 @@ void cmd_scan(const std::vector<std::string> &subArgs) {
|
|||||||
|
|
||||||
uint64_t numEvents = 0;
|
uint64_t numEvents = 0;
|
||||||
|
|
||||||
|
exitOnSigPipe();
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
bool complete = query.process(txn, [&](const auto &sub, uint64_t levId, std::string_view eventPayload){
|
bool complete = query.process(txn, [&](const auto &sub, uint64_t levId, std::string_view eventPayload){
|
||||||
if (count) numEvents++;
|
if (count) numEvents++;
|
||||||
|
@ -16,3 +16,4 @@ uint64_t parseUint64(const std::string &s);
|
|||||||
std::string parseIP(const std::string &ip);
|
std::string parseIP(const std::string &ip);
|
||||||
uint64_t getDBVersion(lmdb::txn &txn);
|
uint64_t getDBVersion(lmdb::txn &txn);
|
||||||
std::string padBytes(std::string_view str, size_t n, char padChar);
|
std::string padBytes(std::string_view str, size_t n, char padChar);
|
||||||
|
void exitOnSigPipe();
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -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");
|
if (str.size() > n) throw herr("unable to pad, string longer than expected");
|
||||||
return std::string(str) + std::string(n - str.size(), padChar);
|
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));
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user