appl.c 2.3 KB

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