Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-24915

getcwd() failure should report errno

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.3.12
    • Affects Version/s: None
    • Component/s: Diagnostics
    • None
    • Fully Compatible
    • ALL
    • Hide
      • EACCES:
        mkdir -p /tmp/data
        mkdir -p noaccess
        cd noaccess
        # Works on (modern) Linux, but fails on OSX:
        chmod 0 .
        mongod --dbpath /tmp/data
        
        bash-3.2$ chmod 0 .
        bash-3.2$ mongod --dbpath /tmp/data
        2016-07-06T12:29:50.913+1000 I -        [main] Assertion failure getcwd(buffer, 1000) src/mongo/db/server_options_helpers.cpp 450
        2016-07-06T12:29:50.928+1000 I CONTROL  [main]
        0x104e899ba 0x104e288d1 0x104e16399 0x104b6207e 0x1048a91c3 0x10456e556 0x10456dae2 0x10457307e 0x1045738c5 0x1045662ae 0x104562204
        ----- BEGIN BACKTRACE -----
        {"backtrace":[{"b":"104561000","o":"9289BA","s":"_ZN5mongo15printStackTraceERNSt3__113basic_ostreamIcNS0_11char_traitsIcEEEE"},{"b":"104561000","o":"8C78D1","s":"_ZN5mongo10logContextEPKc"},{"b":"104561000","o":"8B5399","s":"_ZN5mongo12verifyFailedEPKcS1_j"},{"b":"104561000","o":"60107E","s":"_ZN5mongo18storeServerOptionsERKNS_17optionenvironment11EnvironmentERKNSt3__16vectorINS4_12basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEENS9_ISB_EEEE"},{"b":"104561000","o":"3481C3","s":"_ZN5mongo18storeMongodOptionsERKNS_17optionenvironment11EnvironmentERKNSt3__16vectorINS4_12basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEENS9_ISB_EEEE"},{"b":"104561000","o":"D556","s":"_ZN5mongo45_mongoInitializerFunction_MongodOptions_StoreEPNS_18InitializerContextE"},{"b":"104561000","o":"CAE2","s":"ZNSt3__110__function6__funcIPFN5mongo6StatusEPNS2_18InitializerContextEENS_9allocatorIS7_EES6_EclEOS5"},{"b":"104561000","o":"1207E","s":"_ZNK5mongo11Initializer7executeERKNSt3__16vectorINS1_12basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS6_IS8_EEEERKNS1_3mapIS8_S8_NS1_4lessIS8_EENS6_INS1_4pairIKS8_S8_EEEEEE"},{"b":"104561000","o":"128C5","s":"ZN5mongo21runGlobalInitializersEiPKPKcS3"},{"b":"104561000","o":"52AE","s":"main"},{"b":"104561000","o":"1204","s":"start"}]}
        mongod(_ZN5mongo15printStackTraceERNSt3__113basic_ostreamIcNS0_11char_traitsIcEEEE+0x3A) [0x104e899ba]
        mongod(_ZN5mongo10logContextEPKc+0x171) [0x104e288d1]
        mongod(_ZN5mongo12verifyFailedEPKcS1_j+0x239) [0x104e16399]
        mongod(_ZN5mongo18storeServerOptionsERKNS_17optionenvironment11EnvironmentERKNSt3__16vectorINS4_12basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEENS9_ISB_EEEE+0x397E) [0x104b6207e]
        mongod(_ZN5mongo18storeMongodOptionsERKNS_17optionenvironment11EnvironmentERKNSt3__16vectorINS4_12basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEENS9_ISB_EEEE+0x23) [0x1048a91c3]
        mongod(_ZN5mongo45_mongoInitializerFunction_MongodOptions_StoreEPNS_18InitializerContextE+0x26) [0x10456e556]
        mongod(ZNSt3__110__function6__funcIPFN5mongo6StatusEPNS2_18InitializerContextEENS_9allocatorIS7_EES6_EclEOS5+0x12) [0x10456dae2]
        mongod(_ZNK5mongo11Initializer7executeERKNSt3__16vectorINS1_12basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS6_IS8_EEEERKNS1_3mapIS8_S8_NS1_4lessIS8_EENS6_INS1_4pairIKS8_S8_EEEEEE+0x13E) [0x10457307e]
        mongod(ZN5mongo21runGlobalInitializersEiPKPKcS3+0x355) [0x1045738c5]
        mongod(main+0x8E) [0x1045662ae]
        mongod(start+0x34) [0x104562204]
        -----  END BACKTRACE  -----
        2016-07-06T12:29:50.936+1000 F CONTROL  [main] Failed global initialization: UnknownError: assertion src/mongo/db/server_options_helpers.cpp:450
        
      • ENOENT:
        kev@genique:~$ mkdir -p /tmp/data
        kev@genique:~$ mkdir unlinkme
        kev@genique:~$ cd unlinkme
        kev@genique:~/unlinkme$ mongod --dbpath /tmp/data
        2016-07-06T12:02:26.431+1000 I CONTROL  [initandlisten] MongoDB starting : pid=7540 port=27017 dbpath=/tmp/data 64-bit host=genique
        2016-07-06T12:02:26.431+1000 I CONTROL  [initandlisten] db version v3.2.6
        2016-07-06T12:02:26.431+1000 I CONTROL  [initandlisten] git version: 05552b562c7a0b3143a729aaa0838e558dc49b25
        2016-07-06T12:02:26.431+1000 I CONTROL  [initandlisten] allocator: tcmalloc
        2016-07-06T12:02:26.431+1000 I CONTROL  [initandlisten] modules: none
        2016-07-06T12:02:26.431+1000 I CONTROL  [initandlisten] build environment:
        2016-07-06T12:02:26.431+1000 I CONTROL  [initandlisten]     distarch: x86_64
        2016-07-06T12:02:26.431+1000 I CONTROL  [initandlisten]     target_arch: x86_64
        2016-07-06T12:02:26.431+1000 I CONTROL  [initandlisten] options: { storage: { dbPath: "/tmp/data" } }
        2016-07-06T12:02:26.448+1000 E NETWORK  [initandlisten] listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017
        2016-07-06T12:02:26.449+1000 E NETWORK  [initandlisten]   addr already in use
        2016-07-06T12:02:26.449+1000 E STORAGE  [initandlisten] Failed to set up sockets during startup.
        2016-07-06T12:02:26.449+1000 I CONTROL  [initandlisten] dbexit:  rc: 48
        kev@genique:~/unlinkme$ rmdir ../unlinkme
        kev@genique:~/unlinkme$ mongod --dbpath /tmp/data
        2016-07-06T12:02:34.144+1000 I -        [main] Assertion failure getcwd(buffer, 1000) src/mongo/db/server_options_helpers.cpp 450
        2016-07-06T12:02:34.152+1000 I CONTROL  [main]
         0x12fa192 0x12a5538 0x1291074 0xf87cc1 0xcd0476 0x962ccb 0x95fa24 0x96ac2b 0x96b2dc 0x96b60e 0x962678 0x7f8a1b759ec5 0x959d09
        ----- BEGIN BACKTRACE -----
        {"backtrace":[{"b":"400000","o":"EFA192","s":"_ZN5mongo15printStackTraceERSo"},{"b":"400000","o":"EA5538","s":"_ZN5mongo10logContextEPKc"},{"b":"400000","o":"E91074","s":"_ZN5mongo12verifyFailedEPKcS1_j"},{"b":"400000","o":"B87CC1","s":"_ZN5mongo18storeServerOptionsERKNS_17optionenvironment11EnvironmentERKSt6vectorISsSaISsEE"},{"b":"400000","o":"8D0476","s":"_ZN5mongo18storeMongodOptionsERKNS_17optionenvironment11EnvironmentERKSt6vectorISsSaISsEE"},{"b":"400000","o":"562CCB","s":"_ZN5mongo45_mongoInitializerFunction_MongodOptions_StoreEPNS_18InitializerContextE"},{"b":"400000","o":"55FA24","s":"_ZNSt17_Function_handlerIFN5mongo6StatusEPNS0_18InitializerContextEEPS4_E9_M_invokeERKSt9_Any_dataS3_"},{"b":"400000","o":"56AC2B","s":"_ZNK5mongo11Initializer7executeERKSt6vectorISsSaISsEERKSt3mapISsSsSt4lessISsESaISt4pairIKSsSsEEE"},{"b":"400000","o":"56B2DC","s":"_ZN5mongo21runGlobalInitializersERKSt6vectorISsSaISsEERKSt3mapISsSsSt4lessISsESaISt4pairIKSsSsEEE"},{"b":"400000","o":"56B60E","s":"_ZN5mongo21runGlobalInitializersEiPKPKcS3_"},{"b":"400000","o":"562678","s":"main"},{"b":"7F8A1B738000","o":"21EC5","s":"__libc_start_main"},{"b":"400000","o":"559D09"}]}
         mongod(_ZN5mongo15printStackTraceERSo+0x32) [0x12fa192]
         mongod(_ZN5mongo10logContextEPKc+0x138) [0x12a5538]
         mongod(_ZN5mongo12verifyFailedEPKcS1_j+0xB4) [0x1291074]
         mongod(_ZN5mongo18storeServerOptionsERKNS_17optionenvironment11EnvironmentERKSt6vectorISsSaISsEE+0x2C01) [0xf87cc1]
         mongod(_ZN5mongo18storeMongodOptionsERKNS_17optionenvironment11EnvironmentERKSt6vectorISsSaISsEE+0x26) [0xcd0476]
         mongod(_ZN5mongo45_mongoInitializerFunction_MongodOptions_StoreEPNS_18InitializerContextE+0x2B) [0x962ccb]
         mongod(_ZNSt17_Function_handlerIFN5mongo6StatusEPNS0_18InitializerContextEEPS4_E9_M_invokeERKSt9_Any_dataS3_+0x14) [0x95fa24]
         mongod(_ZNK5mongo11Initializer7executeERKSt6vectorISsSaISsEERKSt3mapISsSsSt4lessISsESaISt4pairIKSsSsEEE+0x1CB) [0x96ac2b]
         mongod(_ZN5mongo21runGlobalInitializersERKSt6vectorISsSaISsEERKSt3mapISsSsSt4lessISsESaISt4pairIKSsSsEEE+0x2C) [0x96b2dc]
         mongod(_ZN5mongo21runGlobalInitializersEiPKPKcS3_+0x31E) [0x96b60e]
         mongod(main+0x68) [0x962678]
         libc.so.6(__libc_start_main+0xF5) [0x7f8a1b759ec5]
         mongod(+0x559D09) [0x959d09]
        -----  END BACKTRACE  -----
        2016-07-06T12:02:34.152+1000 F CONTROL  [main] Failed global initialization: UnknownError: assertion src/mongo/db/server_options_helpers.cpp:450
        kev@genique:~/unlinkme$
        
      Show
      ERANGE: SERVER-24914 EACCES: mkdir -p /tmp/data mkdir -p noaccess cd noaccess # Works on (modern) Linux, but fails on OSX: chmod 0 . mongod --dbpath /tmp/data bash-3.2$ chmod 0 . bash-3.2$ mongod --dbpath /tmp/data 2016-07-06T12:29:50.913+1000 I - [main] Assertion failure getcwd(buffer, 1000) src/mongo/db/server_options_helpers.cpp 450 2016-07-06T12:29:50.928+1000 I CONTROL [main] 0x104e899ba 0x104e288d1 0x104e16399 0x104b6207e 0x1048a91c3 0x10456e556 0x10456dae2 0x10457307e 0x1045738c5 0x1045662ae 0x104562204 ----- BEGIN BACKTRACE ----- {"backtrace":[{"b":"104561000","o":"9289BA","s":"_ZN5mongo15printStackTraceERNSt3__113basic_ostreamIcNS0_11char_traitsIcEEEE"},{"b":"104561000","o":"8C78D1","s":"_ZN5mongo10logContextEPKc"},{"b":"104561000","o":"8B5399","s":"_ZN5mongo12verifyFailedEPKcS1_j"},{"b":"104561000","o":"60107E","s":"_ZN5mongo18storeServerOptionsERKNS_17optionenvironment11EnvironmentERKNSt3__16vectorINS4_12basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEENS9_ISB_EEEE"},{"b":"104561000","o":"3481C3","s":"_ZN5mongo18storeMongodOptionsERKNS_17optionenvironment11EnvironmentERKNSt3__16vectorINS4_12basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEENS9_ISB_EEEE"},{"b":"104561000","o":"D556","s":"_ZN5mongo45_mongoInitializerFunction_MongodOptions_StoreEPNS_18InitializerContextE"},{"b":"104561000","o":"CAE2","s":"ZNSt3__110__function6__funcIPFN5mongo6StatusEPNS2_18InitializerContextEENS_9allocatorIS7_EES6_EclEOS5"},{"b":"104561000","o":"1207E","s":"_ZNK5mongo11Initializer7executeERKNSt3__16vectorINS1_12basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS6_IS8_EEEERKNS1_3mapIS8_S8_NS1_4lessIS8_EENS6_INS1_4pairIKS8_S8_EEEEEE"},{"b":"104561000","o":"128C5","s":"ZN5mongo21runGlobalInitializersEiPKPKcS3"},{"b":"104561000","o":"52AE","s":"main"},{"b":"104561000","o":"1204","s":"start"}]} mongod(_ZN5mongo15printStackTraceERNSt3__113basic_ostreamIcNS0_11char_traitsIcEEEE+0x3A) [0x104e899ba] mongod(_ZN5mongo10logContextEPKc+0x171) [0x104e288d1] mongod(_ZN5mongo12verifyFailedEPKcS1_j+0x239) [0x104e16399] mongod(_ZN5mongo18storeServerOptionsERKNS_17optionenvironment11EnvironmentERKNSt3__16vectorINS4_12basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEENS9_ISB_EEEE+0x397E) [0x104b6207e] mongod(_ZN5mongo18storeMongodOptionsERKNS_17optionenvironment11EnvironmentERKNSt3__16vectorINS4_12basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEENS9_ISB_EEEE+0x23) [0x1048a91c3] mongod(_ZN5mongo45_mongoInitializerFunction_MongodOptions_StoreEPNS_18InitializerContextE+0x26) [0x10456e556] mongod(ZNSt3__110__function6__funcIPFN5mongo6StatusEPNS2_18InitializerContextEENS_9allocatorIS7_EES6_EclEOS5+0x12) [0x10456dae2] mongod(_ZNK5mongo11Initializer7executeERKNSt3__16vectorINS1_12basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS6_IS8_EEEERKNS1_3mapIS8_S8_NS1_4lessIS8_EENS6_INS1_4pairIKS8_S8_EEEEEE+0x13E) [0x10457307e] mongod(ZN5mongo21runGlobalInitializersEiPKPKcS3+0x355) [0x1045738c5] mongod(main+0x8E) [0x1045662ae] mongod(start+0x34) [0x104562204] ----- END BACKTRACE ----- 2016-07-06T12:29:50.936+1000 F CONTROL [main] Failed global initialization: UnknownError: assertion src/mongo/db/server_options_helpers.cpp:450 ENOENT: kev@genique:~$ mkdir -p /tmp/data kev@genique:~$ mkdir unlinkme kev@genique:~$ cd unlinkme kev@genique:~/unlinkme$ mongod --dbpath /tmp/data 2016-07-06T12:02:26.431+1000 I CONTROL [initandlisten] MongoDB starting : pid=7540 port=27017 dbpath=/tmp/data 64-bit host=genique 2016-07-06T12:02:26.431+1000 I CONTROL [initandlisten] db version v3.2.6 2016-07-06T12:02:26.431+1000 I CONTROL [initandlisten] git version: 05552b562c7a0b3143a729aaa0838e558dc49b25 2016-07-06T12:02:26.431+1000 I CONTROL [initandlisten] allocator: tcmalloc 2016-07-06T12:02:26.431+1000 I CONTROL [initandlisten] modules: none 2016-07-06T12:02:26.431+1000 I CONTROL [initandlisten] build environment: 2016-07-06T12:02:26.431+1000 I CONTROL [initandlisten] distarch: x86_64 2016-07-06T12:02:26.431+1000 I CONTROL [initandlisten] target_arch: x86_64 2016-07-06T12:02:26.431+1000 I CONTROL [initandlisten] options: { storage: { dbPath: "/tmp/data" } } 2016-07-06T12:02:26.448+1000 E NETWORK [initandlisten] listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017 2016-07-06T12:02:26.449+1000 E NETWORK [initandlisten] addr already in use 2016-07-06T12:02:26.449+1000 E STORAGE [initandlisten] Failed to set up sockets during startup. 2016-07-06T12:02:26.449+1000 I CONTROL [initandlisten] dbexit: rc: 48 kev@genique:~/unlinkme$ rmdir ../unlinkme kev@genique:~/unlinkme$ mongod --dbpath /tmp/data 2016-07-06T12:02:34.144+1000 I - [main] Assertion failure getcwd(buffer, 1000) src/mongo/db/server_options_helpers.cpp 450 2016-07-06T12:02:34.152+1000 I CONTROL [main] 0x12fa192 0x12a5538 0x1291074 0xf87cc1 0xcd0476 0x962ccb 0x95fa24 0x96ac2b 0x96b2dc 0x96b60e 0x962678 0x7f8a1b759ec5 0x959d09 ----- BEGIN BACKTRACE ----- { "backtrace" :[{ "b" : "400000" , "o" : "EFA192" , "s" : "_ZN5mongo15printStackTraceERSo" },{ "b" : "400000" , "o" : "EA5538" , "s" : "_ZN5mongo10logContextEPKc" },{ "b" : "400000" , "o" : "E91074" , "s" : "_ZN5mongo12verifyFailedEPKcS1_j" },{ "b" : "400000" , "o" : "B87CC1" , "s" : "_ZN5mongo18storeServerOptionsERKNS_17optionenvironment11EnvironmentERKSt6vectorISsSaISsEE" },{ "b" : "400000" , "o" : "8D0476" , "s" : "_ZN5mongo18storeMongodOptionsERKNS_17optionenvironment11EnvironmentERKSt6vectorISsSaISsEE" },{ "b" : "400000" , "o" : "562CCB" , "s" : "_ZN5mongo45_mongoInitializerFunction_MongodOptions_StoreEPNS_18InitializerContextE" },{ "b" : "400000" , "o" : "55FA24" , "s" : "_ZNSt17_Function_handlerIFN5mongo6StatusEPNS0_18InitializerContextEEPS4_E9_M_invokeERKSt9_Any_dataS3_" },{ "b" : "400000" , "o" : "56AC2B" , "s" : "_ZNK5mongo11Initializer7executeERKSt6vectorISsSaISsEERKSt3mapISsSsSt4lessISsESaISt4pairIKSsSsEEE" },{ "b" : "400000" , "o" : "56B2DC" , "s" : "_ZN5mongo21runGlobalInitializersERKSt6vectorISsSaISsEERKSt3mapISsSsSt4lessISsESaISt4pairIKSsSsEEE" },{ "b" : "400000" , "o" : "56B60E" , "s" : "_ZN5mongo21runGlobalInitializersEiPKPKcS3_" },{ "b" : "400000" , "o" : "562678" , "s" : "main" },{ "b" : "7F8A1B738000" , "o" : "21EC5" , "s" : "__libc_start_main" },{ "b" : "400000" , "o" : "559D09" }]} mongod(_ZN5mongo15printStackTraceERSo+0x32) [0x12fa192] mongod(_ZN5mongo10logContextEPKc+0x138) [0x12a5538] mongod(_ZN5mongo12verifyFailedEPKcS1_j+0xB4) [0x1291074] mongod(_ZN5mongo18storeServerOptionsERKNS_17optionenvironment11EnvironmentERKSt6vectorISsSaISsEE+0x2C01) [0xf87cc1] mongod(_ZN5mongo18storeMongodOptionsERKNS_17optionenvironment11EnvironmentERKSt6vectorISsSaISsEE+0x26) [0xcd0476] mongod(_ZN5mongo45_mongoInitializerFunction_MongodOptions_StoreEPNS_18InitializerContextE+0x2B) [0x962ccb] mongod(_ZNSt17_Function_handlerIFN5mongo6StatusEPNS0_18InitializerContextEEPS4_E9_M_invokeERKSt9_Any_dataS3_+0x14) [0x95fa24] mongod(_ZNK5mongo11Initializer7executeERKSt6vectorISsSaISsEERKSt3mapISsSsSt4lessISsESaISt4pairIKSsSsEEE+0x1CB) [0x96ac2b] mongod(_ZN5mongo21runGlobalInitializersERKSt6vectorISsSaISsEERKSt3mapISsSsSt4lessISsESaISt4pairIKSsSsEEE+0x2C) [0x96b2dc] mongod(_ZN5mongo21runGlobalInitializersEiPKPKcS3_+0x31E) [0x96b60e] mongod(main+0x68) [0x962678] libc.so.6(__libc_start_main+0xF5) [0x7f8a1b759ec5] mongod(+0x559D09) [0x959d09] ----- END BACKTRACE ----- 2016-07-06T12:02:34.152+1000 F CONTROL [main] Failed global initialization: UnknownError: assertion src/mongo/db/server_options_helpers.cpp:450 kev@genique:~/unlinkme$

      In various circumstances, getcwd() can return NULL and set errno. The server checks for this, but it results in an inelegant assertion that does not include the errno. This hinders diagnosis of the root cause of the getcwd() failure.

      See also SERVER-24916.

      https://github.com/mongodb/mongo/blob/r3.3.9/src/mongo/db/server_options_helpers.cpp#L462-L464

      Status setupCwd() {
          // setup cwd
          char buffer[1024];
      #ifdef _WIN32
          verify(_getcwd(buffer, 1000));
      #else
          verify(getcwd(buffer, 1000));
      #endif
          serverGlobalParams.cwd = buffer;
          return Status::OK();
      }
      

      Relevant possible errors:

      • ERANGE (Path too long for supplied buffer) (See also SERVER-24914) (POSIX, Linux, Darwin, Windows)
      • EACCES (Permission denied) (POSIX, Linux (kindof), Darwin)
      • ENOMEM (Insufficient memory) (POSIX, Linux, Darwin, Windows)
      • ENOENT (Directory has been unlinked) (Linux, Darwin)

      Manpages:

            Assignee:
            kevin.pulo@mongodb.com Kevin Pulo
            Reporter:
            kevin.pulo@mongodb.com Kevin Pulo
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: