chore: print info msgs to stderr
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
surtur 2022-02-03 00:37:20 +01:00
parent 0e4d1aeef0
commit a3daa722da
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D
10 changed files with 81 additions and 65 deletions

@ -67,6 +67,7 @@ auto Accumulator::src_is_registered(const uint8_t& id) noexcept -> bool {
if (reg) { if (reg) {
fmt::print( fmt::print(
stderr,
"[!] acc(add_source): entropy source \"{}\" already registered", "[!] acc(add_source): entropy source \"{}\" already registered",
_src_id); _src_id);
return true; return true;

@ -60,7 +60,7 @@ public:
[[maybe_unused]] bool scheduled; [[maybe_unused]] bool scheduled;
} }
catch (std::exception& e) { catch (std::exception& e) {
fmt::print("{}\n", e.what()); fmt::print(stderr, "{}\n", e.what());
} }
} }
} }

@ -42,7 +42,7 @@ public:
void add(const std::vector<char>& event) override { void add(const std::vector<char>& event) override {
try { try {
this->pool_id = (this->where_to) % 32; this->pool_id = (this->where_to) % 32;
fmt::print("[i] add to pool {}\n", this->pool_id); fmt::print(stderr, "[i] add to pool {}\n", this->pool_id);
int ret{this->_pools->at(this->pool_id) int ret{this->_pools->at(this->pool_id)
.add_entropy(this->_source_id, event)}; .add_entropy(this->_source_id, event)};
if (ret == 1) { if (ret == 1) {

@ -14,6 +14,7 @@
#include <cassert> #include <cassert>
#include <chrono> #include <chrono>
#include <cstdint> #include <cstdint>
#include <cstdio>
#include <exception> #include <exception>
#include <memory> #include <memory>
#include <mutex> #include <mutex>
@ -40,7 +41,7 @@ Fortuna::Fortuna() {
} }
Fortuna::~Fortuna() noexcept { Fortuna::~Fortuna() noexcept {
this->die_point.wait(); this->die_point.wait();
fmt::print("[*] Fortuna says goodbye!\n"); fmt::print(stderr, "[*] Fortuna says goodbye!\n");
} }
@ -52,11 +53,11 @@ auto Fortuna::random_data(unsigned int n_bytes) -> void {
std::lock_guard<std::mutex> lg(mtx_random_data); std::lock_guard<std::mutex> lg(mtx_random_data);
const auto start{std::chrono::system_clock::now()}; const auto start{std::chrono::system_clock::now()};
fmt::print("random_data starting - {}\n", start); fmt::print(stderr, "random_data starting - {}\n", start);
auto elapsed{std::chrono::duration_cast<std::chrono::milliseconds>( auto elapsed{std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::steady_clock::now().time_since_epoch() - std::chrono::steady_clock::now().time_since_epoch() -
now.time_since_epoch())}; now.time_since_epoch())};
fmt::print("[i] fortuna: last_reseed: {} ago\n", elapsed); fmt::print(stderr, "[i] fortuna: last_reseed: {} ago\n", elapsed);
now = std::chrono::steady_clock::now(); now = std::chrono::steady_clock::now();
try { try {
@ -67,7 +68,8 @@ auto Fortuna::random_data(unsigned int n_bytes) -> void {
const int pools_to_use{ffsll(static_cast<int>(get_reseed_ctr()))}; const int pools_to_use{ffsll(static_cast<int>(get_reseed_ctr()))};
fmt::print("[*] fortuna: current p0 length: {}\n", fmt::print(stderr,
"[*] fortuna: current p0 length: {}\n",
this->R._p_pools->at(0).get_s_byte_count()); this->R._p_pools->at(0).get_s_byte_count());
if (R.Gen.time_to_reseed(R._p_pools->at(0).get_s_byte_count(), if (R.Gen.time_to_reseed(R._p_pools->at(0).get_s_byte_count(),
min_pool_size, min_pool_size,
@ -91,27 +93,29 @@ auto Fortuna::random_data(unsigned int n_bytes) -> void {
s.clear(); s.clear();
} }
fmt::print("[i] fortuna: reseed ctr {}\n", get_reseed_ctr()); fmt::print(stderr, "[i] fortuna: reseed ctr {}\n", get_reseed_ctr());
if (get_reseed_ctr() == 0) { if (get_reseed_ctr() == 0) {
fmt::print("[!] ERROR: reseed ctr is 0, PRNG not seeded!\n"); fmt::print(stderr,
"[!] ERROR: reseed ctr is 0, PRNG not seeded!\n");
throw std::runtime_error("illegal state, PRNG not seeded"); throw std::runtime_error("illegal state, PRNG not seeded");
} }
else { else {
const std::string n{R.Gen.generate_random_data(n_bytes)}; const std::string n{R.Gen.generate_random_data(n_bytes)};
fmt::print( fmt::print(
stderr,
"got you {} proper bytes from generate_random_data -> {}\n", "got you {} proper bytes from generate_random_data -> {}\n",
n_bytes, n_bytes,
n); n);
} }
} }
catch (std::exception& e) { catch (std::exception& e) {
fmt::print("{}\n", e.what()); fmt::print(stderr, "{}\n", e.what());
} }
const auto end{std::chrono::system_clock::now()}; const auto end{std::chrono::system_clock::now()};
const std::chrono::duration<float> diff = end - start; const std::chrono::duration<float> diff = end - start;
fmt::print("random_data done - {}\n", end); fmt::print(stderr, "random_data done - {}\n", end);
fmt::print("getting random data took {:.{}f}s\n", diff.count(), 12); fmt::print(stderr, "getting random data took {:.{}f}s\n", diff.count(), 12);
} // random_data } // random_data
@ -120,8 +124,8 @@ auto Fortuna::seed_file_manager_service() -> void {
{ {
std::lock_guard<std::mutex> p_ul(print_mtx); std::lock_guard<std::mutex> p_ul(print_mtx);
fmt::print("[i] fortuna: starting seed file manager service\n"); fmt::print(stderr, "[i] fortuna: starting seed file manager service\n");
fmt::print("[*] sfm: checkup interval {}\n", checkup_interval); fmt::print(stderr, "[*] sfm: checkup interval {}\n", checkup_interval);
} }
auto right_now{fortuna::Util::current_time()}; auto right_now{fortuna::Util::current_time()};
@ -140,12 +144,12 @@ auto Fortuna::seed_file_manager_service() -> void {
right_now = fortuna::Util::current_time(); right_now = fortuna::Util::current_time();
{ {
std::lock_guard<std::mutex> p_ul(print_mtx); std::lock_guard<std::mutex> p_ul(print_mtx);
fmt::print("[*] sfm: checkup time @{}\n", right_now); fmt::print(stderr, "[*] sfm: checkup time @{}\n", right_now);
} }
if (!sfm.is_job_running()) { if (!sfm.is_job_running()) {
{ {
std::lock_guard<std::mutex> p_ul(print_mtx); std::lock_guard<std::mutex> p_ul(print_mtx);
fmt::print("[*] sfm: job not running, starting\n"); fmt::print(stderr, "[*] sfm: job not running, starting\n");
} }
try { try {
sfm.do_stuff(); sfm.do_stuff();
@ -161,7 +165,7 @@ auto Fortuna::seed_file_manager_service() -> void {
else { else {
{ {
std::lock_guard<std::mutex> p_ul(print_mtx); std::lock_guard<std::mutex> p_ul(print_mtx);
fmt::print("[*] sfm: job running\n"); fmt::print(stderr, "[*] sfm: job running\n");
} }
// sleeping here assumes nothing goes wrong. should sth break, there // sleeping here assumes nothing goes wrong. should sth break, there
// will be no sleeps when trying to restart sfm in the above block // will be no sleeps when trying to restart sfm in the above block
@ -171,7 +175,7 @@ auto Fortuna::seed_file_manager_service() -> void {
} }
std::lock_guard<std::mutex> p_ul(print_mtx); std::lock_guard<std::mutex> p_ul(print_mtx);
fmt::print("[*] sfm: stopping, goodbye!\n\n"); fmt::print(stderr, "[*] sfm: stopping, goodbye!\n\n");
this->die_point.count_down(); this->die_point.count_down();
} }
@ -180,8 +184,9 @@ auto Fortuna::urandom_entropy_src_service() -> void {
{ {
std::lock_guard<std::mutex> p_ul(print_mtx); std::lock_guard<std::mutex> p_ul(print_mtx);
fmt::print("[i] fortuna: starting urandom entropy src service\n"); fmt::print(stderr,
fmt::print("[*] ues: wakeup interval {}\n", wakeup_interval); "[i] fortuna: starting urandom entropy src service\n");
fmt::print(stderr, "[*] ues: wakeup interval {}\n", wakeup_interval);
} }
auto right_now{fortuna::Util::current_time()}; auto right_now{fortuna::Util::current_time()};
@ -196,7 +201,7 @@ auto Fortuna::urandom_entropy_src_service() -> void {
while (this->continue_running.load()) { while (this->continue_running.load()) {
try { try {
std::lock_guard<std::mutex> p_ul(print_mtx); std::lock_guard<std::mutex> p_ul(print_mtx);
fmt::print("[i] now: {}\n", fortuna::Util::current_time()); fmt::print(stderr, "[i] now: {}\n", fortuna::Util::current_time());
// check if ptr still valid // check if ptr still valid
if (this->R._p_pools) { if (this->R._p_pools) {
@ -210,7 +215,7 @@ auto Fortuna::urandom_entropy_src_service() -> void {
catch (std::exception& e) { catch (std::exception& e) {
{ {
std::lock_guard<std::mutex> p_ul(print_mtx); std::lock_guard<std::mutex> p_ul(print_mtx);
fmt::print("[!] ues exception: {}\n", e.what()); fmt::print(stderr, "[!] ues exception: {}\n", e.what());
} }
} }
right_now = fortuna::Util::current_time(); right_now = fortuna::Util::current_time();
@ -219,14 +224,15 @@ auto Fortuna::urandom_entropy_src_service() -> void {
mtx_l.lock(); mtx_l.lock();
{ {
std::lock_guard<std::mutex> p_ul(print_mtx); std::lock_guard<std::mutex> p_ul(print_mtx);
fmt::print("[*] fortuna: current p0 length: {}\n\n", fmt::print(stderr,
"[*] fortuna: current p0 length: {}\n\n",
this->R._p_pools->at(0).get_s_byte_count()); this->R._p_pools->at(0).get_s_byte_count());
} }
mtx_l.unlock(); mtx_l.unlock();
} }
std::lock_guard<std::mutex> p_ul(print_mtx); std::lock_guard<std::mutex> p_ul(print_mtx);
fmt::print("[*] ues: stopping, goodbye!\n\n"); fmt::print(stderr, "[*] ues: stopping, goodbye!\n\n");
this->die_point.count_down(); this->die_point.count_down();
} }

@ -38,7 +38,7 @@ public:
auto set_reseed_ctr_to_null() -> void { auto set_reseed_ctr_to_null() -> void {
std::scoped_lock sl(mtx_accu, print_mtx); std::scoped_lock sl(mtx_accu, print_mtx);
this->_p_accumulator->set_reseed_ctr_to_null(); this->_p_accumulator->set_reseed_ctr_to_null();
fmt::print("reseed_ctr set to 0x00\n"); fmt::print(stderr, "reseed_ctr set to 0x00\n");
} }
auto incr_reseed_ctr() -> void { auto incr_reseed_ctr() -> void {
@ -63,7 +63,7 @@ public:
std::lock_guard<std::mutex> lg(print_mtx); std::lock_guard<std::mutex> lg(print_mtx);
R.initialize_pools(); R.initialize_pools();
fmt::print("[i] fortuna: pools initialized\n"); fmt::print(stderr, "[i] fortuna: pools initialized\n");
} }
this->_p_accumulator->set_pools_ptr(R._p_pools); this->_p_accumulator->set_pools_ptr(R._p_pools);
@ -74,12 +74,13 @@ public:
catch (std::exception& e) { catch (std::exception& e) {
std::lock_guard<std::mutex> lg(print_mtx); std::lock_guard<std::mutex> lg(print_mtx);
fmt::print( fmt::print(
stderr,
"{}\n[!] fortuna: fatal error, PRNG initialization FAILED!\n\n", "{}\n[!] fortuna: fatal error, PRNG initialization FAILED!\n\n",
e.what()); e.what());
} }
std::lock_guard<std::mutex> lg(print_mtx); std::lock_guard<std::mutex> lg(print_mtx);
fmt::print("[*] fortuna: PRNG initialized\n"); fmt::print(stderr, "[*] fortuna: PRNG initialized\n");
} }
auto seed_file_manager_service() -> void; auto seed_file_manager_service() -> void;
@ -88,7 +89,7 @@ public:
auto stop_running() -> int { auto stop_running() -> int {
try { try {
fmt::print("[i] fortuna: received the stop request...\n"); fmt::print(stderr, "[i] fortuna: received the stop request...\n");
this->continue_running.store(false); this->continue_running.store(false);
} }
catch (std::exception& e) { catch (std::exception& e) {

@ -15,6 +15,7 @@
#include <chrono> #include <chrono>
#include <cmath> #include <cmath>
#include <cstdint> #include <cstdint>
#include <cstdio>
#include <mutex> #include <mutex>
#include <stdexcept> #include <stdexcept>
@ -39,7 +40,7 @@ void Generator::initialize_generator() {
try { try {
std::memset(G.k, 0x00, G.k.size()); std::memset(G.k, 0x00, G.k.size());
std::memset(G.ctr.begin(), 0x00, this->ctr_len); std::memset(G.ctr.begin(), 0x00, this->ctr_len);
fmt::print("Generator initialized\n"); fmt::print(stderr, "Generator initialized\n");
} }
catch (CryptoPP::Exception& e) { catch (CryptoPP::Exception& e) {
fmt::print(stderr, "{}\n", e.what()); fmt::print(stderr, "{}\n", e.what());
@ -75,10 +76,10 @@ auto Generator::reseed(const std::string& s) -> void {
std::string a{fortuna::Util::do_sha(da_key + s)}; std::string a{fortuna::Util::do_sha(da_key + s)};
std::memmove(G.k, fortuna::Util::de_hex(a).c_str(), G.k_length); std::memmove(G.k, fortuna::Util::de_hex(a).c_str(), G.k_length);
Generator::ctr_inc(); Generator::ctr_inc();
fmt::print("[i] generator: reseeded\n"); fmt::print(stderr, "[i] generator: reseeded\n");
} }
catch (std::exception& e) { catch (std::exception& e) {
fmt::print("{}", e.what()); fmt::print(stderr, "{}\n", e.what());
throw; throw;
} }
} }
@ -153,9 +154,8 @@ auto Generator::generate_random_data(const unsigned int& n) -> std::string {
std::lock_guard<std::recursive_mutex> lg(mtx); std::lock_guard<std::recursive_mutex> lg(mtx);
if (n == 0) { if (n == 0) {
// do not do this..? // const std::string msg{"zero bytes requested, bailing\n"};
const std::string msg{"zero bytes requested, bailing\n"}; fmt::print(stderr, "[!] error: zero bytes requested, bailing\n");
fmt::print("[*] g: error: {}", msg);
// throw std::invalid_argument(msg); // throw std::invalid_argument(msg);
// TODO(me): throw or not? // TODO(me): throw or not?
// perhaps just return prematurely // perhaps just return prematurely
@ -164,9 +164,7 @@ auto Generator::generate_random_data(const unsigned int& n) -> std::string {
// pre-computed 2^20 // pre-computed 2^20
if (n > 1048576) { if (n > 1048576) {
const std::string msg{"n cannot be > 2^20\n"}; throw std::invalid_argument("[!] error: n cannot be > 2^20\n");
fmt::print("[*] error: {}", msg);
throw std::invalid_argument(msg);
} }
std::string r; std::string r;
@ -179,14 +177,14 @@ auto Generator::generate_random_data(const unsigned int& n) -> std::string {
static_cast<unsigned int>(std::ceil(static_cast<double>(n) / 16))); static_cast<unsigned int>(std::ceil(static_cast<double>(n) / 16)));
std::string rr{generate_blocks(how_many)}; std::string rr{generate_blocks(how_many)};
fmt::print("rr (output from generate_blocks): {}\n", rr); fmt::print(stderr, "rr (output from generate_blocks): {}\n", rr);
// since we're truncating hex, we need to get twice more characters // since we're truncating hex, we need to get twice more characters
r = rr.substr(0, n * 0x02ul); r = rr.substr(0, n * 0x02ul);
rr.clear(); rr.clear();
} }
catch (std::exception& e) { catch (std::exception& e) {
fmt::print("{}", e.what()); fmt::print(stderr, "{}", e.what());
} }
/* re-key */ /* re-key */
@ -202,7 +200,7 @@ auto Generator::generate_random_data(const unsigned int& n) -> std::string {
std::memmove(G.k, dst.c_str(), G.k_length); std::memmove(G.k, dst.c_str(), G.k_length);
} }
catch (std::exception& e) { catch (std::exception& e) {
fmt::print("{}", e.what()); fmt::print(stderr, "{}", e.what());
} }
return r; return r;
} }

@ -21,11 +21,12 @@ auto sigint_handler(int sig_n) -> void {
try { try {
constexpr auto madmsg{"HAHA no not ending on SIGINT, send a SIGTERM"}; constexpr auto madmsg{"HAHA no not ending on SIGINT, send a SIGTERM"};
while (madness-- > 0) { while (madness-- > 0) {
fmt::print("{:<{}}\n", madmsg, 16); fmt::print(stderr, "{:<{}}\n", madmsg, 16);
} }
} }
catch (std::exception& e) { catch (std::exception& e) {
fmt::print("[!] bailing, something (bad) happened: {}\n", e.what()); fmt::print(
stderr, "[!] bailing, something (bad) happened: {}\n", e.what());
throw; throw;
} }
} }
@ -34,8 +35,9 @@ auto sigterm_handler(int sig_n) -> void {
assert(sig_n == 15); assert(sig_n == 15);
try { try {
constexpr auto news{" BREAKING NEWS "}; constexpr auto news{" BREAKING NEWS "};
fmt::print("\n\n{:*^{}}\n\n", news, 79); fmt::print(stderr, "\n\n{:*^{}}\n\n", news, 79);
fmt::print("[i] main: received signal {} (SIGTERM)\n\tpid: {}\n\twill " fmt::print(stderr,
"[i] main: received signal {} (SIGTERM)\n\tpid: {}\n\twill "
"attempt to stop\n", "attempt to stop\n",
sig_n, sig_n,
getpid()); getpid());
@ -47,7 +49,8 @@ auto sigterm_handler(int sig_n) -> void {
} }
} }
catch (std::exception& e) { catch (std::exception& e) {
fmt::print("[!] bailing, something (bad) happened: {}\n", e.what()); fmt::print(
stderr, "[!] bailing, something (bad) happened: {}\n", e.what());
throw; throw;
} }
} }
@ -55,7 +58,7 @@ auto sigterm_handler(int sig_n) -> void {
int main() { int main() {
fmt::print("[*] doing evil stuff\n"); fmt::print(stderr, "[*] doing evil stuff\n");
signal(SIGTERM, chance::sigterm_handler); signal(SIGTERM, chance::sigterm_handler);
signal(SIGINT, chance::sigint_handler); signal(SIGINT, chance::sigint_handler);
@ -81,13 +84,13 @@ int main() {
if (chance::AUTOSTOP) { if (chance::AUTOSTOP) {
auto err{chance::f->stop_running()}; auto err{chance::f->stop_running()};
if (err) { if (err) {
fmt::print("[!] ERROR: failed to stop Fortuna!\n"); fmt::print(stderr, "[!] ERROR: failed to stop Fortuna!\n");
throw std::runtime_error("failed to stop Fortuna nicely"); throw std::runtime_error("failed to stop Fortuna nicely");
} }
} }
} }
catch (std::exception& e) { catch (std::exception& e) {
fmt::print("[!] exiting due to \"{}\"\n", e.what()); fmt::print(stderr, "[!] exiting due to \"{}\"\n", e.what());
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }

@ -38,19 +38,20 @@ auto Pool::add_entropy(const unsigned int& source,
std::string event_str; std::string event_str;
std::atomic<bool> all_ok{false}; std::atomic<bool> all_ok{false};
fmt::print("\tevent_size (bytes): {}\n", event_size); fmt::print(stderr, "\tevent_size (bytes): {}\n", event_size);
try { try {
if (source > 255) { if (source > 255) {
throw std::invalid_argument( throw std::invalid_argument(
"source number outside of interval <0,255>\n"); "source number outside of interval <0,255>\n");
} }
fmt::print("\tsource_id: {}\n", source); fmt::print(stderr, "\tsource_id: {}\n", source);
if (event_size < 1 || event_size > max_event_size) { if (event_size < 1 || event_size > max_event_size) {
const std::string msg{ const std::string msg{
"[!] add_entropy: the length of the event needs to " "[!] add_entropy: the length of the event needs to "
"be from the interval <1,32>"}; "be from the interval <1,32>"};
fmt::print("\tsource: {}\n{}\nevent size: {}\n\tpool_id: {}", fmt::print(stderr,
"\tsource: {}\n{}\nevent size: {}\n\tpool_id: {}",
source, source,
msg, msg,
event_size, event_size,
@ -62,7 +63,7 @@ auto Pool::add_entropy(const unsigned int& source,
} }
} }
catch (const std::exception& e) { catch (const std::exception& e) {
fmt::print("{}\n", e.what()); fmt::print(stderr, "{}\n", e.what());
throw; throw;
} }
@ -78,7 +79,8 @@ auto Pool::add_entropy(const unsigned int& source,
fullevent.push_back(static_cast<char>(event_size)); fullevent.push_back(static_cast<char>(event_size));
fullevent.insert( fullevent.insert(
std::end(fullevent), std::begin(event), std::end(event)); std::end(fullevent), std::begin(event), std::end(event));
fmt::print("\t[i] add_entropy(fullevent): {}\n", fullevent); fmt::print(
stderr, "\t[i] add_entropy(fullevent): {}\n", fullevent);
// FIXME: check size for overflow // FIXME: check size for overflow
// also, atm this counts event size but actually what gets // also, atm this counts event size but actually what gets
@ -88,13 +90,15 @@ auto Pool::add_entropy(const unsigned int& source,
{ {
const std::string digest(fortuna::Util::do_sha(fullevent)); const std::string digest(fortuna::Util::do_sha(fullevent));
fmt::print("\t[i] add_entropy(digest): {}\n", digest); fmt::print(
stderr, "\t[i] add_entropy(digest): {}\n", digest);
append_s(digest); append_s(digest);
} }
} }
fmt::print("\t[i] s.length() (simple char count): {}\n" fmt::print(stderr,
"\t[i] s.length() (simple char count): {}\n"
"\t[i] get_s_byte_count() (byte count): {}\n" "\t[i] get_s_byte_count() (byte count): {}\n"
"\t[i] pool_id: {}\n" "\t[i] pool_id: {}\n"
"\t[i] s: {}\n", "\t[i] s: {}\n",
@ -105,7 +109,7 @@ auto Pool::add_entropy(const unsigned int& source,
this->s); this->s);
} }
catch (const std::exception& e) { catch (const std::exception& e) {
fmt::print("[!] pool(add_entropy): {}\n", e.what()); fmt::print(stderr, "[!] pool(add_entropy): {}\n", e.what());
// FIXME: handle this (as all the other unhandled exceptions) // FIXME: handle this (as all the other unhandled exceptions)
throw; throw;
} }
@ -145,7 +149,7 @@ auto Pool::append_s(const std::string& entropy_s) -> void {
this->s.append(entropy_s); this->s.append(entropy_s);
} }
catch (const std::exception& e) { catch (const std::exception& e) {
fmt::print("{}\n", e.what()); fmt::print(stderr, "{}\n", e.what());
} }
} }

@ -12,6 +12,7 @@
#include <cassert> #include <cassert>
#include <cstdint> #include <cstdint>
#include <cstdio>
#include <fstream> #include <fstream>
#include <memory> #include <memory>
#include <mutex> #include <mutex>
@ -73,7 +74,8 @@ auto SeedFileManager::update_seed_file() -> void {
try { try {
{ {
if (!seed_file_exists()) { if (!seed_file_exists()) {
fmt::print("\t[i] sfm: SEED FILE NOT PRESENT, creating...\n"); fmt::print(stderr,
"\t[i] sfm: SEED FILE NOT PRESENT, creating...\n");
std::fstream f_stream; std::fstream f_stream;
f_stream.open(config.seed_f_path, f_stream.open(config.seed_f_path,
std::fstream::out | std::fstream::trunc); std::fstream::out | std::fstream::trunc);
@ -86,7 +88,7 @@ auto SeedFileManager::update_seed_file() -> void {
if (!f_stream.is_open()) { if (!f_stream.is_open()) {
const std::string msg{"\t[!] sfm: error opening seed file!\n"}; const std::string msg{"\t[!] sfm: error opening seed file!\n"};
fmt::print("{} {}\n", msg, config.seed_f_path); fmt::print(stderr, "{} {}\n", msg, config.seed_f_path);
fortuna::SeedFileManager::IS_RUNNING = false; fortuna::SeedFileManager::IS_RUNNING = false;
throw std::runtime_error(msg); throw std::runtime_error(msg);
@ -99,7 +101,8 @@ auto SeedFileManager::update_seed_file() -> void {
config.seed_f_length) { config.seed_f_length) {
const std::string msg{ const std::string msg{
"\t[!] sfm: error reading seed from file, length mismatch"}; "\t[!] sfm: error reading seed from file, length mismatch"};
fmt::print("{} {}, length: {} vs desired length: {}\n", fmt::print(stderr,
"{} {}, length: {} vs desired length: {}\n",
msg, msg,
config.seed_f_path, config.seed_f_path,
f_stream.gcount(), f_stream.gcount(),
@ -117,7 +120,7 @@ auto SeedFileManager::update_seed_file() -> void {
write_seed_file(); write_seed_file();
} }
catch (std::exception& e) { catch (std::exception& e) {
fmt::print("{}\n", e.what()); fmt::print(stderr, "{}\n", e.what());
fortuna::SeedFileManager::IS_RUNNING = false; fortuna::SeedFileManager::IS_RUNNING = false;
throw; throw;
} }
@ -144,7 +147,7 @@ auto SeedFileManager::write_seed_file() -> void {
true /*pumpAll*/, true /*pumpAll*/,
new CryptoPP::HexDecoder(new CryptoPP::ArraySink(&buff[0], length))); new CryptoPP::HexDecoder(new CryptoPP::ArraySink(&buff[0], length)));
fmt::print("[*] sfm: writing seed file\n"); fmt::print(stderr, "[*] sfm: writing seed file\n");
try { try {
std::ofstream f_stream{config.seed_f_path, std::ofstream f_stream{config.seed_f_path,
@ -153,8 +156,8 @@ auto SeedFileManager::write_seed_file() -> void {
static_cast<int64_t>(config.seed_f_length)); static_cast<int64_t>(config.seed_f_length));
} }
catch (std::exception& e) { catch (std::exception& e) {
fmt::print("[!] sfm: error writing to seed file!\n"); fmt::print(stderr, "[!] sfm: error writing to seed file!\n");
fmt::print("{}\n", e.what()); fmt::print(stderr, "{}\n", e.what());
fortuna::SeedFileManager::IS_RUNNING = false; fortuna::SeedFileManager::IS_RUNNING = false;
throw; throw;
} }

@ -52,12 +52,12 @@ auto UrandomEntropySrc::event(accumulator::EventAdderImpl& adder) -> void {
} }
catch (std::ifstream::failure& e) { catch (std::ifstream::failure& e) {
// FIXME: handle the exception // FIXME: handle the exception
fmt::print("io exception caugth: {}\n", e.what()); fmt::print(stderr, "io exception caugth: {}\n", e.what());
throw; throw;
} }
catch (std::exception& e) { catch (std::exception& e) {
// FIXME: handle the exception // FIXME: handle the exception
fmt::print("[!] ues: exception caugth: {}\n", e.what()); fmt::print(stderr, "[!] ues: exception caugth: {}\n", e.what());
throw; throw;
} }
} }