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;
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;
dh->handle();
//} catch( const std::exception &ch ) {
//std::cout << "Real exception: " << typeid(ch).name() << ", " << ch.what() << std::endl;
+ } catch( const std::string& ch ) {
+ std::cout << "Exception: " << ch << std::endl;
} catch( char const* ch ) {
std::cout << "Exception: " << ch << std::endl;
}
#include <openssl/ssl.h>
+#include "util.h"
#include "io/record.h"
#include "io/opensslBIO.h"
#include "io/slipBio.h"
throw "Error while fetching time?";
}
- log = std::shared_ptr<std::ofstream>(
- new std::ofstream( std::string( "logs/log_" ) + std::to_string( c_time ) ),
- []( std::ofstream * ptr ) {
- ptr->close();
- delete ptr;
- } );
+ log = openLogfile( std::string( "logs/log_" ) + std::to_string( c_time ) );
ssl = std::shared_ptr<SSL>( SSL_new( ctx.get() ), SSL_free );
std::shared_ptr<BIO> bio(
if( !SSL_shutdown( ssl.get() ) && !SSL_shutdown( ssl.get() ) ) {
( *log ) << "ERROR: SSL close failed" << std::endl;
}
+ parent->reset(); // Connection ended
break;
if( !SSL_shutdown( ssl.get() ) && !SSL_shutdown( ssl.get() ) ) {
( *log ) << "ERROR: SSL close failed" << std::endl;
}
-
+ parent->reset(); // Connection ended
break;
}
return std::pair<bool, time_t>( false, 0 );
}
}
+
+std::shared_ptr<std::ofstream> openLogfile( const std::string name) {
+ struct stat buffer;
+ std::string tname = name;
+ int ctr = 2;
+ while(stat (tname.c_str(), &buffer) == 0) {
+ tname = name + "_" + std::to_string(ctr++);
+ }
+ auto res = std::shared_ptr<std::ofstream>(new std::ofstream( tname ),
+ [](std::ofstream *p){
+ p->close();
+ delete p;
+ });
+ if(! res->good() ){
+ throw std::string("Failed to open file for logging: ") + name;
+ }
+ return res;
+}
#include <string>
#include <ctime>
+#include <memory>
void writeFile( const std::string& name, const std::string& content );
std::string readFile( const std::string& name );
std::pair<bool, std::time_t> parseMonthInterval( std::time_t t, const std::string& date );
std::pair<bool, std::time_t> parseYearInterval( std::time_t t, const std::string& date );
+
+std::shared_ptr<std::ofstream> openLogfile( const std::string name);