From 32587d341c20b49720d2026111289c801c3365d3 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Tue, 10 Mar 2015 09:59:43 +0100 Subject: [PATCH] Overhaul build system and add support for disabling inetd support. This patch adds support for a configure script and with it support for disabling inetd support. See the output from ./configure --help * Add configure script * Sprinkle #ifdef fairy dust on svc.c when inetd support is disabled * Use GCC built-in autodep calculator (-MMD -MP) * Fix name space issue with include files, use relative paths * Disable username/group name to uid/gid functions in static builds * Bug out (error) if a user tries to build the bootmisc plugin static Possibly fixes GitHub issue #5 and issue #6. NOTE: The static build has not received any testing at all! Signed-off-by: Joachim Nilsson --- .gitignore | 2 +- Makefile | 52 +++------ README.md | 21 +++- common.mk | 11 +- conf.c | 6 +- configure | 257 +++++++++++++++++++++++++++++++++++++++++++ finit.c | 6 +- finit.h | 2 + helpers.c | 4 +- libite/Makefile | 13 +-- plugin.c | 18 +-- plugins/Makefile | 17 ++- plugins/alsa-utils.c | 6 +- plugins/bootmisc.c | 10 +- plugins/dbus.c | 6 +- plugins/hwclock.c | 6 +- plugins/initctl.c | 8 +- plugins/resolvconf.c | 6 +- plugins/time.c | 2 +- plugins/tty.c | 8 +- plugins/urandom.c | 6 +- plugins/x11-common.c | 6 +- svc.c | 34 +++++- svc.h | 1 + tty.c | 2 +- 25 files changed, 392 insertions(+), 118 deletions(-) create mode 100755 configure diff --git a/.gitignore b/.gitignore index c9dce24f..4db9eed0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ *.o -.*.d +*.d *.so *.gz *.map diff --git a/Makefile b/Makefile index b4b67b9e..945a8bf2 100644 --- a/Makefile +++ b/Makefile @@ -37,54 +37,28 @@ EXEC = finit reboot HEADERS = plugin.h svc.h helpers.h queue.h DISTFILES = LICENSE README CHANGELOG finit.conf services OBJS = finit.o conf.o helpers.o sig.o svc.o plugin.o tty.o inetd.o -SRCS = $(OBJS:.o=.c) -DEPS = $(addprefix .,$(SRCS:.c=.d)) -# Installation paths, always prepended with DESTDIR if set TOPDIR = $(shell pwd) -prefix ?= /usr -sysconfdir ?= /etc -sbindir ?= /sbin -libdir ?= /lib -plugindir ?= $(libdir)/finit/plugins -incdir = $(prefix)/include/finit -datadir = $(prefix)/share/doc/finit -mandir = $(prefix)/share/man/man8 +-include config.mk -# The initctl FIFO, should probably be in /run, not /dev -FINIT_FIFO ?= /dev/initctl -FINIT_CONF ?= $(sysconfdir)/finit.conf -FINIT_RCSD ?= $(sysconfdir)/finit.d +# Figure out source and dependency files +SRCS = $(OBJS:.o=.c) +DEPS = $(SRCS:.c=.d) -# Some people may want to build Finit with statically linked libraries -# invocation: make STATIC=1 -ifeq ($(STATIC), 1) -LDFLAGS += -static -CPPFLAGS += -DPLUGINS_STATIC -PLUGINS = "" -SRCS += $(wjldcard plugins/*.c) -OBJS := $(SRCS:.c=.o) -else -LDFLAGS += -rdynamic -LDLIBS += -ldl -endif - -CFLAGS += -W -Wall -Werror -Os +CFLAGS += -W -Wall -Werror # Disable annoying gcc warning for "warn_unused_result", see GIT 37af997 CPPFLAGS += -U_FORTIFY_SOURCE -CPPFLAGS += -Ilibite -Ilibuev +CPPFLAGS += -I$(TOPDIR) CPPFLAGS += -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -D_GNU_SOURCE CPPFLAGS += -DVERSION=\"$(VERSION)\" -DWHOAMI=\"`whoami`@`hostname`\" -CPPFLAGS += -DFINIT_FIFO=\"$(FINIT_FIFO)\" -DFINIT_CONF=\"$(FINIT_CONF)\" -CPPFLAGS += -DFINIT_RCSD=\"$(FINIT_RCSD)\" -DPLUGIN_PATH=\"$(plugindir)\" LDFLAGS += -L$(TOPDIR)/libite -L$(TOPDIR)/libuev DEPLIBS = libite/libite.a libuev/libuev.a LDLIBS += -lite -luev include common.mk -export libdir plugindir incdir ROOTDIR CPPFLAGS LDFLAGS LDLIBS STATIC -all: $(DEPLIBS) $(EXEC) + +all: config.h $(DEPLIBS) $(EXEC) +$(MAKE) -C plugins $@ $(DEPLIBS): Makefile @@ -93,6 +67,10 @@ $(DEPLIBS): Makefile $(OBJS): Makefile $(DEPLIBS) +config.h: configure + @echo "Please run configure script first." + @exit 1 + finit: $(OBJS) reboot: reboot.o $(DEPLIBS) @@ -149,16 +127,16 @@ uninstall-dev: uninstall: uninstall-exec uninstall-data uninstall-dev clean: - -@$(RM) $(OBJS) $(DEPS) $(EXEC) +$(MAKE) -C plugins $@ +$(MAKE) -C libite $@ +$(MAKE) -C libuev $@ + -@$(RM) $(OBJS) $(DEPS) $(EXEC) distclean: clean - -@$(RM) $(JUNK) unittest *.o .*.d +$(MAKE) -C plugins $@ +$(MAKE) -C libite $@ +$(MAKE) -C libuev $@ + -@$(RM) $(JUNK) config.mk config.h unittest *.o *.html check: $(CHECK) *.c plugins/*.c libite/*.c @@ -186,8 +164,6 @@ dev: distclean cd - >/dev/null; mv $$dir/$(DEV).tar.xz ../; cd ..; \ rm -rf $$dir; md5sum $(DEV).tar.xz | tee $(DEV).tar.xz.md5) -ifneq ($(MAKECMDGOALS),clean) ifneq ($(MAKECMDGOALS),distclean) -include $(DEPS) endif -endif diff --git a/README.md b/README.md index 7baa71f2..5529f2f2 100644 --- a/README.md +++ b/README.md @@ -438,13 +438,13 @@ plugin. Building -------- -The finit build system does not employ the GNU Configure and Build System, -instead standard makefiles are used. The user is encouraged to make source -code changes, using defines and conditionally building plugins instead to -alter the behavior of finit. +The finit build system does not employ the GNU Configure and Build +System, instead standard makefiles are used. The user is encouraged to +make source code changes, use defines and conditionally building plugins +instead to alter the behavior of finit. -The following environment variables are checked by the makefiles and control -what is built and where resulting binaries are installed. +The following environment variables are checked by the makefiles and +control what is built and where resulting binaries are installed. * `ROOTDIR=`: Top directory for building complete system, used in pretty printing. @@ -519,6 +519,15 @@ user's home directory, built and installed to a temporary staging directory. The environment variables `DESTDIR` and `PLUGINS` are changed to suit this particular build. +To target an embedded Linux system, usally a system that use BusyBox +tools instead of udev & C:o, add `CPPGLAGS="-DEMBEDDED_SYSTEM"` to the +build command above. + +**Note:** If you run into problems starting Finit, take a look at + `finit.c`. One of the most common problems is a custom Linux kernel + build that lack `CONFIG_DEVTMPFS`. Another is too much cruft in the + system `/etc/fstab`. + Running ------- diff --git a/common.mk b/common.mk index f5cea04c..9f2cb0b4 100644 --- a/common.mk +++ b/common.mk @@ -2,7 +2,7 @@ ROOTDIR ?= $(TOPDIR) # Some junk files we always want to be removed when doing a make clean. -JUNK = *~ *.bak *.aux *.dvi *.idx *.ind *.log *.ps *.map .*.d DEADJOE semantic.cache *.gdb *.elf core core.* +JUNK = *~ *.bak *.map .*.d *.d DEADJOE semantic.cache *.gdb *.elf core core.* MAKE := @$(MAKE) MAKEFLAGS = --no-print-directory --silent CHECK := cppcheck $(CPPFLAGS) --quiet --enable=all @@ -10,16 +10,13 @@ INSTALL := install --backup=off STRIPINST := $(INSTALL) -s --strip-program=$(CROSS)strip -m 0755 ARFLAGS := crus -# Smart autodependecy generation via GCC -M. -.%.d: %.c - @$(SHELL) -ec "$(CC) -MM $(CFLAGS) $(CPPFLAGS) $< \ - | sed 's,.*: ,$*.o $@ : ,g' > $@; \ - [ -s $@ ] || rm -f $@" +export libdir plugindir incdir ROOTDIR CPPFLAGS LDFLAGS LDLIBS STATIC + # Override default implicit rules %.o: %.c @printf " CC $(subst $(ROOTDIR)/,,$(shell pwd)/$@)\n" - @$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< + @$(CC) $(CFLAGS) $(CPPFLAGS) -c -MMD -MP -o $@ $< %: %.o @printf " LINK $(subst $(ROOTDIR)/,,$(shell pwd)/$@)\n" diff --git a/conf.c b/conf.c index 9a08be1c..75ea48ac 100644 --- a/conf.c +++ b/conf.c @@ -27,7 +27,7 @@ #include "finit.h" #include "svc.h" #include "tty.h" -#include "lite.h" +#include "libite/lite.h" #include "helpers.h" #define MATCH_CMD(l, c, x) \ @@ -246,7 +246,11 @@ static int parse_conf(char *file) /* Classic inetd service */ if (MATCH_CMD(line, "inetd ", x)) { +#ifndef INETD_DISABLED svc_register(SVC_CMD_INETD, x, NULL); +#else + _e("Finit built with inetd support disabled, cannot register service inetd %s!", x); +#endif continue; } diff --git a/configure b/configure new file mode 100755 index 00000000..ca3e71d9 --- /dev/null +++ b/configure @@ -0,0 +1,257 @@ +#!/bin/sh +# Simple home brew configure script, not as fancy as GNU Autotools +# +# --with-plugins="time initctl" +# --enable-static +# --disable-inetd +# +# This creates a configuration where Finit is built statically, with the +# time and initctl plugins built-in, and no inetd support. +# + +# Setup defaults if undefined +defaults() +{ + prefix=${prefix:="/usr"} + sysconfdir=${sysconfdir:="/etc"} + sbindir=${sbindir:="/sbin"} + libdir=${libdir:="/lib"} + pdir="finit/plugins" + plugindir=${plugindir:="$libdir/$pdir"} + # The initctl FIFO, should probably be in /run, not /dev + fifo=${fifo:="/dev/initctl"} + conf="finit.conf" + config=${config:="$sysconfdir/$conf"} + confdir=${confdir:="finit.d"} + rcsd=${rcsd:="$sysconfdir/$confdir"} + debug=${debug:=0} + embedded=${embedded:=0} + inetd=${inetd:=1} + static=${static:=0} +} + +result() +{ + echo + echo "Finit configuration" + echo "========================================================================" +if [ x"$heading" != x"" ]; then + echo "Heading : $heading" +fi + echo "Install prefix : $prefix" + echo "System config dir : $sysconfdir" + echo "Super user bindir : $sbindir" + echo "Shared libs dir : $libdir" + echo "Plugins dir : $plugindir" + echo "FIFO : $fifo" + echo "Config file : $config" + echo "rcs.d/ directory : $rcsd" + if [ $debug -ne 0 ]; then + echo "Debug : ENABLED" + fi + if [ $embedded -ne 0 ]; then + echo "Embedded target : YES (BusyBox getty, and mdev instead of udev)" + fi + if [ $inetd -ne 0 ]; then + echo "Inetd : Built-in" + else + echo "Inetd : DISABLED" + fi + if [ $static -ne 0 ]; then + echo "Static finit : YES" + fi + if [ x"$plugins" = x"" ]; then + echo "Plugins : ALL" + else + echo "Plugins : $plugins" + fi + echo +} + +usage() +{ + defaults + + echo "Run this script to configure finit for your operating system." + echo + echo "Usage: $0 [ARG]" + echo + echo " --prefix=PREFIX Set installation prefix, default '$prefix'" + echo " --sysconfdir=CONF Set conf dir, default '$sysconfdir'" + echo " --sbindir=SBIN Set sbin dir, default '$sbindir'" + echo " --libdir=LIB Set lib dir, default '$libdir'" + echo " --plugindir=DIR Set plugin dir, default '\$libdir/$pdir'" + echo + echo " --with-fifo=FIFO FIFO for initctl plugin, default '$fifo'" + echo " --with-config=CONFIG Finit CONFIG file, default '\$sysconfdir/$conf'" + echo " --with-heading=GREET Display GREET instead of Finit version at boot" + echo " --with-plugins=\"a b c\" Build plugins 'a', 'b' and 'c', either as dynamic .so" + echo " files, or as built-in if --enable-static is given," + echo " defaults to all plugins. Exclude extension!" + echo " --with-rcsd=RCSD Finit RCSD directory, default '\$sysconfdir/$confdir'" + echo + echo " --enable-embedded Enable embedded defaults, BusBox getty, mdev etc." + echo " --enable-debug Enable debug flags, '-O0, -g'" + echo " --enable-static Link finit statically. This disables a few features." + echo " --disable-inetd Disable inetd support if not needed." + echo + echo "The build system also supports external CFLAGS, CPPFLAGS, LDFLAGS, LDLIBS," + echo "and DESTDIR, useful for packaging or cross-compiling." + echo + echo "Example:" + echo " ./configure --enable-embedded --with-plugins=\"initctl tty\"" + echo + echo "Report bugs to https://github.com/troglobit/finit/issues" + echo + + exit 1 +} + +while [ "$*" != "" ]; do + opt=`expr "$1" : "--\([^=]*\)=.*"` + arg=`expr "$1" : "--[^=]*=\(.*\)"` + if [ -z "$opt" ]; then + opt=`expr "$1" : "--\(.*\)"` + fi + shift + + case $opt in + prefix) + prefix="$arg" + ;; + + sysconfdir) + sysconfdir="$arg" + ;; + + sbindir) + sbindir="$arg" + ;; + + libdir) + libdir="$arg" + ;; + + plugindir) + plugindir="$arg" + ;; + + with-fifo) + fifo="$arg" + ;; + + with-config) + config="$arg" + ;; + + with-heading) + heading="$arg" + ;; + + with-plugins) + plugins="$arg" + ;; + + with-rcsd) + rcsd="$arg" + ;; + + enable-debug) + debug=1 + ;; + + enable-embedded) + embedded=1 + ;; + + disable-inetd) + inetd=0 + ;; + + enable-static) + static=1 + ;; + + help) + usage + ;; + + *) + echo "Unknown option: $opt" + usage + ;; + esac +done + +# If no arguments given to configure script, use defaults +defaults +result + +############################################################################## +echo "# Generated by finit configure script." > config.mk +echo "prefix = $prefix" >> config.mk +echo "sysconfdir = $sysconfdir" >> config.mk +echo "sbindir = $sbindir" >> config.mk +echo "libdir = $libdir" >> config.mk +echo "plugindir = $plugindir" >> config.mk +echo "incdir = \$(prefix)/include/finit" >> config.mk +echo "datadir = \$(prefix)/share/doc/finit" >> config.mk +echo "mandir = \$(prefix)/share/man/man8" >> config.mk + +if [ $inetd -eq 0 ]; then + echo >> config.mk + echo "OBJS := \$(filter-out inetd.o, \$(OBJS))" >> config.mk +fi + +echo >> config.mk +if [ $debug -eq 1 ]; then + echo "CPPFLAGS += -O0 -g" >> config.mk +else + echo "CPPFLAGS += -Os" >> config.mk +fi + +echo >> config.mk +if [ $static -ne 0 ]; then + echo "STATIC = 1" >> config.mk + echo "LDFLAGS += -static" >> config.mk + echo "CPPFLAGS += -DENABLE_STATIC" >> config.mk + echo "PLUGINS = \"\"" >> config.mk + if [ x"$plugins" != x"" ]; then + echo "OBJS += \$(addsuffix .o, \$(addprefix plugins/, $plugins))" >> config.mk + else + echo "tmp += \$(wildcard plugins/*.c)" >> config.mk + echo "OBJS += \$(tmp:.c=.o)" >> config.mk + fi +else + echo "STATIC = 0" >> config.mk + echo "LDFLAGS += -rdynamic" >> config.mk + echo "LDLIBS += -ldl" >> config.mk + if [ x"$plugins" != x"" ]; then + echo "PLUGINS = \$(addsuffix .so, $plugins)" >> config.mk + fi +fi + +echo >> config.mk +echo "export libdir plugindir incdir CPPFLAGS LDFLAGS LDLIBS STATIC" >> config.mk + +############################################################################## +echo "/* Generated by finit configure script. */" > config.h + +if [ $embedded -eq 1 ]; then + echo "#define EMBEDDED_SYSTEM" >> config.h +fi + +if [ $inetd -eq 0 ]; then + echo "#define INETD_DISABLED" >> config.h +fi + +if [ x"$heading" != x"" ]; then + echo "#define INIT_HEADING \"$heading\"" >> config.h +fi + +echo "#define FINIT_FIFO \"$fifo\"" >> config.h +echo "#define FINIT_CONF \"$config\"" >> config.h +echo "#define FINIT_RCSD \"$rcsd\"" >> config.h +echo "#define PLUGIN_PATH \"$plugindir\"" >> config.h + + diff --git a/finit.c b/finit.c index ef05865c..857f8c40 100644 --- a/finit.c +++ b/finit.c @@ -35,7 +35,7 @@ #include "svc.h" #include "sig.h" #include "tty.h" -#include "lite.h" +#include "libite/lite.h" #include "inetd.h" int debug = 0; @@ -137,7 +137,11 @@ static int client(int argc, char *argv[]) static void banner(void) { delline(); +#ifdef INIT_HEADING + echo("%s", INIT_HEADING); +#else echo("Finit version " VERSION " (" WHOAMI ") " __DATE__ " " __TIME__); +#endif } int main(int argc, char* argv[]) diff --git a/finit.h b/finit.h index f1a78e8f..3924f4f9 100644 --- a/finit.h +++ b/finit.h @@ -25,6 +25,8 @@ #ifndef FINIT_H_ #define FINIT_H_ +#include "config.h" /* Generated by configure script */ + #include #include #include diff --git a/helpers.c b/helpers.c index 52beec94..f8e33cd2 100644 --- a/helpers.c +++ b/helpers.c @@ -48,7 +48,7 @@ #include "helpers.h" #include "private.h" #include "sig.h" -#include "lite.h" +#include "libite/lite.h" #define NUM_ARGS 16 #define NUM_SCRIPTS 128 /* ought to be enough for anyone */ @@ -710,6 +710,7 @@ int run_parts(char *dir, char *cmd) return 0; } +#ifndef ENABLE_STATIC int getuser(char *username) { struct passwd *usr; @@ -729,6 +730,7 @@ int getgroup(char *group) return grp->gr_gid; } +#endif /* * Other convenience functions diff --git a/libite/Makefile b/libite/Makefile index 982c9644..237f8ba7 100644 --- a/libite/Makefile +++ b/libite/Makefile @@ -31,7 +31,7 @@ endif HEADERS = lite.h OBJS := copyfile.o dir.o fexist.o fisdir.o fmode.o rsync.o OBJS += strlcpy.o strlcat.o strtonum.o -DEPS := $(addprefix ., $(OBJS:.o=.d)) +DEPS := $(OBJS:.o=.d) VER = 0 LIBNAME = libite @@ -44,7 +44,6 @@ else TARGET = $(STATICLIB) $(SOLIB) endif -CHECK_FLAGS = $(CFLAGS) $(CPPFLAGS) all: $(TARGET) @@ -81,14 +80,12 @@ uninstall: $(RM) $(DESTDIR)$(incdir)/$$file; \ done -clean: uninstall - -@$(RM) $(OBJS) $(DEPS) $(TARGET) $(VERLIB) $(STATICLIB) +clean: + -@$(RM) $(OBJS) $(DEPS) $(TARGET) $(SOLIB) $(STATICLIB) -distclean: clean - -@$(RM) $(JUNK) unittest *.o .*.d *.unittest +distclean: + -@$(RM) $(JUNK) unittest *.o *.a *.so* *.unittest -ifneq ($(MAKECMDGOALS),clean) ifneq ($(MAKECMDGOALS),distclean) -include $(DEPS) endif -endif diff --git a/plugin.c b/plugin.c index df22581d..0e1f39d7 100644 --- a/plugin.c +++ b/plugin.c @@ -32,14 +32,14 @@ #include "helpers.h" #include "plugin.h" #include "queue.h" /* BSD sys/queue.h API */ -#include "lite.h" +#include "libite/lite.h" #define is_io_plugin(p) ((p)->io.cb && (p)->io.fd >= 0) static char *plugpath = NULL; /* Set by first load. */ static TAILQ_HEAD(plugin_head, plugin) plugins = TAILQ_HEAD_INITIALIZER(plugins); -#ifndef PLUGINS_STATIC +#ifndef ENABLE_STATIC static void check_plugin_depends(plugin_t *plugin); #endif @@ -52,7 +52,7 @@ int plugin_register(plugin_t *plugin) /* Setup default name if none is provided */ if (!plugin->name) { -#ifndef PLUGINS_STATIC +#ifndef ENABLE_STATIC Dl_info info; if (!dladdr(plugin, &info) || !info.dli_fname) @@ -70,7 +70,7 @@ int plugin_register(plugin_t *plugin) return 0; } -#ifndef PLUGINS_STATIC +#ifndef ENABLE_STATIC /* Resolve plugin dependencies */ check_plugin_depends(plugin); #endif @@ -83,7 +83,7 @@ int plugin_register(plugin_t *plugin) /* Not called, at the moment plugins cannot be unloaded. */ int plugin_unregister(plugin_t *plugin) { -#ifndef PLUGINS_STATIC +#ifndef ENABLE_STATIC TAILQ_REMOVE(&plugins, plugin, link); if (plugin->svc.cb) { @@ -203,7 +203,7 @@ static void init_plugins(uev_ctx_t *ctx) } } -#ifndef PLUGINS_STATIC +#ifndef ENABLE_STATIC /** * load_one - Load one plugin * @path: Path to finit plugins, usually %PLUGIN_PATH @@ -282,12 +282,12 @@ static void check_plugin_depends(plugin_t *plugin) load_one(plugpath, plugin->depends[i]); } } -#endif /* PLUGINS_STATIC */ +#endif /* ENABLE_STATIC */ int plugin_load_all(uev_ctx_t *ctx, char *path) { int fail = 0; -#ifndef PLUGINS_STATIC +#ifndef ENABLE_STATIC DIR *dp = opendir(path); struct dirent *entry; @@ -311,7 +311,7 @@ int plugin_load_all(uev_ctx_t *ctx, char *path) closedir(dp); #else _d("Finit built statically, not loading plugins from %s ...", path); -#endif /* PLUGINS_STATIC */ +#endif /* ENABLE_STATIC */ /* Always initialize plugins */ init_plugins(ctx); diff --git a/plugins/Makefile b/plugins/Makefile index 4f24dee5..8d16a964 100644 --- a/plugins/Makefile +++ b/plugins/Makefile @@ -1,24 +1,23 @@ # Plugin based services architecture for finit -CFLAGS += -fPIC -Os -CPPFLAGS += -I.. +TOPDIR ?= $(shell pwd) +CFLAGS += -fPIC LDFLAGS := $(filter-out -rdynamic, $(LDFLAGS)) LDFLAGS += -shared ifneq ($(STATIC), 1) PLUGINS ?= initctl.so alsa-utils.so bootmisc.so dbus.so hwclock.so \ resolvconf.so urandom.so x11-common.so tty.so time.so -DEPS = $(addprefix .,$(PLUGINS:.so=.d)) +DEPS := $(PLUGINS:.so=.d) endif -TOPDIR ?= $(shell pwd) include ../common.mk all: $(PLUGINS) clean: - -@$(RM) $(PLUGINS) *.o + -@$(RM) $(PLUGINS) -distclean: clean - -@$(RM) $(JUNK) $(DEPS) +distclean: + -@$(RM) *.o *.so $(JUNK) $(DEPS) install: all @install -d $(DESTDIR)$(plugindir) @@ -34,6 +33,6 @@ uninstall: done -@rmdir $(DESTDIR)$(plugindir) 2>/dev/null -ifneq ($(MAKECMDGOALS),clean) - -include $(DEPS) +ifneq ($(MAKECMDGOALS),distclean) +-include $(DEPS) endif diff --git a/plugins/alsa-utils.c b/plugins/alsa-utils.c index 9100521a..a5c5adb1 100644 --- a/plugins/alsa-utils.c +++ b/plugins/alsa-utils.c @@ -21,9 +21,9 @@ * THE SOFTWARE. */ -#include "finit.h" -#include "helpers.h" -#include "plugin.h" +#include "../finit.h" +#include "../helpers.h" +#include "../plugin.h" static void save(void *UNUSED(arg)) { diff --git a/plugins/bootmisc.c b/plugins/bootmisc.c index 4a5d0f56..bb1dc440 100644 --- a/plugins/bootmisc.c +++ b/plugins/bootmisc.c @@ -24,9 +24,13 @@ #include #include -#include "finit.h" -#include "helpers.h" -#include "plugin.h" +#include "../finit.h" +#include "../helpers.h" +#include "../plugin.h" + +#ifdef ENABLE_STATIC +#error This plugin uses getuser(), which relies on dynamically linked GLIBC. Cannot be built statically! +#endif /* * Setup standard FHS 2.3 structure in /var, and diff --git a/plugins/dbus.c b/plugins/dbus.c index 0c3290fb..f01af48c 100644 --- a/plugins/dbus.c +++ b/plugins/dbus.c @@ -21,9 +21,9 @@ * THE SOFTWARE. */ -#include "finit.h" -#include "helpers.h" -#include "plugin.h" +#include "../finit.h" +#include "../helpers.h" +#include "../plugin.h" static void setup(void *UNUSED(arg)) { diff --git a/plugins/hwclock.c b/plugins/hwclock.c index 20382d00..58061d5c 100644 --- a/plugins/hwclock.c +++ b/plugins/hwclock.c @@ -21,9 +21,9 @@ * THE SOFTWARE. */ -#include "finit.h" -#include "helpers.h" -#include "plugin.h" +#include "../finit.h" +#include "../helpers.h" +#include "../plugin.h" static void save(void *UNUSED(arg)) { diff --git a/plugins/initctl.c b/plugins/initctl.c index 0474d8ff..32ae1db8 100644 --- a/plugins/initctl.c +++ b/plugins/initctl.c @@ -29,10 +29,10 @@ #include /* read() */ #include -#include "helpers.h" -#include "plugin.h" -#include "sig.h" -#include "finit.h" +#include "../helpers.h" +#include "../plugin.h" +#include "../sig.h" +#include "../finit.h" static void parse(void *arg, int fd, int events); diff --git a/plugins/resolvconf.c b/plugins/resolvconf.c index c53de5a1..79cfaa9f 100644 --- a/plugins/resolvconf.c +++ b/plugins/resolvconf.c @@ -21,9 +21,9 @@ * THE SOFTWARE. */ -#include "finit.h" -#include "helpers.h" -#include "plugin.h" +#include "../finit.h" +#include "../helpers.h" +#include "../plugin.h" static void setup(void *UNUSED(arg)) { diff --git a/plugins/time.c b/plugins/time.c index 56c27e98..68209379 100644 --- a/plugins/time.c +++ b/plugins/time.c @@ -26,7 +26,7 @@ #include /* STDIN_FILENO */ #include -#include "plugin.h" +#include "../plugin.h" /* UNIX epoch starts midnight, 1st Jan, 1970 */ #define EPOCH_OFFSET 2208988800ULL diff --git a/plugins/tty.c b/plugins/tty.c index 91ffcee6..b165c503 100644 --- a/plugins/tty.c +++ b/plugins/tty.c @@ -28,10 +28,10 @@ #include #include -#include "finit.h" -#include "helpers.h" -#include "plugin.h" -#include "tty.h" +#include "../finit.h" +#include "../helpers.h" +#include "../plugin.h" +#include "../tty.h" static void watcher(void *arg, int fd, int events); diff --git a/plugins/urandom.c b/plugins/urandom.c index 62d3e551..f58d1332 100644 --- a/plugins/urandom.c +++ b/plugins/urandom.c @@ -25,10 +25,10 @@ #include #include -#include "finit.h" +#include "../finit.h" #include "libite/lite.h" -#include "helpers.h" -#include "plugin.h" +#include "../helpers.h" +#include "../plugin.h" static void setup(void *UNUSED(arg)) { diff --git a/plugins/x11-common.c b/plugins/x11-common.c index 17a45044..09819ab2 100644 --- a/plugins/x11-common.c +++ b/plugins/x11-common.c @@ -25,9 +25,9 @@ #include #include -#include "finit.h" -#include "helpers.h" -#include "plugin.h" +#include "../finit.h" +#include "../helpers.h" +#include "../plugin.h" static void setup(void *UNUSED(arg)) { diff --git a/svc.c b/svc.c index 7d175677..d9786b81 100644 --- a/svc.c +++ b/svc.c @@ -32,7 +32,7 @@ #include "private.h" #include "sig.h" #include "tty.h" -#include "lite.h" +#include "libite/lite.h" #include "svc.h" #include "inetd.h" @@ -90,7 +90,7 @@ svc_t *svc_new(void) * Returns: * Always succeeds, returning POSIX OK(0). */ -static int svc_del(svc_t *svc) +int svc_del(svc_t *svc) { if (svc_counter >= 0 && svc_counter < MAX_NUM_SVC) { svc = &services[--svc_counter]; @@ -162,6 +162,7 @@ svc_t *svc_find_by_pid(pid_t pid) return NULL; } +#ifndef INETD_DISABLED svc_t *svc_find_inetd(char *path, char *service, char *proto, char *port) { svc_t *svc; @@ -181,6 +182,7 @@ svc_t *svc_find_inetd(char *path, char *service, char *proto, char *port) return NULL; } +#endif /** * svc_bootstrap - Start bootstrap services and tasks @@ -254,6 +256,7 @@ void svc_runlevel(int newlevel) svc_cmd_t cmd; /* Inetd services have slightly different semantics */ +#ifndef INETD_DISABLED if (svc->type == SVC_CMD_INETD) { if (!ISSET(svc->runlevels, runlevel)) inetd_stop(&svc->inetd); @@ -262,6 +265,7 @@ void svc_runlevel(int newlevel) continue; } +#endif /* All other services consult their callback here */ cmd = svc_enabled(svc, 0, NULL); @@ -327,7 +331,10 @@ void svc_runlevel(int newlevel) */ int svc_register(int type, char *line, char *username) { - int i = 0, forking = 0; + int i = 0; +#ifndef INETD_DISABLED + int forking = 0; +#endif char *service = NULL, *proto = NULL, *iface = NULL, *port = NULL; char *cmd, *desc, *runlevels = NULL; svc_t *svc; @@ -352,10 +359,12 @@ int svc_register(int type, char *line, char *username) while (cmd) { if (cmd[0] != '/' && strchr(cmd, '/')) service = cmd; /* inetd service/proto */ +#ifndef INETD_DISABLED else if (!strncasecmp(cmd, "nowait", 6)) forking = 1; else if (!strncasecmp(cmd, "wait", 4)) forking = 0; +#endif else if (cmd[0] == '@') /* @username[:group] */ username = &cmd[1]; else if (cmd[0] == '[') /* [runlevels] */ @@ -385,6 +394,7 @@ int svc_register(int type, char *line, char *username) *iface++ = 0; } +#ifndef INETD_DISABLED /* Find plugin that provides a callback for this inetd service */ if (type == SVC_CMD_INETD && !strncasecmp(cmd, "internal", 8)) { plugin = plugin_find(service); @@ -398,6 +408,7 @@ int svc_register(int type, char *line, char *username) svc = svc_find_inetd(cmd, service, proto, port); if (svc) return inetd_allow(&svc->inetd, iface); +#endif svc = svc_new(); if (!svc) { @@ -420,6 +431,7 @@ int svc_register(int type, char *line, char *username) strlcpy(svc->username, username, sizeof(svc->username)); } +#ifndef INETD_DISABLED if (svc->type == SVC_CMD_INETD) { int result; @@ -432,6 +444,7 @@ int svc_register(int type, char *line, char *username) return svc_del(svc); } } +#endif if (plugin) { /* Internal plugin provides this service */ @@ -570,8 +583,10 @@ void svc_monitor(pid_t lost) if (tty_respawn(lost)) return; +#ifndef INETD_DISABLED if (inetd_respawn(lost)) return; +#endif for (svc = svc_iterator(1); svc; svc = svc_iterator(0)) { if (lost != svc->pid) @@ -610,7 +625,6 @@ void svc_monitor(pid_t lost) int svc_start(svc_t *svc) { int respawn, sd = 0; - char ifname[IF_NAMESIZE] = "UNKNOWN"; pid_t pid; sigset_t nmask, omask; @@ -633,7 +647,10 @@ int svc_start(svc_t *svc) if (is_norespawn()) return 0; +#ifndef INETD_DISABLED if (SVC_CMD_INETD == svc->type) { + char ifname[IF_NAMESIZE] = "UNKNOWN"; + sd = svc->inetd.watcher.fd; if (svc->inetd.type == SOCK_STREAM) { @@ -663,8 +680,9 @@ int svc_start(svc_t *svc) } FLOG_INFO("Starting inetd service %s for requst from iface %s ...", svc->inetd.name, ifname); - } - else if (SVC_CMD_SERVICE != svc->type) + } else +#endif + if (SVC_CMD_SERVICE != svc->type) print_desc("", svc->desc); else if (!respawn) print_desc("Starting ", svc->desc); @@ -679,7 +697,11 @@ int svc_start(svc_t *svc) if (pid == 0) { int i = 0; int status; +#ifdef ENABLE_STATIC + int uid = 0; /* XXX: Fix better warning that dropprivs is disabled. */ +#else int uid = getuser(svc->username); +#endif struct sigaction sa; char *args[MAX_NUM_SVC_ARGS]; diff --git a/svc.h b/svc.h index c909fe86..d6ce8a7a 100644 --- a/svc.h +++ b/svc.h @@ -109,6 +109,7 @@ static inline svc_t *finit_svc_connect(void) } svc_t *svc_new (void); +int svc_del (svc_t *svc); svc_t *svc_find (char *path); svc_t *svc_find_by_pid (pid_t pid); svc_t *svc_find_inetd (char *path, char *service, char *proto, char *port); diff --git a/tty.c b/tty.c index 6603e9dc..54d1209c 100644 --- a/tty.c +++ b/tty.c @@ -27,7 +27,7 @@ #include "finit.h" #include "helpers.h" -#include "lite.h" +#include "libite/lite.h" #include "tty.h" LIST_HEAD(, tty_node) tty_list = LIST_HEAD_INITIALIZER();