Skip to content

Commit

Permalink
#14 - Fixing pthreads_rwlock_unlock issue for older OS (#15)
Browse files Browse the repository at this point in the history
* Support Build Matrix
* Force C11 on compile
* pthreawd_rwlock_unlock "The pthread_rwlock_unlock() function is
  called to release a lock held on the read-write lock object
  referenced by rwlock. Results are undefined if the read-write
  lock rwlock is not held by the calling thread." On older flavors
  of linux this can be problematic. This PR removes these calls from
  destructor functions.
* Using MHD_USE_SELECT_INTERNALLY for MHD_flag in smoke test
* Update example to use updated MHD_flag
  • Loading branch information
miroswan authored Feb 18, 2020
1 parent de1fbd5 commit cacee63
Show file tree
Hide file tree
Showing 18 changed files with 101 additions and 58 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
docker/Dockerfile
.vscode
prom/build/*
promhttp/build/*
Expand Down
10 changes: 9 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,12 @@ language: c
services:
- docker

script: make
script: make

jobs:
include:
- env: DOCKER_IMAGE=ubuntu:18.04
- env: DOCKER_IMAGE=ubuntu:16.04
- env: DOCKER_IMAGE=debian:buster
- env: DOCKER_IMAGE=debian:stretch
- env: DOCKER_IMAGE=debian:jessie
8 changes: 2 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,13 @@ default: changed_files
@echo -e "\033[1;32mNothing to build\033[0m"
endif

build_and_test: changed_files docker clean build test package smoke
build_and_test: changed_files clean build test package smoke
.PHONY: build_and_test

all: build_and_test docs
.PHONY: all

docker:
pushd docker && make
.PHONY: docker

clean: docker
clean:
./auto dev -e auto -a clean

build: clean
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,9 @@ communication process so please do not be shy. Speak up!
## Misc

* Language level: C11
* Operating Systems:
* Ubuntu 18.04
* Ubuntu 16.04
* Debian Buster
* Debian Stretch
* Debian Jessie
3 changes: 2 additions & 1 deletion auto
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ if [[ "$AUTO_DEBUG" == "1" ]]; then
export AUTO_DEBUG=1
fi

PROJECT_ROOT=$(pushd $(dirname $0) > /dev/null; echo $PWD; popd > /dev/null)
export PROJECT_ROOT=$(pushd $(dirname $0) > /dev/null; echo $PWD; popd > /dev/null)
export DOCKER_IMAGE
PROGRAM_NAME="$(basename $0)"

usage(){
Expand Down
3 changes: 2 additions & 1 deletion autolib/autolib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ lib="$(dirname ${BASH_SOURCE[0]})"

source "${lib}/output.sh"
source "${lib}/build.sh"
source "${lib}/docker.sh"
source "${lib}/env.sh"
source "${lib}/test.sh"
source "${lib}/test.sh"
28 changes: 17 additions & 11 deletions autolib/cmd/dev
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ MUST NOT execute this command from an existing docker container.
-e Execute the following executable
-a Pass an argument to the executable given by -e. You may specify
this flag multiple times. The order is preserved.
-i The docker image to use.
Default: ubuntu:18.04
Options: ubuntu:18.04, ubuntu:16.04, debian:buster, debian:stretch, debian:jessie
EOF

usage() {
Expand All @@ -43,21 +46,21 @@ EOF

source $(dirname ${BASH_SOURCE[0]})/../autolib.sh

declare DOCKER_IMAGE=${DOCKER_IMAGE:=ubuntu:18.04}
declare DOCKER_EXEC
declare -a DOCKER_EXEC_ARGS

run(){
local r
if ! { docker image list | grep -q prometheus-client-c-dev; }; then
autolib_output_banner "Building development container"
pushd docker > /dev/null || return $?
make || {
r=$?
outlib_output_error "Docker Build Failure"
return $r
}
popd > /dev/null
fi
autolib_output_banner "Building development container"
autolib_write_dockerfile "$DOCKER_IMAGE" || return $?
pushd docker > /dev/null || return $?
make || {
r=$?
outlib_output_error "Docker Build Failure"
return $r
}
popd > /dev/null

autolib_output_banner "Entering development environment"
declare -a args
Expand All @@ -75,11 +78,14 @@ run(){
}

main(){
while getopts "he:a:" opt; do
while getopts "he:a:i:" opt; do
case $opt in
( h ) {
usage && exit 0
} ;;
( i ) {
DOCKER_IMAGE="$OPTARG"
} ;;
( e ) {
DOCKER_EXEC="$OPTARG"
} ;;
Expand Down
53 changes: 53 additions & 0 deletions autolib/docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env bash

lib="$(dirname ${BASH_SOURCE[0]})"
source "${lib}/output.sh"

PROJECT_ROOT=$(pushd "$(dirname ${BASH_SOURCE[0]})/.." > /dev/null; echo $PWD; popd > /dev/null)

autolib_debian_template(){
cat <<'EOF'
FROM __DOCKER_IMAGE__
RUN apt-get update && \
apt-get install -y apt-utils && \
apt-get install -y curl tar build-essential git pkg-config gdb valgrind gcc libmicrohttpd-dev doxygen graphviz && \
curl -sL https://github.com/Kitware/CMake/releases/download/v3.14.5/cmake-3.14.5-Linux-x86_64.tar.gz | tar xzf - -C /opt && \
cp /opt/cmake-3.14.5-Linux-x86_64/bin/* /usr/local/bin/ && \
cp -R /opt/cmake-3.14.5-Linux-x86_64/share/cmake-3.14 /usr/local/share/ && \
curl -sL https://dl.google.com/go/go1.13.1.linux-amd64.tar.gz 2> /dev/null | tar xzf - -C /usr/local && \
mkdir -p /gopath/{src,bin} && \
printf 'export GOPATH=/gopath\nexport PATH=$PATH:/usr/local/go/bin:/gopath/bin\n' > /root/.bash_profile && \
printf '#!/usr/bin/env bash\nsource /root/.bash_profile\nexec /bin/bash $@\n' > /entrypoint && \
chmod +x /entrypoint && \
GOPATH=/gopath /usr/local/go/bin/go get github.com/prometheus/prom2json && \
GOPATH=/gopath /usr/local/go/bin/go install github.com/prometheus/prom2json/cmd/prom2json && \
GOPATH=/gopath /usr/local/go/bin/go get github.com/git-chglog/git-chglog && \
GOPATH=/gopath /usr/local/go/bin/go install github.com/git-chglog/git-chglog/cmd/git-chglog && \
rm -rf /var/lib/apt/lists/*
WORKDIR /code
ENTRYPOINT ["/entrypoint"]
EOF
}

autolib_write_dockerfile(){
local docker_image="$1"
local r
case "$docker_image" in
( ubuntu:18.04 | ubuntu:16.04 | debian:buster | debian:stretch | debian:jessie ) {
autolib_debian_template | sed "s/__DOCKER_IMAGE__/$docker_image/g" > ${PROJECT_ROOT}/docker/Dockerfile || {
r=$?
autolib_output_error "failed to generate dockerfile"
return $r
}
} ;;

( * ) {
r=1
autolib_output_error "unsupported DOCKER_IMAGE: $docker_image"
return $r
} ;;
esac
}
20 changes: 0 additions & 20 deletions docker/Dockerfile

This file was deleted.

2 changes: 1 addition & 1 deletion example/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ int main(int argc, const char **argv) {
}


struct MHD_Daemon *daemon = promhttp_start_daemon(MHD_USE_INTERNAL_POLLING_THREAD, 8000, NULL, NULL);
struct MHD_Daemon *daemon = promhttp_start_daemon(MHD_USE_SELECT_INTERNALLY, 8000, NULL, NULL);
if (daemon == NULL) {
return 1;
}
Expand Down
2 changes: 2 additions & 0 deletions prom/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
cmake_minimum_required(VERSION 3.14.5)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)

execute_process(
COMMAND cat ${CMAKE_CURRENT_SOURCE_DIR}/../VERSION
Expand Down
6 changes: 0 additions & 6 deletions prom/src/prom_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,6 @@ int prom_map_destroy(prom_map_t *self) {
prom_free(self->addrs);
self->addrs = NULL;

r = pthread_rwlock_unlock(self->rwlock);
if (r) {
PROM_LOG(PROM_PTHREAD_RWLOCK_UNLOCK_ERROR);
ret = r;
}

r = pthread_rwlock_destroy(self->rwlock);
if (r) {
PROM_LOG(PROM_PTHREAD_RWLOCK_DESTROY_ERROR)
Expand Down
6 changes: 0 additions & 6 deletions prom/src/prom_metric.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,6 @@ int prom_metric_destroy(prom_metric_t *self) {
self->formatter = NULL;
if (r) ret = r;

r = pthread_rwlock_unlock(self->rwlock);
if (r) {
PROM_LOG(PROM_PTHREAD_RWLOCK_UNLOCK_ERROR);
ret = r;
}

r = pthread_rwlock_destroy(self->rwlock);
if (r) {
PROM_LOG(PROM_PTHREAD_RWLOCK_DESTROY_ERROR);
Expand Down
3 changes: 0 additions & 3 deletions prom/src/prom_metric_sample_histogram.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,6 @@ int prom_metric_sample_histogram_destroy(prom_metric_sample_histogram_t *self) {
if (r) ret = r;
self->metric_formatter = NULL;

r = pthread_rwlock_unlock(self->rwlock);
if (r) ret = r;

r = pthread_rwlock_destroy(self->rwlock);
if (r) ret = r;

Expand Down
2 changes: 2 additions & 0 deletions promhttp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
cmake_minimum_required(VERSION 3.14.5)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)

execute_process(
COMMAND cat ${CMAKE_CURRENT_SOURCE_DIR}/../VERSION
Expand Down
2 changes: 2 additions & 0 deletions promtest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
cmake_minimum_required(VERSION 3.14.5)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)

execute_process(
COMMAND cat ${CMAKE_CURRENT_SOURCE_DIR}/../VERSION
Expand Down
2 changes: 1 addition & 1 deletion promtest/test/promtest_counter.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ int promtest_counter_setup(void) {
promhttp_set_active_collector_registry(NULL);

// Start the HTTP server
promtest_daemon = promhttp_start_daemon(MHD_USE_INTERNAL_POLLING_THREAD, 8000, NULL, NULL);
promtest_daemon = promhttp_start_daemon(MHD_USE_SELECT_INTERNALLY, 8000, NULL, NULL);

if (promtest_daemon == NULL) return 1;
else return 0;
Expand Down
2 changes: 1 addition & 1 deletion promtest/test/promtest_gauge.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ int promtest_gauge_setup(void) {
promhttp_set_active_collector_registry(NULL);

// Start the HTTP server
promtest_daemon = promhttp_start_daemon(MHD_USE_INTERNAL_POLLING_THREAD, 8000, NULL, NULL);
promtest_daemon = promhttp_start_daemon(MHD_USE_SELECT_INTERNALLY, 8000, NULL, NULL);

if (promtest_daemon == NULL) return 1;
else return 0;
Expand Down

0 comments on commit cacee63

Please sign in to comment.