Skip to content

Conversation

@n-thumann
Copy link
Contributor

@n-thumann n-thumann commented Aug 4, 2021

Fixes #22612.
When running e.g. ./src/bitcoind -datadir=/tmp/bitcoin -regtest -conf=/tmp/bitcoin/regtest/bitcoin.conf and the specified config cannot be opened (doesn't exist, permission denied, ...), the initialization silently uses the default config.

As voidburn already noted:

I can't think of a situation in which a config file is specified explicitly (in the startup options, as per service unit linked above), but inaccessible, where the fail condition should be to keep booting using defaults instead.

With this patch applied, the initialization will fail immediately, if the specified config file cannot be opened. If no config file is explicitly specified, the behavior is unchanged. This not only affects bitcoind, but also bitcoin-cli and bitcoin-qt.

In the example below the datadir is accessible, but the config file is not due to insufficient permissions:

$ ./src/bitcoind -datadir=/tmp/bitcoin -regtest --debug=1 -conf=/tmp/bitcoin/regtest/bitcoin.conf
Error: Error reading configuration file: specified config file "/tmp/bitcoin/regtest/bitcoin.conf" could not be opened.

@0xB10C
Copy link
Contributor

0xB10C commented Aug 4, 2021

ACK 127b460

I agree that failing to read an explicitly specified config file should fail initialization.

Tested that starting with a non-openable config file throws an error.

@maflcko maflcko requested a review from ryanofsky August 4, 2021 19:12
@n-thumann n-thumann changed the title Check config file cannot be opened util: Check if specified config file cannot be opened Aug 4, 2021
@practicalswift
Copy link
Contributor

Concept ACK

@Zero-1729
Copy link
Contributor

tACK 127b460

Tested on macOS v11.4

Patch works as described. I got the following error from testing both cases: config file doesn't exist and config file is inaccessible (due to permissions):

$ bitcoind -datadir=/tmp/bitcoin -regtest -conf=/tmp/bitcoin/regtest/bitcoin.conf
Error: Error reading configuration file: specified config file "/tmp/bitcoin/regtest/bitcoin.conf" could not be opened.

@theStack
Copy link
Contributor

theStack commented Aug 5, 2021

Concept ACK

Copy link
Contributor

@NikhilBartwal NikhilBartwal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK. Makes sense to fail the initial startup if the config is inaccessible instead of using the default one (which the user might/might not want)

Tested on Manjaro Linux v21.1.0 . The PR patch works as described :)

Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested ACK 127b460

Checked that starting src/bitcoind -conf=doesnt_exist leads to the newly introduced error message (running OpenBSD 6.9 here). Also tested that running the extended test in the second commit fails on master branch.

@maflcko maflcko merged commit f6f7a12 into bitcoin:master Aug 23, 2021
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Aug 23, 2021
…pened

127b460 test: Check if specified config file cannot be opened (nthumann)
6bb5470 util: Check if specified config file cannot be opened (nthumann)

Pull request description:

  Fixes bitcoin#22612.
  When running e.g. `./src/bitcoind -datadir=/tmp/bitcoin -regtest -conf=/tmp/bitcoin/regtest/bitcoin.conf` and the specified config cannot be opened (doesn't exist, permission denied, ...), the initialization silently uses the default config.

  As voidburn already noted:
  > I can't think of a situation in which a config file is specified explicitly (in the startup options, as per service unit linked above), but inaccessible, where the fail condition should be to keep booting using defaults instead.

  With this patch applied, the initialization will fail immediately, if the specified config file cannot be opened. If no config file is explicitly specified, the behavior is unchanged. This not only affects `bitcoind`, but also `bitcoin-cli` and `bitcoin-qt`.

  In the example below the datadir is accessible, but the config file is not due to insufficient permissions:
  ```
  $ ./src/bitcoind -datadir=/tmp/bitcoin -regtest --debug=1 -conf=/tmp/bitcoin/regtest/bitcoin.conf
  Error: Error reading configuration file: specified config file "/tmp/bitcoin/regtest/bitcoin.conf" could not be opened.
  ```

ACKs for top commit:
  0xB10C:
    ACK 127b460
  Zero-1729:
    tACK 127b460
  theStack:
    Tested ACK 127b460

Tree-SHA512: 4fe487921485426f1d1da8d256c388af517b984b639d776aec7b159b3e23b669824093d3bdd31139d9415ed5f5de405b3e6a51b110c8ab471f12b9c99ac67cc1
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The bitcoind service silently loads the default configuration if the .conf file is specified but not readable

8 participants