From fbf3b50085c690e921f51d129c0c079b6643e509 Mon Sep 17 00:00:00 2001 From: Pingkai Liu Date: Mon, 13 Aug 2018 13:37:14 -0400 Subject: [PATCH 1/2] fix musl compile issue. daemonize() reassign stdin/stdout/stderr which is not standard. use dup() instead. --- stud.c | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/stud.c b/stud.c index d31eaca..2aba01e 100644 --- a/stud.c +++ b/stud.c @@ -1750,28 +1750,19 @@ void daemonize () { exit(0); } - /* close standard streams */ - fclose(stdin); - fclose(stdout); - fclose(stderr); - - /* reopen standard streams to null device */ - stdin = fopen(NULL_DEV, "r"); - if (stdin == NULL) { - ERR("Unable to reopen stdin to %s: %s\n", NULL_DEV, strerror(errno)); - exit(1); - } - stdout = fopen(NULL_DEV, "w"); - if (stdout == NULL) { - ERR("Unable to reopen stdout to %s: %s\n", NULL_DEV, strerror(errno)); - exit(1); - } - stderr = fopen(NULL_DEV, "w"); - if (stderr == NULL) { - ERR("Unable to reopen stderr to %s: %s\n", NULL_DEV, strerror(errno)); - exit(1); + /* close standard fds */ + close(0); + close(1); + close(2); + + if (open("/dev/null", O_RDWR) != 0) { + syslog(LOG_ERR, "Unable to open /dev/null: %s", strerror(errno)); + exit(1); } + dup(0); + dup(0); + /* this is child, the new master */ pid_t s = setsid(); if (s < 0) { From 9da6e4f31d6eb80dbd192de7018015fa37e3a8da Mon Sep 17 00:00:00 2001 From: "Liu, Pingkai" Date: Mon, 13 Aug 2018 14:53:18 -0400 Subject: [PATCH 2/2] Add static build option --- Makefile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Makefile b/Makefile index eba3e9c..a13d602 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,12 @@ BINDIR = $(PREFIX)/bin MANDIR = $(PREFIX)/share/man CFLAGS = -O2 -g -std=c99 -fno-strict-aliasing -Wall -W -D_GNU_SOURCE -I/usr/local/include + +ifeq ($(ENABLE_STATIC),1) +LDFLAGS = -static -lssl -lcrypto -lev -lz -ldl -lm -L/usr/local/lib +else LDFLAGS = -lssl -lcrypto -lev -L/usr/local/lib +endif OBJS = stud.o ringbuffer.o configuration.o all: realall