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 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) {