Commit daadaf3
committed
Fix pidfile cleanup when receiving signal
When not using --pidfile option, pidfile_fd is initialized to -1.
However if we are interrupted by signal, when we check the value during
cleanup, the value is 0(!) and we try to delete a null pidfile and log
this error:
^CINFO | Received signal: Interrupt: 2
ERROR| Failed to remove pidfile: "(null)": Bad address
This does not make sense, but we use sigsetjmp(3) for handling signals
and its manual mentions:
The sigsetjmp()/siglongjmp() function pairs save and restore the
signal mask if the argument savemask is non-zero; otherwise, only
the register set and the stack are saved.
It seems that pidfile_fd is restored to the value at the time
sigsetjmp() was called, which may be 0 (or any other value on the
stack). I think this is an old bug, exposed by logging an error when
unlink() fails.
Fix by creating the pidfile and binding listen_fd before calling
sigsetjmp(). When sigsetjmp() restores the stack the value of
pidfile_fd and listen_fd are not affected.
Signed-off-by: Nir Soffer <nirsof@gmail.com>1 parent abdbc35 commit daadaf3
1 file changed
+10
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
406 | 406 | | |
407 | 407 | | |
408 | 408 | | |
409 | | - | |
410 | | - | |
411 | | - | |
412 | | - | |
413 | | - | |
414 | | - | |
415 | | - | |
416 | | - | |
417 | | - | |
418 | | - | |
419 | 409 | | |
420 | 410 | | |
421 | 411 | | |
| |||
432 | 422 | | |
433 | 423 | | |
434 | 424 | | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
435 | 435 | | |
436 | 436 | | |
437 | 437 | | |
| |||
0 commit comments