Skip to content

Commit

Permalink
Add support for socket activation via systemd
Browse files Browse the repository at this point in the history
This prevents the need for starting fcgiwrap explicitly, or using a
tool such as spawn-fcgi. The type of socket does not matter, we merely
accept a single FD passed from pid 1 and listen on it.
  • Loading branch information
falconindy committed Aug 20, 2012
1 parent 0c93fa9 commit 9836d6d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile.in
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ install: all
install -m 644 fcgiwrap.8 $(man8dir) install -m 644 fcgiwrap.8 $(man8dir)


fcgiwrap: fcgiwrap.c fcgiwrap: fcgiwrap.c
@CC@ @AM_CFLAGS@ fcgiwrap.c -o fcgiwrap -lfcgi @LDFLAGS@ @CC@ @AM_CFLAGS@ fcgiwrap.c -o fcgiwrap -lfcgi @systemd_LIBS@ @LDFLAGS@


#>+ 21 #>+ 21
clean: clean:
Expand Down
17 changes: 17 additions & 0 deletions configure.ac
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,13 +14,30 @@ AC_SUBST([AM_CFLAGS])


# Checks for programs. # Checks for programs.
AC_PROG_CC AC_PROG_CC
PKG_PROG_PKG_CONFIG


# Create the config.h. # Create the config.h.
AC_CONFIG_HEADERS([config.h]) AC_CONFIG_HEADERS([config.h])


# Checks for libraries. # Checks for libraries.
AC_CHECK_LIB([fcgi], [FCGX_Init],, [AC_MSG_ERROR([FastCGI library is missing])]) AC_CHECK_LIB([fcgi], [FCGX_Init],, [AC_MSG_ERROR([FastCGI library is missing])])


# systemd support.
AC_ARG_WITH([systemd],
AS_HELP_STRING([--with-systemd], [support systemd socket activation]),
[], [with_systemd=check])
have_systemd=no
if test "x$with_systemd" != "xno"; then
PKG_CHECK_MODULES(systemd, [libsystemd-daemon],
[AC_DEFINE(HAVE_SYSTEMD, 1, [Define if systemd is available])
have_systemd=yes],
have_systemd=no)
if test "x$have_systemd" = xno -a "x$with_systemd" = xyes; then
AC_MSG_ERROR([systemd support requested but libraries not found])
fi
fi
AM_CONDITIONAL(HAVE_LIBSSL, [test "x$have_systemd" = "xyes"])

# Checks for header files. # Checks for header files.
AC_CHECK_HEADERS([fcntl.h],, [AC_MSG_ERROR([fcntl.h header missing])]) AC_CHECK_HEADERS([fcntl.h],, [AC_MSG_ERROR([fcntl.h header missing])])
AC_CHECK_HEADERS([limits.h stdlib.h string.h unistd.h],, [AC_MSG_ERROR([at least one important system header file is missing])]) AC_CHECK_HEADERS([limits.h stdlib.h string.h unistd.h],, [AC_MSG_ERROR([at least one important system header file is missing])])
Expand Down
12 changes: 12 additions & 0 deletions fcgiwrap.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
#include <sys/un.h> #include <sys/un.h>
#include <netinet/in.h> #include <netinet/in.h>


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

/* glibc doesn't seem to export it */ /* glibc doesn't seem to export it */
#ifndef UNIX_PATH_MAX #ifndef UNIX_PATH_MAX
#define UNIX_PATH_MAX 108 #define UNIX_PATH_MAX 108
Expand Down Expand Up @@ -788,6 +792,14 @@ int main(int argc, char **argv)
} }
} }


#ifdef HAVE_SYSTEMD
if (sd_listen_fds(true) > 0) {
/* systemd woke us up. we should never see more than one FD passed to us. */
if (listen_on_fd(SD_LISTEN_FDS_START) < 0) {
return 1;
}
} else
#endif
if (socket_url) { if (socket_url) {
if (setup_socket(socket_url) < 0) { if (setup_socket(socket_url) < 0) {
return 1; return 1;
Expand Down

0 comments on commit 9836d6d

Please sign in to comment.