From 8711bdee8bcf35931df9fbd0f79e75ef34c3f34f Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Thu, 23 Jul 2015 13:15:58 +0200 Subject: [PATCH 1/5] Use posix awk instead of GNU awk We don't use any fancy GNU awk extensions so chekc for a portable awk instead of require GNU awk. --- cmake/Conky.cmake | 10 +++++----- cmake/ConkyCPackSetup.cmake | 2 +- cmake/ConkyPlatformChecks.cmake | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cmake/Conky.cmake b/cmake/Conky.cmake index b9605de8..d9fd1503 100644 --- a/cmake/Conky.cmake +++ b/cmake/Conky.cmake @@ -71,10 +71,10 @@ set(VERSION_MAJOR "1") set(VERSION_MINOR "10") set(VERSION_PATCH "1") -find_program(APP_GAWK gawk) -if(NOT APP_GAWK) - message(FATAL_ERROR "Unable to find program 'gawk'") -endif(NOT APP_GAWK) +find_program(APP_AWK awk) +if(NOT APP_AWK) + message(FATAL_ERROR "Unable to find program 'awk'") +endif(NOT APP_AWK) find_program(APP_WC wc) if(NOT APP_WC) @@ -99,7 +99,7 @@ if(NOT RELEASE) mark_as_advanced(APP_GIT) endif(NOT RELEASE) -mark_as_advanced(APP_GAWK APP_WC APP_DATE APP_UNAME) +mark_as_advanced(APP_AWK APP_WC APP_DATE APP_UNAME) #BUILD_DATE=$(LANG=en_US LC_ALL=en_US LOCALE=en_US date) #BUILD_ARCH="$(uname -sr) ($(uname -m))" diff --git a/cmake/ConkyCPackSetup.cmake b/cmake/ConkyCPackSetup.cmake index a5689228..c1046efa 100644 --- a/cmake/ConkyCPackSetup.cmake +++ b/cmake/ConkyCPackSetup.cmake @@ -44,7 +44,7 @@ endif(CPACK_GENERATOR MATCHES "NSIS") # Source package setup. Compile with "make package_source". set(CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION}-src") set(CPACK_SOURCE_GENERATOR "TBZ2") -execute_process(COMMAND ${APP_UNAME} COMMAND ${APP_GAWK} "{print $1}" +execute_process(COMMAND ${APP_UNAME} COMMAND ${APP_AWK} "{print $1}" RESULT_VARIABLE RETVAL OUTPUT_VARIABLE CPU_ARCH OUTPUT_STRIP_TRAILING_WHITESPACE) diff --git a/cmake/ConkyPlatformChecks.cmake b/cmake/ConkyPlatformChecks.cmake index ca520ed2..a2ebafcb 100644 --- a/cmake/ConkyPlatformChecks.cmake +++ b/cmake/ConkyPlatformChecks.cmake @@ -422,6 +422,6 @@ if(DEBUG) execute_process(COMMAND ${APP_GIT} --git-dir=${CMAKE_CURRENT_SOURCE_DIR}/.git log --since=${VERSION_MAJOR}-${VERSION_MINOR}-01 --pretty=oneline COMMAND - ${APP_WC} -l COMMAND ${APP_GAWK} "{print $1}" RESULT_VARIABLE RETVAL + ${APP_WC} -l COMMAND ${APP_AWK} "{print $1}" RESULT_VARIABLE RETVAL OUTPUT_VARIABLE COMMIT_COUNT OUTPUT_STRIP_TRAILING_WHITESPACE) endif(DEBUG) From 98b063866f77ede2514cfc0ef552b9bcf4a6b25d Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Thu, 23 Jul 2015 13:57:18 +0200 Subject: [PATCH 2/5] Remove use of sysctl.h The sysctl.h is not specified in POSIX. This fixes building with musl libc. --- src/common.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/common.cc b/src/common.cc index 126f30a7..116cd069 100644 --- a/src/common.cc +++ b/src/common.cc @@ -42,7 +42,6 @@ #include #include #include -#include #include #include #include From 476f84cf5928ab4c6d94c6a6f2fc251c5640de92 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Thu, 23 Jul 2015 13:58:02 +0200 Subject: [PATCH 3/5] Use portable version of strerror_r There are 2 variants of strerror_r, GNU extension and a POSIX variant. Use the more portable POSIX variant. Also fix a potensial stack-use-after-return bug, instead of relying on undefined behavoir in GNU libc implementation. The strerror_r manpage says: > This may be either a pointer to a string that the function stores in > buf, or a pointer to some (immutable) static string (in which case buf > is unused). So it does not guarantee that it returns a pointer to some (immutable) static string. It might return a pointer to "buf", in which case we get a stack-use-after-return bug. We fix this by declaring a thread local static buffer which we always return. --- src/c++wrap.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/c++wrap.cc b/src/c++wrap.cc index c21b4735..213f9c4f 100644 --- a/src/c++wrap.cc +++ b/src/c++wrap.cc @@ -26,8 +26,14 @@ #include "c++wrap.hh" #include + +/* force use of POSIX strerror_r instead of non-portable GNU specific */ +#ifdef _GNU_SOURCE +#undef _GNU_SOURCE +#endif #include + #if !defined(HAVE_PIPE2) || !defined(HAVE_O_CLOEXEC) #include @@ -62,8 +68,10 @@ namespace { std::string strerror_r(int errnum) { - char buf[100]; - return strerror_r(errnum, buf, sizeof buf); + static thread_local char buf[100]; + if (strerror_r(errnum, buf, sizeof buf) != 0) + snprintf(buf, sizeof buf, "Unknown error %i", errnum); + return buf; } std::pair pipe2(int flags) From 18877f3992d255882d389dffec0184de8ce699dd Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Thu, 23 Jul 2015 15:58:07 +0200 Subject: [PATCH 4/5] Change ipv6 check to warning instead of fatal error The compile server might not have ipv6 but that does not prevent us from building conky and run it on a machine which has ipv6. --- cmake/ConkyPlatformChecks.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/ConkyPlatformChecks.cmake b/cmake/ConkyPlatformChecks.cmake index a2ebafcb..26d0bea2 100644 --- a/cmake/ConkyPlatformChecks.cmake +++ b/cmake/ConkyPlatformChecks.cmake @@ -105,7 +105,7 @@ endif(BUILD_IRC) if(BUILD_IPV6) find_file(IF_INET6 if_inet6 PATHS /proc/net) if(NOT IF_INET6) - message(FATAL_ERROR "/proc/net/if_inet6 unavailable") + message(WARNING "/proc/net/if_inet6 unavailable") endif(NOT IF_INET6) endif(BUILD_IPV6) From 0956b689ecc7cb89380a419a1136d53f1f3e4d8f Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Thu, 23 Jul 2015 16:36:00 +0200 Subject: [PATCH 5/5] Fix thread local on pre C++11 compilers --- src/c++wrap.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/c++wrap.cc b/src/c++wrap.cc index 213f9c4f..d4a0ec68 100644 --- a/src/c++wrap.cc +++ b/src/c++wrap.cc @@ -33,6 +33,9 @@ #endif #include +#if __cplusplus <= 199711L +#define thread_local __thread +#endif #if !defined(HAVE_PIPE2) || !defined(HAVE_O_CLOEXEC) #include