lightningd/log.c: Fix up handling of SIGHUP.

Fixes: #4240

ChangeLog-Fixed: log: Do not terminate on the second received SIGHUP.
This commit is contained in:
ZmnSCPxj jxPCSnmZ 2020-12-02 09:56:30 +08:00 committed by Rusty Russell
parent 67d8fdcc75
commit a437936c78
2 changed files with 17 additions and 2 deletions

View File

@ -642,7 +642,23 @@ static void setup_log_rotation(struct lightningd *ld)
io_fd_block(signalfds[1], false);
memset(&act, 0, sizeof(act));
act.sa_handler = handle_sighup;
act.sa_flags = SA_RESETHAND;
/* We do not need any particular flags; the sigaction
* default behavior (EINTR any system calls, pass only
* the signo to the handler, retain the same signal
* handler throughout) is fine with us.
*/
act.sa_flags = 0;
/* Block all signals while handling SIGHUP.
* Without this, e.g. an inopportune SIGCHLD while we
* are doing a `write` to the SIGHUP signal pipe could
* prevent us from sending the byte and performing the
* log rotation in the main loop.
*
* The SIGHUP handler does very little anyway, and
* the blocked signals will get delivered soon after
* the SIGHUP handler returns.
*/
sigfillset(&act.sa_mask);
if (sigaction(SIGHUP, &act, NULL) != 0)
err(1, "Setting up SIGHUP handler");

View File

@ -1532,7 +1532,6 @@ def test_feerates(node_factory):
assert htlc_success_cost == htlc_feerate * 703 // 1000
@pytest.mark.xfail(strict=True)
def test_logging(node_factory):
# Since we redirect, node.start() will fail: do manually.
l1 = node_factory.get_node(options={'log-file': 'logfile'}, start=False)