Files
ternfs-XTXMarkets/cpp/core/Common.cpp
Francesco Mazzoli f42ff2b219 Get rid of backtrace machinery
It is currently very fragile, due to:

* Differing versions of compilers/DWARF version result in a variety
    of breakages in the our code which analyzes the DWARF info;

* With musl, libunwind seems to be currently unable to traverse
    beyond signal handlers, due to the DWARF information not
    being present in the signal frame.
    See <https://maskray.me/blog/2022-04-10-unwinding-through-signal-handler>.
    Note that I have not verified that the problem in the blog
    post above is indeed what we're hitting, but it seems plausible.
2023-02-01 12:00:47 +00:00

34 lines
1.0 KiB
C++

#include "Common.hpp"
#include <arpa/inet.h>
#include <netinet/in.h>
#include <string.h>
#include <unistd.h>
// Throwing in static initialization is nasty, and there is no useful stacktrace
// Also use direct syscalls to write the error as iostream might not be initialized
// https://bugs.llvm.org/show_bug.cgi?id=28954
void dieWithError(const char *err) {
size_t remaining = strlen(err);
while (remaining) {
size_t s = write(STDERR_FILENO, err, remaining);
if (s == -1) {
if (errno == EINTR) {
continue;
} else {
_exit(1); // Can't write remaining error but nothing else can be done..
}
}
remaining -= s;
err += s;
}
size_t _ = write(STDERR_FILENO, "\n", 1);
_exit(1);
}
std::ostream& operator<<(std::ostream& out, struct sockaddr_in& addr) {
char buf[INET_ADDRSTRLEN];
inet_ntop(AF_INET, &addr.sin_addr, buf, sizeof(buf));
out << buf << ":" << ntohs(addr.sin_port);
return out;
}