Useful for debugging bitcoin dealing with signals and exiting. Adds a line to debug.log when signal received.
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-
rebroad commented at 7:03 PM on May 14, 2012: contributor
-
laanwj commented at 7:15 AM on May 15, 2012: member
ACK
-
Diapolo commented at 12:38 PM on May 15, 2012: none
Why receives HandleSIGTERM an integer? Seems unused in the diff.
-
laanwj commented at 1:02 PM on May 15, 2012: member
Know your unix :-) signal handlers receive an integer with the signal number.
-
sipa commented at 1:07 PM on May 15, 2012: member
I'd make it "SIGTERM received", but otherwise ACK.
-
Diapolo commented at 1:10 PM on May 15, 2012: none
Unix != Diapolo :-D
-
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.
-
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.
- rebroad closed this on May 15, 2012
-
sipa commented at 3:52 PM on May 15, 2012: member
HandleSIGTERM is apparently used for SIGTERM, SIGINT and SIGHUP.
-
laanwj commented at 4:02 PM on May 15, 2012: member
Ah, named according to the principle of most surprise. Interesting :)
-
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.
- rebroad reopened this on May 17, 2012
-
Diapolo commented at 5:27 PM on May 17, 2012: none
You should rebase this!
-
Display when SIGTERM received (or any signal, for that matter) in debug.log. a52c87899b
-
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.
-
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.
-
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?
-
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.
-
laanwj commented at 8:32 PM on May 18, 2012: member
Ouch. I keep forgetting that we redefine printf in a macro :-(
-
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.
-
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)
-
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. -
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...
- jgarzik closed this on Aug 1, 2012
- suprnurd referenced this in commit c5210a3e5b on Dec 5, 2017
- DrahtBot locked this on Sep 8, 2021