mirror of
https://github.com/hoytech/strfry.git
synced 2025-06-19 17:37:43 +00:00
make bulk export commands gracefully exit on SIGPIPE (for example, if piped to head)
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
#include <arpa/inet.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <algorithm>
|
||||
#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");
|
||||
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