Skip to content
Browse files

SERVER-7294 Terminate at startup on bad logpath.

  • Loading branch information...
1 parent f1c1215 commit d267f9e5de521b60af1e42b80b3ed0d0571e3d96 @andy10gen andy10gen committed Oct 8, 2012
Showing with 11 additions and 26 deletions.
  1. +11 −26 src/mongo/db/cmdline.cpp
View
37 src/mongo/db/cmdline.cpp
@@ -281,8 +281,6 @@ namespace mongo {
}
}
- string logpath;
-
#ifndef _WIN32
if (params.count("unixSocketPrefix")) {
cmdLine.socket = params["unixSocketPrefix"].as<string>();
@@ -303,26 +301,6 @@ namespace mongo {
::_exit(EXIT_BADOPTIONS);
}
- if ( params.count( "logpath" ) ) {
- // test logpath
- logpath = params["logpath"].as<string>();
- verify( logpath.size() );
- if ( logpath[0] != '/' ) {
- logpath = cmdLine.cwd + "/" + logpath;
- }
- bool exists = boost::filesystem::exists( logpath );
- FILE * test = fopen( logpath.c_str() , "a" );
- if ( ! test ) {
- cout << "can't open [" << logpath << "] for log file: " << errnoWithDescription() << endl;
- ::_exit(-1);
- }
- fclose( test );
- // if we created a file, unlink it (to avoid confusing log rotation code)
- if ( ! exists ) {
- unlink( logpath.c_str() );
- }
- }
-
cout.flush();
cerr.flush();
@@ -402,11 +380,18 @@ namespace mongo {
cout << "Cant use both a logpath and syslog " << endl;
::_exit(EXIT_BADOPTIONS);
}
-
- if ( logpath.size() == 0 )
- logpath = params["logpath"].as<string>();
+ string logpath = params["logpath"].as<string>();
+ if (logpath.empty()) {
+ cout << "Empty logpath option.";
+ ::_exit(EXIT_BADOPTIONS);
+ }
+ logpath = boost::filesystem::complete(logpath, cmdLine.cwd).native_file_string();
+
uassert( 10033 , "logpath has to be non-zero" , logpath.size() );
- initLogging( logpath , params.count( "logappend" ) );
+ if (!initLogging(logpath, params.count("logappend"))) {
+ cout << "Bad logpath value: \"" << logpath << "\"; terminating." << endl;
+ ::_exit(EXIT_BADOPTIONS);
+ }
}
if ( params.count("pidfilepath")) {

0 comments on commit d267f9e

Please sign in to comment.
Something went wrong with that request. Please try again.