From 726f0d428d9a4ef82b65c06cd7018240975c829a Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Mon, 14 Mar 2016 22:30:15 +0100 Subject: [PATCH] Initial conversion to GNU Configure & Build System Signed-off-by: Joachim Nilsson --- Makefile | 193 ------------------ Makefile.am | 62 ++++++ autogen.sh | 3 + configure | 473 -------------------------------------------- configure.ac | 239 ++++++++++++++++++++++ initctl.c | 3 +- plugin.c | 1 + plugins/Makefile | 53 ----- plugins/Makefile.am | 19 ++ service.c | 17 +- 10 files changed, 340 insertions(+), 723 deletions(-) delete mode 100644 Makefile create mode 100644 Makefile.am create mode 100755 autogen.sh delete mode 100755 configure create mode 100644 configure.ac delete mode 100644 plugins/Makefile create mode 100644 plugins/Makefile.am diff --git a/Makefile b/Makefile deleted file mode 100644 index d4d7d3fe..00000000 --- a/Makefile +++ /dev/null @@ -1,193 +0,0 @@ -# Finit - Fast /sbin/init replacement w/ I/O, hook & service plugins -# -# Copyright (c) 2008-2010 Claudio Matsuoka -# Copyright (c) 2008-2015 Joachim Nilsson -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. - -.PHONY: all install clean distclean dist \ - install-exec install-data install-dev \ - uninstall-exec uninstall-data uninstall-dev - -#VERSION = $(shell git tag -l | tail -1) -VERSION = 3.0-beta1 -NAME = finit -PKG = $(NAME)-$(VERSION) -DEV = $(NAME)-dev -ARCHTOOL = `which git-archive-all` -ARCHIVE = $(PKG).tar -ARCHIVEZ = ../$(ARCHIVE).xz -EXEC = finit initctl reboot -HEADERS = finit.h plugin.h svc.h inetd.h helpers.h queue.h cond.h -DISTFILES = LICENSE README ChangeLog finit.conf services -OBJS = finit.o api.o client.o conf.o exec.o helpers.o pid.o sig.o \ - svc.o service.o plugin.o tty.o inetd.o cond.o cond-w.o -DEPLIBS = -TOPDIR = $(shell pwd) --include config.mk - -# Figure out source and dependency files -SRCS = $(OBJS:.o=.c) -DEPS = $(SRCS:.c=.d) - -CFLAGS += -W -Wall -# Disable annoying gcc warning for "warn_unused_result", see GIT 37af997 -CPPFLAGS += -U_FORTIFY_SOURCE -CPPFLAGS += -I$(TOPDIR) -CPPFLAGS += -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE -CPPFLAGS += -DVERSION=\"$(VERSION)\" -DWHOAMI=\"`whoami`@`hostname`\" - -include common.mk - - -all: config.h $(EXEC) - +$(MAKE) -C plugins $@ - -$(DEPLIBS): Makefile - +$(MAKE) -C `dirname \`dirname $@\`` all - -$(OBJS): Makefile - -config.h: configure - @echo "Please run configure script first." - @exit 1 - -finit: $(OBJS) $(DEPLIBS) - -initctl: initctl.o svc.o helpers.o cond.o $(DEPLIBS) - -reboot: reboot.o $(DEPLIBS) - -install-exec: all - @$(INSTALL) -d $(DESTDIR)$(FINIT_RCSD) - @$(INSTALL) -d $(DESTDIR)$(sbindir) - @for file in $(EXEC); do \ - printf " INSTALL $(DESTDIR)$(sbindir)/$$file\n"; \ - $(STRIPINST) $$file $(DESTDIR)$(sbindir)/$$file; \ - done - @printf " INSTALL $(DESTDIR)$(sbindir)/service\n" - @$(INSTALL) -m 0755 service $(DESTDIR)$(sbindir)/service - printf " INSTALL $(DESTDIR)$(sbindir)/telinit\n" - @ln -sf finit $(DESTDIR)$(sbindir)/telinit - $(MAKE) -C plugins install -ifndef LIBITE - $(MAKE) -C libite install-exec -endif - -install-data: - @$(INSTALL) -d $(DESTDIR)$(datadir) - @$(INSTALL) -d $(DESTDIR)$(mandir) - @for file in $(DISTFILES); do \ - printf " INSTALL $(DESTDIR)$(datadir)/$$file\n"; \ - $(INSTALL) -m 0644 $$file $(DESTDIR)$(datadir)/$$file; \ - done - -install-dev: - @$(INSTALL) -d $(DESTDIR)$(incdir) - @for file in $(HEADERS); do \ - printf " INSTALL $(DESTDIR)$(incdir)/$$file\n"; \ - $(INSTALL) -m 0644 $$file $(DESTDIR)$(incdir)/$$file; \ - done -ifndef LIBITE - $(MAKE) -C libite install-dev -endif -ifndef LIBUEV - $(MAKE) -C libuev install-dev -endif - -install: install-exec install-data install-dev - -uninstall-exec: - -@for file in $(EXEC); do \ - printf " REMOVE $(DESTDIR)$(sbindir)/$$file\n"; \ - rm $(DESTDIR)$(sbindir)/$$file 2>/dev/null; \ - done - -@for file in service telinit; do \ - printf " REMOVE $(DESTDIR)$(sbindir)/$$file\n"; \ - rm $(DESTDIR)$(sbindir)/$$file 2>/dev/null; \ - done - -@rmdir $(DESTDIR)$(sbindir) 2>/dev/null - -@rmdir $(DESTDIR)$(FINIT_RCSD) 2>/dev/null - $(MAKE) -C plugins uninstall -ifndef LIBITE - $(MAKE) -C libite uninstall -endif - -uninstall-data: - -@for file in $(DISTFILES); do \ - printf " REMOVE $(DESTDIR)$(datadir)/$$file\n"; \ - rm $(DESTDIR)$(datadir)/$$file 2>/dev/null; \ - done - -@rmdir $(DESTDIR)$(mandir) 2>/dev/null - -@rmdir $(DESTDIR)$(datadir) 2>/dev/null - -uninstall-dev: - -@$(RM) -rf $(DESTDIR)$(incdir) 2>/dev/null - -uninstall: uninstall-exec uninstall-data uninstall-dev - -clean: - +$(MAKE) -C plugins $@ -ifndef LIBITE - +$(MAKE) -C libite $@ -endif -ifndef LIBUEV - +$(MAKE) -C libuev $@ -endif - -@$(RM) $(OBJS) $(DEPS) $(EXEC) 2>/dev/null - -distclean: clean - +$(MAKE) -C plugins $@ -ifndef LIBITE - +$(MAKE) -C libite $@ -endif -ifndef LIBUEV - +$(MAKE) -C libuev $@ -endif - -@$(RM) $(JUNK) config.mk config.h unittest *.o *.html 2>/dev/null - -check: - $(CHECK) *.c plugins/*.c - -dist: - @if [ x"$(ARCHTOOL)" = x"" ]; then \ - echo "Missing git-archive-all from https://github.com/Kentzo/git-archive-all"; \ - exit 1; \ - fi - @if [ -e $(ARCHIVEZ) ]; then \ - echo "Distribution already exists."; \ - exit 1; \ - fi - @echo "Building xz tarball of $(PKG) in parent dir..." - @$(ARCHTOOL) ../$(ARCHIVE) - @xz ../$(ARCHIVE) - @md5sum $(ARCHIVEZ) | tee $(ARCHIVEZ).md5 - -dev: distclean - @echo "Building unstable xz $(DEV) in parent dir..." - -@$(RM) -f ../$(DEV).tar.xz* - @(dir=`mktemp -d`; mkdir $$dir/$(DEV); cp -a . $$dir/$(DEV); \ - cd $$dir; tar --exclude=.git --exclude=contrib \ - -c -J -f $(DEV).tar.xz $(DEV); \ - cd - >/dev/null; mv $$dir/$(DEV).tar.xz ../; cd ..; \ - rm -rf $$dir; md5sum $(DEV).tar.xz | tee $(DEV).tar.xz.md5) - -ifneq ($(MAKECMDGOALS),distclean) --include $(DEPS) -endif diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 00000000..a42e28fd --- /dev/null +++ b/Makefile.am @@ -0,0 +1,62 @@ +ACLOCAL_AMFLAGS = -I m4 +sbin_PROGRAMS = finit initctl reboot +finit_SOURCES = finit.c api.c client.c conf.c exec.c helpers.c pid.c \ + sig.c svc.c service.c plugin.c tty.c cond.c cond-w.c +if INETD +finit_SOURCES += inetd.c +endif +finit_CFLAGS = -W -Wall -Wextra -std=gnu99 +finit_LDADD = libite/libite.a libuev/libuev.la -ldl +if STATIC +finit_LDADD += plugins/libplug.la +endif +DEPENDENCIES = libite/libite.a libuev/libuev.la +initctl_SOURCES = initctl.c svc.c helpers.c cond.c +initctl_LDADD = libite/libite.a +reboot_SOURCES = reboot.c +SYMLINK = telinit init +DIST_SUBDIRS = libite libuev +SUBDIRS = plugins +doc_DATA = README.md LICENSE finit.conf services +EXTRA_DIST = README.md LICENSE ChangeLog.md finit.conf services +AM_CPPFLAGS = -U_FORTIFY_SOURCE +AM_CPPFLAGS += -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE +AM_CPPFLAGS += -DFINIT_CONF=\"$(conf)\" -DFINIT_RCSD=\"$(rcsd)\" -DFINIT_FIFO=\"$(fifo)\" \ + -DPLUGIN_PATH=\"$(plugindir)\" + +# Slightly ugly hacks to prevent the build system from installing +# libuev/libite, which it does if we use the more plain SUBDIRS. +$(DEPENDENCIES): + @$(MAKE) -C `dirname $@` all + +clean-local: + @-for dep in $(DEPENDENCIES); do \ + $(MAKE) -C `dirname $$dep` clean; \ + done + +# Hook in install to add finit --> telinit symlink(s) +install-exec-hook: + @for file in $(SYMLINK); do \ + link=$(DESTDIR)$(sbindir)/$$file; \ + test "`readlink $$link`" = "finit" && continue; \ + $(LN_S) finit $$link; \ + done + +uninstall-hook: + @for file in $(SYMLINK); do \ + $(RM) $(DESTDIR)$(sbindir)/$$file; \ + done + +# Target to run when building a release +release: dist + @for file in $(DIST_ARCHIVES); do \ + md5sum $$file > ../$$file.md5; \ + done + @mv $(DIST_ARCHIVES) ../ + @echo + @echo "Resulting release files:" + @echo "=================================================================" + @for file in $(DIST_ARCHIVES); do \ + printf "$$file \tDistribution tarball\n"; \ + printf "$$file.md5\t"; cat ../$$file.md5 | cut -f1 -d' '; \ + done diff --git a/autogen.sh b/autogen.sh new file mode 100755 index 00000000..69ad0e18 --- /dev/null +++ b/autogen.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +autoreconf -W portability -vifm diff --git a/configure b/configure deleted file mode 100755 index fc1112da..00000000 --- a/configure +++ /dev/null @@ -1,473 +0,0 @@ -#!/bin/sh -# Simple home brew configure script, not as fancy as GNU Autotools -# -# --with-plugins="time initctl" -# --enable-static -# --disable-inetd -# --disable-plugins -# -# 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() -{ - heading=${heading:='"Finit v" VERSION'} - 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"} - random=${random:="/var/lib/urandom/random-seed"} - conf="finit.conf" - config=${config:="$sysconfdir/$conf"} - confdir=${confdir:="finit.d"} - rcsd=${rcsd:="$sysconfdir/$confdir"} - console=${console:='_PATH_CONSOLE'} - shell=${shell:='_PATH_BSHELL'} - defuser=${defuser:="root"} - defhost=${defhost:="noname"} - runlevel=${runlevel:=2} - debug=${debug:=0} - embedded=${embedded:=0} - dbus=${dbus:=0} - remount=${remount:=0} - inetd=${inetd:=1} - verbose=${verbose:=1} - kernel_quiet=${kernel_quiet:=1} - static=${static:=0} - disable_plugins=${disable_plugins:=0} -} - -result() -{ - echo - echo "Finit configuration" - echo "========================================================================" - echo "Heading : $heading" - 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" - echo "Default console : $console" -# echo "Fallback shell : $shell" - if [ x"$sysroot" != x"" ]; then - echo "Swap rootfs to : $sysroot" - fi - echo "Default username : $defuser" - echo "Default hostname : $defhost" - echo "Default runlevel : $runlevel" - - 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 [ $dbus -ne 0 ]; then - echo "D-Bus : YES, remember to install dbus.so plugin as well!" - fi - - if [ $remount -ne 0 ]; then - echo "Remount ROOT fs : YES, / will be remounted as read-write at bootstrap" - fi - - if [ x"$random" != x"" ]; then - echo "Random seed : $random" - fi - - if [ $inetd -ne 0 ]; then - echo "Inetd : Built-in" - else - echo "Inetd : DISABLED" - fi - - if [ x"$libite" = x"" ]; then - echo "Libite (LITE) : Built-in" - else - echo "Libite (LITE) : $libite + {/lib, /include}" - fi - - if [ x"$libuev" = x"" ]; then - echo "LibuEv : Built-in" - else - echo "LibuEv : $libuev + {/lib, /include}" - fi - - if [ $verbose -ne 1 ]; then - echo "Quiet Finit : YES" - else - echo "Quiet Finit : NO, verbose output (default)" - fi - - if [ $kernel_quiet -eq 1 ]; then - echo "Kernel Quiet : YES, silent after inital boot (default)" - else - echo "Kernel Quiet : NO" - fi - - if [ $static -ne 0 ]; then - echo "Static Finit : YES" - fi - - if [ $disable_plugins -eq 1 ]; then - echo "Plugins : DISABLED" - else - if [ x"$plugins" = x"" ]; then - echo "Plugins : ALL" - else - echo "Plugins : $plugins" - fi - fi - echo -} - -usage() -{ - defaults - - echo "Run this script to configure finit for your operating system." - echo - echo "Usage: $0 [ARG]" - echo - echo " --help This help text" - 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-randomseed=SEED Seed /dev/urandom at boot from SEED. Usually found in" - echo " standard Linux systems at $random" - echo " which is also the default. Requires urandom plugin!" - 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 " --with-console=DEV Console to use, default: /dev/console" -# echo " --with-shell=PATH Fallback shell to use, default: /bin/sh" - echo " --with-sysroot=PATH Some distributions keep a different (writable) rootfs" - echo " that is used at runtime, usually /sysroot or /mnt" - echo " --with-username=USER User for 'startx' .conf option, default: root" - echo " --with-hostname=NAME Hostname, if /etc/hostname is missing, default: noname" - echo " --with-runlevel=LEVEL Runlevel to switch to after bootstrap (S), default: 2" - echo " --with-libite=PATH Look for libite in PATH/include and PATH/lib" - echo " This is for disabling the use of built-in libite." - echo " --with-libuev=PATH Look for libuEv in PATH/include and PATH/lib" - echo " This is for disabling the use of built-in libuEv." - echo - echo " --enable-embedded Embedded defaults, BusBox getty, mdev etc." - echo " --enable-dbus Enable D-Bus plugin. Note: install plugin as well!" - echo " --enable-rw-rootfs Remount / as read-write at bootstrap, not for embedded" - echo " --enable-debug Enable debug flags, '-O0, -g'" - echo " --enable-quiet Quiet mode, reduce screen output to absolute minimum" - echo " --enable-static Link statically. This disables a few features." - echo " --disable-inetd Disable inetd support if not needed." - echo " --disable-kernel-quiet Disable kernel cmdline quiet, default enabled." - echo " --disable-plugins Disable plugins" - 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-randomseed) - random="$arg" - ;; - - with-plugins) - plugins="$arg" - ;; - - with-rcsd) - rcsd="$arg" - ;; - - with-console) - console="\"$arg\"" - ;; - - with-shell) - shell="\"$arg\"" - ;; - - with-sysroot) - sysroot="$arg" - ;; - - with-usename) - defuser="$arg" - ;; - - with-hostname) - defhost="$arg" - ;; - - with-runlevel) - runlevel="$arg" - ;; - - with-libite) - libite="$arg" - ;; - - with-libuev) - libuev="$arg" - ;; - - enable-debug) - debug=1 - ;; - - enable-embedded) - embedded=1 - ;; - - enable-dbus) - dbus=1 - ;; - - enable-rw-rootfs) - remount=1 - ;; - - enable-quiet) - verbose=0 - ;; - - enable-static) - static=1 - ;; - - disable-inetd) - inetd=0 - ;; - - disable-kernel-quiet) - kernel_quiet=0 - ;; - - disable-plugins) - disable_plugins=1 - ;; - - help) - usage - ;; - - *) - echo "Unknown option: $opt" - usage - ;; - esac -done - -# If no arguments given to configure script, use defaults -defaults - -############################################################################## -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 -echo "FINIT_RCSD = $rcsd" >> 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 "CFLAGS += -O0 -g" >> config.mk -else - echo "CFLAGS += -O2" >> 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 [ $disable_plugins -ne 1 ]; then - 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 - 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 - -if [ x"$libite" != x"" ]; then - echo "LIBITE = $libite" >> config.mk - echo "CPPFLAGS += -I\$(LIBITE)/include" >> config.mk - echo "LDFLAGS += -L\$(LIBITE)/lib" >> config.mk - echo "LDLIBS += -l:libite.so.2" >> config.mk -else - echo "LDFLAGS += -L\$(TOPDIR)/libite" >> config.mk - echo "DEPLIBS += libite/.libs/libite.a" >> config.mk -fi - -if [ x"$libuev" != x"" ]; then - echo "LIBUEV = $libuev" >> config.mk - echo "CPPFLAGS += -I\$(LIBUEV)/include" >> config.mk - echo "LDFLAGS += -L\$(LIBUEV)/lib" >> config.mk - echo "LDLIBS += -l:libuev.so.1" >> config.mk -else - echo "LDFLAGS += -L\$(TOPDIR)/libuev" >> config.mk - echo "DEPLIBS += libuev/.libs/libuev.a" >> config.mk -fi - -echo >> config.mk -echo "export libdir plugindir incdir" >> config.mk -echo "export CFLAGS CPPFLAGS LDFLAGS LDLIBS STATIC" >> config.mk - -############################################################################## -echo "/* Generated by finit configure script. */" > config.h -echo >> config.h -echo "#ifndef FINIT_CONFIG_H_" >> config.h -echo "#define FINIT_CONFIG_H_" >> config.h -echo >> config.h -echo "#define INIT_HEADING $heading" >> config.h -echo "#define VERBOSE_MODE $verbose" >> config.h -echo "#define KERNEL_QUIET $kernel_quiet" >> config.h -if [ $embedded -eq 1 ]; then - echo "#define EMBEDDED_SYSTEM 1" >> config.h - echo "#define SETUP_DEVFS \"/sbin/mdev -s\"" >> config.h - echo "#define GETTY \"/sbin/getty -L\"" >> config.h - echo "#define GETTY_BUSYBOX 1" >> config.h - echo "#define BAUDRATE 115200" >> config.h -else - echo "#define SETUP_DEVFS \"/sbin/udevd --daemon\"" >> config.h - echo "#define GETTY \"/sbin/getty -8\"" >> config.h - echo "#define GETTY_AGETTY 1" >> config.h - echo "#define BAUDRATE 38400" >> config.h -fi -if [ $remount -eq 1 ]; then - echo "#define REMOUNT_ROOTFS 1" >> config.h -fi -if [ $dbus -eq 1 ]; then - echo "#define HAVE_DBUS 1" >> config.h -fi - -if [ $inetd -eq 0 ]; then - echo "#define INETD_DISABLED" >> 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 CONSOLE $console" >> config.h -echo "#define FALLBACK_SHELL $shell" >> config.h -if [ x"$sysroot" != x"" ]; then - echo "#define SYSROOT \"$sysroot\"" >> config.h -fi -echo "#define PLUGIN_PATH \"$plugindir\"" >> config.h -if [ x"$random" != x"" ]; then - echo "#define RANDOMSEED \"$random\"" >> config.h -fi -echo "#define DEFUSER \"$defuser\"" >> config.h -echo "#define DEFHOST \"$defhost\"" >> config.h -echo "#define RUNLEVEL $runlevel" >> config.h - -echo >> config.h -echo "#endif /* FINIT_CONFIG_H_ */" >> config.h - -# Call configure in local libite if --with-libite is not selected -if [ x"$libite" = x"" ]; then - set -e - cd libite - test -e Makefile && make distclean >/dev/null - ./autogen.sh - ./configure - cd - - set +e -fi - -# Call configure in local libuev if --with-libuev is not selected -if [ x"$libuev" = x"" ]; then - set -e - cd libuev - test -e Makefile && make distclean >/dev/null - ./autogen.sh - ./configure - cd - - set +e -fi - -# Show resulting config -result diff --git a/configure.ac b/configure.ac new file mode 100644 index 00000000..93c1732d --- /dev/null +++ b/configure.ac @@ -0,0 +1,239 @@ +# Use v2.61 for backwards compat with Ubuntu 12.04 LTS +AC_PREREQ([2.61]) +AC_INIT(Finit, 3.0-beta1, https://github.com/troglobit/finit/issues, finit, http://troglobit.com/finit.html) +AM_INIT_AUTOMAKE([1.11 foreign no-dist-gzip dist-xz subdir-objects]) +AM_SILENT_RULES([yes]) + +AC_CONFIG_SRCDIR([finit.c]) +AC_CONFIG_HEADER([config.h]) +AC_CONFIG_FILES([Makefile plugins/Makefile]) +AC_CONFIG_FILES([libite/Makefile]) +AC_CONFIG_FILES([libuev/Makefile libuev/examples/Makefile]) + +# Older versions of autoconf (<2.58) do not have AC_CONFIG_MACRO_DIR() +#m4_include([m4/misc.m4]) +#m4_include([m4/mroute.m4]) +AC_CONFIG_MACRO_DIR([m4]) + +# Change default prefix, we're PID 1 after all ... +AC_PREFIX_DEFAULT([/]) +datarootdir=/usr/share +AC_SUBST([datarootdir]) + +# Default plugins +#plugins_all="alsa-utils bootmisc dbus hwclock initctl netlink pidfile resolvconf time tty urandom x11-common" + +# Checks for programs. +AC_PROG_CC +AC_PROG_LN_S +AC_PROG_INSTALL + +# Configuration. +AC_HEADER_STDC +AC_CHECK_FUNCS(strstr getopt) + +# Check for uint[8,16,32]_t +AC_TYPE_UINT8_T +AC_TYPE_UINT16_T +AC_TYPE_UINT32_T + +# Needed for the libraries +AM_PROG_AR +LT_INIT([shared disable-static dlopen]) +#LT_INIT([dlopen]) +AM_CONDITIONAL([ENABLE_EXAMPLES], [test "$enable_examples" = yes]) + +# Check for configured Finit features +AC_ARG_ENABLE(embedded, + AS_HELP_STRING([--enable-embedded], [Embedded defaults, BusBox getty, mdev etc.])) + +AC_ARG_ENABLE(rw-rootfs, + AS_HELP_STRING([--enable-rw-rootfs], [Remount / as read-write at bootstrap, not for embedded])) + +AC_ARG_ENABLE(quiet, + AS_HELP_STRING([--enable-quiet], [Quiet mode, reduce screen output to absolute minimum])) + +AC_ARG_ENABLE(inetd, + AS_HELP_STRING([--disable-inetd], [Disable inetd support if not needed, default enabled])) + +AC_ARG_ENABLE(kernel-quiet, + AS_HELP_STRING([--disable-kernel-quiet], [Disable kernel cmdline quiet, default enabled])) + +AC_ARG_WITH(fifo, + AS_HELP_STRING([--with-fifo=FIFO], [Old Finit initctl FIFO, default /dev/initctl]), + [fifo=$withval], [fifo=/dev/initctl]) + +AC_ARG_WITH(config, + AS_HELP_STRING([--with-config=CONFIG], [Finit CONFIG file, default $sysconfdir/finit.conf]), + [conf=$withval], [conf='$(sysconfdir)/finit.conf']) + +AC_ARG_WITH(heading, + AS_HELP_STRING([--with-heading=GREET], [Display GREET instead of Finit version at boot]), + [heading=$withval], [heading='$(PACKAGE_NAME) v$(PACKAGE_VERSION)']) + +AC_ARG_WITH(plugindir, + AS_HELP_STRING([--with-plugindir=DIR], [Finit plugins directory, default $libdir/finit/plugins]), + [pkglibdir=$withval], [pkglibdir='$(libdir)/finit/plugins']) +AC_SUBST([pkglibdir]) + +#AC_ARG_WITH(plugins, +# AS_HELP_STRING([--with-plugins=LIST], [Finit plugins to build, default $plugins_all]), +# [plugins=$withval], [plugins=$plugins_all]) +#plugins_src="" +#plugins_lib="" +#for plug in $plugins; do +# plugins_src="${plugins_src} ${plug}.c" +# plugins_lib="${plugins_lib} ${plug}.la" +#done +#AC_SUBST([plugins_src]) +#AC_SUBST([plugins_lib]) + +AC_ARG_WITH(rcsd, + AS_HELP_STRING([--with-rcsd=DIR], [Finit rc.d/ directory, default $sysconfdir/finit.d]), + [rcsd=$withval], [rcsd='$(sysconfdir)/finit.d']) +AC_SUBST(rcsd) + +AC_ARG_WITH(console, + AS_HELP_STRING([--with-console=DEV], [Console to use, default: /dev/console]), + [console=$withval], [console=/dev/console]) + +AC_ARG_WITH(shell, + AS_HELP_STRING([--with-shell=PATH], [Fallback shell to use, default: /bin/sh]), + [shell=$withval], [shell=/bin/sh]) + +AC_ARG_WITH(username, + AS_HELP_STRING([--with-username=USER], [User for 'startx' .conf option, default: root]), + [username=$withval], [username=root]) + +AC_ARG_WITH(hostname, + AS_HELP_STRING([--with-hostname=NAME], [Hostname, if /etc/hostname is missing, default: noname]), + [hostname=$withval], [hostname=noname]) + +AC_ARG_WITH(runlevel, + AS_HELP_STRING([--with-runlevel=N], [Runlevel to switch to after bootstrap, default: 2]), + [runlevel=$withval], [runlevel=2]) + +### Enable features ########################################################################### + +# Create config.h from selected features and fallback defautls +AS_IF([test "x$enable_embedded" = "xyes"],[ + AC_DEFINE(EMBEDDED_SYSTEM, 1, [Target an embedded system with BusyBox]) + AC_DEFINE(SETUP_DEVFS, "/sbin/mdev -s", [Command to populate /dev]) + AC_DEFINE(GETTY, "/sbin/getty -L", [Command to start getty on login prompt]) + AC_DEFINE(GETTY_BUSYBOX, 1, [Use BusyBox getty call syntax]) + AC_DEFINE(BAUDRATE, 115200, [Default getty baudrate]) + ],[ + AC_DEFINE(SETUP_DEVFS, "/sbin/udevd --daemon", [Command to populate /dev]) + AC_DEFINE(GETTY, "/sbin/getty -8", [Command to start getty on login prompt]) + AC_DEFINE(GETTY_AGETTY, 1, [Use standard agetty call syntax]) + AC_DEFINE(BAUDRATE, 38400, [Default getty baudrate])]) + +AS_IF([test "x$enable_rw-rootfs" = "xyes"],[ + AC_DEFINE(REMOUNT_ROOTFS, 1, [Remount / as rw at boot])]) + +AS_IF([test "x$enable_quiet" = "xyes"],[ + AC_DEFINE(VERBOSE_MODE, 0, [Quiet Finit]) + ],[ + AC_DEFINE(VERBOSE_MODE, 1, [Verbose output, default])]) + +### Disable features ########################################################################### +AS_IF([test "x$enable_inetd" != "xno"],enable_inetd="yes",[ + AC_DEFINE(INETD_DISABLED, 1, [Disable built-in inetd])]) + +AS_IF([test "x$enable_kernel-quiet" != "xno"],[ + AC_DEFINE(KERNEL_QUIET, 0, [Will print stopping/starting/etc messages]) + ],[ + AC_DEFINE(KERNEL_QUIET, 1, [Silent after initial boot, default]) + ]) + +### With features ############################################################################## +AS_IF([test "x$with_fifo" != "xno"],[ + AS_IF([test "x$fifo" = "xyes"],[ + AC_MSG_ERROR([Must supply argument])]) + ],[ + fifo='/dev/initctl']) +AC_SUBST(fifo) + +AS_IF([test "x$with_confing" != "xno"],[ + AS_IF([test "x$config" = "xyes"],[ + AC_MSG_ERROR([Must supply argument])]) + ],[ + conf='$(sysconfdir)/finit.conf']) +AC_SUBST(conf) + +AS_IF([test "x$with_heading" != "xno"],[ + AS_IF([test "x$heading" = "xyes"],[ + AC_MSG_ERROR([Must supply argument])]) + ],[ + heading='$(libdir)/finit']) +AC_DEFINE_UNQUOTED(INIT_HEADING, "$heading", [Displayed by Finit at boot]) + +#AS_IF([test "x$with_plugindir" != "xno"],[ +# AS_IF([test "x$plugindir" = "xyes"],[ +# AC_MSG_ERROR([Must supply argument])]) +# ],[ +# plugindir='$(libdir)/finit']) +#AC_SUBST(plugindir) + +#AS_IF([test "x$with_rcsd" != "xno"],[ +# AS_IF([test "x$rcsd" = "xyes"],[ +# AC_MSG_ERROR([Must supply argument])]) +# ],[ +# rcsd='$(sysconfdir)/finit.d']) + +AS_IF([test "x$with_console" != "xno"],[ + AS_IF([test "x$console" = "xyes"],[ + AC_MSG_ERROR([Must supply argument])]) + ],[ + console=/dev/console]) +AC_DEFINE_UNQUOTED(CONSOLE, "$console", [Default console to use]) + +AS_IF([test "x$with_shell" != "xno"],[ + AS_IF([test "x$shell" = "xyes"],[ + AC_MSG_ERROR([Must supply argument])]) + ],[ + shell=/bin/sh]) +AC_DEFINE_UNQUOTED(FALLBACK_SHELL, "$shell", [Used if no login getty]) + +AS_IF([test "x$with_username" != "xno"],[ + AS_IF([test "x$username" = "xyes"],[ + AC_MSG_ERROR([Must supply argument])]) + ],[ + username=root]) +AC_DEFINE_UNQUOTED(DEFUSER, "$username", [Used for startx .conf option]) + +AS_IF([test "x$with_hostname" != "xno"],[ + AS_IF([test "x$hostname" = "xyes"],[ + AC_MSG_ERROR([Must supply argument])]) + ],[ + hostname=noname]) +AC_DEFINE_UNQUOTED(DEFHOST, "$hostname", [For /etc/hostname]) + +AS_IF([test "x$with_runlevel" != "xno"],[ + AS_IF([test "x$runlevel" = "xyes"],[ + AC_MSG_ERROR([Runlevel must be a number, 1-9, but not 6 (reboot)])]) + AC_DEFINE_UNQUOTED(RUNLEVEL, $runlevel, [Runlevel to start after S]) + ],[ + AC_DEFINE(RUNLEVEL, 2, [Default runlevel to start after S])]) + +# Check if user has downloaded a GitHub ZIP file and attempt to fix it. +AC_MSG_CHECKING([status of GIT submodules]) +if test ! -e libite/lite.h; then + AC_MSG_RESULT([Missing!]) + AC_MSG_CHECKING([if we can update all submodules]) + run=`git submodule update --init` + if test $? -ne 0; then + AC_MSG_RESULT([Failed! No Internet access?]) + exit 1 + fi + AC_MSG_RESULT([Yes, all fixed!]) +else + AC_MSG_RESULT([OK]) +fi + +# Control build with automake flags +AM_CONDITIONAL(STATIC, [test "x$enable_static" = "xyes"]) +AM_CONDITIONAL(INETD, [test "x$enable_inetd" = "xyes"]) + +# Generate all files +AC_OUTPUT diff --git a/initctl.c b/initctl.c index 11fae21b..de709306 100644 --- a/initctl.c +++ b/initctl.c @@ -27,6 +27,7 @@ #include #include +#include "config.h" #include "finit.h" #include "cond.h" #include "helpers.h" @@ -182,7 +183,7 @@ static int do_cond(char *UNUSED(arg)) static int show_version(char *UNUSED(arg)) { - puts("v" VERSION); + puts("v" PACKAGE_VERSION); return 0; } diff --git a/plugin.c b/plugin.c index f0f53b83..40bf75d4 100644 --- a/plugin.c +++ b/plugin.c @@ -27,6 +27,7 @@ #include #include +#include "config.h" #include "finit.h" #include "private.h" #include "helpers.h" diff --git a/plugins/Makefile b/plugins/Makefile deleted file mode 100644 index 112e6e06..00000000 --- a/plugins/Makefile +++ /dev/null @@ -1,53 +0,0 @@ -# Plugin based services architecture for finit --include ../config.mk - -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 \ - netlink.so pidfile.so -DEPS := $(PLUGINS:.so=.d) -endif - -include ../common.mk - -ifneq ($(STATIC), 1) -all: $(PLUGINS) -else -all: - @true -endif - -clean: - -@$(RM) $(PLUGINS) - -distclean: - -@$(RM) *.o *.so $(JUNK) $(DEPS) - -ifneq ($(STATIC), 1) -install: all - @install -d $(DESTDIR)$(plugindir) - @for plugin in $(PLUGINS); do \ - echo " INSTALL $(DESTDIR)$(plugindir)/$$plugin"; \ - $(STRIPINST) $$plugin $(DESTDIR)$(plugindir)/$$plugin; \ - done - -uninstall: - -@for plugin in $(PLUGINS); do \ - echo " RM $(DESTDIR)$(plugindir)/$$plugin"; \ - rm $(DESTDIR)$(plugindir)/$$plugin 2>/dev/null; \ - done - -@rmdir $(DESTDIR)$(plugindir) 2>/dev/null -else -install: - @true -uninstall: - @true -endif - -ifneq ($(MAKECMDGOALS),distclean) --include $(DEPS) -endif diff --git a/plugins/Makefile.am b/plugins/Makefile.am new file mode 100644 index 00000000..bb356588 --- /dev/null +++ b/plugins/Makefile.am @@ -0,0 +1,19 @@ +AM_LDFLAGS = -module -avoid-version -shared -no-undefined -export-dynamic +AM_CPPFLAGS = -U_FORTIFY_SOURCE +AM_CPPFLAGS += -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE +AM_CPPFLAGS += -DFINIT_FIFO=\"$(fifo)\" + +if STATIC +noinst_LTLIBRARIES = libplug.la +libplug_la_SOURCES = alsa-utils.c bootmisc.c dbus.c hwclock.c \ + initctl.c netlink.c pidfile.c resolvconf.c \ + time.c tty.c urandom.c x11-common.c +else +pkglib_LTLIBRARIES = alsa-utils.la bootmisc.la dbus.la hwclock.la \ + initctl.la netlink.la pidfile.la resolvconf.la \ + time.la tty.la urandom.la x11-common.la + +# Clean up .la files installed by libtool despite being in -module mode +install-exec-hook: + @(cd $(DESTDIR)$(pkglibdir) && $(RM) $(pkglib_LTLIBRARIES)) +endif diff --git a/service.c b/service.c index 36482a77..49f3eba9 100644 --- a/service.c +++ b/service.c @@ -144,12 +144,14 @@ static int service_start(svc_t *svc) print_desc("", svc->desc); } +#ifndef INETD_DISABLED if (svc_is_inetd(svc)) { result = inetd_start(&svc->inetd); if (verbose) print_result(result); return result; } +#endif /* Block sigchild while forking. */ sigemptyset(&nmask); @@ -192,12 +194,15 @@ static int service_start(svc_t *svc) args[i] = NULL; /* Redirect inetd socket to stdin for connection */ +#ifndef INETD_DISABLED if (svc_is_inetd_conn(svc)) { dup2(svc->stdin, STDIN_FILENO); close(svc->stdin); dup2(STDIN_FILENO, STDOUT_FILENO); dup2(STDIN_FILENO, STDERR_FILENO); - } else if (debug) { + } else +#endif + if (debug) { int fd; char buf[CMD_SIZE] = ""; @@ -225,6 +230,7 @@ static int service_start(svc_t *svc) else status = execv(svc->cmd, args); /* XXX: Maybe use execve() to be able to launch scripts? */ +#ifndef INETD_DISABLED if (svc_is_inetd_conn(svc)) { if (svc->inetd.type == SOCK_STREAM) { close(STDIN_FILENO); @@ -232,13 +238,15 @@ static int service_start(svc_t *svc) close(STDERR_FILENO); } } - +#endif exit(status); } svc->pid = pid; +#ifndef INETD_DISABLED if (svc_is_inetd_conn(svc) && svc->inetd.type == SOCK_STREAM) close(svc->stdin); +#endif if (SVC_TYPE_RUN == svc->type) { result = WEXITSTATUS(complete(svc->cmd, pid)); @@ -265,6 +273,7 @@ static int service_stop(svc_t *svc) if (!svc) return 1; +#ifndef INETD_DISABLED if (svc_is_inetd(svc)) { int do_print = runlevel != 1 && verbose && svc->block != SVC_BLOCK_INETD_BUSY; @@ -278,6 +287,7 @@ static int service_stop(svc_t *svc) print_result(0); return 0; } +#endif if (svc->pid <= 1) { _d("Bad PID %d for %s, SIGTERM", svc->pid, svc->desc); @@ -784,6 +794,7 @@ restart: break; case SVC_DONE_STATE: +#ifndef INETD_DISABLED if (svc_is_inetd_conn(svc)) { if (svc->inetd.svc->block == SVC_BLOCK_INETD_BUSY) { svc->inetd.svc->block = 0; @@ -792,7 +803,7 @@ restart: service_unregister(svc); return; } - +#endif if (svc_is_changed(svc)) svc_set_state(svc, SVC_HALTED_STATE); break;