Display when SIGTERM received (or any signal, for that matter) in debug.log #1305

pull rebroad wants to merge 1 commits into bitcoin:master from rebroad:DisplaySIGTERM changing 1 files +2 −1
  1. rebroad commented at 7:03 PM on May 14, 2012: contributor

    Useful for debugging bitcoin dealing with signals and exiting. Adds a line to debug.log when signal received.

  2. laanwj commented at 7:15 AM on May 15, 2012: member

    ACK

  3. Diapolo commented at 12:38 PM on May 15, 2012: none

    Why receives HandleSIGTERM an integer? Seems unused in the diff.

  4. laanwj commented at 1:02 PM on May 15, 2012: member

    Know your unix :-) signal handlers receive an integer with the signal number.

  5. sipa commented at 1:07 PM on May 15, 2012: member

    I'd make it "SIGTERM received", but otherwise ACK.

  6. Diapolo commented at 1:10 PM on May 15, 2012: none

    Unix != Diapolo :-D

  7. rebroad commented at 2:09 PM on May 15, 2012: contributor

    @sipa or how about, considering that function will be run with any signal, displaying the signal number received..?

  8. rebroad commented at 3:09 PM on May 15, 2012: contributor

    @sipa I've just realised this change is also in another pull request. :-s I've avoided saying SIGTERM received, as this is a specific signal (15), so saying that might be misleading, whereas it's true to say the function HandleSIGTERM() is called.

  9. rebroad commented at 3:09 PM on May 15, 2012: contributor

    I'll close this pull request in favour of the other which includes this change and others.

  10. rebroad closed this on May 15, 2012

  11. sipa commented at 3:52 PM on May 15, 2012: member

    HandleSIGTERM is apparently used for SIGTERM, SIGINT and SIGHUP.

  12. laanwj commented at 4:02 PM on May 15, 2012: member

    Ah, named according to the principle of most surprise. Interesting :)

  13. rebroad commented at 4:37 PM on May 15, 2012: contributor

    I suspect HandleSIGTERM would run if SIGUSR1 was sent too. Any signal other than 9, probably.

  14. sipa commented at 4:46 PM on May 15, 2012: member

    @rebroad no signal handler is installed for SIGUSR1. See the beginning of AppInit2 in init.cpp.

  15. rebroad reopened this on May 17, 2012

  16. rebroad commented at 4:43 PM on May 17, 2012: contributor

    Since this was getting ACKs, I've re-opened it. It's more likely to get pulled than pull #1311, which it's a subset of. I should probably break #1311 into smaller pieces....

  17. Diapolo commented at 5:27 PM on May 17, 2012: none

    You should rebase this!

  18. rebroad commented at 5:29 PM on May 17, 2012: contributor

    @Diapolo I can do... does it make much difference? (rebased now)

  19. Display when SIGTERM received (or any signal, for that matter) in debug.log. a52c87899b
  20. Diapolo commented at 5:31 PM on May 17, 2012: none

    Yes, just take a look under https://github.com/bitcoin/bitcoin/pull/1305/commits what do you see :)? Use <pre>git fetch upstream</pre> <pre>git rebase upstream</pre> to ensure you have the current master as base.

  21. rebroad commented at 5:34 PM on May 17, 2012: contributor

    @Diapolo I see 1 commit and 1 diff. What do you see? That's also what I saw before I rebased.

  22. Diapolo commented at 5:37 PM on May 17, 2012: none

    I saw 4 commits and 3 of which were not from you ;). Now I see a single one, which is good.

  23. luke-jr commented at 6:47 PM on May 18, 2012: member

    What stops this from creating a deadlock when a signal is received inside the "printf" replacement log function?

  24. sipa commented at 7:29 PM on May 18, 2012: member

    @luke-jr how exactly?

  25. luke-jr commented at 8:05 PM on May 18, 2012: member

    @sipa printf needs to use a lock to ensure multiple threads aren't writing at the same time, but signals can interrupt writes (while that lock is held). If this happens, the printf in the signal handler will try to lock again, and block. Even if the lock is recursive, there is a risk of the signal printf mixing output with the ongoing one.

  26. laanwj commented at 8:32 PM on May 18, 2012: member

    Ouch. I keep forgetting that we redefine printf in a macro :-(

  27. Diapolo commented at 9:27 PM on May 18, 2012: none

    @laanwj You were updating the function a few days ago ^^...

  28. rebroad commented at 5:17 PM on May 21, 2012: contributor

    @luke-jr what would be your ideal solution for this (other than removing the prinf)?

  29. luke-jr commented at 5:25 PM on May 21, 2012: member

    I think it might be safe to create a new thread just for the printf. Then the signal returns - locks get released on their normal schedule, etc - while the second thread waits to acquire whatever locks it needs to log.

  30. rebroad commented at 9:51 AM on May 22, 2012: contributor

    @luke-jr when I get time I'll have a dabble with this. I'm fairly new to the whole thread thing, but I was thinking of moving ProcessBlock() into a thread of it's own so that it doesn't block the reception of messages (which it appears to do currently, based upon the timestamps in debug.log)

  31. laanwj commented at 6:46 AM on July 17, 2012: member

    Creating a thread sounds like a terrible kludge. That the safest way is to save the "signal status" to a global variable in the signal handler and let the Shutdown function pick it up and print it. Python, for example, does signal handling in this way.

    Btw, instead (or, in addition to) the numeric signal it should probably print the signal name, converted using strsignal.

  32. rebroad commented at 10:15 AM on July 26, 2012: contributor

    @laanwj That does sound like a decent solution. I will update this to do that, when I get time...

  33. jgarzik commented at 3:46 PM on August 1, 2012: contributor

    NAK, possible deadlock. printf() obtains a lock, which can get really messy when signals are involved. You might even be inside the printf lock itself.

    Maybe set a 'got_sigterm' boolean that triggers a print elsewhere...

  34. jgarzik closed this on Aug 1, 2012

  35. suprnurd referenced this in commit c5210a3e5b on Dec 5, 2017
  36. DrahtBot locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-22 18:16 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me