#ifndef __SIGNAL_COMMON_H #define __SIGNAL_COMMON_H #include <string.h> #define NGX_OK 0 #define NGX_ERROR -1 #define NGX_AGAIN -2 #define NGX_BUSY -3 #define NGX_DONE -4 #define NGX_DECLINED -5 #define NGX_ABORT -6 #define ngx_memset_zero(buf, n) memset(buf, 0, n) #endif
#ifndef __SIG_PROCESS_H #define __SIG_PROCESS_H #define SIGNAL_INT SIGINT #define SIGNAL_MAP(xxx) xxx(SIGNAL_INT, signal_handler) xxx(0, NULL) #define MAP_GEN(h, n) {h, #h, n}, #endif
#include <signal.h> #include <stdio.h> #include "signal_process.h" #include "signal_common.h" typedef struct{ int signo; char *signame; void (*handler)(int signo); }signal_t; static void signal_handler(int signo); signal_t signals[]={SIGNAL_MAP(MAP_GEN)}; static void signal_handler(int signo) { #if __DEBUG__ printf("signal_handler: [%d] ", signo); #endif switch(signo) { case SIGINT: break; case SIGHUP: break; case SIGCHLD: break; } return; } int signal_init() { signal_t *sig; struct sigaction sa; for(sig=signals; sig->signo != 0; sig++) { ngx_memset_zero(&sa, sizeof(struct sigaction)); sa.sa_handler = sig->handler; sigemptyset(&sa.sa_mask); if(sigaction(sig->signo, &sa, NULL) == -1){ return NGX_ERROR; } } return NGX_OK; } int main() { signal_init(); while(1) {}; }