* Signal handler (Unix only) */
| 547 | * Signal handler (Unix only) |
| 548 | */ |
| 549 | static void |
| 550 | sigTermHandler(SIGNAL_ARGS) |
| 551 | { |
| 552 | int i; |
| 553 | char errbuf[1]; |
| 554 | |
| 555 | /* |
| 556 | * Some platforms allow delivery of new signals to interrupt an active |
| 557 | * signal handler. That could muck up our attempt to send PQcancel, so |
| 558 | * disable the signals that setup_cancel_handler enabled. |
| 559 | */ |
| 560 | pqsignal(SIGINT, SIG_IGN); |
| 561 | pqsignal(SIGTERM, SIG_IGN); |
| 562 | pqsignal(SIGQUIT, SIG_IGN); |
| 563 | |
| 564 | /* |
| 565 | * If we're in the leader, forward signal to all workers. (It seems best |
| 566 | * to do this before PQcancel; killing the leader transaction will result |
| 567 | * in invalid-snapshot errors from active workers, which maybe we can |
| 568 | * quiet by killing workers first.) Ignore any errors. |
| 569 | */ |
| 570 | if (signal_info.pstate != NULL) |
| 571 | { |
| 572 | for (i = 0; i < signal_info.pstate->numWorkers; i++) |
| 573 | { |
| 574 | pid_t pid = signal_info.pstate->parallelSlot[i].pid; |
| 575 | |
| 576 | if (pid != 0) |
| 577 | kill(pid, SIGTERM); |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | /* |
| 582 | * Send QueryCancel if we have a connection to send to. Ignore errors, |
| 583 | * there's not much we can do about them anyway. |
| 584 | */ |
| 585 | if (signal_info.myAH != NULL && signal_info.myAH->connCancel != NULL) |
| 586 | (void) PQcancel(signal_info.myAH->connCancel, errbuf, sizeof(errbuf)); |
| 587 | |
| 588 | /* |
| 589 | * Report we're quitting, using nothing more complicated than write(2). |
| 590 | * When in parallel operation, only the leader process should do this. |
| 591 | */ |
| 592 | if (!signal_info.am_worker) |
| 593 | { |
| 594 | if (progname) |
| 595 | { |
| 596 | write_stderr(progname); |
| 597 | write_stderr(": "); |
| 598 | } |
| 599 | write_stderr("terminated by user\n"); |
| 600 | } |
| 601 | |
| 602 | /* |
| 603 | * And die, using _exit() not exit() because the latter will invoke atexit |
| 604 | * handlers that can fail if we interrupted related code. |
| 605 | */ |
| 606 | _exit(1); |
nothing calls this directly
no test coverage detected