static void sigaction_handler(int sig, siginfo_t *si, void *context) { static siginfo_t empty_siginfo; UNUSED(context); if (!si) si = &empty_siginfo; switch (sig) { case SIGTERM:{ #if XXEMBEDDED_EANBLE int i, act; for (i = 30; i > 0; --i) { if (((act = check_action()) == ACT_IDLE) || (act == ACT_REBOOT)) break; fprintf(stderr, "Busy with %d. Waiting before shutdown... %d", act, i); sleep(1); } nvram_do_commit(); #endif Cdbg(DBE, "Shut down arpping....SIGTERM"); is_shutdown = 1; break; } case SIGINT: break; case SIGALRM: break; case SIGHUP: break; case SIGCHLD: break; case SIGUSR1: //- Remove all g_kill_list = 1; break; } }
static void sigaction_handler(int sig, siginfo_t *si, void *context) { static siginfo_t empty_siginfo; UNUSED(context); if (!si) si = &empty_siginfo; switch (sig) { case SIGTERM:{ #if EMBEDDED_EANBLE int i, act; for (i = 30; i > 0; --i) { if (((act = check_action()) == ACT_IDLE) || (act == ACT_REBOOT)) break; fprintf(stderr, "Busy with %d. Waiting before shutdown... %d", act, i); sleep(1); } nvram_do_commit(); #endif is_shutdown = 1; break; } case SIGINT: break; case SIGALRM: break; case SIGHUP: break; case SIGCHLD: break; case SIGUSR1:{ //- Remove all smb_srv_info_t *c; smb_srv_info_t *tmp = NULL; c = smb_srv_info_list; if( c != NULL ){ while(1){ int end = (c->next==NULL) ? 1 : 0; if(end==0){ tmp = c->next; Cdbg(DBE, "next, ip=%s", tmp->ip->ptr); } else tmp = NULL; if(c){ Cdbg(DBE, "remove , ip=[%s]", c->ip->ptr); DLIST_REMOVE(smb_srv_info_list,c); free(c); } else break; if(end==1) break; c = tmp; } } //free(smb_srv_info_list); g_threadIndex = 0; Cdbg(DBE, "222222222222222222222222222222222222222222222222222"); break; break; } } }
int main(int argc, char **argv) { UNUSED(argc); //- Check if same process is running. FILE *fp = fopen(LIGHTTPD_MONITOR_PID_FILE_PATH, "r"); if (fp) { fclose(fp); return 0; } //- Write PID file pid_t pid = getpid(); fp = fopen(LIGHTTPD_MONITOR_PID_FILE_PATH, "w"); if (!fp) { exit(EXIT_FAILURE); } fprintf(fp, "%d\n", pid); fclose(fp); #if EMBEDDED_EANBLE sigset_t sigs_to_catch; /* set the signal handler */ sigemptyset(&sigs_to_catch); sigaddset(&sigs_to_catch, SIGTERM); sigprocmask(SIG_UNBLOCK, &sigs_to_catch, NULL); signal(SIGTERM, sigaction_handler); #else struct sigaction act; memset(&act, 0, sizeof(act)); act.sa_handler = SIG_IGN; sigaction(SIGPIPE, &act, NULL); sigaction(SIGUSR1, &act, NULL); act.sa_sigaction = sigaction_handler; sigemptyset(&act.sa_mask); act.sa_flags = SA_SIGINFO; sigaction(SIGINT, &act, NULL); sigaction(SIGTERM, &act, NULL); sigaction(SIGHUP, &act, NULL); sigaction(SIGALRM, &act, NULL); sigaction(SIGCHLD, &act, NULL); #endif time_t prv_ts = time(NULL); int stop_arp_count = 0; int commit_count = 0; while (!is_shutdown) { sleep(10); int start_lighttpd = 0; int start_lighttpd_arp = 0; time_t cur_ts = time(NULL); #if EMBEDDED_EANBLE if (!pids("lighttpd")) { start_lighttpd = 1; } if (!pids("lighttpd-arpping")) { start_lighttpd_arp = 1; } #else if (!system("pidof lighttpd")) { start_lighttpd = 1; } if (!system("pidof lighttpd-arpping")) { start_lighttpd_arp = 1; } #endif //-every 30 sec if(cur_ts - prv_ts >= 30) { if(start_lighttpd) { #if EMBEDDED_EANBLE system("/usr/sbin/lighttpd -f /tmp/lighttpd.conf -D &"); #else system("./_inst/sbin/lighttpd -f lighttpd.conf &"); #endif } if(start_lighttpd_arp) { #if EMBEDDED_EANBLE system("/usr/sbin/lighttpd-arpping -f br0 &"); #else system("./_inst/sbin/lighttpd-arpping -f eth0 &"); #endif } //-every 2 hour if(stop_arp_count>=240) { stop_arpping_process(); stop_arp_count=0; } //-every 12 hour if(commit_count>=1440) { #if EMBEDDED_EANBLE int i, act; for (i = 30; i > 0; --i) { if (((act = check_action()) == ACT_IDLE) || (act == ACT_REBOOT)) break; fprintf(stderr, "Busy with %d. Waiting before shutdown... %d", act, i); sleep(1); } nvram_do_commit(); #endif commit_count=0; } prv_ts = cur_ts; stop_arp_count++; commit_count++; } } Cdbg(DBE, "Success to terminate lighttpd-monitor....."); exit(EXIT_SUCCESS); return 0; }