From 3b6f05dbc25ef2dae48f031f5560da072343b7aa Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Tue, 21 Sep 2021 15:46:55 +0200 Subject: [PATCH] prepare for dockerizing --- Dockerfile | 34 ++++++++++++++++++++++++++++++++++ sink/Makefile | 2 +- sink/logging.c | 4 +++- sink/sink20169.c | 6 +++++- 4 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..71d8675 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,34 @@ +FROM alpine:3.13 AS builder + +ARG VERSION + +COPY sink/ /tmp/sink + +RUN \ + apk update && \ + apk add alpine-sdk && \ + apk add libconfig-dev && \ + apk add postgresql-dev && \ + cd /tmp/sink && \ + make VERSION=${VERSION} + + +FROM alpine:3.13 + +COPY --from=builder /tmp/sink/build/sink20169 /usr/local/bin/ + +RUN \ + apk add --no-cache libpq && \ + apk add --no-cache libconfig && \ + mkdir /etc/sink + +EXPOSE 20169/udp + +VOLUME /etc/sink + +CMD [ "/usr/local/bin/sink20169", "-f", "/etc/sink/sink20169.cfg", "-n", "nobody", "-v" ] + + + + + diff --git a/sink/Makefile b/sink/Makefile index aced2ed..e2365a5 100644 --- a/sink/Makefile +++ b/sink/Makefile @@ -5,7 +5,7 @@ sha256.c \ sink20169.c \ logging.c -VERSION := $(shell git rev-parse --short=8 HEAD) +VERSION ?= $(shell git rev-parse --short=8 HEAD) UNAME_S := $(shell uname -s) CC = gcc diff --git a/sink/logging.c b/sink/logging.c index e1d4e4f..221b9e9 100644 --- a/sink/logging.c +++ b/sink/logging.c @@ -7,6 +7,8 @@ #include extern bool verbose; +extern bool debug; + int facility = LOG_LOCAL0; void setfacility(const char *facility_p) { @@ -42,7 +44,7 @@ void logmsg(int prio, const char* format, ...) { vsnprintf(buf, sizeof(buf), format, vl); va_end(vl); - if (verbose) { + if (verbose && (debug || (prio != LOG_DEBUG))) { printf("%s\n", buf); } diff --git a/sink/sink20169.c b/sink/sink20169.c index 8e3d900..d3b941b 100644 --- a/sink/sink20169.c +++ b/sink/sink20169.c @@ -53,7 +53,7 @@ typedef struct { } t_commonHandle; bool verbose = false; - +bool debug = false; int openDatabaseConnection(t_commonHandle *handle) { @@ -347,6 +347,7 @@ void usage() { printf("\nUsage\n"); printf(" -f FILENAME ...... Config file to be used\n"); printf(" -v ............... Verbose, writes all logging on stdout too\n"); + printf(" -d ............... Also log debug output\n"); printf(" -s FACILITY ...... Sets syslog facility, only LOCAL[0..7]\n"); printf(" USER and DAEMON are supported\n"); printf(" -n USER .......... If started as root drop privileges and become\n"); @@ -374,6 +375,9 @@ int main(int argc, char **argv) { case 'v': verbose = true; break; + case 'd': + debug = true; + break; case 's': setfacility(optarg); break;