---------- * PgstatCollectorMain() - * * Start up the statistics collector process. This is the body of the * postmaster child process. * * The argc/argv parameters are valid only in EXEC_BACKEND case. * ---------- */
| 3494 | * ---------- |
| 3495 | */ |
| 3496 | NON_EXEC_STATIC void |
| 3497 | PgstatCollectorMain(int argc, char *argv[]) |
| 3498 | { |
| 3499 | int len; |
| 3500 | PgStat_Msg msg; |
| 3501 | int wr; |
| 3502 | WaitEvent event; |
| 3503 | WaitEventSet *wes; |
| 3504 | |
| 3505 | /* |
| 3506 | * Ignore all signals usually bound to some action in the postmaster, |
| 3507 | * except SIGHUP and SIGQUIT. Note we don't need a SIGUSR1 handler to |
| 3508 | * support latch operations, because we only use a local latch. |
| 3509 | */ |
| 3510 | pqsignal(SIGHUP, SignalHandlerForConfigReload); |
| 3511 | pqsignal(SIGINT, SIG_IGN); |
| 3512 | pqsignal(SIGTERM, SIG_IGN); |
| 3513 | pqsignal(SIGQUIT, SignalHandlerForShutdownRequest); |
| 3514 | pqsignal(SIGALRM, SIG_IGN); |
| 3515 | pqsignal(SIGPIPE, SIG_IGN); |
| 3516 | pqsignal(SIGUSR1, SIG_IGN); |
| 3517 | pqsignal(SIGUSR2, SIG_IGN); |
| 3518 | /* Reset some signals that are accepted by postmaster but not here */ |
| 3519 | pqsignal(SIGCHLD, SIG_DFL); |
| 3520 | PG_SETMASK(&UnBlockSig); |
| 3521 | |
| 3522 | MyBackendType = B_STATS_COLLECTOR; |
| 3523 | init_ps_display(NULL); |
| 3524 | |
| 3525 | /* |
| 3526 | * Read in existing stats files or initialize the stats to zero. |
| 3527 | */ |
| 3528 | pgStatRunningInCollector = true; |
| 3529 | pgStatDBHash = pgstat_read_statsfiles(InvalidOid, true, true); |
| 3530 | |
| 3531 | /* Prepare to wait for our latch or data in our socket. */ |
| 3532 | wes = CreateWaitEventSet(CurrentMemoryContext, 3); |
| 3533 | AddWaitEventToSet(wes, WL_LATCH_SET, PGINVALID_SOCKET, MyLatch, NULL); |
| 3534 | AddWaitEventToSet(wes, WL_POSTMASTER_DEATH, PGINVALID_SOCKET, NULL, NULL); |
| 3535 | AddWaitEventToSet(wes, WL_SOCKET_READABLE, pgStatSock, NULL, NULL); |
| 3536 | |
| 3537 | /* |
| 3538 | * Loop to process messages until we get SIGQUIT or detect ungraceful |
| 3539 | * death of our parent postmaster. |
| 3540 | * |
| 3541 | * For performance reasons, we don't want to do ResetLatch/WaitLatch after |
| 3542 | * every message; instead, do that only after a recv() fails to obtain a |
| 3543 | * message. (This effectively means that if backends are sending us stuff |
| 3544 | * like mad, we won't notice postmaster death until things slack off a |
| 3545 | * bit; which seems fine.) To do that, we have an inner loop that |
| 3546 | * iterates as long as recv() succeeds. We do check ConfigReloadPending |
| 3547 | * inside the inner loop, which means that such interrupts will get |
| 3548 | * serviced but the latch won't get cleared until next time there is a |
| 3549 | * break in the action. |
| 3550 | */ |
| 3551 | for (;;) |
| 3552 | { |
| 3553 | /* Clear any already-pending wakeups */ |
no test coverage detected