rezalas / riftshadow

Dedicated to the preservation of the game and modernization of a classic mud codebase.
MIT License
18 stars 14 forks source link

Capture OS signals for proper cleanup #258

Open sean-gilliam opened 7 months ago

sean-gilliam commented 7 months ago

Since Riftshadow has several threads / connections open, we should consider capturing at least the following signals using signal or sigaction.

There may be others. These are the ones that spring to mind though. Note that sigaction is Linux-only I believe.

Example:

int main(void)
{
    signal(SIGINT, sigIntHandler);
}

void sigIntHandler(int signum)
{
   // Some database connection cleanup
   exit(1);
}
int main(void)
{
    struct sigaction psa;
    memset (&psa, 0, sizeof (psa));
    psa.sa_handler = sigIntHandler;
    sigaction (SIGINT, &psa, NULL);
}

void sigIntHandler(int signum)
{
   // Some database connection cleanup
   exit(1);
}