Skip to content

Specifying -datadir= to a non existent path creates directories or fails to stderr #337

@jburkle

Description

@jburkle

I experienced this while testing out testnet-in-a-box. If I specify a path to a directory that does not exist, but is 1 directory level lower than an actual path, I get a "missing bitcoin.conf" error:

candide@candide-VirtualBox:/code/bitcoin_testinbox$ bitcoin -datadir=/home/candide/code/bitcoin_testinbox/asdf/ -daemon
candide@candide-VirtualBox:
/code/bitcoin_testinbox$ bitcoin server starting

candide@candide-VirtualBox:~/code/bitcoin_testinbox$ Warning: To use the "-daemon" option, you must set rpcpassword=
in the configuration file: /home/candide/code/bitcoin_testinbox/asdf/bitcoin.conf
If the file does not exist, create it with owner-readable-only file permissions.

10:58:06 PM: Debug: In file ./src/unix/threadpsx.cpp at line 253: 'pthread_mutex_destroy()' failed with error 0x00000010 (Device or resource busy).

Also, the program actually creates the non existent directory.

Additionally, If I specify a path more than 1 directory level lower than an existing path, I get a much more verbose error to stderr:

candide@candide-VirtualBox:/code/bitcoin_testinbox$ bitcoin -datadir=/home/candide/code/bitcoin_testinbox/asdf/new/dir -daemon
candide@candide-VirtualBox:
/code/bitcoin_testinbox$


EXCEPTION: N5boost16exception_detail10clone_implINS0_19error_info_injectorINS_10filesystem22basic_filesystem_errorINS3_10basic_pathISsNS3_11path_traitsEEEEEEEEE
boost::filesystem::create_directory: No such file or directory: "/home/candide/code/bitcoin_testinbox/asdf/new/dir"
bitcoin in AppInit()


EXCEPTION: >N5boost16exception_detail10clone_implINS0_19error_info_injectorINS_10filesystem22basic_filesystem_errorINS3_10basic_pathISsNS3_11path_traitsEEEEEEEEE
boost::filesystem::create_directory: No such file or directory: "/home/candide/code/bitcoin_testinbox/asdf/new/dir"
bitcoin in CMyApp::OnUnhandledException()

terminate called after throwing an instance of '>boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::filesystem::basic_filesystem_error<boost::filesystem::basic_path<std::string, boost::filesystem::path_traits> > > >'
what(): boost::filesystem::create_directory: No such file or directory: "/home/candide/code/bitcoin_testinbox/asdf/new/dir"

I have some thoughts on this. Number 1, the code should check if the datadir being specified actually exists before it continues. If the datadir does not exist, the program should probably exit with a "specified datadir does not exist" error. Further, when passing the -daemon flag, the bitcoin program should create a log file automatically in the datadir directory, or allow a -logdir at the command line (if one is not specified, default to datadir for logdir, or syslog, or anything other than screen dumps). All stderr should be directed to the log file instead of the terminal.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions