mirror of
https://github.com/troglobit/finit.git
synced 2026-10-23 11:44:37 +00:00
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 <troglobit@gmail.com>
This commit is contained in:
1 parent
a74b640507
commit
32587d341c
25 files changed
+392
-118
No files matched your search
+1
-1
@@ -1,5 +1,5 @@
|
||||
*.o
|
||||
.*.d
|
||||
*.d
|
||||
*.so
|
||||
*.gz
|
||||
*.map
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
-------
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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[])
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
#ifndef FINIT_H_
|
||||
#define FINIT_H_
|
||||
|
||||
#include "config.h" /* Generated by configure script */
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <paths.h>
|
||||
|
||||
@@ -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
|
||||
|
||||
+5
-8
@@ -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
|
||||
@@ -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);
|
||||
|
||||
+8
-9
@@ -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
|
||||
@@ -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))
|
||||
{
|
||||
|
||||
+7
-3
@@ -24,9 +24,13 @@
|
||||
#include <string.h>
|
||||
#include <utmp.h>
|
||||
|
||||
#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
|
||||
|
||||
+3
-3
@@ -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))
|
||||
{
|
||||
|
||||
+3
-3
@@ -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))
|
||||
{
|
||||
|
||||
+4
-4
@@ -29,10 +29,10 @@
|
||||
#include <unistd.h> /* read() */
|
||||
#include <sys/stat.h>
|
||||
|
||||
#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);
|
||||
|
||||
|
||||
@@ -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))
|
||||
{
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@
|
||||
#include <unistd.h> /* STDIN_FILENO */
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include "plugin.h"
|
||||
#include "../plugin.h"
|
||||
|
||||
/* UNIX epoch starts midnight, 1st Jan, 1970 */
|
||||
#define EPOCH_OFFSET 2208988800ULL
|
||||
|
||||
+4
-4
@@ -28,10 +28,10 @@
|
||||
#include <sys/inotify.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#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);
|
||||
|
||||
|
||||
+3
-3
@@ -25,10 +25,10 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#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))
|
||||
{
|
||||
|
||||
@@ -25,9 +25,9 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "finit.h"
|
||||
#include "helpers.h"
|
||||
#include "plugin.h"
|
||||
#include "../finit.h"
|
||||
#include "../helpers.h"
|
||||
#include "../plugin.h"
|
||||
|
||||
static void setup(void *UNUSED(arg))
|
||||
{
|
||||
|
||||
@@ -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];
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user