Convert finit to use libev and fix so plugin ctors runs on dlopen().

Lots of cleanup and simplification of the main code in this commit.
Most notably libev has been added to take care of the main loop and
monitor services. Still TODO is migrating to use the libev signal
handling.

Convert initctl.c:listen_initctl() to a plugin instead.  This also
meant introducing a new form of I/O plugin to finit, also handled
by libev.

Load plugins *after* we've setup the base filesystem (BASEFS) in case
plugins reside on a filesystem not reachable before "mount -a" has run.
This also has the side effect of lining up nicely with the first level
plugin hooks.

If a plugin wants to hook up with a loded service we connect them by
their respective numeric IDs in plugin_register().  I.e., the service
monitor checks if a service has a registered callback, which in turn
decides if a service should be started, stopped or reloaded.

Rip out old EeePC distribution defines from finit.h, none of it really
applies anymore.  If you need distribution specific settings this is
the place to put them.

Make hookpoint names (#defines) clearer: after BASEFS, after networking,
after all setup, etc.

Use #inlude_next <signal.h> in signal.h to include system header file!

Simplify service monitor: move essential code to svc.c and rip out
the TIPC dependency. Write your own service.so plugin, or wait for
a more complete example of how to extend service monitoring using
the primitives in svc.c

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson committed 2012-09-25 14:23:23 +02:00
1 parent 5dda9051ac
commit 0e02429e75
25 files changed
+620 -1073

No files matched your search

+9 -7
View File
@@ -1,6 +1,7 @@
# finit - The Improved fast init
#
# Copyright (c) 2008 Claudio Matsuoka
# Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
# Copyright (c) 2008-2012 Joachim Nilsson <troglobit@gmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@@ -30,19 +31,18 @@ PLUGIN_DIR ?= /lib/finit/plugins
VERSION = 1.0-pre
PKG = finit-$(VERSION)
EXEC = finit
OBJS = finit.o helpers.o initctl.o signal.o svc.o ipc.o service.o \
strlcpy.o plugin.o
OBJS = finit.o helpers.o signal.o svc.o plugin.o
OBJS += strlcpy.o
SRCS = $(OBJS:.o=.c)
DEPS = $(addprefix .,$(SRCS:.c=.d))
CFLAGS += -W -Wall -Werror -Os
# Disable annoying gcc warning for "warn_unused_result", see GIT 37af997
CPPFLAGS += -U_FORTIFY_SOURCE
CPPFLAGS += -I$(ROOTDIR)/$(CONFIG_LINUXDIR)/include/
CPPFLAGS += -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -D_GNU_SOURCE
CPPFLAGS += -DVERSION=\"$(VERSION)\" -DWHOAMI=\"`whoami`@`hostname`\"
CPPFLAGS += -DPLUGIN_PATH=\"$(PLUGIN_DIR)\"
LDFLAGS += -rdynamic
LDLIBS += -ldl
LDLIBS += -ldl -lev
prefix ?= /usr/local
sysconfdir ?= /etc
@@ -50,7 +50,7 @@ datadir = $(prefix)/share/doc/finit
mandir = $(prefix)/share/man/man8
include common.mk
export PLUGIN_DIR ROOTDIR
export PLUGIN_DIR ROOTDIR CPPFLAGS
all: Makefile $(EXEC)
$(MAKE) -C plugins $@
@@ -69,12 +69,14 @@ install: all
printf " INSTALL $(DESTDIR)$(prefix)/sbin/$$file\n"; \
install -m 0755 $$file $(DESTDIR)$(prefix)/sbin/$$file; \
done
$(MAKE) -C plugins $@
uninstall:
-@for file in $(EXEC); do \
printf " REMOVE $(DESTDIR)$(prefix)/sbin/$$file\n"; \
$(RM) $(DESTDIR)$(prefix)/sbin/$$file; \
rm $(DESTDIR)$(prefix)/sbin/$$file 2>/dev/null; \
done
$(MAKE) -C plugins $@
clean:
-@$(RM) $(OBJS) $(DEPS) $(EXEC)