X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Fapps%2Fsigner.cpp;h=6b49241fc6747a3b658a1b915562d2d6cf3340f4;hb=156855b7e12c3a0254590da514b0d0e8efe469f4;hp=dc9e702c54a7d6cc917d4ce962866a44a99ac0af;hpb=9e866a1a2facc8cb1565cd660c6b6d482f18ecb1;p=cassiopeia.git diff --git a/src/apps/signer.cpp b/src/apps/signer.cpp index dc9e702..6b49241 100644 --- a/src/apps/signer.cpp +++ b/src/apps/signer.cpp @@ -1,6 +1,8 @@ + #include #include #include +#include #include "db/database.h" #include "db/mysql.h" @@ -10,6 +12,7 @@ #include "io/bios.h" #include "io/slipBio.h" #include "io/recordHandler.h" +#include "log/logger.hpp" #include "util.h" #include "config.h" @@ -21,7 +24,7 @@ extern std::string serialPath; -int main( int argc, const char* argv[] ) { +int main( int argc, const char* argv[] ) try { ( void ) argc; ( void ) argv; @@ -34,31 +37,48 @@ int main( int argc, const char* argv[] ) { #endif if( parseConfig( path ) != 0 ) { + logger::fatal( "Could not parse configuration file." ); return -1; } std::shared_ptr ssl_lib = ssl_lib_ref; if( serialPath == "" ) { - std::cout << "Error: no serial device is given" << std::endl; + logger::fatal( "Error: No device for the serial connection was given." ); return -1; } std::shared_ptr conn = openSerial( serialPath ); std::shared_ptr slip1( BIO_new( toBio() ), BIO_free ); - ( ( SlipBIO* )slip1->ptr )->setTarget( std::shared_ptr( new OpensslBIOWrapper( conn ) ) ); + static_cast( slip1->ptr )->setTarget( std::shared_ptr( new OpensslBIOWrapper( conn ) ), true ); DefaultRecordHandler* dh = new DefaultRecordHandler( std::shared_ptr( new SimpleOpensslSigner( ) ), slip1 ); + logger::note( "Entering mainloop" ); while( true ) { try { dh->handle(); //} catch( const std::exception &ch ) { //std::cout << "Real exception: " << typeid(ch).name() << ", " << ch.what() << std::endl; - } catch( char const* ch ) { - std::cout << "Exception: " << ch << std::endl; + } catch( const std::exception& e ) { + logger::error( "Exception: ", e.what() ); } } return -1; + +} catch( std::exception& e ) { + try { + logger::fatalf( "Fatal Error: %s!\n", e.what() ); + }catch( std::exception &e){ + printf( "Fatal Error (+logger failed): %s!\n", e.what() ); + } + return -1; +} catch( ... ) { + try{ + logger::fatal( "Fatal Error: Unknown Exception!\n" ); + }catch( std::exception &e){ + printf( "Fatal Error (+ logger failed): %s!\n", e.what() ); + } + return -1; }