Skip to content

Commit eef702b

Browse files
Mr-DaveDevMr-Dave
authored andcommitted
Fix builds on musl based systems
* Fix pthread_setname_np detection Commit 6617c6f replaced AC_LINK_IFELSE with AC_COMPILE_IFELSE. This has broken the pthread_setname_np detection as compilation will always succeed even if pthread_setname_np is not available (if the function is not found, a simple warning will be displayed in config.log). The correct fix is to put back AC_LINK_IFELSE with -pthread in LIBS otherwise compilation will fail on toolchain without pthread_setname_np. Signed-off-by: Fabrice Fontaine <[email protected]> * Check for pthread_getname_np On some toolchains (like musl), pthread_setname_np is available but not pthread_getname_np so add this check in configure.ac Signed-off-by: Fabrice Fontaine <[email protected]> * Revision for detection of XSI vs GNU variants of strerror
1 parent fe0f201 commit eef702b

File tree

6 files changed

+62
-24
lines changed

6 files changed

+62
-24
lines changed

.travis.yml

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,18 @@ matrix:
3737
services: docker
3838
language: c
3939
compiler: gcc
40+
- os: linux
41+
env: DOCKER_IMAGE=alpine:latest
42+
services: docker
43+
language: c
44+
compiler: gcc
4045

4146
before_install:
42-
- if [ "x$DOCKER_IMAGE" != "x" ]; then
47+
- if [ "$DOCKER_IMAGE" = "alpine:latest" ]; then
48+
echo $DOCKER_IMAGE;
49+
docker pull $DOCKER_IMAGE;
50+
docker run -d -v $(pwd):/motion -w /motion $DOCKER_IMAGE /bin/sh -c 'while true; do sleep 1; done';
51+
elif [ "x$DOCKER_IMAGE" != "x" ]; then
4352
echo $DOCKER_IMAGE;
4453
docker pull $DOCKER_IMAGE;
4554
docker run -d -v $(pwd):/motion -w /motion $DOCKER_IMAGE /bin/bash -c 'while true; do sleep 1; done';
@@ -50,11 +59,13 @@ before_script:
5059
brew upgrade ffmpeg pkg-config jpeg;
5160
brew install ffmpeg pkg-config libjpeg;
5261
autoreconf -fiv;
53-
fi;
54-
- if [ "$BUILD_IMAGE" = "14.04" ]; then
62+
elif [ "$BUILD_IMAGE" = "14.04" ]; then
5563
autoreconf -fiv;
56-
fi;
57-
- if [ "x$DOCKER_IMAGE" != "x" ]; then
64+
elif [ "$DOCKER_IMAGE" = "alpine:latest" ]; then
65+
docker exec $(docker ps -aq) /bin/sh -c 'apk update';
66+
docker exec $(docker ps -aq) /bin/sh -c 'apk add alpine-sdk autoconf automake pkgconf libtool libjpeg-turbo-dev libzip-dev ffmpeg-dev';
67+
docker exec $(docker ps -aq) /bin/sh -c 'autoreconf -fiv';
68+
elif [ "x$DOCKER_IMAGE" != "x" ]; then
5869
docker exec $(docker ps -aq) /bin/bash -c 'apt-get -qq update';
5970
docker exec $(docker ps -aq) /bin/bash -c 'apt-get install -y build-essential libjpeg8-dev libzip-dev autoconf automake pkgconf libtool git';
6071
docker exec $(docker ps -aq) /bin/bash -c 'apt-get install -y libavformat-dev libavcodec-dev libavutil-dev libswscale-dev libavdevice-dev';
@@ -65,10 +76,10 @@ before_script:
6576
script:
6677
- if [ $TRAVIS_OS_NAME = osx ]; then
6778
./configure --with-developer-flags && make;
68-
fi;
69-
- if [ "$BUILD_IMAGE" = "14.04" ]; then
79+
elif [ "$BUILD_IMAGE" = "14.04" ]; then
7080
./test_builds.sh;
71-
fi;
72-
- if [ "x$DOCKER_IMAGE" != "x" ]; then
81+
elif [ "$DOCKER_IMAGE" = "alpine:latest" ]; then
82+
docker exec $(docker ps -aq) /bin/sh -c './test_builds.sh';
83+
elif [ "x$DOCKER_IMAGE" != "x" ]; then
7384
docker exec $(docker ps -aq) /bin/bash -c './test_builds.sh';
7485
fi;

configure.ac

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,18 +128,53 @@ fi
128128
if test x$THREADS = xyes; then
129129
TEMP_LIBS="$TEMP_LIBS -pthread"
130130
TEMP_CFLAGS="${TEMP_CFLAGS} -D_THREAD_SAFE"
131-
fi
132131

133132
##############################################################################
134133
### Check for pthread_setname_np (nonstandard GNU extension)
135134
##############################################################################
136-
AC_MSG_CHECKING([for pthread_setname_np])
137-
AC_COMPILE_IFELSE(
135+
AC_MSG_CHECKING([for pthread_setname_np])
136+
HOLD_LIBS="$LIBS"
137+
LIBS="$TEMP_LIBS"
138+
AC_LINK_IFELSE(
138139
[AC_LANG_PROGRAM([#include <pthread.h>], [pthread_setname_np(pthread_self(), "name")])],
139140
[AC_DEFINE([HAVE_PTHREAD_SETNAME_NP], [1], [Define if you have pthread_setname_np function.])
140141
AC_MSG_RESULT([yes])],
141142
[AC_MSG_RESULT([no])] )
142143

144+
##############################################################################
145+
### Check for pthread_getname_np (nonstandard GNU extension)
146+
##############################################################################
147+
AC_MSG_CHECKING([for pthread_getname_np])
148+
AC_LINK_IFELSE(
149+
[AC_LANG_PROGRAM([#include <pthread.h>], [pthread_getname_np(pthread_self(), NULL, 0)])],
150+
[AC_DEFINE([HAVE_PTHREAD_GETNAME_NP], [1], [Define if you have pthread_getname_np function.])
151+
AC_MSG_RESULT([yes])],
152+
[AC_MSG_RESULT([no])] )
153+
154+
LIBS="$HOLD_LIBS"
155+
fi
156+
157+
##############################################################################
158+
### Check for XSI strerror_r
159+
##############################################################################
160+
AC_MSG_CHECKING([for XSI strerror_r])
161+
HOLD_CFLAGS="$CFLAGS"
162+
CFLAGS="$CFLAGS -Werror"
163+
AC_LINK_IFELSE(
164+
[AC_LANG_SOURCE[
165+
#include <string.h>
166+
#include <errno.h>
167+
int main(int argc, char** argv) {
168+
char buf[1024];
169+
int ret = strerror_r(ENOMEM, buf, sizeof(buf));
170+
return ret;
171+
}
172+
]],
173+
[AC_DEFINE([XSI_STRERROR_R], [1], [Define if you have XSI strerror_r function.])
174+
AC_MSG_RESULT([yes])],
175+
[AC_MSG_RESULT([no])] )
176+
CFLAGS="$HOLD_CFLAGS"
177+
143178
##############################################################################
144179
### Check for JPG
145180
##############################################################################

logger.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,8 @@ void motion_log(int level, unsigned int type, int errno_flag, const char *fmt, .
206206
*/
207207
errno_save = errno;
208208

209-
char threadname[32] = "unknown";
210-
#if ((!defined(BSD) && HAVE_PTHREAD_SETNAME_NP) || defined(__APPLE__))
211-
pthread_getname_np(pthread_self(), threadname, sizeof(threadname));
212-
#endif
209+
char threadname[32];
210+
util_threadname_get(threadname);
213211

214212
/*
215213
* Prefix the message with the thread number and name,

motion.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3772,7 +3772,7 @@ void util_threadname_set(const char *abbr, int threadnbr, const char *threadname
37723772

37733773
void util_threadname_get(char *threadname){
37743774

3775-
#if ((!defined(BSD) && HAVE_PTHREAD_SETNAME_NP) || defined(__APPLE__))
3775+
#if ((!defined(BSD) && HAVE_PTHREAD_GETNAME_NP) || defined(__APPLE__))
37763776
char currname[16];
37773777
pthread_getname_np(pthread_self(), currname, sizeof(currname));
37783778
snprintf(threadname, sizeof(currname), "%s",currname);

motion.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,6 @@ struct image_data;
100100
#define ATTRIBUTE_UNUSED
101101
#endif
102102

103-
/* strerror_r() XSI vs GNU */
104-
#if (defined(BSD)) || ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE)
105-
#define XSI_STRERROR_R
106-
#endif
107-
108-
109103
/*
110104
* The macro below defines a version of sleep using nanosleep
111105
* If a signal such as SIG_CHLD interrupts the sleep we just continue sleeping

stream.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <arpa/inet.h>
2626
#include <netdb.h>
2727
#include <ctype.h>
28-
#include <sys/fcntl.h>
28+
#include <fcntl.h>
2929

3030
#define STREAM_REALM "Motion Stream Security Access"
3131
#define KEEP_ALIVE_TIMEOUT 100

0 commit comments

Comments
 (0)