Commit f0c6d54
committed
Handle signals with kqueue
We used sigsetjmp() and siglogjmp() for signal handling, which is very
hard to use correctly and too magical. Replace it with the kqueue(),
which can notify events on sockets and signals.
The get signals with kqueue, we need to block them. This has the nice
property that no function in any thread will fail with EINTR when we
receive a signal, which simplifies the code.
We setup signal handling before we open the pidfile, so receiving a
signal after the pidfile was created will always remove the pidfile.
Before this change we has a small window when receiving a signal would
terminate the process without removing the pidfile.
To wait for connection or signal, we wait for kqueue events. If we
receiving a signal we break the loop and exit normally, since
termination by signal is normal. This can help programs running
socket_vment that may be confused by exit code 1.
Notes:
- Keeping listen_fd in blocking mode to simplify the code. accept()
should not block when we receive a EVFILT_READ event. We can change to
non-blocking mode later if this assumption is wrong.
Signed-off-by: Nir Soffer <nirsof@gmail.com>1 parent 1a5c1d8 commit f0c6d54
1 file changed
+88
-24
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
| 11 | + | |
| 12 | + | |
10 | 13 | | |
11 | 14 | | |
12 | 15 | | |
| |||
19 | 22 | | |
20 | 23 | | |
21 | 24 | | |
| 25 | + | |
| 26 | + | |
22 | 27 | | |
23 | 28 | | |
24 | 29 | | |
| |||
280 | 285 | | |
281 | 286 | | |
282 | 287 | | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | 288 | | |
290 | 289 | | |
291 | 290 | | |
| |||
391 | 390 | | |
392 | 391 | | |
393 | 392 | | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
394 | 434 | | |
395 | 435 | | |
396 | 436 | | |
397 | 437 | | |
398 | 438 | | |
399 | 439 | | |
400 | 440 | | |
| 441 | + | |
401 | 442 | | |
402 | 443 | | |
403 | 444 | | |
| |||
411 | 452 | | |
412 | 453 | | |
413 | 454 | | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
414 | 467 | | |
415 | 468 | | |
416 | 469 | | |
| |||
426 | 479 | | |
427 | 480 | | |
428 | 481 | | |
429 | | - | |
430 | | - | |
431 | | - | |
432 | | - | |
433 | | - | |
434 | | - | |
435 | | - | |
436 | | - | |
437 | | - | |
438 | | - | |
439 | 482 | | |
440 | 483 | | |
441 | 484 | | |
| |||
452 | 495 | | |
453 | 496 | | |
454 | 497 | | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
455 | 502 | | |
456 | | - | |
457 | | - | |
458 | | - | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
459 | 507 | | |
460 | 508 | | |
461 | | - | |
462 | | - | |
463 | | - | |
464 | | - | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
465 | 526 | | |
466 | 527 | | |
467 | 528 | | |
| |||
480 | 541 | | |
481 | 542 | | |
482 | 543 | | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
483 | 547 | | |
484 | 548 | | |
485 | 549 | | |
| |||
0 commit comments