motion: Backport upstream commit to fix running on musl.
authorRosen Penev <redacted>
Sat, 15 Sep 2018 17:37:19 +0000 (10:37 -0700)
committerRosen Penev <redacted>
Sat, 15 Sep 2018 17:39:53 +0000 (10:39 -0700)
Reported on OpenWrt forums

https://forum.openwrt.org/t/motion-segmentation-fault-after-upgrade-to-4-14-68/21276

Signed-off-by: Rosen Penev <redacted>
multimedia/motion/Makefile
multimedia/motion/patches/010-Initialize-the-thread-at-start-of-main.patch [new file with mode: 0644]

index 517d7ec7963697238dcbf8c0d87d26a165b29eeb..8b3ca6fd47309ef3a2b787ffe94613c8eb7fee1d 100644 (file)
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=motion
 PKG_VERSION:=4.1.1
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 
 PKG_MAINTAINER:=Roger D <rogerdammit@gmail.com>
 PKG_LICENSE:=GPLv2
diff --git a/multimedia/motion/patches/010-Initialize-the-thread-at-start-of-main.patch b/multimedia/motion/patches/010-Initialize-the-thread-at-start-of-main.patch
new file mode 100644 (file)
index 0000000..5e8eafa
--- /dev/null
@@ -0,0 +1,94 @@
+From 3c7cbd685017c1bf9ba2eaa811b63842bec28f64 Mon Sep 17 00:00:00 2001
+From: Mr-DaveDev <MotionMrDaveDev@gmail.com>
+Date: Mon, 1 Jan 2018 13:07:08 -0700
+Subject: [PATCH] Initialize the thread at start of main
+
+Closes #589
+---
+ logger.c |  5 -----
+ motion.c | 30 ++++++++++++++++--------------
+ 2 files changed, 16 insertions(+), 19 deletions(-)
+
+diff --git a/logger.c b/logger.c
+index c55044b..5ef2f85 100644
+--- a/logger.c
++++ b/logger.c
+@@ -193,11 +193,6 @@ void motion_log(int level, unsigned int type, int errno_flag, const char *fmt, .
+     //printf("log_type %d, type %d level %d\n", log_type, type, level);
+-    /*
+-     * If pthread_getspecific fails (e.g., because the thread's TLS doesn't
+-     * contain anything for thread number, it returns NULL which casts to zero,
+-     * which is nice because that's what we want in that case.
+-     */
+     threadnr = (unsigned long)pthread_getspecific(tls_key_threadnr);
+     /*
+diff --git a/motion.c b/motion.c
+index 985d4b2..9fe58c1 100644
+--- a/motion.c
++++ b/motion.c
+@@ -2886,10 +2886,6 @@ static void motion_startup(int daemonize, int argc, char *argv[])
+     }
+-    //set_log_level(cnt_list[0]->log_level);
+-
+-    MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "Motion "VERSION" Started");
+-
+     if ((cnt_list[0]->conf.log_file) && (strncmp(cnt_list[0]->conf.log_file, "syslog", 6))) {
+         set_log_mode(LOGMODE_FILE);
+         ptr_logfile = set_logfile(cnt_list[0]->conf.log_file);
+@@ -2908,6 +2904,8 @@ static void motion_startup(int daemonize, int argc, char *argv[])
+         MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "Logging to syslog");
+     }
++    MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "Motion "VERSION" Started");
++
+     if ((cnt_list[0]->conf.log_type_str == NULL) ||
+         !(cnt_list[0]->log_type = get_log_type(cnt_list[0]->conf.log_type_str))) {
+         cnt_list[0]->log_type = TYPE_DEFAULT;
+@@ -3053,8 +3051,22 @@ int main (int argc, char **argv)
+      */
+     struct sigaction sig_handler_action;
+     struct sigaction sigchild_action;
++
++
+     setup_signals(&sig_handler_action, &sigchild_action);
++    /*
++     * Create and a thread attribute for the threads we spawn later on.
++     * PTHREAD_CREATE_DETACHED means to create threads detached, i.e.
++     * their termination cannot be synchronized through 'pthread_join'.
++     */
++    pthread_attr_init(&thread_attr);
++    pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED);
++
++    /* Create the TLS key for thread number. */
++    pthread_key_create(&tls_key_threadnr, NULL);
++    pthread_setspecific(tls_key_threadnr, (void *)(0));
++
+     motion_startup(1, argc, argv);
+     ffmpeg_global_init();
+@@ -3102,16 +3114,6 @@ int main (int argc, char **argv)
+     if (cnt_list[0]->conf.setup_mode)
+         MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "Motion running in setup mode.");
+-    /*
+-     * Create and a thread attribute for the threads we spawn later on.
+-     * PTHREAD_CREATE_DETACHED means to create threads detached, i.e.
+-     * their termination cannot be synchronized through 'pthread_join'.
+-     */
+-    pthread_attr_init(&thread_attr);
+-    pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED);
+-
+-    /* Create the TLS key for thread number. */
+-    pthread_key_create(&tls_key_threadnr, NULL);
+     do {
+         if (restart) {
+-- 
+2.7.4
+
git clone https://git.99rst.org/PROJECT