You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
2.8 KiB

  1. #include <dirent.h>
  2. #include <iterator>
  3. #include <cstdlib>
  4. #include <cstring>
  5. #include <sstream>
  6. #include <iostream>
  7. #include <stdlib.h>
  8. #include <string>
  9. #include <sys/stat.h>
  10. #include <syslog.h>
  11. #include <unistd.h>
  12. #include <vector>
  13. #include <sqlite3.h>
  14. #include <util/notifications.h>
  15. #include <util/calendar_parsing.h>
  16. #include <io/debug.h>
  17. const int MINUTE = 1000000;
  18. void update_database() {
  19. std::vector<ical::ical_object*> objects = util::parse_cal_dir();
  20. }
  21. void do_heartbeat()
  22. {
  23. util::notify("Testing", "");
  24. update_database();
  25. }
  26. // For security purposes, we don't allow any arguments to be passed into the daemon
  27. int main(void)
  28. {
  29. // Define variables
  30. //pid_t pid, sid;
  31. //// Fork the current process
  32. //pid = fork();
  33. //// The parent process continues with a process ID greater than 0
  34. //if(pid > 0)
  35. //{
  36. // exit(EXIT_SUCCESS);
  37. //}
  38. //// A process ID lower than 0 indicates a failure in either process
  39. //else if(pid < 0)
  40. //{
  41. // exit(EXIT_FAILURE);
  42. //}
  43. //// The parent process has now terminated, and the forked child process will continue
  44. //// (the pid of the child process was 0)
  45. //// Since the child process is a daemon, the umask needs to be set so files and logs can be written
  46. //umask(0);
  47. //// Open system logs for the child process
  48. //openlog("daemon-named", LOG_NOWAIT | LOG_PID, LOG_USER);
  49. //syslog(LOG_NOTICE, "Successfully started daemon-name");
  50. //// Generate a session ID for the child process
  51. //sid = setsid();
  52. //// Ensure a valid SID for the child process
  53. //if(sid < 0)
  54. //{
  55. // // Log failure and exit
  56. // syslog(LOG_ERR, "Could not generate session ID for child process");
  57. // // If a new session ID could not be generated, we must terminate the child process
  58. // // or it will be orphaned
  59. // exit(EXIT_FAILURE);
  60. //}
  61. //// Change the current working directory to a directory guaranteed to exist
  62. //if((chdir("/")) < 0)
  63. //{
  64. // // Log failure and exit
  65. // syslog(LOG_ERR, "Could not change working directory to /");
  66. // // If our guaranteed directory does not exist, terminate the child process to ensure
  67. // // the daemon has not been hijacked
  68. // exit(EXIT_FAILURE);
  69. //}
  70. //// A daemon cannot use the terminal, so close standard file descriptors for security reasons
  71. //close(STDIN_FILENO);
  72. //close(STDOUT_FILENO);
  73. //close(STDERR_FILENO);
  74. // Daemon-specific intialization should go here
  75. const int SLEEP_INTERVAL = 5 * MINUTE;
  76. // Enter daemon loop
  77. while(1)
  78. {
  79. // Execute daemon heartbeat, where your recurring activity occurs
  80. do_heartbeat();
  81. exit(0);
  82. // Sleep for a period of time
  83. sleep(SLEEP_INTERVAL);
  84. }
  85. // Close system logs for the child process
  86. //syslog(LOG_NOTICE, "Stopping daemon-name");
  87. //closelog();
  88. // Terminate the child process when the daemon completes
  89. exit(EXIT_SUCCESS);
  90. }