Skip to content

Conversation

@riordant
Copy link
Contributor

@riordant riordant commented Feb 21, 2019

Introduction

As discussed with @laanwj on IRC:

  • PID file creation was never enabled for Windows, as the pid_t filetype is not available for it. However, the WIN32 API contains the header Processthreadsapi.h which in turn contains the function GetCurrentProcessId(). This function is called at a higher level by _getpid() EDIT: _getpid() is not available to the MSVC compiler used in the AppVeyor build. As a result, I have changed the function call toGetCurrentProcessId(), which performs the same function and is available to both MinGW & MSVC.
    This allows one to capture the PID in Windows, without any additional includes - the above function is already available.

  • Within this PR, I have added a separate line that calls GetCurrentProcessId() in the case of a WIN compilation, and the usual getpid() otherwise. All code blocks processing PID file logic that avoid WIN32 have been changed to consider it. I have also updated the preprocessor definitions in libbitcoin_server.vcxproj.in to suppress a warning related to std::strerror for the MSVC build, that was causing the AppVeyor build to fail (see @fanquake comment below).

Rationale

  • Consistency between OS's running Bitcoin
    • Applications which build off of bitcoind, such as novel front-end clients, often need access to the PID in order to control the daemon. Instead of designing some alternate way of doing this for one system, it should be consistent between all of them.

In collaboration with @joernroeder

@laanwj
Copy link
Member

laanwj commented Feb 21, 2019

+4 -10 and adds a feature, this is a great first contribution, thanks!
utACK ca33ac10d36199395bd6553db77e5ceacfdb925e (given that this passes Travis and Appveyor)

@riordant
Copy link
Contributor Author

Force pushed in order to add co-author.

@fanquake fanquake requested a review from ken2812221 February 21, 2019 12:54
Copy link
Contributor

@ken2812221 ken2812221 left a comment

Choose a reason for hiding this comment

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

utACK c4372b8b18d2fab2101d904289b78f87703bb6b9
You might have to include process.h?

@fanquake
Copy link
Member

Appveyor build is failing with:

c:\projects\bitcoin\src\init.cpp(112): error C3861: '_getpid': identifier not found [C:\projects\bitcoin\build_msvc\libbitcoin_server\libbitcoin_server.vcxproj]

c:\projects\bitcoin\src\init.cpp(119): error C4996: 'strerror': This function or variable may be unsafe. Consider using strerror_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. [C:\projects\bitcoin\build_msvc\libbitcoin_server\libbitcoin_server.vcxproj]

@fanquake
Copy link
Member

I compiled this PR inside WSL and ran bitcoin-qt on a Windows 10 system.
Looks like bitcoin.pid is created correctly, and contains the correct PID.

windows

@riordant
Copy link
Contributor Author

Update: AppVeyor build should now pass. I have updated the description with details

src/init.cpp Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Use fsbridge::get_filesystem_error_message(e) instead of e.what()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, can be added. Just note this was not added/modified by me and was merged in #15278 a few days ago

Copy link
Contributor

Choose a reason for hiding this comment

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

That was OK to use e.what() in other OS except Windows. So you have to use fsbridge::get_filesystem_error_message(e) instead.

@practicalswift
Copy link
Contributor

Concept ACK

Excellent first-time contribution! Thanks! Hope to see more PR:s from you! :-)

@hebasto
Copy link
Member

hebasto commented Feb 24, 2019

Concept ACK.

@laanwj
Copy link
Member

laanwj commented Feb 25, 2019

utACK after squash, I think this is better as one commit to have an atomic change

- Add available WIN PID function
- Consider WIN32 in each relevant case
- Add new preprocessor definitions to suppress warning
- Update error message for generic OS

Co-authored-by: Jörn Röder <[email protected]>
@riordant
Copy link
Contributor Author

Yep agree, done.

@laanwj
Copy link
Member

laanwj commented Feb 25, 2019

thanks!
utACK 3f5ad62

@laanwj laanwj merged commit 3f5ad62 into bitcoin:master Feb 25, 2019
laanwj added a commit that referenced this pull request Feb 25, 2019
3f5ad62 Enable PID file creation on Windows - Add available WIN PID function - Consider WIN32 in each relevant case - Add new preprocessor definitions to suppress warning - Update error message for generic OS (riordant)

Pull request description:

  # Introduction

  As discussed with @laanwj on IRC:

  - PID file creation was never enabled for Windows, as the `pid_t` filetype is not available for it. However, the WIN32 API contains the header [`Processthreadsapi.h`](https://github.com/CodeShark/x86_64-w64-mingw32/blob/master/include/processthreadsapi.h) which in turn contains the function [`GetCurrentProcessId()`](https://docs.microsoft.com/en-gb/windows/desktop/api/processthreadsapi/nf-processthreadsapi-getcurrentprocessid). ~~This function is called at a higher level by [`_getpid()`](https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/getpid?view=vs-2017)~~ EDIT: `_getpid()` is not available to the MSVC compiler used in the AppVeyor build. As a result, I have changed the function call to`GetCurrentProcessId()`, which performs the same function and is available to both MinGW & MSVC.
  This allows one to capture the PID in Windows, without any additional includes - the above function is already available.

  - Within this PR, I have added a separate line that calls `GetCurrentProcessId()` in the case of a WIN compilation, and the usual `getpid()` otherwise. All code blocks processing PID file logic that avoid WIN32 have been changed to consider it. I have also updated the preprocessor definitions in `libbitcoin_server.vcxproj.in` to suppress a warning related to `std::strerror` for the MSVC build, that was causing the AppVeyor build to fail (see @fanquake comment below).

  # Rationale
  - Consistency between OS's running Bitcoin
      - Applications which build off of `bitcoind`, such as novel front-end clients, often need access to the PID in order to control the daemon. Instead of designing some alternate way of doing this for one system, it should be consistent between all of them.

  In collaboration with @joernroeder

Tree-SHA512: 22fcbf866e99115d12ed29716e68d200d4c118ae2f7b188b7705dc0cf5f0cd0ce5fb18f772744c6238eecd9e6d0922c615e2f0e12a7fe7c810062a79d97aa6a2
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Apr 20, 2020
Summary:
Enable PID file creation on Windows
- Add available WIN PID function
- Consider WIN32 in each relevant case
- Add new preprocessor definitions to suppress warning
- Update error message for generic OS

Co-authored-by: Jörn Röder <[email protected]>

This is a backport of Core [[bitcoin/bitcoin#15456 | PR15456]]

Depends on D5775

Test Plan:
  make check

Run the win64 build and run bitcon-qt

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D5776
ftrader pushed a commit to bitcoin-cash-node/bitcoin-cash-node that referenced this pull request Aug 17, 2020
Summary:
Enable PID file creation on Windows
- Add available WIN PID function
- Consider WIN32 in each relevant case
- Add new preprocessor definitions to suppress warning
- Update error message for generic OS

Co-authored-by: Jörn Röder <[email protected]>

This is a backport of Core [[bitcoin/bitcoin#15456 | PR15456]]

Depends on D5775

Test Plan:
  make check

Run the win64 build and run bitcon-qt

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D5776
6293 pushed a commit to 6293/dash that referenced this pull request Nov 27, 2021
3f5ad62 Enable PID file creation on Windows - Add available WIN PID function - Consider WIN32 in each relevant case - Add new preprocessor definitions to suppress warning - Update error message for generic OS (riordant)

Pull request description:

  # Introduction

  As discussed with @laanwj on IRC:

  - PID file creation was never enabled for Windows, as the `pid_t` filetype is not available for it. However, the WIN32 API contains the header [`Processthreadsapi.h`](https://github.com/CodeShark/x86_64-w64-mingw32/blob/master/include/processthreadsapi.h) which in turn contains the function [`GetCurrentProcessId()`](https://docs.microsoft.com/en-gb/windows/desktop/api/processthreadsapi/nf-processthreadsapi-getcurrentprocessid). ~~This function is called at a higher level by [`_getpid()`](https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/getpid?view=vs-2017)~~ EDIT: `_getpid()` is not available to the MSVC compiler used in the AppVeyor build. As a result, I have changed the function call to`GetCurrentProcessId()`, which performs the same function and is available to both MinGW & MSVC.
  This allows one to capture the PID in Windows, without any additional includes - the above function is already available.

  - Within this PR, I have added a separate line that calls `GetCurrentProcessId()` in the case of a WIN compilation, and the usual `getpid()` otherwise. All code blocks processing PID file logic that avoid WIN32 have been changed to consider it. I have also updated the preprocessor definitions in `libbitcoin_server.vcxproj.in` to suppress a warning related to `std::strerror` for the MSVC build, that was causing the AppVeyor build to fail (see @fanquake comment below).

  # Rationale
  - Consistency between OS's running Bitcoin
      - Applications which build off of `bitcoind`, such as novel front-end clients, often need access to the PID in order to control the daemon. Instead of designing some alternate way of doing this for one system, it should be consistent between all of them.

  In collaboration with @joernroeder

Tree-SHA512: 22fcbf866e99115d12ed29716e68d200d4c118ae2f7b188b7705dc0cf5f0cd0ce5fb18f772744c6238eecd9e6d0922c615e2f0e12a7fe7c810062a79d97aa6a2
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Dec 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants