Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of github.com:mongodb/mongo

  • Loading branch information...
commit 6cacecacdb9870cbb3013ce6cc87c6f39b19335b 2 parents 3f55adc + fac1f12
Dwight Merriman dwight authored
Showing with 5,975 additions and 771 deletions.
  1. +12 −2 SConstruct
  2. +0 −23 buildscripts/bb.py
  3. +3,361 −0 buildscripts/cpplint.py
  4. +106 −0 buildscripts/lint.py
  5. +2 −0  buildscripts/smoke.py
  6. +7 −1 buildscripts/utils.py
  7. +1 −0  jstests/multiVersion/multi_version_sharding_passthrough.js
  8. +24 −0 jstests/rename6.js
  9. +3 −1 jstests/replsets/stepdown.js
  10. +13 −8 jstests/replsets/stepdown2.js
  11. +6 −1 src/mongo/SConscript
  12. +1 −1  src/mongo/base/global_initializer.cpp
  13. +1 −1  src/mongo/base/global_initializer_registerer.cpp
  14. +3 −3 src/mongo/base/initializer_dependency_graph.h
  15. +1 −1  src/mongo/base/make_string_vector.cpp
  16. +10 −9 src/mongo/bson/bson_db.h
  17. +14 −13 src/mongo/bson/bsondemo/bsondemo.cpp
  18. +1 −1  src/mongo/client/authentication_table.h
  19. +15 −0 src/mongo/client/clientOnly-private.h
  20. +1 −1  src/mongo/client/clientOnly.cpp
  21. +1 −1  src/mongo/client/connpool.h
  22. +16 −1 src/mongo/client/constants.h
  23. +1 −1  src/mongo/client/dbclient_rs.cpp
  24. +1 −1  src/mongo/client/dbclient_rs.h
  25. +1 −1  src/mongo/client/dbclientinterface.h
  26. +1 −1  src/mongo/client/distlock.h
  27. +15 −0 src/mongo/client/examples/insert_demo.cpp
  28. +15 −0 src/mongo/client/examples/mongoperf.cpp
  29. +18 −16 src/mongo/client/mongo_client_lib.cpp
  30. +4 −4 src/mongo/client/parallel.cpp
  31. +1 −1  src/mongo/client/parallel.h
  32. +15 −0 src/mongo/client/simple_client_demo.cpp
  33. +2 −2 src/mongo/db/btree.h
  34. +16 −0 src/mongo/db/btreebuilder.h
  35. +3 −3 src/mongo/db/cap.cpp
  36. +1 −11 src/mongo/db/client.cpp
  37. +10 −0 src/mongo/db/clientcursor.cpp
  38. +9 −1 src/mongo/db/clientcursor.h
  39. +26 −5 src/mongo/db/cloner.cpp
  40. +106 −49 src/mongo/db/cmdline.cpp
  41. +7 −1 src/mongo/db/cmdline.h
  42. +224 −0 src/mongo/db/cmdline_test.cpp
  43. +16 −0 src/mongo/db/collection.h
  44. +17 −1 src/mongo/db/commands/cpuprofile.cpp
  45. +1 −0  src/mongo/db/commands/distinct.cpp
  46. +1 −0  src/mongo/db/commands/find_and_modify.cpp
  47. +16 −0 src/mongo/db/commands/fsync.cpp
  48. +14 −13 src/mongo/db/commands/fsync.h
  49. +1 −0  src/mongo/db/commands/group.cpp
  50. +6 −5 src/mongo/db/commands/hashcmd.cpp
  51. +16 −0 src/mongo/db/commands/isself.cpp
  52. +1 −0  src/mongo/db/commands/mr.cpp
  53. +1 −0  src/mongo/db/commands/mr.h
  54. +16 −0 src/mongo/db/curop-inl.h
  55. +16 −0 src/mongo/db/d_globals.cpp
  56. +17 −0 src/mongo/db/d_globals.h
  57. +16 −0 src/mongo/db/databaseholder.h
  58. +63 −61 src/mongo/db/db.cpp
  59. +11 −1 src/mongo/db/dbcommands.cpp
  60. +1 −0  src/mongo/db/dbcommands_admin.cpp
  61. +17 −0 src/mongo/db/dbcommands_generic.cpp
  62. +2 −3 src/mongo/db/dbeval.cpp
  63. +1 −1  src/mongo/db/diskloc.h
  64. +14 −13 src/mongo/db/driverHelpers.cpp
  65. +17 −1 src/mongo/db/dur.h
  66. +1 −1  src/mongo/db/dur_preplogbuffer.cpp
  67. +2 −2 src/mongo/db/dur_recover.cpp
  68. +16 −0 src/mongo/db/dur_recover.h
  69. +16 −0 src/mongo/db/dur_stats.h
  70. +0 −54 src/mongo/db/globals.h
  71. +7 −0 src/mongo/db/hasher.h
  72. +3 −5 src/mongo/db/hashindex.cpp
  73. +2 −1  src/mongo/db/hashindex.h
  74. +2 −2 src/mongo/db/index_update.cpp
  75. +1 −1  src/mongo/db/instance.cpp
  76. +1 −1  src/mongo/db/json.cpp
  77. +188 −0 src/mongo/db/keypattern.cpp
  78. +156 −0 src/mongo/db/keypattern.h
  79. +17 −1 src/mongo/db/memconcept.cpp
  80. +19 −2 src/mongo/db/memconcept.h
  81. +2 −0  src/mongo/db/mongod.vcxproj
  82. +6 −0 src/mongo/db/mongod.vcxproj.filters
  83. +31 −29 src/mongo/db/namespace_details.cpp
  84. +33 −15 src/mongo/db/namespace_details.h
  85. +65 −0 src/mongo/db/namespacestring.h
  86. +76 −0 src/mongo/db/namespacestring_test.cpp
  87. +1 −1  src/mongo/db/nonce.cpp
  88. +15 −9 src/mongo/db/oplog.cpp
  89. +17 −0 src/mongo/db/oplogreader.h
  90. +36 −10 src/mongo/db/ops/update.cpp
  91. +19 −1 src/mongo/db/ops/update.h
  92. +35 −15 src/mongo/db/ops/update_internal.cpp
  93. +11 −4 src/mongo/db/ops/update_internal.h
  94. +17 −0 src/mongo/db/pagefault.cpp
  95. +17 −0 src/mongo/db/pagefault.h
  96. +5 −2 src/mongo/db/pdfile.cpp
  97. +4 −0 src/mongo/db/pdfile.h
  98. +1 −1  src/mongo/db/pipeline/document.h
  99. +1 −1  src/mongo/db/pipeline/document_source.cpp
  100. +1 −1  src/mongo/db/pipeline/document_source_limit.cpp
  101. +1 −1  src/mongo/db/pipeline/document_source_match.cpp
  102. +1 −1  src/mongo/db/pipeline/document_source_unwind.cpp
  103. +1 −1  src/mongo/db/pipeline/expression.h
  104. +2 −2 src/mongo/db/pipeline/pipeline.cpp
  105. +1 −1  src/mongo/db/projection.cpp
  106. +1 −68 src/mongo/db/queryutil.cpp
  107. +7 −26 src/mongo/db/queryutil.h
  108. +82 −5 src/mongo/db/record.cpp
  109. +1 −1  src/mongo/db/repl.cpp
  110. +1 −1  src/mongo/db/repl/bgsync.cpp
  111. +1 −1  src/mongo/db/repl/rs.cpp
  112. +13 −0 src/mongo/db/repl/rs_config.cpp
  113. +6 −0 src/mongo/db/repl/rs_config.h
  114. +16 −0 src/mongo/db/repl/rs_exception.h
  115. +1 −1  src/mongo/db/repl/rs_initialsync.cpp
  116. +1 −1  src/mongo/db/repl/rs_initiate.cpp
  117. +3 −3 src/mongo/db/repl/rs_rollback.cpp
  118. +1 −1  src/mongo/db/repl/rs_sync.h
  119. +16 −0 src/mongo/db/resource.h
  120. +1 −1  src/mongo/dbtests/accumulatortests.cpp
  121. +0 −15 src/mongo/dbtests/basictests.cpp
  122. +3 −3 src/mongo/dbtests/btreetests.cpp
  123. +2 −2 src/mongo/dbtests/documentsourcetests.cpp
  124. +1 −1  src/mongo/dbtests/documenttests.cpp
  125. +1 −1  src/mongo/dbtests/expressiontests.cpp
  126. +1 −1  src/mongo/dbtests/jsobjtests.cpp
  127. +2 −2 src/mongo/dbtests/perf/btreeperf.cpp
  128. +3 −3 src/mongo/dbtests/queryoptimizercursortests.cpp
  129. +47 −0 src/mongo/dbtests/repltests.cpp
  130. +1 −1  src/mongo/dbtests/spin_lock_test.cpp
  131. +16 −0 src/mongo/dbtests/stacktests.cpp
  132. +2 −0  src/mongo/dbtests/test.vcxproj
  133. +6 −0 src/mongo/dbtests/test.vcxproj.filters
  134. +1 −3 src/mongo/dbtests/updatetests.cpp
  135. +16 −0 src/mongo/platform/basic.h
  136. +31 −0 src/mongo/platform/bits.h
  137. +13 −0 src/mongo/platform/bits_test.cpp
  138. +2 −1  src/mongo/platform/random.h
  139. +16 −0 src/mongo/platform/windows_basic.h
  140. +1 −1  src/mongo/s/balancer_policy.h
  141. +3 −3 src/mongo/s/chunk.cpp
  142. +9 −7 src/mongo/s/d_chunk_manager.cpp
  143. +7 −6 src/mongo/s/d_chunk_manager.h
  144. +2 −2 src/mongo/s/d_logic.h
  145. +33 −16 src/mongo/s/d_migrate.cpp
  146. +4 −4 src/mongo/s/d_writeback.h
  147. +2 −2 src/mongo/s/grid.h
  148. +4 −0 src/mongo/s/mongos.vcxproj
  149. +12 −0 src/mongo/s/mongos.vcxproj.filters
  150. +0 −5 src/mongo/s/s_only.cpp
  151. +7 −1 src/mongo/s/server.cpp
  152. +1 −1  src/mongo/s/shard_version.h
  153. +7 −17 src/mongo/s/shardkey.cpp
  154. +21 −20 src/mongo/s/shardkey.h
  155. +1 −1  src/mongo/scripting/bson_template_evaluator.cpp
  156. +1 −1  src/mongo/scripting/engine_spidermonkey.cpp
  157. +18 −1 src/mongo/server.h
  158. +1 −1  src/mongo/shell/db.js
  159. +10 −9 src/mongo/shell/linenoise.cpp
  160. +2 −0  src/mongo/shell/mk_wcwidth.cpp
  161. +2 −0  src/mongo/shell/mk_wcwidth.h
  162. +1 −1  src/mongo/shell/shardingtest.js
  163. +1 −1  src/mongo/shell/shell_utils_extended.cpp
  164. +1 −1  src/mongo/shell/utils_sh.js
  165. +2 −7 src/mongo/tools/restore.cpp
  166. +2 −2 src/mongo/tools/sniffer.cpp
  167. +4 −2 src/mongo/tools/tool.cpp
  168. +15 −0 src/mongo/unittest/unittest_main.cpp
  169. +2 −2 src/mongo/util/admin_access.h
  170. +2 −2 src/mongo/util/alignedbuilder.cpp
  171. +4 −4 src/mongo/util/background.h
  172. +18 −0 src/mongo/util/checksum.h
  173. +16 −0 src/mongo/util/compress.cpp
  174. +16 −0 src/mongo/util/compress.h
  175. +1 −1  src/mongo/util/concurrency/list.h
  176. +16 −0 src/mongo/util/concurrency/mapsf.h
  177. +17 −1 src/mongo/util/concurrency/mutexdebugger.h
  178. +16 −0 src/mongo/util/concurrency/qlock.h
  179. +16 −0 src/mongo/util/concurrency/race.h
  180. +17 −0 src/mongo/util/concurrency/rwlockimpl.cpp
  181. +16 −0 src/mongo/util/concurrency/rwlockimpl.h
  182. +16 −0 src/mongo/util/concurrency/simplerwlock.h
  183. +1 −1  src/mongo/util/file_allocator.h
  184. +1 −4 src/mongo/util/hashtab.h
  185. +4 −4 src/mongo/util/map_util.h
  186. +6 −6 src/mongo/util/md5main.cpp
  187. +14 −4 src/mongo/util/mmap.cpp
  188. +5 −13 src/mongo/util/mmap.h
  189. +16 −15 src/mongo/util/mongoutils/html.h
  190. +1 −1  src/mongo/util/net/message.h
  191. +1 −1  src/mongo/util/net/message_port.h
  192. +11 −11 src/mongo/util/net/sock.cpp
  193. +1 −1  src/mongo/util/queue.h
  194. +1 −1  src/mongo/util/ramlog.h
  195. +16 −0 src/mongo/util/stack_introspect.cpp
  196. +15 −0 src/mongo/util/stack_introspect.h
  197. +16 −0 src/mongo/util/startup_test.cpp
  198. +1 −15 src/mongo/util/text.h
  199. +16 −0 src/mongo/util/version.h
  200. +1 −1  src/third_party/boost/boost/functional/hash/detail/float_functions.hpp
14 SConstruct
View
@@ -14,7 +14,6 @@
# several, subordinate SConscript files, which describe specific build rules.
import buildscripts
-import buildscripts.bb
import datetime
import imp
import os
@@ -39,7 +38,6 @@ SConsignFile( scons_data_dir + "/sconsign" )
DEFAULT_INSTALL_DIR = "/usr/local"
-buildscripts.bb.checkOk()
def findSettingsSetup():
sys.path.append( "." )
@@ -916,6 +914,18 @@ def doStyling( env , target , source ):
env.Alias( "style" , [] , [ doStyling ] )
env.AlwaysBuild( "style" )
+# --- lint ----
+
+
+
+def doLint( env , target , source ):
+ import buildscripts.lint
+ if not buildscripts.lint.run_lint( [ "src/mongo/" ] ):
+ raise Exception( "lint errors" )
+
+env.Alias( "lint" , [] , [ doLint ] )
+env.AlwaysBuild( "lint" )
+
# ---- INSTALL -------
23 buildscripts/bb.py
View
@@ -1,23 +0,0 @@
-# bb tools
-
-import os
-import re
-
-def checkOk():
- dir = os.getcwd()
- m = re.compile( ".*/.*_V(\d+\.\d+)/mongo" ).findall( dir )
- if len(m) == 0:
- return
- if len(m) > 1:
- raise Exception( "unexpected: " + str(m) )
-
- m = "v" + m[0]
- print( m )
- print( "expected version [" + m + "]" )
-
- from subprocess import Popen, PIPE
- diff = Popen( [ "git", "diff", "origin/v1.2" ], stdout=PIPE ).communicate()[ 0 ]
- if len(diff) > 0:
- print( diff )
- raise Exception( "build bot broken?" )
-
3,361 buildscripts/cpplint.py
View
3,361 additions, 0 deletions not shown
106 buildscripts/lint.py
View
@@ -0,0 +1,106 @@
+
+import sys
+import codecs
+
+import cpplint
+import utils
+
+
+def run_lint( paths, nudgeOn=False ):
+ # errors are as of 10/14
+ # idea is not to let it any new type of error
+ # as we knock one out, we should remove line
+ # note: not all of these are things we want, so please check first
+
+ nudge = [] # things we'd like to turn on sson, so don't make worse
+ later = [] # things that are unlikely anytime soon, so meh
+ never = [] # things we totally disagree with
+
+ never.append( '-build/header_guard' ) # errors found: 345
+ nudge.append( '-build/include' ) # errors found: 924
+ nudge.append( '-build/include_order' ) # errors found: 511
+ nudge.append( '-build/include_what_you_use' ) # errors found: 986
+ nudge.append( '-build/namespaces' ) # errors found: 131
+ never.append( '-readability/braces' ) # errors found: 880
+ later.append( '-readability/casting' ) # errors found: 748
+ nudge.append( '-readability/function' ) # errors found: 49
+ later.append( '-readability/streams' ) # errors found: 72
+ later.append( '-readability/todo' ) # errors found: 309
+ nudge.append( '-runtime/arrays' ) # errors found: 5
+ later.append( '-runtime/explicit' ) # errors found: 322
+ later.append( '-runtime/int' ) # errors found: 1420
+ later.append( '-runtime/printf' ) # errors found: 29
+ nudge.append( '-runtime/references' ) # errors found: 1338
+ nudge.append( '-runtime/rtti' ) # errors found: 36
+ nudge.append( '-runtime/sizeof' ) # errors found: 57
+ nudge.append( '-runtime/string' ) # errors found: 6
+ nudge.append( '-runtime/threadsafe_fn' ) # errors found: 46
+ never.append( '-whitespace/blank_line' ) # errors found: 2080
+ never.append( '-whitespace/braces' ) # errors found: 962
+ later.append( '-whitespace/comma' ) # errors found: 621
+ later.append( '-whitespace/comments' ) # errors found: 2189
+ later.append( '-whitespace/end_of_line' ) # errors found: 4340
+ later.append( '-whitespace/labels' ) # errors found: 58
+ later.append( '-whitespace/line_length' ) # errors found: 14500
+ later.append( '-whitespace/newline' ) # errors found: 1520
+ nudge.append( '-whitespace/operators' ) # errors found: 2297
+ never.append( '-whitespace/parens' ) # errors found: 49058
+ nudge.append( '-whitespace/semicolon' ) # errors found: 121
+ nudge.append( '-whitespace/tab' ) # errors found: 233
+
+ filters = later + never
+ if not nudgeOn:
+ filters = filters + nudge
+
+
+ sourceFiles = []
+ for x in paths:
+ utils.getAllSourceFiles( sourceFiles, x )
+
+
+ args = [ "--filter=" + ",".join( filters ) , "--counting=detailed" ] + sourceFiles
+ filenames = cpplint.ParseArguments( args )
+
+ def _ourIsTestFilename(fn):
+ if fn.find( "dbtests" ) >= 0:
+ return True
+ if fn.endswith( "_test.cpp" ):
+ return True
+ return False
+
+ cpplint._IsTestFilename = _ourIsTestFilename
+
+ # Change stderr to write with replacement characters so we don't die
+ # if we try to print something containing non-ASCII characters.
+ sys.stderr = codecs.StreamReaderWriter(sys.stderr,
+ codecs.getreader('utf8'),
+ codecs.getwriter('utf8'),
+ 'replace')
+
+ cpplint._cpplint_state.ResetErrorCounts()
+ for filename in filenames:
+ cpplint.ProcessFile(filename, cpplint._cpplint_state.verbose_level)
+ cpplint._cpplint_state.PrintErrorCounts()
+
+ return cpplint._cpplint_state.error_count == 0
+
+
+if __name__ == "__main__":
+ paths = []
+ nudge = False
+
+ for arg in sys.argv[1:]:
+ if arg.startswith( "--" ):
+ arg = arg[2:]
+ if arg == "nudge":
+ nudge = True
+ else:
+ print( "unknown arg [%s]" % arg )
+ sys.exit(-1)
+ paths.append( arg )
+
+ if len(paths) == 0:
+ paths.append( "src/mongo/" )
+
+ if not run_lint( paths, nudge ):
+ sys.exit(-1)
2  buildscripts/smoke.py
View
@@ -341,6 +341,8 @@ def skipTest(path):
return True
if parentDir == "dur": # SERVER-7317
return True
+ if parentDir == "disk": # SERVER-7356
+ return True
authTestsToSkip = [("sharding", "read_pref_rs_client.js"), # SERVER-6972
("sharding", "sync_conn_cmd.js"), #SERVER-6327
8 buildscripts/utils.py
View
@@ -15,7 +15,12 @@
def getAllSourceFiles( arr=None , prefix="." ):
if arr is None:
arr = []
-
+
+ if not os.path.isdir( prefix ):
+ # assume a file
+ arr.append( prefix )
+ return arr
+
for x in os.listdir( prefix ):
if x.startswith( "." ) or x.startswith( "pcre-" ) or x.startswith( "32bit" ) or x.startswith( "mongodb-" ) or x.startswith("debian") or x.startswith( "mongo-cxx-driver" ):
continue
@@ -24,6 +29,7 @@ def getAllSourceFiles( arr=None , prefix="." ):
getAllSourceFiles( arr , full )
else:
if full.endswith( ".cpp" ) or full.endswith( ".h" ) or full.endswith( ".c" ):
+ full = full.replace( "//" , "/" )
arr.append( full )
return arr
1  jstests/multiVersion/multi_version_sharding_passthrough.js
View
@@ -10,6 +10,7 @@ var testsToIgnore = [ /dbadmin/,
/geo.*/,
/indexh/,
/remove5/,
+ /rename6/,
/update4/,
/loglong/,
/logpath/,
24 jstests/rename6.js
View
@@ -0,0 +1,24 @@
+// Test for SERVER-7017
+// We shouldn't rename a collection when one of its indexes will generate a namespace
+// that is greater than 120 chars. To do this we create a long index name and try
+// and rename the collection to one with a much longer name. We use the test database
+// by default and we add this here to ensure we are using it
+testDB = db.getSiblingDB("test")
+c = "rename2c";
+dbc = testDB.getCollection(c);
+d = "dest4567890123456789012345678901234567890123456789012345678901234567890"
+dbd = testDB.getCollection(d);
+dbc.ensureIndex({ "name" : 1,
+ "date" : 1,
+ "time" : 1,
+ "renameCollection" : 1,
+ "mongodb" : 1,
+ "testing" : 1,
+ "data" : 1});
+//Checking for the newly created index and the _id index in original collection
+assert.eq(2, testDB.system.indexes.find( { "ns" : "test." + c } ).count(), "Long Rename Init");
+//Should fail to rename collection as the index namespace is too long
+assert.commandFailed( dbc.renameCollection( dbd ) , "Long Rename Exec" );
+//Since we failed we should have the 2 indexes unmoved and no indexes under the new collection name
+assert.eq(2, testDB.system.indexes.find( { "ns" : "test." + c } ).count(), "Long Rename Result 1");
+assert.eq(0, testDB.system.indexes.find( { "ns" : "test." + d } ).count(), "Long Rename Result 2");
4 jstests/replsets/stepdown.js
View
@@ -75,6 +75,8 @@ catch (e) {
print("\nawait");
replTest.awaitReplication();
+// 31000 may have just voted for 31001, preventing it from becoming primary for the first 30 seconds
+// of this assert.soon
assert.soon(function() {
try {
var result = master.getDB("admin").runCommand({isMaster: 1});
@@ -82,7 +84,7 @@ assert.soon(function() {
} catch (x) {
return false;
}
-});
+}, 'wait for 31000 to be primary', 60000);
master = replTest.getMaster();
var firstMaster = master;
21 jstests/replsets/stepdown2.js
View
@@ -69,9 +69,12 @@ catch (e) {
print("\nawait");
replTest.awaitReplication();
-master = replTest.getMaster();
+assert.soon(function() {
+ master = replTest.getMaster();
+ return master == replTest.nodes[0];
+});
var firstMaster = master;
-print("\nmaster is now "+firstMaster);
+print("\nmaster is now 31000");
try {
printjson(master.getDB("admin").runCommand({replSetStepDown : 100, force : true}));
@@ -80,7 +83,7 @@ catch (e) {
print(e);
}
-print("\nget a master");
+print("\nget new master (31001)");
replTest.getMaster();
assert.soon(function() {
@@ -89,11 +92,10 @@ assert.soon(function() {
}, 'making sure '+firstMaster+' isn\'t still master', 60000);
-print("\ncheck shutdown command");
+print("\ncheck shutdown command on 31000");
master = replTest.liveNodes.master;
-var slave = replTest.liveNodes.slaves[0];
-var slaveId = replTest.getNodeId(slave);
+var slave = replTest.nodes[0];
try {
slave.adminCommand({shutdown :1})
@@ -102,9 +104,12 @@ catch (e) {
print(e);
}
-print("\nsleeping");
+print("\nwait until 31001 knows 31000 is down");
-sleep(2000);
+assert.soon(function() {
+ var result = master.adminCommand({replSetGetStatus: 1});
+ return result.members[0].health == 0;
+});
print("\nrunning shutdown without force on master: "+master);
7 src/mongo/SConscript
View
@@ -65,6 +65,9 @@ env.CppUnitTest('bson_field_test', ['bson/bson_field_test.cpp'],
env.CppUnitTest('bson_validate_test', ['bson/bson_validate_test.cpp'],
LIBDEPS=['bson'])
+env.CppUnitTest('namespacestring_test', ['db/namespacestring_test.cpp'],
+ LIBDEPS=['bson'])
+
commonFiles = [ "pch.cpp",
"buildinfo.cpp",
"db/hasher.cpp",
@@ -129,6 +132,7 @@ env.StaticLibrary("coredb", [
"db/pipeline/pipeline.cpp",
"db/dbcommands_generic.cpp",
"db/dbwebserver.cpp",
+ "db/keypattern.cpp",
"db/matcher.cpp",
"db/pipeline/accumulator.cpp",
"db/pipeline/accumulator_add_to_set.cpp",
@@ -322,7 +326,8 @@ serverOnlyFiles = [ "db/curop.cpp",
"db/pipeline/document_source_cursor.cpp",
"db/driverHelpers.cpp" ]
-env.Library( "dbcmdline", "db/cmdline.cpp" )
+env.Library( "dbcmdline", "db/cmdline.cpp", LIBDEPS=['bson'] )
+env.CppUnitTest('cmdline_test', 'db/cmdline_test.cpp', LIBDEPS=['dbcmdline'])
env.Library('stacktrace', 'util/stacktrace.cpp')
2  src/mongo/base/global_initializer.cpp
View
@@ -33,4 +33,4 @@ namespace {
} // namespace
-} // namesapce mongo
+} // namespace mongo
2  src/mongo/base/global_initializer_registerer.cpp
View
@@ -40,4 +40,4 @@ namespace mongo {
}
}
-} // namesapce mongo
+} // namespace mongo
6 src/mongo/base/initializer_dependency_graph.h
View
@@ -35,7 +35,7 @@ namespace mongo {
*
* Instances of this class are used in two phases. In the first phase, the graph is constructed
* by repeated calls to addInitializer(). In the second phase, a user calls the topSort()
- * method to produce an initialization order that respects the dependences among operations, and
+ * method to produce an initialization order that respects the dependencies among operations, and
* then uses the getInitializerFunction() to get the behavior function for each operation, in
* turn.
*
@@ -53,8 +53,8 @@ namespace mongo {
/**
* Add a new initializer node, named "name", to the dependency graph, with the given
- * behavior, "fn", and the given "prerequisites" (input dependences) and "dependents"
- * (output dependences).
+ * behavior, "fn", and the given "prerequisites" (input dependencies) and "dependents"
+ * (output dependencies).
*
* If "!fn" (fn is NULL in function pointer parlance), returns status with code
* ErrorCodes::badValue. If "name" is a duplicate of a name already present in the graph,
2  src/mongo/base/make_string_vector.cpp
View
@@ -36,4 +36,4 @@ namespace mongo {
return result;
}
-} // namspace mongo
+} // namespace mongo
19 src/mongo/bson/bson_db.h
View
@@ -1,12 +1,4 @@
-/** @file bson_db.h
-
- This file contains the implementation of BSON-related methods that are required
- by the MongoDB database server.
-
- Normally, for standalone BSON usage, you do not want this file - it will tend to
- pull in some other files from the MongoDB project. Thus, bson.h (the main file
- one would use) does not include this file.
-*/
+/** @file bson_db.h */
/* Copyright 2009 10gen Inc.
*
@@ -23,6 +15,15 @@
* limitations under the License.
*/
+/*
+ This file contains the implementation of BSON-related methods that are required
+ by the MongoDB database server.
+
+ Normally, for standalone BSON usage, you do not want this file - it will tend to
+ pull in some other files from the MongoDB project. Thus, bson.h (the main file
+ one would use) does not include this file.
+*/
+
#pragma once
#include "../util/optime.h"
27 src/mongo/bson/bsondemo/bsondemo.cpp
View
@@ -1,16 +1,4 @@
-/** @file bsondemo.cpp
-
- Example of use of BSON from C++.
-
- Requires boost (headers only).
- Works headers only (the parts actually exercised herein that is - some functions require .cpp files).
-
- To build and run:
- g++ -o bsondemo bsondemo.cpp
- ./bsondemo
-
- Windows: project files are available in this directory for bsondemo.cpp for use with Visual Studio.
-*/
+/** @file bsondemo.cpp */
/*
* Copyright 2010 10gen Inc.
@@ -28,6 +16,19 @@
* limitations under the License.
*/
+/*
+ Example of use of BSON from C++.
+
+ Requires boost (headers only).
+ Works headers only (the parts actually exercised herein that is - some functions require .cpp files).
+
+ To build and run:
+ g++ -o bsondemo bsondemo.cpp
+ ./bsondemo
+
+ Windows: project files are available in this directory for bsondemo.cpp for use with Visual Studio.
+*/
+
#include "../bson.h"
#include <iostream>
#include <vector>
2  src/mongo/client/authentication_table.h
View
@@ -46,7 +46,7 @@ namespace mongo {
Auth getAuthForDb( const std::string& dbname ) const;
- // Takes the authentication state from the given BSONObj, replcacing whatever state it had.
+ // Takes the authentication state from the given BSONObj, replacing whatever state it had.
void setFromBSON( const BSONObj& obj );
BSONObj toBSON() const;
15 src/mongo/client/clientOnly-private.h
View
@@ -1,3 +1,18 @@
+/* Copyright 2012 10gen Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
#pragma once
namespace mongo {
namespace shell_utils {
2  src/mongo/client/clientOnly.cpp
View
@@ -11,7 +11,7 @@
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing puermissions and
+ * See the License for the specific language governing permissions and
* limitations under the License.
*/
2  src/mongo/client/connpool.h
View
@@ -99,7 +99,7 @@ namespace mongo {
Generally, use ScopedDbConnection and do not call these directly.
This class, so far, is suitable for use with unauthenticated connections.
- Support for authenticated connections requires some adjustements: please
+ Support for authenticated connections requires some adjustments: please
request...
Usage:
17 src/mongo/client/constants.h
View
@@ -1,5 +1,20 @@
// constants.h
+/* Copyright 2012 10gen Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
#pragma once
namespace mongo {
@@ -16,7 +31,7 @@ namespace mongo {
/* Have to update config from the server, usually $err is also set */
ResultFlag_ShardConfigStale = 4,
- /* for backward compatability: this let's us know the server supports
+ /* for backward compatibility: this let's us know the server supports
the QueryOption_AwaitData option. if it doesn't, a repl slave client should sleep
a little between getMore's.
*/
2  src/mongo/client/dbclient_rs.cpp
View
@@ -1507,7 +1507,7 @@ namespace mongo {
}
void DBClientReplicaSet::killCursor( long long cursorID ) {
- // we should neve call killCursor on a replica set conncetion
+ // we should never call killCursor on a replica set connection
// since we don't know which server it belongs to
// can't assume master because of slave ok
// and can have a cursor survive a master change
2  src/mongo/client/dbclient_rs.h
View
@@ -38,7 +38,7 @@ namespace mongo {
* manages state about a replica set for client
* keeps tabs on whose master and what slaves are up
* can hand a slave to someone for SLAVE_OK
- * one instace per process per replica set
+ * one instance per process per replica set
* TODO: we might be able to use a regular Node * to avoid _lock
*/
class ReplicaSetMonitor {
2  src/mongo/client/dbclientinterface.h
View
@@ -56,7 +56,7 @@ namespace mongo {
// an extended period of time.
QueryOption_OplogReplay = 1 << 3,
- /** The server normally times out idle cursors after an inactivy period to prevent excess memory uses
+ /** The server normally times out idle cursors after an inactivity period to prevent excess memory uses
Set this option to prevent that.
*/
QueryOption_NoCursorTimeout = 1 << 4,
2  src/mongo/client/distlock.h
View
@@ -61,7 +61,7 @@ namespace mongo {
* unique name across the system (e.g., "balancer"). A lock is taken by writing a document in the configdb's locks
* collection with that name.
*
- * To be maintained, each taken lock needs to be revalidaded ("pinged") within a pre-established amount of time. This
+ * To be maintained, each taken lock needs to be revalidated ("pinged") within a pre-established amount of time. This
* class does this maintenance automatically once a DistributedLock object was constructed.
*/
class DistributedLock {
15 src/mongo/client/examples/insert_demo.cpp
View
@@ -1,3 +1,18 @@
+/* Copyright 2009 10gen Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
/*
C++ client program which inserts documents in a MongoDB database.
15 src/mongo/client/examples/mongoperf.cpp
View
@@ -1,3 +1,18 @@
+/* Copyright 2009 10gen Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
/*
How to build and run:
34 src/mongo/client/mongo_client_lib.cpp
View
@@ -1,4 +1,21 @@
-/* @file client_lib.cpp
+/* @file client_lib.cpp */
+
+/* Copyright 2009 10gen Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
MongoDB C++ Driver
@@ -23,21 +40,6 @@
- Linker.Input.Additional Dependencies - add ws2_32.lib for the Winsock library.
*/
-/* Copyright 2009 10gen Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
#if defined(_WIN32)
// C4800 forcing value to bool 'true' or 'false' (performance warning)
#pragma warning( disable : 4800 )
8 src/mongo/client/parallel.cpp
View
@@ -1639,7 +1639,7 @@ namespace mongo {
}
}
catch ( std::exception& e ) {
- error() << "Future::spawnComand (part 1) exception: " << e.what() << endl;
+ error() << "Future::spawnCommand (part 1) exception: " << e.what() << endl;
_ok = false;
_done = true;
}
@@ -1678,13 +1678,13 @@ namespace mongo {
if( staleNS.size() == 0 ) staleNS = _db;
if( i >= maxRetries ){
- error() << "Future::spawnComand (part 2) stale config exception" << causedBy( e ) << endl;
+ error() << "Future::spawnCommand (part 2) stale config exception" << causedBy( e ) << endl;
throw e;
}
if( i >= maxRetries / 2 ){
if( ! versionManager.forceRemoteCheckShardVersionCB( staleNS ) ){
- error() << "Future::spawnComand (part 2) no config detected" << causedBy( e ) << endl;
+ error() << "Future::spawnCommand (part 2) no config detected" << causedBy( e ) << endl;
throw e;
}
}
@@ -1708,7 +1708,7 @@ namespace mongo {
continue;
}
catch ( std::exception& e ) {
- error() << "Future::spawnComand (part 2) exception: " << causedBy( e ) << endl;
+ error() << "Future::spawnCommand (part 2) exception: " << causedBy( e ) << endl;
break;
}
2  src/mongo/client/parallel.h
View
@@ -66,7 +66,7 @@ namespace mongo {
/**
* this is a cursor that works over a set of servers
- * can be used in serial/paralellel as controlled by sub classes
+ * can be used in serial/parallel as controlled by sub classes
*/
class ClusteredCursor {
public:
15 src/mongo/client/simple_client_demo.cpp
View
@@ -1,3 +1,18 @@
+/* Copyright 2009 10gen Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
/* simple_client_demo.cpp
See also : http://www.mongodb.org/pages/viewpage.action?pageId=133415
4 src/mongo/db/btree.h
View
@@ -404,7 +404,7 @@ namespace mongo {
/**
* Preconditions:
* - key / recordLoc are > all existing keys
- * - The keys in prevChild and their descendents are between all existing
+ * - The keys in prevChild and their descendants are between all existing
* keys and 'key'.
* Postconditions:
* - If there is space for key without packing, it is inserted as the
@@ -607,7 +607,7 @@ namespace mongo {
* so assignment of const is sometimes nonideal.
*
* TODO There are several cases in which the 'this' pointer is invalidated
- * as a result of deallocation. A seperate class representing a btree would
+ * as a result of deallocation. A separate class representing a btree would
* alleviate some fragile cases where the implementation must currently
* behave correctly if the 'this' pointer is suddenly invalidated by a
* callee.
16 src/mongo/db/btreebuilder.h
View
@@ -1,3 +1,19 @@
+/**
+* Copyright (C) 2012 10gen Inc.
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero General Public License, version 3,
+* as published by the Free Software Foundation.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
#pragma once
#include "btree.h"
6 src/mongo/db/cap.cpp
View
@@ -258,7 +258,7 @@ namespace mongo {
}
DiskLoc fr = theCapExtent()->firstRecord;
- theDataFileMgr.deleteRecord(ns, fr.rec(), fr, true); // ZZZZZZZZZZZZ
+ theDataFileMgr.deleteRecord(this, ns, fr.rec(), fr, true); // ZZZZZZZZZZZZ
compact();
if( ++passes > maxPasses ) {
log() << "passes ns:" << ns << " len:" << len << " maxPasses: " << maxPasses << '\n';
@@ -353,7 +353,7 @@ namespace mongo {
// Delete the newest record, and coalesce the new deleted
// record with existing deleted records.
- theDataFileMgr.deleteRecord(ns, curr.rec(), curr, true);
+ theDataFileMgr.deleteRecord(this, ns, curr.rec(), curr, true);
compact();
// This is the case where we have not yet had to remove any
@@ -433,7 +433,7 @@ namespace mongo {
// Clear all references to this namespace.
ClientCursor::invalidate( ns );
- NamespaceDetailsTransient::clearForPrefix( ns );
+ NamespaceDetailsTransient::resetCollection( ns );
// Get a writeable reference to 'this' and reset all pertinent
// attributes.
12 src/mongo/db/client.cpp
View
@@ -96,19 +96,9 @@ namespace mongo {
/* each thread which does db operations has a Client object in TLS.
call this when your thread starts.
*/
-#if defined _DEBUG
- static unsigned long long nThreads = 0;
- void assertStartingUp() {
- verify( nThreads <= 1 );
- }
-#else
- void assertStartingUp() { }
-#endif
-
Client& Client::initThread(const char *desc, AbstractMessagingPort *mp) {
#if defined(_DEBUG)
- {
- nThreads++; // never decremented. this is for casi class asserts
+ {
if( sizeof(void*) == 8 ) {
StackChecker sc;
sc.init();
10 src/mongo/db/clientcursor.cpp
View
@@ -427,6 +427,16 @@ namespace mongo {
return b.obj();
}
+ BSONObj ClientCursor::extractKey( const KeyPattern& usingKeyPattern ) const {
+ KeyPattern currentIndex( _c->indexKeyPattern() );
+ if ( usingKeyPattern.isCoveredBy( currentIndex ) && ! currentIndex.isSpecial() ){
+ BSONObj currKey = _c->currKey();
+ BSONObj prettyKey = currKey.replaceFieldNames( currentIndex.toBSON() );
+ return usingKeyPattern.extractSingleKey( prettyKey );
+ }
+ return usingKeyPattern.extractSingleKey( _c->current() );
+ }
+
void ClientCursor::fillQueryResultFromObj( BufBuilder &b, const MatchDetails* details ) const {
const Projection::KeyOnly *keyFieldsOnly = c()->keyFieldsOnly();
if ( keyFieldsOnly ) {
10 src/mongo/db/clientcursor.h
View
@@ -38,6 +38,7 @@
#include "matcher.h"
#include "projection.h"
#include "s/d_chunk_manager.h"
+#include "mongo/db/keypattern.h"
namespace mongo {
@@ -290,6 +291,13 @@ namespace mongo {
*/
BSONObj extractFields(const BSONObj &pattern , bool fillWithNull = false) ;
+ /** Extract elements from the object this cursor currently points to, using the expression
+ * specified in KeyPattern. Will use a covered index if the one in this cursor is usable.
+ * TODO: there are some cases where a covered index could be used but is not, for instance
+ * if both this index and the keyPattern are {a : "hashed"}
+ */
+ BSONObj extractKey( const KeyPattern& usingKeyPattern ) const;
+
void fillQueryResultFromObj( BufBuilder &b, const MatchDetails* details = NULL ) const;
bool currentIsDup() { return _c->getsetdup( _c->currLoc() ); }
@@ -383,7 +391,7 @@ namespace mongo {
private: // methods
- // cursors normally timeout after an inactivy period to prevent excess memory use
+ // cursors normally timeout after an inactivity period to prevent excess memory use
// setting this prevents timeout of the cursor in question.
void noTimeout() { _pinValue++; }
31 src/mongo/db/cloner.cpp
View
@@ -721,6 +721,9 @@ namespace mongo {
class CmdRenameCollection : public Command {
public:
+ // Absolute maximum Namespace is 128 incl NUL
+ // Namespace is 128 minus .$ and $extra so 120 before additions
+ static const int maxNamespaceLen = 120;
CmdRenameCollection() : Command( "renameCollection" ) {}
virtual bool adminOnly() const {
return true;
@@ -746,6 +749,28 @@ namespace mongo {
return false;
}
+ string sourceDB = nsToDatabase(source);
+ string targetDB = nsToDatabase(target);
+ string databaseName = sourceDB;
+ databaseName += ".system.indexes";
+
+ int longestIndexNameLength = 0;
+ vector<BSONObj> oldIndSpec = Helpers::findAll(databaseName, BSON("ns" << source));
+ for (size_t i = 0; i < oldIndSpec.size(); ++i) {
+ int thisLength = oldIndSpec[i].getField("name").valuesize();
+ if (thisLength > longestIndexNameLength) {
+ longestIndexNameLength = thisLength;
+ }
+ }
+ unsigned int longestAllowed = maxNamespaceLen - longestIndexNameLength - 1;
+ if (target.size() > longestAllowed) {
+ StringBuilder sb;
+ sb << "collection name length of " << target.size()
+ << " exceeds maximum length of " << longestAllowed
+ << ", allowing for index names";
+ uasserted(16451, sb.str());
+ }
+
bool capped = false;
long long size = 0;
{
@@ -773,11 +798,7 @@ namespace mongo {
// if we are renaming in the same database, just
// rename the namespace and we're done.
{
- char from[256];
- nsToDatabase( source.c_str(), from );
- char to[256];
- nsToDatabase( target.c_str(), to );
- if ( strcmp( from, to ) == 0 ) {
+ if ( sourceDB == targetDB ) {
renameNamespace( source.c_str(), target.c_str(), cmdObj["stayTemp"].trueValue() );
// make sure we drop counters etc
Top::global.collectionDropped( source );
155 src/mongo/db/cmdline.cpp
View
@@ -16,17 +16,19 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "pch.h"
-#include "cmdline.h"
-#include "commands.h"
-#include "../util/password.h"
-#include "../util/net/listen.h"
-#include "../bson/util/builder.h"
+#include "mongo/pch.h"
+
+#include "mongo/db/cmdline.h"
+
+#include "mongo/util/map_util.h"
+#include "mongo/bson/util/builder.h"
#include "mongo/util/mongoutils/str.h"
+#include "mongo/util/net/listen.h"
+#include "mongo/util/password.h"
+
#ifdef _WIN32
#include <direct.h>
#endif
-#include "globals.h"
#define MAX_LINE_LENGTH 256
@@ -36,6 +38,9 @@ namespace po = boost::program_options;
namespace mongo {
+ static bool _isPasswordArgument(char const* argumentName);
+ static bool _isPasswordSwitch(char const* switchName);
+
namespace {
BSONArray argvArray;
BSONObj parsedOpts;
@@ -143,13 +148,16 @@ namespace {
return;
}
- bool CmdLine::store( int argc , char ** argv ,
+ bool CmdLine::store( const std::vector<std::string>& argv,
boost::program_options::options_description& visible,
boost::program_options::options_description& hidden,
boost::program_options::positional_options_description& positional,
boost::program_options::variables_map &params ) {
+ if (argv.empty())
+ return false;
+
{
// setup binary name
cmdLine.binaryName = argv[0];
@@ -183,7 +191,8 @@ namespace {
all.add( visible );
all.add( hidden );
- po::store( po::command_line_parser(argc, argv)
+ po::store( po::command_line_parser(std::vector<std::string>(argv.begin() + 1,
+ argv.end()))
.options( all )
.positional( positional )
.style( style )
@@ -215,21 +224,10 @@ namespace {
{
BSONArrayBuilder b;
- for (int i=0; i < argc; i++) {
- b << argv[i];
- if ( mongoutils::str::equals(argv[i], "--sslPEMKeyPassword")
- || mongoutils::str::equals(argv[i], "-sslPEMKeyPassword")
- || mongoutils::str::equals(argv[i], "--servicePassword")
- || mongoutils::str::equals(argv[i], "-servicePassword")) {
- b << "<password>";
- i++;
-
- // hide password from ps output
- char* arg = argv[i];
- while (*arg) {
- *arg++ = 'x';
- }
- }
+ std::vector<std::string> censoredArgv = argv;
+ censor(&censoredArgv);
+ for (size_t i=0; i < censoredArgv.size(); i++) {
+ b << censoredArgv[i];
}
argvArray = b.arr();
}
@@ -246,7 +244,7 @@ namespace {
if (value.as<string>().empty())
b.appendBool(key, true); // boost po uses empty string for flags like --quiet
else {
- if ( key == "servicePassword" || key == "sslPEMKeyPassword" ) {
+ if ( _isPasswordArgument(key.c_str()) ) {
b.append( key, "<password>" );
}
else {
@@ -369,39 +367,98 @@ namespace {
return true;
}
- void printCommandLineOpts() {
- log() << "options: " << parsedOpts << endl;
+ static bool _isPasswordArgument(const char* argumentName) {
+ static const char* const passwordArguments[] = {
+ "sslPEMKeyPassword",
+ "servicePassword",
+ NULL // Last entry sentinel.
+ };
+ for (const char* const* current = passwordArguments; *current; ++current) {
+ if (mongoutils::str::equals(argumentName, *current))
+ return true;
+ }
+ return false;
+ }
+
+ static bool _isPasswordSwitch(const char* switchName) {
+ if (switchName[0] != '-')
+ return false;
+ size_t i = 1;
+ if (switchName[1] == '-')
+ i = 2;
+ switchName += i;
+
+ return _isPasswordArgument(switchName);
}
- class CmdGetCmdLineOpts : Command {
- public:
- CmdGetCmdLineOpts(): Command("getCmdLineOpts") {}
- void help(stringstream& h) const { h << "get argv"; }
- virtual LockType locktype() const { return NONE; }
- virtual bool adminOnly() const { return true; }
- virtual bool slaveOk() const { return true; }
-
- virtual bool run(const string&, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
- result.append("argv", argvArray);
- result.append("parsed", parsedOpts);
- return true;
+ static void _redact(char* arg) {
+ for (; *arg; ++arg)
+ *arg = 'x';
+ }
+
+ void CmdLine::censor(std::vector<std::string>* args) {
+ for (size_t i = 0; i < args->size(); ++i) {
+ std::string& arg = args->at(i);
+ const std::string::iterator endSwitch = std::find(arg.begin(), arg.end(), '=');
+ std::string switchName(arg.begin(), endSwitch);
+ if (_isPasswordSwitch(switchName.c_str())) {
+ if (endSwitch == arg.end()) {
+ if (i + 1 < args->size()) {
+ args->at(i + 1) = "<password>";
+ }
+ }
+ else {
+ arg = switchName + "=<password>";
+ }
+ }
+ }
+ }
+
+ void CmdLine::censor(int argc, char** argv) {
+ // Algorithm: For each arg in argv:
+ // Look for an equal sign in arg; if there is one, temporarily nul it out.
+ // check to see if arg is a password switch. If so, overwrite the value
+ // component with xs.
+ // restore the nul'd out equal sign, if any.
+ for (int i = 0; i < argc; ++i) {
+
+ char* const arg = argv[i];
+ char* const firstEqSign = strchr(arg, '=');
+ if (NULL != firstEqSign) {
+ *firstEqSign = '\0';
+ }
+
+ if (_isPasswordSwitch(arg)) {
+ if (NULL == firstEqSign) {
+ if (i + 1 < argc) {
+ _redact(argv[i + 1]);
+ }
+ }
+ else {
+ _redact(firstEqSign + 1);
+ }
+ }
+
+ if (NULL != firstEqSign) {
+ *firstEqSign = '=';
+ }
}
+ }
- } cmdGetCmdLineOpts;
+ void printCommandLineOpts() {
+ log() << "options: " << parsedOpts << endl;
+ }
- casi< map<string,ParameterValidator*> * > pv_all (NULL);
+ map<string,ParameterValidator*>* pv_all(NULL);
ParameterValidator::ParameterValidator( const string& name ) : _name( name ) {
if ( ! pv_all)
- pv_all.ref() = new map<string,ParameterValidator*>();
- (*pv_all.ref())[_name] = this;
+ pv_all = new map<string,ParameterValidator*>();
+ (*pv_all)[_name] = this;
}
-
- ParameterValidator * ParameterValidator::get( const string& name ) {
- map<string,ParameterValidator*>::const_iterator i = pv_all.get()->find( name );
- if ( i == pv_all.get()->end() )
- return NULL;
- return i->second;
+
+ ParameterValidator* ParameterValidator::get( const string& name ) {
+ return mapFindWithDefault(*pv_all, name, static_cast<ParameterValidator*>(NULL));
}
}
8 src/mongo/db/cmdline.h
View
@@ -156,12 +156,18 @@ namespace mongo {
/**
* @return true if should run program, false if should exit
*/
- static bool store( int argc , char ** argv ,
+ static bool store( const std::vector<std::string>& argv,
boost::program_options::options_description& visible,
boost::program_options::options_description& hidden,
boost::program_options::positional_options_description& positional,
boost::program_options::variables_map &output );
+ /**
+ * Blot out sensitive fields in the argv array.
+ */
+ static void censor(int argc, char** argv);
+ static void censor(std::vector<std::string>* args);
+
static BSONArray getArgvArray();
static BSONObj getParsedOpts();
224 src/mongo/db/cmdline_test.cpp
View
@@ -0,0 +1,224 @@
+/**
+ * Copyright (C) 2012 10gen Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <boost/range/size.hpp>
+#include <string>
+#include <vector>
+
+#include "mongo/db/cmdline.h"
+#include "mongo/unittest/unittest.h"
+
+namespace mongo {
+
+ CmdLine cmdLine;
+
+namespace {
+
+ void testCensoringArgv(const char* const * expected,
+ const char* const * toCensor,
+ int elementCount) {
+
+ std::vector<std::string> toCensorStringVec(toCensor, toCensor + elementCount);
+ std::vector<char*> arrayStandin;
+ for (size_t i = 0; i < toCensorStringVec.size(); ++i)
+ arrayStandin.push_back(&*toCensorStringVec[i].begin());
+
+ char** argv = &*arrayStandin.begin();
+
+ CmdLine::censor(elementCount, argv);
+
+ for (int i = 0; i < elementCount; ++i) {
+ ASSERT_EQUALS(std::string(expected[i]), std::string(argv[i]));
+ }
+ }
+
+ void testCensoringVector(const char* const * expected,
+ const char* const * toCensor,
+ int elementCount) {
+
+ std::vector<std::string> actual(toCensor, toCensor + elementCount);
+
+ CmdLine::censor(&actual);
+
+ for (int i = 0; i < elementCount; ++i) {
+ ASSERT_EQUALS(std::string(expected[i]), actual[i]);
+ }
+ }
+
+ TEST(ArgvCensorTests, NothingCensored) {
+ const char* const argv[] = {
+ "first",
+ "second",
+ "sslPEMKeyPassword=KEEP",
+ "---sslPEMKeyPassword=KEEP",
+ "sslPEMKeyPassword",
+ "KEEP",
+ "servicePassword=KEEP",
+ "--servicePassword-",
+ "KEEP",
+ "--servicePasswordFake=KEEP"
+ };
+ const int argc = boost::size(argv);
+ testCensoringArgv(argv, argv, argc);
+ }
+
+ TEST(ArgvCensorTests, SomeStuffCensoredDoubleHyphen) {
+ const char* const argv[] = {
+ "first",
+ "second",
+ "--sslPEMKeyPassword=LOSEME",
+ "--sslPEMKeyPassword",
+ "Really, loose me!",
+ "--servicePassword=bad news",
+ "--servicePassword-",
+ "KEEP",
+ "--servicePassword",
+ "get out of dodge"
+ };
+ const int argc = boost::size(argv);
+
+ const char* const expected[] = {
+ "first",
+ "second",
+ "--sslPEMKeyPassword=xxxxxx",
+ "--sslPEMKeyPassword",
+ "xxxxxxxxxxxxxxxxx",
+ "--servicePassword=xxxxxxxx",
+ "--servicePassword-",
+ "KEEP",
+ "--servicePassword",
+ "xxxxxxxxxxxxxxxx"
+ };
+ ASSERT_EQUALS(boost::size(expected), argc);
+
+ testCensoringArgv(expected, argv, argc);
+ }
+
+ TEST(ArgvCensorTests, SomeStuffCensoredSingleHyphen) {
+ const char* const argv[] = {
+ "first",
+ "second",
+ "-sslPEMKeyPassword=LOSEME",
+ "-sslPEMKeyPassword",
+ "Really, loose me!",
+ "-servicePassword=bad news",
+ "-servicePassword-",
+ "KEEP",
+ "-servicePassword",
+ "get out of dodge"
+ };
+ const int argc = boost::size(argv);
+
+ const char* const expected[] = {
+ "first",
+ "second",
+ "-sslPEMKeyPassword=xxxxxx",
+ "-sslPEMKeyPassword",
+ "xxxxxxxxxxxxxxxxx",
+ "-servicePassword=xxxxxxxx",
+ "-servicePassword-",
+ "KEEP",
+ "-servicePassword",
+ "xxxxxxxxxxxxxxxx"
+ };
+ ASSERT_EQUALS(boost::size(expected), argc);
+
+ testCensoringArgv(expected, argv, argc);
+ }
+
+ TEST(VectorCensorTests, NothingCensored) {
+ const char* const argv[] = {
+ "first",
+ "second",
+ "sslPEMKeyPassword=KEEP",
+ "---sslPEMKeyPassword=KEEP",
+ "sslPEMKeyPassword",
+ "KEEP",
+ "servicePassword=KEEP",
+ "--servicePassword-",
+ "KEEP",
+ "--servicePasswordFake=KEEP"
+ };
+ const int argc = boost::size(argv);
+ testCensoringVector(argv, argv, argc);
+ }
+
+ TEST(VectorCensorTests, SomeStuffCensoredDoubleHyphen) {
+ const char* const argv[] = {
+ "first",
+ "second",
+ "--sslPEMKeyPassword=LOSEME",
+ "--sslPEMKeyPassword",
+ "Really, loose me!",
+ "--servicePassword=bad news",
+ "--servicePassword-",
+ "KEEP",
+ "--servicePassword",
+ "get out of dodge"
+ };
+ const int argc = boost::size(argv);
+
+ const char* const expected[] = {
+ "first",
+ "second",
+ "--sslPEMKeyPassword=<password>",
+ "--sslPEMKeyPassword",
+ "<password>",
+ "--servicePassword=<password>",
+ "--servicePassword-",
+ "KEEP",
+ "--servicePassword",
+ "<password>"
+ };
+ ASSERT_EQUALS(boost::size(expected), argc);
+
+ testCensoringVector(expected, argv, argc);
+ }
+
+ TEST(VectorCensorTests, SomeStuffCensoredSingleHyphen) {
+ const char* const argv[] = {
+ "first",
+ "second",
+ "-sslPEMKeyPassword=LOSEME",
+ "-sslPEMKeyPassword",
+ "Really, loose me!",
+ "-servicePassword=bad news",
+ "-servicePassword-",
+ "KEEP",
+ "-servicePassword",
+ "get out of dodge"
+ };
+ const int argc = boost::size(argv);
+
+ const char* const expected[] = {
+ "first",
+ "second",
+ "-sslPEMKeyPassword=<password>",
+ "-sslPEMKeyPassword",
+ "<password>",
+ "-servicePassword=<password>",
+ "-servicePassword-",
+ "KEEP",
+ "-servicePassword",
+ "<password>"
+ };
+ ASSERT_EQUALS(boost::size(expected), argc);
+
+ testCensoringVector(expected, argv, argc);
+ }
+
+} // namespace
+} // namespace mongo
16 src/mongo/db/collection.h
View
@@ -1,5 +1,21 @@
// @file collection.h
+/**
+* Copyright (C) 2012 10gen Inc.
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero General Public License, version 3,
+* as published by the Free Software Foundation.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
#pragma once
#include "namespace.h"
18 src/mongo/db/commands/cpuprofile.cpp
View
@@ -1,6 +1,22 @@
// @file cpuprofile.cpp
/**
+* Copyright (C) 2012 10gen Inc.
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero General Public License, version 3,
+* as published by the Free Software Foundation.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/**
* This module provides commands for starting and stopping the Google perftools
* cpu profiler linked into mongod.
*
@@ -18,7 +34,7 @@
* /usr/local:
*
* scons --release --use-cpu-profiler \
- * --cpppath=/usr/local/include --libpath=/usr/loca/lib
+ * --cpppath=/usr/local/include --libpath=/usr/local/lib
*/
#include "google/profiler.h"
1  src/mongo/db/commands/distinct.cpp
View
@@ -1,6 +1,7 @@
// distinct.cpp
/**
+* Copyright (C) 2012 10gen Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
1  src/mongo/db/commands/find_and_modify.cpp
View
@@ -1,6 +1,7 @@
// find_and_modify.cpp
/**
+* Copyright (C) 2012 10gen Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
16 src/mongo/db/commands/fsync.cpp
View
@@ -1,5 +1,21 @@
// fsync.cpp
+/**
+* Copyright (C) 2012 10gen Inc.
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero General Public License, version 3,
+* as published by the Free Software Foundation.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
#include "mongo/pch.h"
#include "mongo/db/commands/fsync.h"
27 src/mongo/db/commands/fsync.h
View
@@ -1,17 +1,18 @@
/**
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
+* Copyright (C) 2012 10gen Inc.
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero General Public License, version 3,
+* as published by the Free Software Foundation.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
#pragma once
1  src/mongo/db/commands/group.cpp
View
@@ -1,6 +1,7 @@
// group.cpp
/**
+* Copyright (C) 2012 10gen Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
11 src/mongo/db/commands/hashcmd.cpp
View
@@ -1,8 +1,4 @@
-/* hashcmd.cpp
- *
- * Defines a shell command for hashing a BSONElement value
- */
-
+// hashcmd.cpp
/**
* Copyright (C) 2012 10gen Inc.
@@ -20,6 +16,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+/*
+ * Defines a shell command for hashing a BSONElement value
+ */
+
+
#include "mongo/db/commands.h"
#include "mongo/db/hasher.h"
16 src/mongo/db/commands/isself.cpp
View
@@ -1,5 +1,21 @@
// isself.cpp
+/**
+* Copyright (C) 2012 10gen Inc.
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero General Public License, version 3,
+* as published by the Free Software Foundation.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
#include "pch.h"
#include "../../util/net/listen.h"
#include "../commands.h"
1  src/mongo/db/commands/mr.cpp
View
@@ -1,6 +1,7 @@
// mr.cpp
/**
+ * Copyright (C) 2012 10gen Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
1  src/mongo/db/commands/mr.h
View
@@ -1,6 +1,7 @@
// mr.h
/**
+ * Copyright (C) 2012 10gen Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
16 src/mongo/db/curop-inl.h
View
@@ -1 +1,17 @@
+/**
+* Copyright (C) 2012 10gen Inc.
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero General Public License, version 3,
+* as published by the Free Software Foundation.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
#include "curop.h"
16 src/mongo/db/d_globals.cpp
View
@@ -1,5 +1,21 @@
// @file d_globals.cpp
+/**
+* Copyright (C) 2012 10gen Inc.
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero General Public License, version 3,
+* as published by the Free Software Foundation.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
#include "pch.h"
#include "d_globals.h"
#include "../util/concurrency/rwlock.h"
17 src/mongo/db/d_globals.h
View
@@ -1,4 +1,21 @@
// @file d_globals.h
+
+/**
+* Copyright (C) 2012 10gen Inc.
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero General Public License, version 3,
+* as published by the Free Software Foundation.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
//
// these are global variables used in mongod ("d"). also used in test binary as that is effectively a variation on mongod code.
// that is, these are not in mongos.
16 src/mongo/db/databaseholder.h
View
@@ -1,5 +1,21 @@
// @file databaseholder.h
+/**
+* Copyright (C) 2012 10gen Inc.
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero General Public License, version 3,
+* as published by the Free Software Foundation.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
#pragma once
#include "mongo/db/database.h"
124 src/mongo/db/db.cpp
View
@@ -615,11 +615,6 @@ void show_help_text(po::options_description options) {
cout << options << endl;
};
-/* Return error string or "" if no errors. */
-string arg_error_check(int argc, char* argv[]) {
- return "";
-}
-
static int mongoDbMain(int argc, char* argv[], char** envp);
int main(int argc, char* argv[], char** envp) {
@@ -627,12 +622,13 @@ int main(int argc, char* argv[], char** envp) {
::_exit(exitCode);
}
-static int mongoDbMain(int argc, char* argv[], char **envp) {
- static StaticObserver staticObserver;
+static void buildOptionsDescriptions(po::options_description *pVisible,
+ po::options_description *pHidden,
+ po::positional_options_description *pPositional) {
- mongo::runGlobalInitializersOrDie(argc, argv, envp);
-
- getcurns = ourgetns;
+ po::options_description& visible_options = *pVisible;
+ po::options_description& hidden_options = *pHidden;
+ po::positional_options_description& positional_options = *pPositional;
po::options_description general_options("General options");
#if defined(_WIN32)
@@ -642,12 +638,8 @@ static int mongoDbMain(int argc, char* argv[], char **envp) {
po::options_description ms_options("Master/slave options");
po::options_description rs_options("Replica set options");
po::options_description sharding_options("Sharding options");
- po::options_description visible_options("Allowed options");
- po::options_description hidden_options("Hidden options");
po::options_description ssl_options("SSL options");
- po::positional_options_description positional_options;
-
CmdLine::addGlobalOptions( general_options , hidden_options , ssl_options );
StringBuilder dbpathBuilder;
@@ -745,7 +737,13 @@ static int mongoDbMain(int argc, char* argv[], char **envp) {
visible_options.add(ssl_options);
#endif
Module::addOptions( visible_options );
+}
+
+static int mongoDbMain(int argc, char* argv[], char **envp) {
+ static StaticObserver staticObserver;
+ getcurns = ourgetns;
+ mongo::runGlobalInitializersOrDie(argc, argv, envp);
setupCoreSignals();
setupSignals( false );
@@ -766,31 +764,36 @@ static int mongoDbMain(int argc, char* argv[], char **envp) {
if( argc == 1 )
cout << dbExecCommand << " --help for help and startup options" << endl;
+ po::options_description visible_options("Allowed options");
+ po::options_description hidden_options("Hidden options");
+ po::positional_options_description positional_options;
+ buildOptionsDescriptions(&visible_options, &hidden_options, &positional_options);
+
{
po::variables_map params;
- string error_message = arg_error_check(argc, argv);
- if (error_message != "") {
- cout << error_message << endl << endl;
- show_help_text(visible_options);
- return 0;
+ if (!CmdLine::store(std::vector<std::string>(argv, argv + argc),
+ visible_options,
+ hidden_options,
+ positional_options,
+ params)) {
+ ::_exit(EXIT_FAILURE);
}
- if ( ! CmdLine::store( argc , argv , visible_options , hidden_options , positional_options , params ) )
- return EXIT_FAILURE;
-
- if (!initializeServerGlobalState(params.count("shutdown")))
- return EXIT_FAILURE;
-
if (params.count("help")) {
show_help_text(visible_options);
- return 0;
+ ::_exit(EXIT_SUCCESS);
}
if (params.count("version")) {
cout << mongodVersion() << endl;
printGitVersion();
- return 0;
+ ::_exit(EXIT_SUCCESS);
+ }
+ if (params.count("sysinfo")) {
+ sysRuntimeInfo();
+ ::_exit(EXIT_SUCCESS);
}
+
if ( params.count( "dbpath" ) ) {
dbpath = params["dbpath"].as<string>();
if ( params.count( "fork" ) && dbpath[0] != '/' ) {
@@ -835,7 +838,7 @@ static int mongoDbMain(int argc, char* argv[], char **envp) {
if( params.count("dur") || params.count( "journal" ) ) {
if (journalExplicit) {
log() << "Can't specify both --journal and --nojournal options." << endl;
- return EXIT_BADOPTIONS;
+ ::_exit(EXIT_BADOPTIONS);
}
journalExplicit = true;
cmdLine.dur = true;
@@ -902,14 +905,10 @@ static int mongoDbMain(int argc, char* argv[], char **envp) {
}
_diaglog.setLevel(x);
}
- if (params.count("sysinfo")) {
- sysRuntimeInfo();
- return 0;
- }
if (params.count("repair")) {
if (journalExplicit && cmdLine.dur) {
log() << "Can't specify both --journal and --repair options." << endl;
- return EXIT_BADOPTIONS;
+ ::_exit(EXIT_BADOPTIONS);
}
Record::MemoryTrackingEnabled = false;
@@ -1052,31 +1051,28 @@ static int mongoDbMain(int argc, char* argv[], char **envp) {
if( repairpath.empty() )
repairpath = dbpath;
- Module::configAll( params );
- dataFileSync.go();
-
+ // The "command" option is deprecated. For backward compatibility, still support the "run"
+ // and "dbppath" command. The "run" command is the same as just running mongod, so just
+ // falls through.
if (params.count("command")) {
vector<string> command = params["command"].as< vector<string> >();
- if (command[0].compare("run") == 0) {
- if (command.size() > 1) {
- cout << "Too many parameters to 'run' command" << endl;
- cout << visible_options << endl;
- return 0;
- }
-
- initAndListen(cmdLine.port);
- return 0;
- }
-
if (command[0].compare("dbpath") == 0) {
cout << dbpath << endl;
- return 0;
+ ::_exit(EXIT_SUCCESS);
+ }
+
+ if (command[0].compare("run") != 0) {
+ cout << "Invalid command: " << command[0] << endl;
+ cout << visible_options << endl;
+ ::_exit(EXIT_FAILURE);
}
- cout << "Invalid command: " << command[0] << endl;
- cout << visible_options << endl;
-