Fix builds on musl based systems

* Fix pthread_setname_np detection

Commit 6617c6f2c8 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 <fontaine.fabrice@gmail.com>

* 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 <fontaine.fabrice@gmail.com>

* Revision for detection of XSI vs GNU variants of strerror
This commit is contained in:
Mr-DaveDev
2017-12-09 15:42:16 -07:00
committed by Mr-Dave
parent fe0f201345
commit eef702b3d7
6 changed files with 62 additions and 24 deletions

View File

@@ -37,9 +37,18 @@ matrix:
services: docker
language: c
compiler: gcc
- os: linux
env: DOCKER_IMAGE=alpine:latest
services: docker
language: c
compiler: gcc
before_install:
- if [ "x$DOCKER_IMAGE" != "x" ]; then
- if [ "$DOCKER_IMAGE" = "alpine:latest" ]; then
echo $DOCKER_IMAGE;
docker pull $DOCKER_IMAGE;
docker run -d -v $(pwd):/motion -w /motion $DOCKER_IMAGE /bin/sh -c 'while true; do sleep 1; done';
elif [ "x$DOCKER_IMAGE" != "x" ]; then
echo $DOCKER_IMAGE;
docker pull $DOCKER_IMAGE;
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:
brew upgrade ffmpeg pkg-config jpeg;
brew install ffmpeg pkg-config libjpeg;
autoreconf -fiv;
fi;
- if [ "$BUILD_IMAGE" = "14.04" ]; then
elif [ "$BUILD_IMAGE" = "14.04" ]; then
autoreconf -fiv;
fi;
- if [ "x$DOCKER_IMAGE" != "x" ]; then
elif [ "$DOCKER_IMAGE" = "alpine:latest" ]; then
docker exec $(docker ps -aq) /bin/sh -c 'apk update';
docker exec $(docker ps -aq) /bin/sh -c 'apk add alpine-sdk autoconf automake pkgconf libtool libjpeg-turbo-dev libzip-dev ffmpeg-dev';
docker exec $(docker ps -aq) /bin/sh -c 'autoreconf -fiv';
elif [ "x$DOCKER_IMAGE" != "x" ]; then
docker exec $(docker ps -aq) /bin/bash -c 'apt-get -qq update';
docker exec $(docker ps -aq) /bin/bash -c 'apt-get install -y build-essential libjpeg8-dev libzip-dev autoconf automake pkgconf libtool git';
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:
script:
- if [ $TRAVIS_OS_NAME = osx ]; then
./configure --with-developer-flags && make;
fi;
- if [ "$BUILD_IMAGE" = "14.04" ]; then
elif [ "$BUILD_IMAGE" = "14.04" ]; then
./test_builds.sh;
fi;
- if [ "x$DOCKER_IMAGE" != "x" ]; then
elif [ "$DOCKER_IMAGE" = "alpine:latest" ]; then
docker exec $(docker ps -aq) /bin/sh -c './test_builds.sh';
elif [ "x$DOCKER_IMAGE" != "x" ]; then
docker exec $(docker ps -aq) /bin/bash -c './test_builds.sh';
fi;

View File

@@ -128,18 +128,53 @@ fi
if test x$THREADS = xyes; then
TEMP_LIBS="$TEMP_LIBS -pthread"
TEMP_CFLAGS="${TEMP_CFLAGS} -D_THREAD_SAFE"
fi
##############################################################################
### Check for pthread_setname_np (nonstandard GNU extension)
##############################################################################
AC_MSG_CHECKING([for pthread_setname_np])
AC_COMPILE_IFELSE(
AC_MSG_CHECKING([for pthread_setname_np])
HOLD_LIBS="$LIBS"
LIBS="$TEMP_LIBS"
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([#include <pthread.h>], [pthread_setname_np(pthread_self(), "name")])],
[AC_DEFINE([HAVE_PTHREAD_SETNAME_NP], [1], [Define if you have pthread_setname_np function.])
AC_MSG_RESULT([yes])],
[AC_MSG_RESULT([no])] )
##############################################################################
### Check for pthread_getname_np (nonstandard GNU extension)
##############################################################################
AC_MSG_CHECKING([for pthread_getname_np])
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([#include <pthread.h>], [pthread_getname_np(pthread_self(), NULL, 0)])],
[AC_DEFINE([HAVE_PTHREAD_GETNAME_NP], [1], [Define if you have pthread_getname_np function.])
AC_MSG_RESULT([yes])],
[AC_MSG_RESULT([no])] )
LIBS="$HOLD_LIBS"
fi
##############################################################################
### Check for XSI strerror_r
##############################################################################
AC_MSG_CHECKING([for XSI strerror_r])
HOLD_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -Werror"
AC_LINK_IFELSE(
[AC_LANG_SOURCE[
#include <string.h>
#include <errno.h>
int main(int argc, char** argv) {
char buf[1024];
int ret = strerror_r(ENOMEM, buf, sizeof(buf));
return ret;
}
]],
[AC_DEFINE([XSI_STRERROR_R], [1], [Define if you have XSI strerror_r function.])
AC_MSG_RESULT([yes])],
[AC_MSG_RESULT([no])] )
CFLAGS="$HOLD_CFLAGS"
##############################################################################
### Check for JPG
##############################################################################

View File

@@ -206,10 +206,8 @@ void motion_log(int level, unsigned int type, int errno_flag, const char *fmt, .
*/
errno_save = errno;
char threadname[32] = "unknown";
#if ((!defined(BSD) && HAVE_PTHREAD_SETNAME_NP) || defined(__APPLE__))
pthread_getname_np(pthread_self(), threadname, sizeof(threadname));
#endif
char threadname[32];
util_threadname_get(threadname);
/*
* Prefix the message with the thread number and name,

View File

@@ -3772,7 +3772,7 @@ void util_threadname_set(const char *abbr, int threadnbr, const char *threadname
void util_threadname_get(char *threadname){
#if ((!defined(BSD) && HAVE_PTHREAD_SETNAME_NP) || defined(__APPLE__))
#if ((!defined(BSD) && HAVE_PTHREAD_GETNAME_NP) || defined(__APPLE__))
char currname[16];
pthread_getname_np(pthread_self(), currname, sizeof(currname));
snprintf(threadname, sizeof(currname), "%s",currname);

View File

@@ -100,12 +100,6 @@ struct image_data;
#define ATTRIBUTE_UNUSED
#endif
/* strerror_r() XSI vs GNU */
#if (defined(BSD)) || ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE)
#define XSI_STRERROR_R
#endif
/*
* The macro below defines a version of sleep using nanosleep
* If a signal such as SIG_CHLD interrupts the sleep we just continue sleeping

View File

@@ -25,7 +25,7 @@
#include <arpa/inet.h>
#include <netdb.h>
#include <ctype.h>
#include <sys/fcntl.h>
#include <fcntl.h>
#define STREAM_REALM "Motion Stream Security Access"
#define KEEP_ALIVE_TIMEOUT 100