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.

94 lines
3.2 KiB

  1. From 3c7cbd685017c1bf9ba2eaa811b63842bec28f64 Mon Sep 17 00:00:00 2001
  2. From: Mr-DaveDev <MotionMrDaveDev@gmail.com>
  3. Date: Mon, 1 Jan 2018 13:07:08 -0700
  4. Subject: [PATCH] Initialize the thread at start of main
  5. Closes #589
  6. ---
  7. logger.c | 5 -----
  8. motion.c | 30 ++++++++++++++++--------------
  9. 2 files changed, 16 insertions(+), 19 deletions(-)
  10. diff --git a/logger.c b/logger.c
  11. index c55044b..5ef2f85 100644
  12. --- a/logger.c
  13. +++ b/logger.c
  14. @@ -193,11 +193,6 @@ void motion_log(int level, unsigned int type, int errno_flag, const char *fmt, .
  15. //printf("log_type %d, type %d level %d\n", log_type, type, level);
  16. - /*
  17. - * If pthread_getspecific fails (e.g., because the thread's TLS doesn't
  18. - * contain anything for thread number, it returns NULL which casts to zero,
  19. - * which is nice because that's what we want in that case.
  20. - */
  21. threadnr = (unsigned long)pthread_getspecific(tls_key_threadnr);
  22. /*
  23. diff --git a/motion.c b/motion.c
  24. index 985d4b2..9fe58c1 100644
  25. --- a/motion.c
  26. +++ b/motion.c
  27. @@ -2886,10 +2886,6 @@ static void motion_startup(int daemonize, int argc, char *argv[])
  28. }
  29. - //set_log_level(cnt_list[0]->log_level);
  30. -
  31. - MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "Motion "VERSION" Started");
  32. -
  33. if ((cnt_list[0]->conf.log_file) && (strncmp(cnt_list[0]->conf.log_file, "syslog", 6))) {
  34. set_log_mode(LOGMODE_FILE);
  35. ptr_logfile = set_logfile(cnt_list[0]->conf.log_file);
  36. @@ -2908,6 +2904,8 @@ static void motion_startup(int daemonize, int argc, char *argv[])
  37. MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "Logging to syslog");
  38. }
  39. + MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "Motion "VERSION" Started");
  40. +
  41. if ((cnt_list[0]->conf.log_type_str == NULL) ||
  42. !(cnt_list[0]->log_type = get_log_type(cnt_list[0]->conf.log_type_str))) {
  43. cnt_list[0]->log_type = TYPE_DEFAULT;
  44. @@ -3053,8 +3051,22 @@ int main (int argc, char **argv)
  45. */
  46. struct sigaction sig_handler_action;
  47. struct sigaction sigchild_action;
  48. +
  49. +
  50. setup_signals(&sig_handler_action, &sigchild_action);
  51. + /*
  52. + * Create and a thread attribute for the threads we spawn later on.
  53. + * PTHREAD_CREATE_DETACHED means to create threads detached, i.e.
  54. + * their termination cannot be synchronized through 'pthread_join'.
  55. + */
  56. + pthread_attr_init(&thread_attr);
  57. + pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED);
  58. +
  59. + /* Create the TLS key for thread number. */
  60. + pthread_key_create(&tls_key_threadnr, NULL);
  61. + pthread_setspecific(tls_key_threadnr, (void *)(0));
  62. +
  63. motion_startup(1, argc, argv);
  64. ffmpeg_global_init();
  65. @@ -3102,16 +3114,6 @@ int main (int argc, char **argv)
  66. if (cnt_list[0]->conf.setup_mode)
  67. MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "Motion running in setup mode.");
  68. - /*
  69. - * Create and a thread attribute for the threads we spawn later on.
  70. - * PTHREAD_CREATE_DETACHED means to create threads detached, i.e.
  71. - * their termination cannot be synchronized through 'pthread_join'.
  72. - */
  73. - pthread_attr_init(&thread_attr);
  74. - pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED);
  75. -
  76. - /* Create the TLS key for thread number. */
  77. - pthread_key_create(&tls_key_threadnr, NULL);
  78. do {
  79. if (restart) {
  80. --
  81. 2.7.4