/** *断言 */ void nc_assert(const char *cond, const char *file, int line, int panic) { log_error("assert '%s' failed @ (%s, %d)", cond, file, line); if (panic) { nc_stacktrace(1); abort(); } }
void signal_handler(int signo) { struct signal *sig; void (*action)(void); char *actionstr; bool done; for (sig = signals; sig->signo != 0; sig++) { if (sig->signo == signo) { break; } } ASSERT(sig->signo != 0); actionstr = ""; action = NULL; done = false; switch (signo) { case SIGUSR1: break; case SIGUSR2: break; case SIGTTIN: actionstr = ", up logging level"; action = log_level_up; break; case SIGTTOU: actionstr = ", down logging level"; action = log_level_down; break; // using svc -h to close program is our convention, so we take it as SIGINT //case SIGHUP: //actionstr = ", reopening log file"; //action = log_reopen; //break; case SIGHUP: case SIGINT: done = true; actionstr = ", exiting"; break; case SIGSEGV: nc_stacktrace(1); actionstr = ", core dumping"; raise(SIGSEGV); break; default: NOT_REACHED(); } loga("signal %d (%s) received%s", signo, sig->signame, actionstr); if (action != NULL) { action(); } if (done) { exit(1); } }