Skip to content

Conversation

laanwj
Copy link
Member

@laanwj laanwj commented May 8, 2014

  • Log the name of the error as well as the error code if a network problem
    happens. This makes network troubleshooting more convenient
    • Use thread-safe strerror_r and the WIN32 equivalent FormatMessage.
  • Replace non-threadsafe gmtime and setlocale
    • Make DateTimeStrFormat use boost::posix_time
    • Also re-enable the util_DateTimeStrFormat tests, as they are no
      longer platform specific

@laanwj laanwj changed the title 2014 05 replace strerror gmtime Replace non-threadsafe strerror gmtime setlocale May 8, 2014
#ifdef STRERROR_R_CHAR_P /* GNU variant can return a pointer */
s = strerror_r(err, buf, sizeof(buf));
#else /* POSIX variant always returns message in buffer */
(void) strerror_r(err, buf, sizeof(buf));
Copy link
Member

Choose a reason for hiding this comment

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

Why can't we just always use this form?

Copy link
Member

Choose a reason for hiding this comment

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

Should be safe as long as we put something like

#if defined(_GNU_SOURCE) || _POSIX_C_SOURCE < 200112L
#  error "We might be getting GNU strerror_r here"
#endif

Copy link
Member Author

Choose a reason for hiding this comment

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

Well I get the GNU form here by default...
It would be possible to define _POSIX_C_SOURCE in the configure script, but there is no telling what impact that will have on other functions. Detecting what form to use is the safer way.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, the documentation clarifies. The GNU version may return something else than buf... puke

Copy link
Member Author

Choose a reason for hiding this comment

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

Exactly, in that case buf will remain empty :(

@laanwj laanwj added this to the 0.9.2 milestone May 14, 2014
@sipa
Copy link
Member

sipa commented May 22, 2014

untested ACK

#ifdef WIN32
std::string NetworkErrorString(int err)
{
char buf[256];
Copy link

Choose a reason for hiding this comment

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

Couldn't you write just char buf[256] = 0; and it would zero the first array element?

Choose a reason for hiding this comment

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

But that version is more likely to confuse people. I prefer laanwj's more obvious version, even though it's one line longer.

Copy link
Member Author

Choose a reason for hiding this comment

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

@Diapolo That would zero out the entire buffer, which is not necessary here (according to the documentation FormatMessage will always return a null-terminated string or nothing at all).

http://msdn.microsoft.com/en-us/library/windows/desktop/ms679351%28v=vs.85%29.aspx

I see though that we don't check the output of FormatMessageA - which can fail, itself. We should probably set a default message (like 'Unknown') in case it fails. Edit: fixed

laanwj added 2 commits May 23, 2014 09:45
Log the name of the error as well as the error code if a network problem
happens. This makes network troubleshooting more convenient.

Use thread-safe strerror_r and the WIN32 equivalent FormatMessage.
Make DateTimeStrFormat use boost::posix_time.

Also re-enable the util_DateTimeStrFormat tests, as they are no
longer platform specific.
@laanwj laanwj merged commit 3e8ac6a into bitcoin:master May 23, 2014
laanwj added a commit that referenced this pull request May 23, 2014
3e8ac6a Replace non-threadsafe gmtime and setlocale (Wladimir J. van der Laan)
a60838d Replace non-threadsafe strerror (Wladimir J. van der Laan)
@BitcoinPullTester
Copy link

Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/3e8ac6af9a993e262d1160fb2e6e1e1f1d5d19f2 for binaries and test log.
This test script verifies pulls every time they are updated. It, however, dies sometimes and fails to test properly. If you are waiting on a test, please check timestamps to verify that the test.log is moving at http://jenkins.bluematt.me/pull-tester/current/
Contact BlueMatt on freenode if something looks broken.

pyritepirate referenced this pull request in pyritepirate/pyrite Jan 25, 2019
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants