diff --git a/Makefile.am b/Makefile.am index 9760e458..63f8250c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,5 @@ ACLOCAL_AMFLAGS = -I m4 -SUBDIRS = man plugins src system test tmpfiles.d +SUBDIRS = man plugins src system tmpfiles.d doc_DATA = README.md LICENSE contrib/finit.conf EXTRA_DIST = README.md LICENSE ChangeLog.md contrib/finit.conf @@ -9,6 +9,17 @@ endif if DOC SUBDIRS += doc endif +if LIBSYSTEMD +SUBDIRS += libsystemd +endif + +if LIBSYSTEMD +SUBDIRS += test +# Explicit dependency to ensure libsystemd is built before test +test: libsystemd +else +SUBDIRS += test +endif if BASH bashdir = $(BASH_DIR) diff --git a/configure.ac b/configure.ac index 5e591fd1..64d05de7 100644 --- a/configure.ac +++ b/configure.ac @@ -12,6 +12,7 @@ AC_CONFIG_FILES([Makefile contrib/debian/Makefile contrib/debian/finit.d/Makefile contrib/debian/finit.d/available/Makefile contrib/void/Makefile contrib/void/finit.d/Makefile contrib/void/finit.d/available/Makefile doc/Makefile + libsystemd/Makefile libsystemd/libsystemd.pc man/Makefile plugins/Makefile src/Makefile @@ -168,6 +169,10 @@ AC_ARG_WITH(watchdog, AS_HELP_STRING([--with-watchdog@<:@=DEV@:>@], [Enable built-in watchdog, default: /dev/watchdog]), [watchdog=$withval], [with_watchdog=no watchdog=]) +AC_ARG_WITH(libsystemd, + AS_HELP_STRING([--with-libsystemd], [Build replacement libsystemd library, default: yes]), + [with_libsystemd=$withval], [with_libsystemd=yes]) + AC_ARG_WITH(hook-scripts-path, AS_HELP_STRING([--with-hook-scripts-path=DIR], [Base directory for hook scripts, default $libexecdir/finit/hook]), [hook_scripts_path=$withval], [hook_scripts_path=yes]) @@ -308,6 +313,9 @@ AS_IF([test "x$with_watchdog" != "xno"], [ AC_DEFINE_UNQUOTED(WDT_DEVNODE, "$watchdog", [Built-in watchdog device node])], [ watchdog=]) +AS_IF([test "x$with_libsystemd" != "xno"], [ + AC_DEFINE(HAVE_LIBSYSTEMD, 1, [Build replacement libsystemd library support])]) + AS_IF([test "x$enable_hook_scripts_plugin" != "xno"], [ AS_IF([test "x$hook_scripts_path" = "xyes"], [hook_scripts_path=$libexecdir/finit/hook]) AC_EXPAND_DIR(hook_scripts_path, "$hook_scripts_path") @@ -319,14 +327,15 @@ AS_IF([test "x$with_plugin_path" != "xno"], [ AC_DEFINE_UNQUOTED(EXTERNAL_PLUGIN_PATH, "$plugin_path", [Built-in default: /usr/lib/finit/plugins:/usr/local/lib/finit/plugins])]) # Control build with automake flags -AM_CONDITIONAL(BASH, [test "x$bash_dir" != "xno"]) -AM_CONDITIONAL(STATIC, [test "x$enable_static" = "xyes"]) -AM_CONDITIONAL(KEVENTD, [test "x$with_keventd" != "xno"]) -AM_CONDITIONAL(SULOGIN, [test "x$with_sulogin" != "xno"]) -AM_CONDITIONAL(WATCHDOGD, [test "x$with_watchdog" != "xno"]) -AM_CONDITIONAL(DOC, [test "x$enable_doc" = "xyes"]) -AM_CONDITIONAL(CONTRIB, [test "x$enable_contrib" = "xyes"]) -AM_CONDITIONAL(TESTSERV, [test "x$enable_testserv_plugin" = "xyes"]) +AM_CONDITIONAL(BASH, [test "x$bash_dir" != "xno"]) +AM_CONDITIONAL(STATIC, [test "x$enable_static" = "xyes"]) +AM_CONDITIONAL(KEVENTD, [test "x$with_keventd" != "xno"]) +AM_CONDITIONAL(SULOGIN, [test "x$with_sulogin" != "xno"]) +AM_CONDITIONAL(WATCHDOGD, [test "x$with_watchdog" != "xno"]) +AM_CONDITIONAL(LIBSYSTEMD, [test "x$with_libsystemd" != "xno"]) +AM_CONDITIONAL(DOC, [test "x$enable_doc" = "xyes"]) +AM_CONDITIONAL(CONTRIB, [test "x$enable_contrib" = "xyes"]) +AM_CONDITIONAL(TESTSERV, [test "x$enable_testserv_plugin" = "xyes"]) # Workaround for as-of-yet unreleased runstatedir support, planned for # autoconf 2.70, which some major distros have backported. @@ -408,6 +417,7 @@ Optional features: Built-in sulogin......: $with_sulogin $sulogin Built-in watchdogd....: $with_watchdog $watchdog Built-in logrotate....: $enable_logrotate + Replacement libsystemd: $with_libsystemd Use cgroup v2.........: $enable_cgroup Parse kernel cmdline..: $enable_kernel_cmdline Keep kernel logging...: $enable_kernel_logging diff --git a/libsystemd/.gitignore b/libsystemd/.gitignore new file mode 100644 index 00000000..52829a19 --- /dev/null +++ b/libsystemd/.gitignore @@ -0,0 +1,7 @@ +.deps/* +.libs/* +.dirstamp +*.lo +libsystemd.* +Makefile +Makefile.in diff --git a/libsystemd/Makefile.am b/libsystemd/Makefile.am new file mode 100644 index 00000000..cbde1500 --- /dev/null +++ b/libsystemd/Makefile.am @@ -0,0 +1,12 @@ +# libsystemd replacement library +lib_LTLIBRARIES = libsystemd.la +libsystemd_la_SOURCES = sd-daemon.c sd-daemon.h +libsystemd_la_LDFLAGS = -version-info 0:0:0 + +# pkg-config support +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = libsystemd.pc + +# Install header to systemd/ subdirectory +systemddir = $(includedir)/systemd +systemd_HEADERS = sd-daemon.h \ No newline at end of file diff --git a/libsystemd/libsystemd.pc.in b/libsystemd/libsystemd.pc.in new file mode 100644 index 00000000..17881f60 --- /dev/null +++ b/libsystemd/libsystemd.pc.in @@ -0,0 +1,10 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: libsystemd +Description: Finit replacement for systemd notification library +Version: @PACKAGE_VERSION@ +Libs: -L${libdir} -lsystemd +Cflags: -I${includedir} \ No newline at end of file diff --git a/test/src/sd-daemon.c b/libsystemd/sd-daemon.c similarity index 100% rename from test/src/sd-daemon.c rename to libsystemd/sd-daemon.c diff --git a/test/src/sd-daemon.h b/libsystemd/sd-daemon.h similarity index 100% rename from test/src/sd-daemon.h rename to libsystemd/sd-daemon.h diff --git a/src/Makefile.am b/src/Makefile.am index 04ff8137..f9fb60ec 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -9,6 +9,7 @@ endif sbin_PROGRAMS = finit initctl pkglibexec_PROGRAMS = getty logit runparts tmpfiles + if SULOGIN pkglibexec_PROGRAMS += sulogin endif diff --git a/test/notify.sh b/test/notify.sh index e77a0141..9baa37f4 100755 --- a/test/notify.sh +++ b/test/notify.sh @@ -25,6 +25,15 @@ test_one() type=$1 service=$2 + # Skip systemd tests if serv doesn't have libsystemd support + if [ "$type" = "systemd" ]; then + if ! "$TEST_DIR/src/serv" -C | grep -q "libsystemd"; then + sep + say "Skipping systemd test - serv built without libsystemd support" + return 0 + fi + fi + sep # num=$(run "find /proc/1/fd |wc -l") diff --git a/test/src/.gitignore b/test/src/.gitignore index 8d844137..fdb16e7f 100644 --- a/test/src/.gitignore +++ b/test/src/.gitignore @@ -1,5 +1,5 @@ /Makefile /Makefile.in - +/.libs/ /.deps/ /serv diff --git a/test/src/Makefile.am b/test/src/Makefile.am index a54bbae1..9cebdeea 100644 --- a/test/src/Makefile.am +++ b/test/src/Makefile.am @@ -1,4 +1,8 @@ noinst_PROGRAMS = serv -serv_SOURCES = serv.c sd-daemon.c sd-daemon.h -serv_CPPFLAGS = -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE +serv_SOURCES = serv.c +serv_CPPFLAGS = -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE -I$(top_builddir) +if LIBSYSTEMD +serv_CPPFLAGS += -I$(top_srcdir)/libsystemd +serv_SOURCES += $(top_srcdir)/libsystemd/sd-daemon.c +endif diff --git a/test/src/serv.c b/test/src/serv.c index b8ece7b9..dd9567e2 100644 --- a/test/src/serv.c +++ b/test/src/serv.c @@ -5,6 +5,10 @@ * in foregrund it does not create a PID file by default. */ +#ifdef HAVE_CONFIG_H +#include +#endif + #include #include #include @@ -16,7 +20,9 @@ #include #include #include +#ifdef HAVE_LIBSYSTEMD #include "sd-daemon.h" +#endif #define PROGNM "serv" @@ -146,6 +152,16 @@ static void pidfile(char *pidfn) } } +static int capabilities(void) +{ +#ifdef HAVE_LIBSYSTEMD + puts("libsystemd"); +#endif + puts("s6"); + + return 0; +} + static int usage(int rc) { FILE *fp = rc ? stderr : stdout; @@ -153,6 +169,7 @@ static int usage(int rc) fprintf(fp, "%s [-nhp] [-P FILE]\n" "\n" + " -C Show capabilities and exit\n" " -c Crash (exit) immediately\n" " -e K:V Verify K environment variable is V value\n" " -E K Verify K is not set in the environment\n" @@ -195,11 +212,13 @@ int main(int argc, char *argv[]) char cmd[80]; int c; - while ((c = getopt(argc, argv, "ce:E:f:F:hi:nN:pP:r:")) != EOF) { + while ((c = getopt(argc, argv, "cCe:E:f:F:hi:nN:pP:r:")) != EOF) { switch (c) { case 'c': do_crash = 1; break; + case 'C': + return capabilities(); case 'e': verify_env(optarg); break; @@ -295,11 +314,15 @@ int main(int argc, char *argv[]) err(1, "Failed closing notify socket"); do_notify = 0; } else { +#ifdef HAVE_LIBSYSTEMD int rc; inf("Notifying Finit on NOTIFY_SOCKET"); rc = sd_notify(0, "READY=1"); inf("sd_notify () => %d", rc); +#else + inf("Skipping systemd notify - built without libsystemd support"); +#endif } } if (do_pidfile > 0)