#include "debugbreak.h" #include "plt.h" // static int appl_init() // { // int ret = 0; // if( cloud_init() != 0 ){ // ret = -1; // }else if( snap_init() != 0 ){ // ret = -1; // } // log_dbg("%s, ret:%d", __func__,ret); // return ret; // } // static void appl_task() // { // mac_exe(); // cloud_exe(); // snap_exe(); // } // static int appl_init_timer() // { // struct sigevent evp; // struct itimerspec ts; // timer_t timer; // int ret; // memset(&evp, 0, sizeof(evp)); // evp.sigev_value.sival_ptr = &timer; // evp.sigev_notify = SIGEV_THREAD; // evp.sigev_notify_function = appl_task; // evp.sigev_value.sival_int = 3; //作为handle()的参数 // ret = timer_create(CLOCK_REALTIME, &evp, &timer); // if( ret){ // perror("timer_create"); // } // ts.it_interval.tv_sec = 1; // ts.it_interval.tv_nsec = 0; // ts.it_value.tv_sec = 1; // ts.it_value.tv_nsec = 0; // ret = timer_settime(timer, TIMER_ABSTIME, &ts, NULL); // if( ret ) // { // perror("timer_settime"); // } // } // static int appl_run() // { // //appl_init_timer(); // while(1){ // mac_exe(); // cloud_exe(); // snap_exe(); // usleep(950000); // 950ms // } // } /* * System function daemon() replacement based on FreeBSD implementation. * Original source file CVS tag: * $FreeBSD: src/lib/libc/gen/daemon.c,v 1.3 2000/01/27 23:06:14 jasone Exp $ */ static int appl_become_daemon(nochdir, noclose) int nochdir, noclose; { int fd; switch (fork()) { case -1: return (-1); case 0: break; default: _exit(0); } if (setsid() == -1) return (-1); if (!nochdir) (void)chdir("/"); if (!noclose && (fd = open("/dev/null", O_RDWR, 0)) != -1) { (void)dup2(fd, STDIN_FILENO); (void)dup2(fd, STDOUT_FILENO); (void)dup2(fd, STDERR_FILENO); if (fd > 2) (void)close(fd); } return (0); } extern int DAEMON; int appl_main() { int ret = 0; syslog(LOG_INFO, "%s, ++", __func__); if (DAEMON == 1) { if (appl_become_daemon(true, false) != 0) { syslog(LOG_INFO, "%s, become daemon fail", __func__); ret = -1; goto leave; } } // debug_break(); ems_init(); ems_run(); leave: syslog(LOG_INFO, "%s, --, ret:%d", __func__, ret); return ret; }