Skip to content

Commit

Permalink
systemd: replace vendored files with libsystemd (beanstalkd#577)
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmayhew authored May 28, 2020
1 parent cde9fe9 commit c73be66
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 707 deletions.
18 changes: 16 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ LDLIBS?=

OS?=$(shell uname | tr 'A-Z' 'a-z')
INSTALL?=install
PKG_CONFIG?=pkg-config

ifeq ($(OS),sunos)
override LDFLAGS += -lxnet -lsocket -lnsl
Expand All @@ -26,7 +27,6 @@ OFILES=\
net.o\
primes.o\
prot.o\
sd-daemon.o\
serv.o\
time.o\
tube.o\
Expand All @@ -43,12 +43,26 @@ TOFILES=\

HFILES=\
dat.h\
sd-daemon.h\

ifeq ($(OS),linux)
LDLIBS+=-lrt
endif

# systemd support can be configured via USE_SYSTEMD:
# no: disabled
# yes: enabled, build fails if libsystemd is not found
# otherwise: enabled if libsystemd is found
ifneq ($(USE_SYSTEMD),no)
ifeq ($(shell $(PKG_CONFIG) --exists libsystemd && echo $$?),0)
LDLIBS+=$(shell $(PKG_CONFIG) --libs libsystemd)
CPPFLAGS+=-DHAVE_LIBSYSTEMD
else
ifeq ($(USE_SYSTEMD),yes)
$(error USE_SYSTEMD is set to "$(USE_SYSTEMD)", but $(PKG_CONFIG) cannot find libsystemd)
endif
endif
endif

CLEANFILES=\
vers.c\
$(wildcard *.gc*)
Expand Down
7 changes: 6 additions & 1 deletion net.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "dat.h"
#include "sd-daemon.h"
#include <netdb.h>
#include <stdio.h>
#include <unistd.h>
Expand All @@ -12,6 +11,10 @@
#include <netinet/in.h>
#include <netinet/tcp.h>

#ifdef HAVE_LIBSYSTEMD
#include <systemd/sd-daemon.h>
#endif

static int
set_nonblocking(int fd)
{
Expand Down Expand Up @@ -211,6 +214,7 @@ make_unix_socket(char *path)
int
make_server_socket(char *host, char *port)
{
#ifdef HAVE_LIBSYSTEMD
int fd = -1, r;

/* See if we got a listen fd from systemd. If so, all socket options etc
Expand Down Expand Up @@ -247,6 +251,7 @@ make_server_socket(char *host, char *port)
}
return fd;
}
#endif

if (host && !strncmp(host, "unix:", 5)) {
return make_unix_socket(&host[5]);
Expand Down
Loading

0 comments on commit c73be66

Please sign in to comment.