appl.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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(int nochdir, int noclose)
  60. {
  61. int fd;
  62. switch (fork())
  63. {
  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. {
  77. (void)dup2(fd, STDIN_FILENO);
  78. (void)dup2(fd, STDOUT_FILENO);
  79. (void)dup2(fd, STDERR_FILENO);
  80. if (fd > 2)
  81. (void)close(fd);
  82. }
  83. return (0);
  84. }
  85. extern int DAEMON;
  86. int appl_main()
  87. {
  88. int ret = 0;
  89. printf("%s, ++", __func__);
  90. if (DAEMON == 1)
  91. {
  92. if (appl_become_daemon(true, false) != 0)
  93. {
  94. printf("%s, become daemon fail", __func__);
  95. ret = -1;
  96. goto leave;
  97. }
  98. }
  99. ems_init();
  100. ems_run();
  101. leave:
  102. printf("%s, --, ret:%d", __func__, ret);
  103. // pthread_join(thrd_dtsd1352, NULL);
  104. pthread_exit(0);
  105. return ret;
  106. }