From 5b457730146f536ff4e41f5ddfed1750eb0d836b Mon Sep 17 00:00:00 2001 From: User Decke Date: Sat, 4 Jan 2014 22:08:43 +0000 Subject: [PATCH 01/13] misc: Consistently use hts_strdupa() instead of libc strdupa() which is Linux specific. --- src/epggrab/channel.c | 2 +- src/idnode.c | 2 +- src/input/mpegts/linuxdvb/linuxdvb_mux.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/epggrab/channel.c b/src/epggrab/channel.c index 974bcf38..8cdff425 100644 --- a/src/epggrab/channel.c +++ b/src/epggrab/channel.c @@ -191,7 +191,7 @@ epggrab_channel_t *epggrab_channel_find epggrab_channel_t *ec; static epggrab_channel_t *skel = NULL; if (!skel) skel = calloc(1, sizeof(epggrab_channel_t)); - skel->id = strdupa(id); + skel->id = tvh_strdupa(id); /* Replace / with # */ // Note: this is a bit of a nasty fix for #1774, but will do for now diff --git a/src/idnode.c b/src/idnode.c index c260f505..d9f45d16 100644 --- a/src/idnode.c +++ b/src/idnode.c @@ -488,7 +488,7 @@ idnode_cmp_sort case PT_STR: { int r; - const char *stra = strdupa(idnode_get_str(ina, sort->key) ?: ""); + const char *stra = tvh_strdupa(idnode_get_str(ina, sort->key) ?: ""); const char *strb = idnode_get_str(inb, sort->key); if (sort->dir == IS_ASC) r = strcmp(stra ?: "", strb ?: ""); diff --git a/src/input/mpegts/linuxdvb/linuxdvb_mux.c b/src/input/mpegts/linuxdvb/linuxdvb_mux.c index 0ef5ab90..96cfb424 100644 --- a/src/input/mpegts/linuxdvb/linuxdvb_mux.c +++ b/src/input/mpegts/linuxdvb/linuxdvb_mux.c @@ -443,7 +443,7 @@ linuxdvb_mux_dvbs_class_orbital_set ( void *o, const void *s ) { int pos, save = 0; char dir; - char *tmp = strdupa(s); + char *tmp = tvh_strdupa(s); linuxdvb_mux_t *lm = o; dir = tmp[strlen(tmp)-1]; From b9344a0f3bf7c771edb43b0e4cc517d4465de9ea Mon Sep 17 00:00:00 2001 From: User Decke Date: Sat, 4 Jan 2014 22:16:58 +0000 Subject: [PATCH 02/13] build: Fix compile warning with clang 3.3 src/descrambler/cwc.c:493:11: error: comparison of unsigned expression < 0 is always false [-Werror,-Wtautological-compare] if (len < 0) return -1; ~~~ ^ ~ --- src/descrambler/cwc.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/descrambler/cwc.c b/src/descrambler/cwc.c index b070d817..9a068476 100755 --- a/src/descrambler/cwc.c +++ b/src/descrambler/cwc.c @@ -490,7 +490,6 @@ cwc_send_msg(cwc_t *cwc, const uint8_t *msg, size_t len, int sid, int enq, uint1 tvhtrace("cwc", "sending message sid %d len %"PRIsize_t" enq %d", sid, len, enq); tvhlog_hexdump("cwc", msg, len); - if (len < 0) return -1; buf[0] = (len - 2) >> 8; buf[1] = (len - 2) & 0xff; From 9f9f816a348a5e8dbb208f9ff081e8ab1d24606b Mon Sep 17 00:00:00 2001 From: User Decke Date: Sat, 4 Jan 2014 22:23:46 +0000 Subject: [PATCH 03/13] build: Fix compiler warning and properly cast return value of pthread_self() to long --- src/tvhlog.c | 2 +- src/wrappers.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tvhlog.c b/src/tvhlog.c index ac42dc3c..ece17b33 100644 --- a/src/tvhlog.c +++ b/src/tvhlog.c @@ -307,7 +307,7 @@ void tvhlogv ( const char *file, int line, /* Basic message */ l = 0; if (options & TVHLOG_OPT_THREAD) { - l += snprintf(buf + l, sizeof(buf) - l, "tid %ld: ", pthread_self()); + l += snprintf(buf + l, sizeof(buf) - l, "tid %ld: ", (long)pthread_self()); } l += snprintf(buf + l, sizeof(buf) - l, "%s: ", subsys); if (options & TVHLOG_OPT_FILELINE && severity >= LOG_DEBUG) diff --git a/src/wrappers.c b/src/wrappers.c index 4167b902..ef63508e 100644 --- a/src/wrappers.c +++ b/src/wrappers.c @@ -99,7 +99,7 @@ thread_wrapper ( void *p ) /* Run */ tvhdebug("thread", "created thread %ld [%s / %p(%p)]", - pthread_self(), ts->name, ts->run, ts->arg); + (long)pthread_self(), ts->name, ts->run, ts->arg); void *r = ts->run(ts->arg); free(ts); From 8093e67b55ca492b30f5904a0ce2d12a3d69c93c Mon Sep 17 00:00:00 2001 From: Bernhard Froehlich Date: Sun, 5 Jan 2014 21:47:25 +0100 Subject: [PATCH 04/13] install: Properly install manpages in mandir/man1 which also fixes Bug#1064. --- support/posix.mk | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/support/posix.mk b/support/posix.mk index db621b80..404245a9 100644 --- a/support/posix.mk +++ b/support/posix.mk @@ -7,8 +7,8 @@ INSTICON= ${DESTDIR}$(prefix)/share/icons/hicolor/scalable/apps install: ${PROG} ${MAN} install -d ${DESTDIR}${bindir} install ${PROG} ${DESTDIR}${bindir}/tvheadend - install -d ${DESTDIR}${mandir} - install ${MAN} ${DESTDIR}${mandir}/tvheadend.1 + install -d ${DESTDIR}${mandir}/man1 + install ${MAN} ${DESTDIR}${mandir}/man1/tvheadend.1 for bundle in ${BUNDLES}; do \ mkdir -p ${DESTDIR}${datadir}/tvheadend/$$bundle ;\ @@ -19,5 +19,5 @@ install: ${PROG} ${MAN} uninstall: rm -f ${DESTDIR}${bindir}/tvheadend - rm -f ${DESTDIR}${mandir}/tvheadend.1 + rm -f ${DESTDIR}${mandir}/man1/tvheadend.1 rm -rf ${DESTDIR}${datadir}/tvheadend From d2e4af6529302e7eb0760cdf64e1b0ad4d519bc1 Mon Sep 17 00:00:00 2001 From: Bernhard Froehlich Date: Sun, 5 Jan 2014 21:53:28 +0100 Subject: [PATCH 05/13] build: Hide glibc workarounds in PLATFORM_LINUX because it does only make sense on Linux. --- src/tvheadend.h | 2 ++ src/wrappers.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/tvheadend.h b/src/tvheadend.h index bc7b5dca..0bb2be80 100644 --- a/src/tvheadend.h +++ b/src/tvheadend.h @@ -603,12 +603,14 @@ int rmtree ( const char *path ); char *regexp_escape ( const char *str ); +#ifdef PLATFORM_LINUX /* glibc wrapper */ #if !__GLIBC_PREREQ(2,8) void qsort_r(void *base, size_t nmemb, size_t size, int (*cmp)(const void *, const void *, void *), void *aux); #endif +#endif /* PLATFORM_LINUX */ /* printing */ # if __WORDSIZE == 64 diff --git a/src/wrappers.c b/src/wrappers.c index ef63508e..07b08d07 100644 --- a/src/wrappers.c +++ b/src/wrappers.c @@ -123,6 +123,7 @@ tvhthread_create0 return r; } +#ifdef PLATFORM_LINUX /* * qsort_r wrapper for pre GLIBC 2.8 */ @@ -148,3 +149,4 @@ qsort_r(void *base, size_t nmemb, size_t size, qsort(base, nmemb, size, qsort_r_wrap); } #endif /* GLIBC < 2.8 */ +#endif /* PLATFORM_LINUX */ From 7bf3a13d671f8f1b1ac5384b0d2b2db8ca3d503c Mon Sep 17 00:00:00 2001 From: Bernhard Froehlich Date: Sun, 5 Jan 2014 21:59:29 +0100 Subject: [PATCH 06/13] build: Fix clang compiler warning --- src/idnode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/idnode.c b/src/idnode.c index d9f45d16..56a3addd 100644 --- a/src/idnode.c +++ b/src/idnode.c @@ -660,7 +660,7 @@ void idnode_set_sort ( idnode_set_t *is, idnode_sort_t *sort ) { - qsort_r(is->is_array, is->is_count, sizeof(idnode_t*), idnode_cmp_sort, sort); + qsort_r(is->is_array, is->is_count, sizeof(idnode_t*), idnode_cmp_sort, (void*)sort); } void From ffff0b34c497412dff2140c0800cbd9b8fe909c5 Mon Sep 17 00:00:00 2001 From: Bernhard Froehlich Date: Sun, 5 Jan 2014 22:02:18 +0100 Subject: [PATCH 07/13] freebsd: Assume all devices on FreeBSD are USB 2.0 per default because FreeBSD does not have sysfs to read the device speed and type properly. The good thing is that there are no PCI devices that support V4L right now so all supported devices are from webcamd which only supports USB devices so that default is always correct. --- src/main.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main.c b/src/main.c index 967eddfb..adae1a8b 100644 --- a/src/main.c +++ b/src/main.c @@ -946,8 +946,13 @@ get_device_connection(const char *dev) snprintf(path, sizeof(path), "/sys/class/%s/device/speed", dev); if(readlinefromfile(path, l, sizeof(l))) { +#if defined(PLATFORM_FREEBSD) + // Assume USB 2.0 on FreeBSD because there are no supported PCI devices + return HOSTCONNECTION_USB480; +#else // Unable to read speed, assume it's PCI return HOSTCONNECTION_PCI; +#endif } else { speed = atoi(l); From c21d42e4ceba670e92ed4adab244e1c800cab428 Mon Sep 17 00:00:00 2001 From: Bernhard Froehlich Date: Sun, 5 Jan 2014 22:13:12 +0100 Subject: [PATCH 08/13] misc: Add ifdefs for linux specific prctl(2) --- src/main.c | 9 ++++++++- src/wrappers.c | 7 ++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index adae1a8b..0e1ad899 100644 --- a/src/main.c +++ b/src/main.c @@ -29,7 +29,6 @@ #include #include #include -#include #include #include @@ -64,6 +63,10 @@ #include "plumbing/transcoding.h" #endif +#ifdef PLATFORM_LINUX +#include +#endif + /* Command line option struct */ typedef struct str_list { @@ -681,9 +684,13 @@ main(int argc, char **argv) /* Make dumpable */ if (opt_dump) { +#ifdef PLATFORM_LINUX if (chdir("/tmp")) tvhwarn("START", "failed to change cwd to /tmp"); prctl(PR_SET_DUMPABLE, 1); +#else + tvhwarn("START", "Coredumps not implemented on your platform"); +#endif } umask(0); diff --git a/src/wrappers.c b/src/wrappers.c index 07b08d07..2f85adc3 100644 --- a/src/wrappers.c +++ b/src/wrappers.c @@ -3,10 +3,13 @@ #include #include /* See NOTES */ #include -#include #include #include +#ifdef PLATFORM_LINUX +#include +#endif + int tvh_open(const char *pathname, int flags, mode_t mode) { @@ -94,8 +97,10 @@ thread_wrapper ( void *p ) { struct thread_state *ts = p; +#ifdef PLATFORM_LINUX /* Set name */ prctl(PR_SET_NAME, ts->name); +#endif /* Run */ tvhdebug("thread", "created thread %ld [%s / %p(%p)]", From 727357e1bd5156c6401e5d914999b7f044b6ddc3 Mon Sep 17 00:00:00 2001 From: Bernhard Froehlich Date: Wed, 8 Jan 2014 14:32:52 +0000 Subject: [PATCH 09/13] Revert "freebsd: Assume all devices on FreeBSD are USB 2.0 per default because" This reverts commit fd75ad6d3d71429f9e82339bd5abdb391725923b. --- src/main.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/main.c b/src/main.c index 0e1ad899..528940e6 100644 --- a/src/main.c +++ b/src/main.c @@ -953,13 +953,8 @@ get_device_connection(const char *dev) snprintf(path, sizeof(path), "/sys/class/%s/device/speed", dev); if(readlinefromfile(path, l, sizeof(l))) { -#if defined(PLATFORM_FREEBSD) - // Assume USB 2.0 on FreeBSD because there are no supported PCI devices - return HOSTCONNECTION_USB480; -#else // Unable to read speed, assume it's PCI return HOSTCONNECTION_PCI; -#endif } else { speed = atoi(l); From 4559e36dc175f0793ed417a25fc44f0dc9516b91 Mon Sep 17 00:00:00 2001 From: Bernhard Froehlich Date: Wed, 8 Jan 2014 14:39:26 +0000 Subject: [PATCH 10/13] pthread: Set name of thread for easier debugging on FreeBSD --- src/wrappers.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/wrappers.c b/src/wrappers.c index 2f85adc3..cc702aea 100644 --- a/src/wrappers.c +++ b/src/wrappers.c @@ -97,9 +97,12 @@ thread_wrapper ( void *p ) { struct thread_state *ts = p; -#ifdef PLATFORM_LINUX +#if defined(PLATFORM_LINUX) /* Set name */ prctl(PR_SET_NAME, ts->name); +#elif defined(PLATFORM_FREEBSD) + /* Set name of thread */ + pthread_set_name_np(pthread_self(), ts->name); #endif /* Run */ From 0370fb3e418d49c415c71d76f289f1670fb1e915 Mon Sep 17 00:00:00 2001 From: Bernhard Froehlich Date: Fri, 10 Jan 2014 20:40:31 +0000 Subject: [PATCH 11/13] pthread: Add missing include for pthread_set_name_np(3) --- src/wrappers.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/wrappers.c b/src/wrappers.c index cc702aea..4343fc50 100644 --- a/src/wrappers.c +++ b/src/wrappers.c @@ -10,6 +10,10 @@ #include #endif +#ifdef PLATFORM_FREEBSD +#include +#endif + int tvh_open(const char *pathname, int flags, mode_t mode) { From 9fd07c65a4a9b1e442b7f70d82d0f7f6be62ffd8 Mon Sep 17 00:00:00 2001 From: Bernhard Froehlich Date: Fri, 10 Jan 2014 20:49:23 +0000 Subject: [PATCH 12/13] build: Add missing include for Dl_info on FreeBSD which is only used when execinfo is enabled. src/trap.c:144: error: 'Dl_info' undeclared (first use in this function) src/trap.c:144: error: expected ';' before 'dli' cc1: warnings being treated as errors src/trap.c:187: warning: implicit declaration of function 'dladdr' src/trap.c:187: error: 'dli' undeclared (first use in this function) --- src/trap.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/trap.c b/src/trap.c index 42697906..db9a3799 100644 --- a/src/trap.c +++ b/src/trap.c @@ -33,6 +33,7 @@ char tvh_binshasum[20]; #include #if ENABLE_EXECINFO #include +#include #endif #include #include From 226ae844bc79b4c295a1441e63cc28639cb7e5ea Mon Sep 17 00:00:00 2001 From: Bernhard Froehlich Date: Fri, 10 Jan 2014 20:51:26 +0000 Subject: [PATCH 13/13] build: declare environ explicitly on FreeBSD src/trap.c:107: error: 'environ' undeclared (first use in this function) --- src/trap.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/trap.c b/src/trap.c index db9a3799..00664724 100644 --- a/src/trap.c +++ b/src/trap.c @@ -53,6 +53,10 @@ static char tmpbuf[1024]; static char libs[1024]; static char self[PATH_MAX]; +#ifdef PLATFORM_FREEBSD +extern char **environ; +#endif + static void sappend(char *buf, size_t l, const char *fmt, ...) {