]> WPIA git - cassiopeia.git/blobdiff - src/apps/client.cpp
chg: replace default std::shared_ptr<…>() with explicit nullptr for empty return...
[cassiopeia.git] / src / apps / client.cpp
index 7c5bf0888b5a9bb3ac6996e7e02cd1ec19ca2aa7..71ef1790cd70cbb65d56b22c586614ffb195b4e6 100644 (file)
@@ -30,7 +30,7 @@ extern std::unordered_map<std::string, std::shared_ptr<CAConfig>> CAs;
 void checkCRLs( std::shared_ptr<Signer> sign ) {
     std::cout << "Signing CRLs" << std::endl;
 
-    for( auto x : CAs ) {
+    for( auto& x : CAs ) {
         std::cout << "Checking: " << x.first << std::endl;
 
         if( !x.second->crlNeedsResign() ) {
@@ -50,11 +50,9 @@ void checkCRLs( std::shared_ptr<Signer> sign ) {
 }
 
 int main( int argc, const char* argv[] ) {
-    ( void ) argc;
-    ( void ) argv;
     bool once = false;
 
-    if( argc == 2 && std::string( "--once" ) == std::string( argv[1] ) ) {
+    if( argc == 2 && std::string( "--once" ) == argv[1] ) {
         once = true;
     }
 
@@ -107,14 +105,9 @@ int main( int argc, const char* argv[] ) {
             continue;
         }
 
-        std::ofstream* logP = new std::ofstream( std::string( "logs/" ) + job->id + std::string( "_" ) + job->warning + std::string( ".log" ) );
-        std::shared_ptr<std::ofstream> logPtr(
-            logP,
-            []( std::ofstream * ptr ) {
-                ( *ptr ).close();
-                delete ptr;
-            } );
-        std::ofstream& log = *logP;
+        std::shared_ptr<std::ofstream> logPtr = openLogfile( std::string( "logs/" ) + job->id + std::string( "_" ) + job->warning + std::string( ".log" ) );
+
+        std::ofstream& log = *( logPtr.get() );
 
         sign->setLog( logPtr );
         log << "TASK ID: " << job->id << std::endl;
@@ -159,8 +152,15 @@ int main( int argc, const char* argv[] ) {
                 log << "FINE: CERTIFICATE LOG: " << res->log << std::endl;
                 log << "FINE: CERTIFICATE:" << std::endl << res->certificate << std::endl;
                 std::string fn = writeBackFile( job->target.c_str(), res->certificate, keyDir );
+
+                if( fn.empty() ) {
+                    log << "ERROR: Writeback of the certificate failed." << std::endl;
+                    jp->failJob( job );
+                    continue;
+                }
+
                 res->crt_name = fn;
-                jp->writeBack( job, res );
+                jp->writeBack( job, res ); //! \FIXME: Check return value
                 log << "FINE: signing done." << std::endl;
 
                 if( DAEMON ) {
@@ -195,6 +195,8 @@ int main( int argc, const char* argv[] ) {
                 jp->finishJob( job );
             } catch( const char* c ) {
                 std::cout << "Exception: " << c << std::endl;
+            } catch( const std::string& c ) {
+                std::cout << "Exception: " << c << std::endl;
             }
         } else {
             log << "Unknown job type" << job->task << std::endl;