MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / sigShutdownHandler

Function sigShutdownHandler

src/server.cpp:6786–6819  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6784}
6785
6786static void sigShutdownHandler(int sig) {
6787 const char *msg;
6788
6789 switch (sig) {
6790 case SIGINT:
6791 msg = "Received SIGINT scheduling shutdown...";
6792 break;
6793 case SIGTERM:
6794 msg = "Received SIGTERM scheduling shutdown...";
6795 break;
6796 default:
6797 msg = "Received shutdown signal, scheduling shutdown...";
6798 };
6799
6800 /* SIGINT is often delivered via Ctrl+C in an interactive session.
6801 * If we receive the signal the second time, we interpret this as
6802 * the user really wanting to quit ASAP without waiting to persist
6803 * on disk. */
6804 if ((g_pserver->shutdown_asap || g_pserver->soft_shutdown) && sig == SIGINT) {
6805 serverLogFromHandler(LL_WARNING, "You insist... exiting now.");
6806 rdbRemoveTempFile(g_pserver->rdbThreadVars.tmpfileNum, 1);
6807 g_pserver->garbageCollector.shutdown();
6808 _Exit(1); /* Exit with an error since this was not a clean shutdown. */
6809 } else if (g_pserver->loading) {
6810 serverLogFromHandler(LL_WARNING, "Received shutdown signal during loading, exiting now.");
6811 _Exit(0); // calling dtors is undesirable, exit immediately
6812 }
6813
6814 serverLogFromHandler(LL_WARNING, msg);
6815 if (g_pserver->config_soft_shutdown)
6816 g_pserver->soft_shutdown = true;
6817 else
6818 g_pserver->shutdown_asap = 1;
6819}
6820
6821void setupSignalHandlers(void) {
6822 struct sigaction act;

Callers

nothing calls this directly

Calls 3

serverLogFromHandlerFunction · 0.85
rdbRemoveTempFileFunction · 0.85
shutdownMethod · 0.45

Tested by

no test coverage detected