Skip to content

Conversation

@practicalswift
Copy link
Contributor

@practicalswift practicalswift commented May 2, 2018

Handle unsuccessful fseek(...):s.

Note to reviewers: What is the most appropriate course of actions for each of these unsuccessful fseek(...):s?

static const char buf[65536] = {};
fseek(file, offset, SEEK_SET);
if (fseek(file, offset, SEEK_SET)) {
return;
Copy link
Member

Choose a reason for hiding this comment

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

Just returning here is fine - this call is only advisory.

// Restart the file with some of the end
std::vector<char> vch(RECENT_DEBUG_HISTORY_SIZE, 0);
fseek(file, -((long)vch.size()), SEEK_END);
if (fseek(file, -((long)vch.size()), SEEK_END)) {
Copy link
Member

Choose a reason for hiding this comment

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

Not sure what should be done here. As-is it will silently fail to shrink the log file but should continue logging otherwise? Maybe log an error message?

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree with @laanwj: an additional error message would make sense.

file >> header;
fseek(file.Get(), postx.nTxOffset, SEEK_CUR);
if (fseek(file.Get(), postx.nTxOffset, SEEK_CUR)) {
return error("%s: fseek(...) failed", __func__);
Copy link
Member

Choose a reason for hiding this comment

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

LGTM

@jonasschnelli
Copy link
Contributor

utACK 29c9bdc (though a LogPrint in ShrinkDebugFile() would be even better).

@practicalswift
Copy link
Contributor Author

practicalswift commented May 3, 2018

@laanwj @jonasschnelli Regarding logging in ShrinkDebugFile(…) – what about the following:

diff --git a/src/logging.cpp b/src/logging.cpp
index 2a55d36..b57b17e 100644
--- a/src/logging.cpp
+++ b/src/logging.cpp
@@ -255,6 +255,7 @@ void BCLog::Logger::ShrinkDebugFile()
         // Restart the file with some of the end
         std::vector<char> vch(RECENT_DEBUG_HISTORY_SIZE, 0);
         if (fseek(file, -((long)vch.size()), SEEK_END)) {
+            LogPrintf("Failed to shrink debug file: fseek(...) failed\n");
             fclose(file);
             return;
         }

Looks good?

@laanwj
Copy link
Member

laanwj commented May 3, 2018

@practicalswift maybe "debug log file" instead of "debug file"?

@practicalswift
Copy link
Contributor Author

@laanwj @jonasschnelli Added a commit for the logging. Please re-review :-)

Copy link
Contributor

@jonasschnelli jonasschnelli left a comment

Choose a reason for hiding this comment

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

utACK 20ce5af

@laanwj
Copy link
Member

laanwj commented May 3, 2018

utACK 20ce5af

@laanwj laanwj merged commit 20ce5af into bitcoin:master May 7, 2018
laanwj added a commit that referenced this pull request May 7, 2018
20ce5af Print a log message if we fail to shrink the debug log file (practicalswift)
29c9bdc Handle unsuccessful fseek(...):s (practicalswift)

Pull request description:

  Handle unsuccessful `fseek(...)`:s.

  **Note to reviewers:** What is the most appropriate course of actions for each of these unsuccessful `fseek(...)`:s?

Tree-SHA512: 5b3d82dbdd15d434d3f08dcb4df62888da4df8541d2586f56a4e529083005f6782c39e10645acd1ec403da83061bbfd8dbf2dddc66e09268d410ad0918c61876
jasonbcox pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Sep 27, 2019
Summary:
20ce5af Print a log message if we fail to shrink the debug log file (practicalswift)
29c9bdc Handle unsuccessful fseek(...):s (practicalswift)

Pull request description:

  Handle unsuccessful `fseek(...)`:s.

  **Note to reviewers:** What is the most appropriate course of actions for each of these unsuccessful `fseek(...)`:s?

Tree-SHA512: 5b3d82dbdd15d434d3f08dcb4df62888da4df8541d2586f56a4e529083005f6782c39e10645acd1ec403da83061bbfd8dbf2dddc66e09268d410ad0918c61876

Backport of Core PR13149
bitcoin/bitcoin#13149

Test Plan:
  make check
  test_runner.py

Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc

Reviewed By: deadalnix, Fabien, O1 Bitcoin ABC, #bitcoin_abc

Differential Revision: https://reviews.bitcoinabc.org/D4021
jonspock pushed a commit to jonspock/devault that referenced this pull request Dec 22, 2019
Summary:
20ce5af Print a log message if we fail to shrink the debug log file (practicalswift)
29c9bdc Handle unsuccessful fseek(...):s (practicalswift)

Pull request description:

  Handle unsuccessful `fseek(...)`:s.

  **Note to reviewers:** What is the most appropriate course of actions for each of these unsuccessful `fseek(...)`:s?

Tree-SHA512: 5b3d82dbdd15d434d3f08dcb4df62888da4df8541d2586f56a4e529083005f6782c39e10645acd1ec403da83061bbfd8dbf2dddc66e09268d410ad0918c61876

Backport of Core PR13149
bitcoin/bitcoin#13149

Test Plan:
  make check
  test_runner.py

Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc

Reviewed By: deadalnix, Fabien, O1 Bitcoin ABC, #bitcoin_abc

Differential Revision: https://reviews.bitcoinabc.org/D4021
jonspock pushed a commit to jonspock/devault that referenced this pull request Dec 22, 2019
Summary:
20ce5af Print a log message if we fail to shrink the debug log file (practicalswift)
29c9bdc Handle unsuccessful fseek(...):s (practicalswift)

Pull request description:

  Handle unsuccessful `fseek(...)`:s.

  **Note to reviewers:** What is the most appropriate course of actions for each of these unsuccessful `fseek(...)`:s?

Tree-SHA512: 5b3d82dbdd15d434d3f08dcb4df62888da4df8541d2586f56a4e529083005f6782c39e10645acd1ec403da83061bbfd8dbf2dddc66e09268d410ad0918c61876

Backport of Core PR13149
bitcoin/bitcoin#13149

Test Plan:
  make check
  test_runner.py

Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc

Reviewed By: deadalnix, Fabien, O1 Bitcoin ABC, #bitcoin_abc

Differential Revision: https://reviews.bitcoinabc.org/D4021
jonspock pushed a commit to jonspock/devault that referenced this pull request Dec 22, 2019
Summary:
20ce5af Print a log message if we fail to shrink the debug log file (practicalswift)
29c9bdc Handle unsuccessful fseek(...):s (practicalswift)

Pull request description:

  Handle unsuccessful `fseek(...)`:s.

  **Note to reviewers:** What is the most appropriate course of actions for each of these unsuccessful `fseek(...)`:s?

Tree-SHA512: 5b3d82dbdd15d434d3f08dcb4df62888da4df8541d2586f56a4e529083005f6782c39e10645acd1ec403da83061bbfd8dbf2dddc66e09268d410ad0918c61876

Backport of Core PR13149
bitcoin/bitcoin#13149

Test Plan:
  make check
  test_runner.py

Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc

Reviewed By: deadalnix, Fabien, O1 Bitcoin ABC, #bitcoin_abc

Differential Revision: https://reviews.bitcoinabc.org/D4021
jonspock pushed a commit to jonspock/devault that referenced this pull request Dec 23, 2019
Summary:
20ce5af Print a log message if we fail to shrink the debug log file (practicalswift)
29c9bdc Handle unsuccessful fseek(...):s (practicalswift)

Pull request description:

  Handle unsuccessful `fseek(...)`:s.

  **Note to reviewers:** What is the most appropriate course of actions for each of these unsuccessful `fseek(...)`:s?

Tree-SHA512: 5b3d82dbdd15d434d3f08dcb4df62888da4df8541d2586f56a4e529083005f6782c39e10645acd1ec403da83061bbfd8dbf2dddc66e09268d410ad0918c61876

Backport of Core PR13149
bitcoin/bitcoin#13149

Test Plan:
  make check
  test_runner.py

Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc

Reviewed By: deadalnix, Fabien, O1 Bitcoin ABC, #bitcoin_abc

Differential Revision: https://reviews.bitcoinabc.org/D4021
proteanx pushed a commit to devaultcrypto/devault that referenced this pull request Dec 23, 2019
Summary:
20ce5af Print a log message if we fail to shrink the debug log file (practicalswift)
29c9bdc Handle unsuccessful fseek(...):s (practicalswift)

Pull request description:

  Handle unsuccessful `fseek(...)`:s.

  **Note to reviewers:** What is the most appropriate course of actions for each of these unsuccessful `fseek(...)`:s?

Tree-SHA512: 5b3d82dbdd15d434d3f08dcb4df62888da4df8541d2586f56a4e529083005f6782c39e10645acd1ec403da83061bbfd8dbf2dddc66e09268d410ad0918c61876

Backport of Core PR13149
bitcoin/bitcoin#13149

Test Plan:
  make check
  test_runner.py

Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc

Reviewed By: deadalnix, Fabien, O1 Bitcoin ABC, #bitcoin_abc

Differential Revision: https://reviews.bitcoinabc.org/D4021
@practicalswift practicalswift deleted the fseek branch April 10, 2021 19:34
UdjinM6 pushed a commit to UdjinM6/dash that referenced this pull request Jun 5, 2021
20ce5af Print a log message if we fail to shrink the debug log file (practicalswift)
29c9bdc Handle unsuccessful fseek(...):s (practicalswift)

Pull request description:

  Handle unsuccessful `fseek(...)`:s.

  **Note to reviewers:** What is the most appropriate course of actions for each of these unsuccessful `fseek(...)`:s?

Tree-SHA512: 5b3d82dbdd15d434d3f08dcb4df62888da4df8541d2586f56a4e529083005f6782c39e10645acd1ec403da83061bbfd8dbf2dddc66e09268d410ad0918c61876
TheArbitrator pushed a commit to TheArbitrator/dash that referenced this pull request Jun 7, 2021
20ce5af Print a log message if we fail to shrink the debug log file (practicalswift)
29c9bdc Handle unsuccessful fseek(...):s (practicalswift)

Pull request description:

  Handle unsuccessful `fseek(...)`:s.

  **Note to reviewers:** What is the most appropriate course of actions for each of these unsuccessful `fseek(...)`:s?

Tree-SHA512: 5b3d82dbdd15d434d3f08dcb4df62888da4df8541d2586f56a4e529083005f6782c39e10645acd1ec403da83061bbfd8dbf2dddc66e09268d410ad0918c61876
gades pushed a commit to cosanta/cosanta-core that referenced this pull request Apr 30, 2022
20ce5af Print a log message if we fail to shrink the debug log file (practicalswift)
29c9bdc Handle unsuccessful fseek(...):s (practicalswift)

Pull request description:

  Handle unsuccessful `fseek(...)`:s.

  **Note to reviewers:** What is the most appropriate course of actions for each of these unsuccessful `fseek(...)`:s?

Tree-SHA512: 5b3d82dbdd15d434d3f08dcb4df62888da4df8541d2586f56a4e529083005f6782c39e10645acd1ec403da83061bbfd8dbf2dddc66e09268d410ad0918c61876
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 18, 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.

4 participants