Pārlūkot izejas kodu

motion: fix segmentation fault under musl libc

During startup, motion calls pthread_getspecific() through motion_log()
before pthread_key_create() has been called yet. This works on glibc and
uclibc but segfaults on musl because motion is relying on undefined
behaviour here.

Move the pthread initialization before motion_startup() so that
tls_key_threadnr is initialized when motion_log() is called.

Also enforce the use of strerror_r() on musl by defining XSI_STRERROR_R
on all non-glibc systems because the supposed replacement code is broken
and crashes on musl.

References:
http://www.lavrsen.dk/foswiki/bin/view/Motion/BugReport2015x09x30x203633

Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
Jo-Philipp Wich 9 gadus atpakaļ
vecāks
revīzija
926b68c15d

+ 2
- 2
multimedia/motion/Makefile Parādīt failu

@@ -1,5 +1,5 @@
1 1
 #
2
-# Copyright (C) 2008-2011 OpenWrt.org
2
+# Copyright (C) 2008-2015 OpenWrt.org
3 3
 #
4 4
 # This is free software, licensed under the GNU General Public License v2.
5 5
 # See /LICENSE for more information.
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
9 9
 
10 10
 PKG_NAME:=motion
11 11
 PKG_VERSION=3.4.0-20141018-$(PKG_SOURCE_VERSION)
12
-PKG_RELEASE:=1
12
+PKG_RELEASE:=2
13 13
 
14 14
 PKG_MAINTAINER:=Roger D <rogerdammit@gmail.com>
15 15
 PKG_LICENSE:=GPLv2

+ 49
- 0
multimedia/motion/patches/100-musl-compat.patch Parādīt failu

@@ -0,0 +1,49 @@
1
+--- a/motion.c
2
++++ b/motion.c
3
+@@ -2630,6 +2630,17 @@ int main (int argc, char **argv)
4
+     struct sigaction sigchild_action;
5
+     setup_signals(&sig_handler_action, &sigchild_action);
6
+ 
7
++    /*
8
++     * Create and a thread attribute for the threads we spawn later on.
9
++     * PTHREAD_CREATE_DETACHED means to create threads detached, i.e.
10
++     * their termination cannot be synchronized through 'pthread_join'.
11
++     */
12
++    pthread_attr_init(&thread_attr);
13
++    pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED);
14
++
15
++    /* Create the TLS key for thread number. */
16
++    pthread_key_create(&tls_key_threadnr, NULL);
17
++
18
+     motion_startup(1, argc, argv);
19
+ 
20
+ #ifdef HAVE_FFMPEG
21
+@@ -2648,17 +2659,6 @@ int main (int argc, char **argv)
22
+     if (cnt_list[0]->conf.setup_mode)
23
+         MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "%s: Motion running in setup mode.");
24
+ 
25
+-    /*
26
+-     * Create and a thread attribute for the threads we spawn later on.
27
+-     * PTHREAD_CREATE_DETACHED means to create threads detached, i.e.
28
+-     * their termination cannot be synchronized through 'pthread_join'.
29
+-     */
30
+-    pthread_attr_init(&thread_attr);
31
+-    pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED);
32
+-
33
+-    /* Create the TLS key for thread number. */
34
+-    pthread_key_create(&tls_key_threadnr, NULL);
35
+-
36
+     do {
37
+         if (restart) {
38
+             /*
39
+--- a/motion.h
40
++++ b/motion.h
41
+@@ -84,7 +84,7 @@
42
+ #endif
43
+ 
44
+ /* strerror_r() XSI vs GNU */
45
+-#if (defined(BSD)) || ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE)
46
++#if (defined(BSD)) || ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE) || (!defined(__GLIBC__))
47
+ #define XSI_STRERROR_R
48
+ #endif
49
+