appl.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #include "debugbreak.h"
  2. #include "plt.h"
  3. // static int appl_init()
  4. // {
  5. // int ret = 0;
  6. // if( cloud_init() != 0 ){
  7. // ret = -1;
  8. // }else if( snap_init() != 0 ){
  9. // ret = -1;
  10. // }
  11. // log_dbg("%s, ret:%d", __func__,ret);
  12. // return ret;
  13. // }
  14. // static void appl_task()
  15. // {
  16. // mac_exe();
  17. // cloud_exe();
  18. // snap_exe();
  19. // }
  20. // static int appl_init_timer()
  21. // {
  22. // struct sigevent evp;
  23. // struct itimerspec ts;
  24. // timer_t timer;
  25. // int ret;
  26. // memset(&evp, 0, sizeof(evp));
  27. // evp.sigev_value.sival_ptr = &timer;
  28. // evp.sigev_notify = SIGEV_THREAD;
  29. // evp.sigev_notify_function = appl_task;
  30. // evp.sigev_value.sival_int = 3; //作为handle()的参数
  31. // ret = timer_create(CLOCK_REALTIME, &evp, &timer);
  32. // if( ret){
  33. // perror("timer_create");
  34. // }
  35. // ts.it_interval.tv_sec = 1;
  36. // ts.it_interval.tv_nsec = 0;
  37. // ts.it_value.tv_sec = 1;
  38. // ts.it_value.tv_nsec = 0;
  39. // ret = timer_settime(timer, TIMER_ABSTIME, &ts, NULL);
  40. // if( ret )
  41. // {
  42. // perror("timer_settime");
  43. // }
  44. // }
  45. // static int appl_run()
  46. // {
  47. // //appl_init_timer();
  48. // while(1){
  49. // mac_exe();
  50. // cloud_exe();
  51. // snap_exe();
  52. // usleep(950000); // 950ms
  53. // }
  54. // }
  55. /*
  56. * System function daemon() replacement based on FreeBSD implementation.
  57. * Original source file CVS tag:
  58. * $FreeBSD: src/lib/libc/gen/daemon.c,v 1.3 2000/01/27 23:06:14 jasone Exp $
  59. */
  60. static int appl_become_daemon(nochdir, noclose)
  61. int nochdir, noclose;
  62. {
  63. int fd;
  64. switch (fork())
  65. {
  66. case -1:
  67. return (-1);
  68. case 0:
  69. break;
  70. default:
  71. _exit(0);
  72. }
  73. if (setsid() == -1)
  74. return (-1);
  75. if (!nochdir)
  76. (void)chdir("/");
  77. if (!noclose && (fd = open("/dev/null", O_RDWR, 0)) != -1)
  78. {
  79. (void)dup2(fd, STDIN_FILENO);
  80. (void)dup2(fd, STDOUT_FILENO);
  81. (void)dup2(fd, STDERR_FILENO);
  82. if (fd > 2)
  83. (void)close(fd);
  84. }
  85. return (0);
  86. }
  87. extern int DAEMON;
  88. int appl_main()
  89. {
  90. int ret = 0;
  91. syslog(LOG_INFO, "%s, ++", __func__);
  92. if (DAEMON == 1)
  93. {
  94. if (appl_become_daemon(true, false) != 0)
  95. {
  96. syslog(LOG_INFO, "%s, become daemon fail", __func__);
  97. ret = -1;
  98. goto leave;
  99. }
  100. }
  101. // debug_break();
  102. ems_init();
  103. ems_run();
  104. leave:
  105. syslog(LOG_INFO, "%s, --, ret:%d", __func__, ret);
  106. return ret;
  107. }