@@ -428,8 +428,11 @@ bool AppInit2()
428
428
FILE* file = fopen (pathLockFile.string ().c_str (), " a" ); // empty lock file; created if it doesn't exist.
429
429
if (file) fclose (file);
430
430
static boost::interprocess::file_lock lock (pathLockFile.string ().c_str ());
431
+ /* Set a cstring to hold the datadir path cause we use it several times
432
+ * throughout init. */
433
+ const char * pszDataDir = GetDataDir ().string ().c_str ();
431
434
if (!lock.try_lock ())
432
- return InitError (strprintf (_ (" Cannot obtain a lock on data directory %s. Paycoin is probably already running." ), GetDataDir (). string (). c_str () ));
435
+ return InitError (strprintf (_ (" Cannot obtain a lock on data directory %s. Paycoin is probably already running." ), pszDataDir ));
433
436
434
437
#if !defined(WIN32) && !defined(QT_GUI)
435
438
if (fDaemon )
@@ -459,7 +462,7 @@ bool AppInit2()
459
462
printf (" Paycoin version %s (%s)\n " , FormatFullVersion ().c_str (), CLIENT_DATE.c_str ());
460
463
printf (" Using OpenSSL version %s\n " , SSLeay_version (SSLEAY_VERSION));
461
464
printf (" Default data directory %s\n " , GetDefaultDataDir ().string ().c_str ());
462
- printf (" Used data directory %s\n " , GetDataDir (). string (). c_str () );
465
+ printf (" Used data directory %s\n " , pszDataDir );
463
466
464
467
// Check and update minium version protocol after a given time.
465
468
if (time (NULL ) >= MICROPRIMES_STAGGER_DOWN)
@@ -471,6 +474,15 @@ bool AppInit2()
471
474
//
472
475
if (fDaemon )
473
476
fprintf (stdout, " Paycoin server starting\n " );
477
+
478
+ if (!bitdb.Open (GetDataDir ()))
479
+ {
480
+ string msg = strprintf (_ (" Error initializing database environment %s!"
481
+ " To recover, BACKUP THAT DIRECTORY, then remove"
482
+ " everything from it except for wallet.dat." ), pszDataDir);
483
+ return InitError (msg);
484
+ }
485
+
474
486
int64 nStart;
475
487
476
488
// ********************************************************* Step 5: network initialization
@@ -582,7 +594,7 @@ bool AppInit2()
582
594
printf (" Loading block index...\n " );
583
595
nStart = GetTimeMillis ();
584
596
if (!LoadBlockIndex ())
585
- strErrors << _ (" Error loading blkindex.dat" ) << " \n " ;
597
+ return InitError ( _ (" Error loading blkindex.dat" )) ;
586
598
587
599
// as LoadBlockIndex can take several minutes, it's possible the user
588
600
// requested to kill bitcoin-qt during the last operation. If so, exit.
0 commit comments