From d270222698d2d4987e012396aa31807876618511 Mon Sep 17 00:00:00 2001 From: ZmnSCPxj jxPCSnmZ Date: Wed, 2 Dec 2020 09:56:30 +0800 Subject: [PATCH] lightningd/log.c: Fix up handling of SIGHUP. Fixes: #4240 --- lightningd/log.c | 18 +++++++++++++++++- tests/test_misc.py | 1 - 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lightningd/log.c b/lightningd/log.c index 47628e35b508..59af178357de 100644 --- a/lightningd/log.c +++ b/lightningd/log.c @@ -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"); diff --git a/tests/test_misc.py b/tests/test_misc.py index 4be50f9a5127..4e4d1719fa49 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -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)