MEDIUM: add haproxy-systemd-wrapper

Currently, to reload haproxy configuration, you have to use "-sf".

There is a problem with this way of doing things. First of all, in the systemd world,
reload commands should be "oneshot" ones, which means they should not be the new main
process but rather a tool which makes a call to it and then exits. With the current approach,
the reload command is the new main command and moreover, it makes the previous one exit.
Systemd only tracks the main program, seeing it ending, it assumes it either finished or failed,
and kills everything remaining as a grabage collector. We then end up with no haproxy running
at all.

This patch adds wrapper around haproxy, no changes at all have been made into it,
so it's not intrusive and doesn't change anything for other hosts. What this wrapper does
is basically launching haproxy as a child, listen to the SIGUSR2 (not to conflict with
haproxy itself) signal, and spawing a new haproxy with "-sf" as a child to relay the
first one.

Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
diff --git a/Makefile b/Makefile
index f1eed55..ca9e1b2 100644
--- a/Makefile
+++ b/Makefile
@@ -593,7 +593,7 @@
 	@echo
 	@exit 1
 else
-all: haproxy
+all: haproxy haproxy-systemd-wrapper
 endif
 
 OBJS = src/haproxy.o src/sessionhash.o src/base64.o src/protocol.o \
@@ -618,12 +618,17 @@
 OBJS += src/trace.o
 endif
 
+WRAPPER_OBJS = src/haproxy-systemd-wrapper.o
+
 # Not used right now
 LIB_EBTREE = $(EBTREE_DIR)/libebtree.a
 
 haproxy: $(OBJS) $(OPTIONS_OBJS) $(EBTREE_OBJS)
 	$(LD) $(LDFLAGS) -o $@ $^ $(LDOPTS)
 
+haproxy-systemd-wrapper: $(WRAPPER_OBJS)
+	$(LD) $(LDFLAGS) -o $@ $^ $(LDOPTS)
+
 $(LIB_EBTREE): $(EBTREE_OBJS)
 	$(AR) rv $@ $^
 
@@ -646,6 +651,11 @@
 	      -DBUILD_OPTIONS='"$(strip $(BUILD_OPTIONS))"' \
 	       -c -o $@ $<
 
+src/haproxy-systemd-wrapper.o:	src/haproxy-systemd-wrapper.c
+	$(CC) $(COPTS) \
+	      -DSBINDIR='"$(strip $(SBINDIR))"' \
+	       -c -o $@ $<
+
 src/dlmalloc.o: $(DLMALLOC_SRC)
 	$(CC) $(COPTS) -DDEFAULT_MMAP_THRESHOLD=$(DLMALLOC_THRES) -c -o $@ $<
 
@@ -659,9 +669,10 @@
 		install -m 644 doc/$$x.txt $(DESTDIR)$(DOCDIR) ; \
 	done
 
-install-bin: haproxy
+install-bin: haproxy haproxy-systemd-wrapper
 	install -d $(DESTDIR)$(SBINDIR)
 	install haproxy $(DESTDIR)$(SBINDIR)
+	install haproxy-systemd-wrapper $(DESTDIR)$(SBINDIR)
 
 install: install-bin install-man install-doc
 
@@ -670,6 +681,7 @@
 	for dir in . src include/* doc ebtree; do rm -f $$dir/*~ $$dir/*.rej $$dir/core; done
 	rm -f haproxy-$(VERSION).tar.gz haproxy-$(VERSION)$(SUBVERS).tar.gz
 	rm -f haproxy-$(VERSION) nohup.out gmon.out
+	rm -f haproxy-systemd-wrapper
 
 tags:
 	find src include \( -name '*.c' -o -name '*.h' \) -print0 | \