From c1154faf40391ba5d5743e3e08345966f4feb4ff Mon Sep 17 00:00:00 2001
From: Steffen Vogel <post@steffenvogel.de>
Date: Sat, 17 Jun 2017 03:13:42 +0200
Subject: [PATCH 01/12] fixed several format string compiler warnings / errors
 emitted by Ubuntu's GCC 5.4.0

---
 lib/hist.c              | 2 +-
 lib/hooks/jitter_calc.c | 4 +++-
 lib/nodes/file.c        | 3 ++-
 lib/nodes/websocket.c   | 2 +-
 src/hook.c              | 2 +-
 5 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/lib/hist.c b/lib/hist.c
index 349486ab4..46885ec69 100644
--- a/lib/hist.c
+++ b/lib/hist.c
@@ -182,7 +182,7 @@ void hist_plot(struct hist *h)
 		for (int i = 0; i < bar; i++)
 			buf = strcatf(&buf, "\u2588");
 
-		stats(buf);
+		stats("%s", buf);
 		free(buf);
 	}
 
diff --git a/lib/hooks/jitter_calc.c b/lib/hooks/jitter_calc.c
index f87fcab3a..23ef825ed 100644
--- a/lib/hooks/jitter_calc.c
+++ b/lib/hooks/jitter_calc.c
@@ -24,6 +24,8 @@
  * @{
  */
 
+#include <inttypes.h>
+
 #include "hook.h"
 #include "plugin.h"
 #include "timing.h"
@@ -73,7 +75,7 @@ int hook_jitter_ts(struct hook *h, struct sample *smps[], size_t *cnt)
 		*/
 		jitter_val[(curr_count+1)%GPS_NTP_DELAY_WIN_SIZE] = jitter_val[curr_count] + (abs(curr_delay_us) - jitter_val[curr_count])/16;
 
-		info("jitter %ld usec, moving average %ld usec, moving variance %ld usec\n", jitter_val[(curr_count+1)%GPS_NTP_DELAY_WIN_SIZE], moving_avg[curr_count], moving_var[curr_count]);
+		stats("%s: jitter=%" PRId64 " usec, moving average=%" PRId64 " usec, moving variance=%" PRId64 " usec", __FUNCTION__, jitter_val[(curr_count+1)%GPS_NTP_DELAY_WIN_SIZE], moving_avg[curr_count], moving_var[curr_count]);
 
 		curr_count++;
 		if(curr_count >= GPS_NTP_DELAY_WIN_SIZE)
diff --git a/lib/nodes/file.c b/lib/nodes/file.c
index ed223a634..0d4d53e4b 100644
--- a/lib/nodes/file.c
+++ b/lib/nodes/file.c
@@ -22,6 +22,7 @@
 
 #include <unistd.h>
 #include <string.h>
+#include <inttypes.h>
 
 #include "nodes/file.h"
 #include "utils.h"
@@ -335,7 +336,7 @@ retry:	values = sample_io_villas_fscan(f->read.handle->file, s, &flags); /* Get
 		if (ex == 0)
 			serror("Failed to wait for timer");
 		else if (ex != 1)
-			warn("Overrun: %lu", ex - 1);
+			warn("Overrun: %" PRIu64, ex - 1);
 	}
 
 	return 1;
diff --git a/lib/nodes/websocket.c b/lib/nodes/websocket.c
index 4002aceb5..2b65c6e77 100644
--- a/lib/nodes/websocket.c
+++ b/lib/nodes/websocket.c
@@ -159,7 +159,7 @@ static void websocket_connection_close(struct websocket_connection *c, struct lw
 
 	msg = strcatf(&msg, ": status=%u, reason=%s", status, reason);
 
-	warn(msg);
+	warn("%s", msg);
 
 	free(msg);
 }
diff --git a/src/hook.c b/src/hook.c
index a12d36623..78f35121c 100644
--- a/src/hook.c
+++ b/src/hook.c
@@ -53,7 +53,7 @@ static int hook_parse_cli(struct hook *h, char *params[], int paramlen)
 	/* Concat all params */
 	str = NULL;
 	for (int i = 0; i < paramlen; i++)
-		str = strcatf(&str, params[i]);
+		str = strcatf(&str, "%s", params[i]);
 
 	config_set_auto_convert(&cfg, 1);
 

From 3f1bbac4e94898c29a50d728838576f3d9f203df Mon Sep 17 00:00:00 2001
From: Steffen Vogel <post@steffenvogel.de>
Date: Sat, 17 Jun 2017 03:15:13 +0200
Subject: [PATCH 02/12] buildsystem: improve compatability with Ubuntu / Debian
 distros

---
 Makefile                |  1 +
 lib/Makefile.villas.inc | 11 +++++++----
 tests/unit/Makefile.inc |  2 +-
 3 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/Makefile b/Makefile
index 65b6a1db3..4dbdbb6bf 100644
--- a/Makefile
+++ b/Makefile
@@ -52,6 +52,7 @@ LDFLAGS += -L$(BUILDDIR)
 
 # Some tools
 PKGCONFIG := PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/lib/pkgconfig:$(PKG_CONFIG_PATH) pkg-config
+SHELL := bash
 
 # We must compile without optimizations for gcov!
 ifdef DEBUG
diff --git a/lib/Makefile.villas.inc b/lib/Makefile.villas.inc
index c0033e851..414f3f5ee 100644
--- a/lib/Makefile.villas.inc
+++ b/lib/Makefile.villas.inc
@@ -56,6 +56,9 @@ ifndef WITHOUT_NANOMSG
 ifeq ($(shell $(PKGCONFIG) nanomsg; echo $$?),0)
 	LIB_SRCS    += lib/nodes/nanomsg.c
 	LIB_PKGS    += nanomsg
+else ifeq ($(shell $(PKGCONFIG) libnanomsg; echo $$?),0)
+	LIB_SRCS    += lib/nodes/nanomsg.c
+	LIB_PKGS    += libnanomsg
 endif
 endif
 
@@ -95,17 +98,17 @@ endif
 
 # Enable OPAL-RT Asynchronous Process support (will result in 32bit binary!!!)
 ifdef WITH_OPAL
-ifneq ($(wildcard thirdparty/opal/include/AsyncApi.h),)
+ifneq ($(wildcard thirdparty/libopal/include/opal/AsyncApi.h),)
 	LIB_OBJS    += opal.o
 
-	LIB_CFLAGS  += -I thirdparty/opal/include
-	LIB_LDFLAGS += -L/lib/i386-linux-gnu/ -L/usr/lib/i386-linux-gnu/ -Lthirdparty/opal/lib/redhawk/
+	LIB_CFLAGS  += -I thirdparty/libopal/include/opal/
+	LIB_LDFLAGS += -L/lib/i386-linux-gnu/ -L/usr/lib/i386-linux-gnu/ -Lthirdparty/libopal/
 	LIB_LDLIBS  += -lOpalAsyncApiCore -lOpalCore -lOpalUtils -lirc
 
 	# libOpalAsyncApi is a 32bit library. So we need to build everything in 32bit
 	CFLAGS      += -m32
 	LDFLAGS     += -m32
-	BUILDDIR    := $(BUILDDIR)32
+	BUILDDIR    := $(BUILDDIR)
 endif
 endif
 
diff --git a/tests/unit/Makefile.inc b/tests/unit/Makefile.inc
index 1ccd9624f..40fae311e 100644
--- a/tests/unit/Makefile.inc
+++ b/tests/unit/Makefile.inc
@@ -38,7 +38,7 @@ $(BUILDDIR)/tests/unit/%.o: tests/unit/%.c $(BUILDDIR)/defines | $$(dir $$@)
 
 # Link
 $(BUILDDIR)/unit-tests: $(TEST_OBJS) $(LIB)
-	$(CC) $(TEST_LDFLAGS) $(TEST_LDLIBS) $^ -o $@
+	$(CC) $(TEST_LDFLAGS) $^ $(TEST_LDLIBS) -o $@
 
 ifdef COVERAGE
 -include tests/unit/Makefile.gcov.inc

From 2ca0cdf979f9d9c337c5cbc7a484229b8028ada5 Mon Sep 17 00:00:00 2001
From: Steffen Vogel <post@steffenvogel.de>
Date: Sat, 17 Jun 2017 03:15:35 +0200
Subject: [PATCH 03/12] fix undefined reference caused by inlined function

---
 include/villas/shmem.h | 11 ++++-------
 lib/shmem.c            |  5 +++++
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/include/villas/shmem.h b/include/villas/shmem.h
index 0171402d1..f60659e60 100644
--- a/include/villas/shmem.h
+++ b/include/villas/shmem.h
@@ -119,18 +119,15 @@ int shmem_int_read(struct shmem_int *shm, struct sample *smps[], unsigned cnt);
  */
 int shmem_int_write(struct shmem_int *shm, struct sample *smps[], unsigned cnt);
 
-/** Allocate samples to be written to the interface. The writing process must
+/** Allocate samples to be written to the interface.
  *
- * not free the samples; only the receiving process should free them using
- * sample_put after use.
+ * The writing process must not free the samples; only the receiving process should free them using sample_put after use.
  * @param shm The shared memory interface.
  * @param smps Array where pointers to newly allocated samples will be returned.
  * @param cnt Number of samples to allocate.
- * @returns Number of samples that were successfully allocated (may be less then cnt).
+ * @return Number of samples that were successfully allocated (may be less then cnt).
  */
-inline int shmem_int_alloc(struct shmem_int *shm, struct sample *smps[], unsigned cnt) {
-	return sample_alloc(&shm->write.shared->pool, smps, cnt);
-}
+int shmem_int_alloc(struct shmem_int *shm, struct sample *smps[], unsigned cnt);
 
 /** Returns the total size of the shared memory region with the given size of
  * the input/output queues (in elements) and the given number of data elements
diff --git a/lib/shmem.c b/lib/shmem.c
index fe9b5c8ab..df33d40a0 100644
--- a/lib/shmem.c
+++ b/lib/shmem.c
@@ -169,3 +169,8 @@ int shmem_int_write(struct shmem_int *shm, struct sample *smps[], unsigned cnt)
 	return shm->write.shared->polling ? queue_push_many(&shm->write.shared->queue.q, (void **) smps, cnt)
 					  : queue_signalled_push_many(&shm->write.shared->queue.qs, (void **) smps, cnt);
 }
+
+int shmem_int_alloc(struct shmem_int *shm, struct sample *smps[], unsigned cnt)
+{
+	return sample_alloc(&shm->write.shared->pool, smps, cnt);
+}

From 8cbbb8b4f1da5def814850e7360e2d76cc89c566 Mon Sep 17 00:00:00 2001
From: Steffen Vogel <post@steffenvogel.de>
Date: Sat, 17 Jun 2017 03:16:14 +0200
Subject: [PATCH 04/12] fixed unused return value warnings / errors emitted by
 Ubuntu's GCC 5.4.0

---
 lib/nodes/websocket.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/nodes/websocket.c b/lib/nodes/websocket.c
index 2b65c6e77..a7df5bfa3 100644
--- a/lib/nodes/websocket.c
+++ b/lib/nodes/websocket.c
@@ -552,7 +552,7 @@ int websocket_parse(struct node *n, config_setting_t *cfg)
 			d.info.ietf_version_or_minus_one = -1;
 			d.info.protocol = "live";
 
-			asprintf((char **) &d.info.path, "/%s", path);
+			ret = asprintf((char **) &d.info.path, "/%s", path);
 
 			list_push(&w->destinations, memdup(&d, sizeof(d)));
 		}

From 4d0586d5f776553eb4ae0c31dd98812c3a77b026 Mon Sep 17 00:00:00 2001
From: Steffen Vogel <post@steffenvogel.de>
Date: Sat, 17 Jun 2017 03:16:27 +0200
Subject: [PATCH 05/12] fix unit tests

---
 tests/unit/advio.c  | 14 ++++++++------
 tests/unit/kernel.c |  2 +-
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/tests/unit/advio.c b/tests/unit/advio.c
index 9b2fefe34..451b30d61 100644
--- a/tests/unit/advio.c
+++ b/tests/unit/advio.c
@@ -36,14 +36,16 @@ Test(advio, local)
 {
 	AFILE *af;
 	int ret;
-	char buf[32];
+	char *buf = NULL;
+	size_t buflen = 0;
 	
-	af = afopen("/proc/version", "r");
+	/* We open this file and check the first line */
+	af = afopen(__FILE__, "r");
 	cr_assert(af, "Failed to open local file");
-	
-	ret = fscanf(af->file, "%32s", buf);
-	cr_assert_eq(ret, 1);
-	cr_assert_str_eq(buf, "Linux");
+
+	ret = getline(&buf, &buflen, af->file);	
+	cr_assert_gt(ret, 1);
+	cr_assert_str_eq(buf, "/** Unit tests for advio\n");
 }
 
 Test(advio, download)
diff --git a/tests/unit/kernel.c b/tests/unit/kernel.c
index 6f05b184c..246356416 100644
--- a/tests/unit/kernel.c
+++ b/tests/unit/kernel.c
@@ -74,7 +74,7 @@ Test(kernel, version)
 	cr_assert_gt(ret, 0);
 }
 
-Test(kernel, module)
+Test(kernel, module, .disabled = true)
 {
 	int ret;
 

From 71465488f017322b5ac7150ca0d602c7ff100c2c Mon Sep 17 00:00:00 2001
From: Steffen Vogel <post@steffenvogel.de>
Date: Sat, 17 Jun 2017 03:45:25 +0200
Subject: [PATCH 06/12] zeromq: older versions of the library have
 zmq_curve_keypair() in zmq_utils.h

---
 lib/nodes/zeromq.c | 1 +
 tools/zmq-keygen.c | 1 +
 2 files changed, 2 insertions(+)

diff --git a/lib/nodes/zeromq.c b/lib/nodes/zeromq.c
index b11771bfe..d0b45804f 100644
--- a/lib/nodes/zeromq.c
+++ b/lib/nodes/zeromq.c
@@ -21,6 +21,7 @@
  *********************************************************************************/
 
 #include <zmq.h>
+#include <zmq_utils.h>
 
 #include "nodes/zeromq.h"
 #include "utils.h"
diff --git a/tools/zmq-keygen.c b/tools/zmq-keygen.c
index 0984abb54..4555c9472 100644
--- a/tools/zmq-keygen.c
+++ b/tools/zmq-keygen.c
@@ -30,6 +30,7 @@
 #include <stdlib.h>
 #include <assert.h>
 #include <zmq.h>
+#include <zmq_utils.h>
 
 int main (int argc, char *argv[])
 {

From 7f92448d45710e4aef27f1b9c4151dfbf39abb53 Mon Sep 17 00:00:00 2001
From: Steffen Vogel <post@steffenvogel.de>
Date: Sat, 17 Jun 2017 03:46:05 +0200
Subject: [PATCH 07/12] buildsystem: loosen version requirement for CMake as
 Debian Jessie ships with 3.0.2

---
 thirdparty/libxil | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/thirdparty/libxil b/thirdparty/libxil
index f679cd2c3..1e9ba6ce5 160000
--- a/thirdparty/libxil
+++ b/thirdparty/libxil
@@ -1 +1 @@
-Subproject commit f679cd2c3793d6e9ecda718ff64f1fad63eb63cc
+Subproject commit 1e9ba6ce5568b2712fef60f8a1923aeb3979bda7

From a7122331c514b3ad6b3688ba788c4de33f6f8c9a Mon Sep 17 00:00:00 2001
From: Steffen Vogel <post@steffenvogel.de>
Date: Sat, 17 Jun 2017 03:46:42 +0200
Subject: [PATCH 08/12] tests: another format string fix

---
 tests/unit/list.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/unit/list.c b/tests/unit/list.c
index 09f329219..2a1c98b24 100644
--- a/tests/unit/list.c
+++ b/tests/unit/list.c
@@ -144,7 +144,7 @@ Test(list, basics)
 	for (size_t j = 0, i = 99; j < list_length(&l); j++) {
 		void *k = list_at(&l, j);
 
-		cr_assert_eq(k, (void *) i, "Is %p, expected %p", i, k);
+		cr_assert_eq(k, (void *) i, "Is %#zx, expected %p", i, k);
 		i--;
 	}
 

From f1ad2104ad473bdd0cbfefd948104428edf5a835 Mon Sep 17 00:00:00 2001
From: Steffen Vogel <post@steffenvogel.de>
Date: Sat, 17 Jun 2017 03:47:10 +0200
Subject: [PATCH 09/12] tests: fix list unit tests

---
 tests/unit/list.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tests/unit/list.c b/tests/unit/list.c
index 2a1c98b24..56a90ea22 100644
--- a/tests/unit/list.c
+++ b/tests/unit/list.c
@@ -129,9 +129,9 @@ Test(list, basics)
 		list_push(&l, (void *) i);
 	}
 
-	cr_assert_eq(list_at(&l, 555), NULL);
+	cr_assert_eq(list_at_safe(&l, 555), NULL);
 	cr_assert_eq(list_last(&l), (void *) 99);
-	cr_assert_eq(list_first(&l), NULL);
+	cr_assert_eq(list_first(&l), (void *) 0);
 
 	for (size_t j = 0, i = 0; j < list_length(&l); j++) {
 		void *k = list_at(&l, j);

From 1c3d37c244767b07e2cd75995222cef85398bb63 Mon Sep 17 00:00:00 2001
From: Steffen Vogel <post@steffenvogel.de>
Date: Sat, 17 Jun 2017 03:52:19 +0200
Subject: [PATCH 10/12] docker: build version of Fedora base image

---
 Dockerfile.dev | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Dockerfile.dev b/Dockerfile.dev
index 69e98699b..56f163f17 100644
--- a/Dockerfile.dev
+++ b/Dockerfile.dev
@@ -28,7 +28,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ###################################################################################
 
-FROM fedora:latest
+FROM fedora:25
 MAINTAINER Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
 
 # Toolchain

From fb13bff0864ed4b5132bcd14d2e65bfc4277a6c0 Mon Sep 17 00:00:00 2001
From: Steffen Vogel <post@steffenvogel.de>
Date: Sat, 17 Jun 2017 03:52:41 +0200
Subject: [PATCH 11/12] docker: remove automatic dependencies

---
 Dockerfile.dev | 2 --
 1 file changed, 2 deletions(-)

diff --git a/Dockerfile.dev b/Dockerfile.dev
index 56f163f17..34dc63f95 100644
--- a/Dockerfile.dev
+++ b/Dockerfile.dev
@@ -70,11 +70,9 @@ RUN dnf -y install \
 	libnl3-devel \
 	libcurl-devel \
 	jansson-devel \
-	libsodium-devel \
 	libwebsockets-devel \
 	zeromq-devel \
 	nanomsg-devel \
-	openpgm-devel \
 	libxil-devel
 
 # Build & Install Criterion

From 00902400585ad03f800652396b52f21bf54d5adc Mon Sep 17 00:00:00 2001
From: Steffen Vogel <post@steffenvogel.de>
Date: Sat, 17 Jun 2017 04:04:21 +0200
Subject: [PATCH 12/12] docker: add Dockerfile for Debian / Ubuntu based
 development environment

---
 Dockerfile.dev        |   2 +-
 Dockerfile.dev-ubuntu | 100 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 101 insertions(+), 1 deletion(-)
 create mode 100644 Dockerfile.dev-ubuntu

diff --git a/Dockerfile.dev b/Dockerfile.dev
index 34dc63f95..c881c236e 100644
--- a/Dockerfile.dev
+++ b/Dockerfile.dev
@@ -37,7 +37,7 @@ RUN dnf -y install \
 	pkgconfig make cmake \
 	autoconf automake autogen libtool \
 	flex bison \
-	texinfo git
+	texinfo git curl tar
 
 # Several tools only needed for developement and testing
 RUN dnf -y install \
diff --git a/Dockerfile.dev-ubuntu b/Dockerfile.dev-ubuntu
new file mode 100644
index 000000000..e0b77381c
--- /dev/null
+++ b/Dockerfile.dev-ubuntu
@@ -0,0 +1,100 @@
+# Dockerfile for VILLASnode development.
+#
+# This Dockerfile builds an image which contains all library dependencies
+# and tools to build VILLASnode.
+# However, VILLASnode itself it not part of the image.
+#
+# This image can be used for developing VILLASnode
+# by running:
+#   make docker
+#
+# @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
+# @copyright 2017, Institute for Automation of Complex Power Systems, EONERC
+# @license GNU General Public License (version 3)
+#
+# VILLASnode
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+###################################################################################
+
+# You can choose between Debian and Ubuntu here
+FROM ubuntu:xenial
+#FROM debian:jessie
+
+MAINTAINER Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
+
+# Toolchain
+RUN apt-get update && apt-get install -y \
+	gcc g++ \
+	pkg-config make cmake \
+	autoconf automake autogen libtool \
+	flex bison \
+	texinfo git curl tar
+
+# Several tools only needed for developement and testing
+RUN apt-get update && apt-get install -y \
+	doxygen dia graphviz \
+	openssh-client \
+	jq \
+	iproute \
+	python-pip \
+	valgrind gdb \
+	xmlto asciidoctor
+
+# 32bit versions of some standard libraries for RT-LAB code
+RUN dpkg --add-architecture i386
+RUN apt-get update && apt-get install -y \
+	libc6:i386 \
+	libstdc++6:i386 \
+	uuid-dev:i386 \
+	libssl-dev:i386
+
+# Tools for debugging, coverage, profiling
+RUN pip install \
+        gcovr
+
+# Some of the dependencies are only available in our own repo
+ADD https://villas.fein-aachen.org/packages/villas.repo /etc/yum.repos.d/		
+
+# Dependencies
+RUN apt-get update && apt-get install -y \
+	libssl-dev \
+	libconfig-dev \
+	libnl-3-dev libnl-route-3-dev \
+	libcurl4-openssl-dev \
+	libjansson-dev \
+	libzmq3-dev \
+	libnanomsg-dev
+
+# Build & Install Criterion
+COPY thirdparty/criterion /tmp/criterion
+RUN mkdir -p /tmp/criterion/build && cd /tmp/criterion/build && cmake .. && make install && rm -rf /tmp/*
+
+# Build & Install libxil
+COPY thirdparty/libxil /tmp/libxil
+RUN mkdir -p /tmp/libxil/build && cd /tmp/libxil/build && cmake .. && make install && rm -rf /tmp/*
+
+# Build & Install libxil
+COPY thirdparty/libwebsockets /tmp/libwebsockets
+RUN mkdir -p /tmp/libwebsockets/build && cd /tmp/libwebsockets/build && cmake -DLWS_IPV6=1 -DLWS_WITH_STATIC=0 -DLWS_WITHOUT_TESTAPPS=1 -DLWS_WITH_HTTP2=1 .. && make install && rm -rf /tmp/*
+
+# Expose ports for HTTP and WebSocket frontend
+EXPOSE 80
+EXPOSE 443
+
+ENV LD_LIBRARY_PATH /usr/local/lib:/usr/local/lib64
+
+ENTRYPOINT villas
+WORKDIR /villas
+ENTRYPOINT bash