Compare commits

..
35 Commits
Author SHA1 Message Date
Joachim Nilsson 757911f149 Bump version for release and update copyright years.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2014-04-21 16:03:54 +02:00
Joachim Nilsson 35b771fb42 Add empty space for formatting.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2014-04-21 15:51:33 +02:00
Joachim Nilsson 720f1b0e5b Strip output when loading .conf files.
If not standard finit.conf, then we want to show just the base name.
E.g., loading first /etc/finit.conf then /etc/finit.d/services.conf

Loading configuration ............. vs
Loading services configuration ....

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2014-04-21 15:46:09 +02:00
Joachim Nilsson 292a3be515 lite.h: Add some helper string comparison methods.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2014-04-21 15:45:23 +02:00
Joachim Nilsson 5ed407e493 helpers.c: Fix mix of off-by-one errors in new print() code.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2014-04-21 14:09:23 +02:00
Joachim Nilsson 40988b901c Unify print_desc() & print_result() in print() and refactor ...
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2014-04-21 14:05:56 +02:00
Joachim Nilsson 26d49b2027 Yet another minor bugfix to new include function.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2014-04-21 12:05:55 +02:00
Joachim Nilsson 10386ee4de Bug fix and document new include <CONF> syntax.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2014-04-21 12:03:10 +02:00
Joachim Nilsson 773d2e65d6 README: Update docs on extended syntax and behavior for tty setting
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2014-04-21 11:17:31 +02:00
Joachim Nilsson 3e29d883fa tty.c:tty_start() - Fix strcmp() foobar from f6f2895, must use strncmp()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2014-04-21 11:08:34 +02:00
Joachim Nilsson f6f2895524 Add support for a fallback shell if no tty is setup
Try to do better by the user, by default, if no tty is specified in the
finit.conf.  This way the user will at least have a way to interact with
the system and repair it.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2014-04-19 22:58:20 +02:00
Joachim Nilsson 62287f8fcc Add support for including .conf files.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2014-04-19 22:56:19 +02:00
Joachim Nilsson be3257f805 print_desc() - Allow arguments to be NULL.
Signed-off-by: Joachim Nilsson <joachim.nilsson@westermo.se>
2014-04-19 22:25:56 +02:00
Joachim Nilsson 1bf3aa528a Fix duplicate link and cleanup contact section.
Signed-off-by: Joachim Nilsson <joachim.nilsson@westermo.se>
2014-04-19 19:31:00 +02:00
Joachim Nilsson 056236c9f8 Freshen up README, TODO, and .conf example, spell check.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2014-04-19 19:19:57 +02:00
Joachim Nilsson 71fff76111 svc.[ch]: Fix possible out of bounds and NULL ptr deref
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2014-04-12 16:41:20 +02:00
Joachim Nilsson 1095724e5c libite: Fix cppcheck warnings in rsync unit test
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2014-04-12 16:34:57 +02:00
Joachim Nilsson e81c2f2f90 libite: Minor style cleanup of fsendfile()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2014-04-12 16:21:41 +02:00
Joachim Nilsson 9f91b4c050 libite: Simplify and fix another memleak in copyfile()
- Simplify: reduce indentation depth
- Always check for error condition first, cleaner code
- Make sure buffer is always freed, use same exit everyhere
- Use readable, but still short, local variable names

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2014-04-12 16:11:59 +02:00
Joachim Nilsson 7ada824e3e Makefile: Add support for make check to run cppcheck
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2014-04-12 16:08:30 +02:00
Joachim Nilsson 7cf7591f0a run_getty(): Handle STDIO descriptors better.
The cppcheck tool raised an alert to the missing close() for
stdin when a console is opened for a getty.  This patch fixes
that warning and also makes the code slighlty more readable.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2014-04-12 15:15:43 +02:00
Joachim Nilsson 143a257c25 libite: Copy utility fixes and new functionality
- Add support for symlinks to copyfile()
- Fix memory leak in copy_filep()
- New function, fsendfile(), copy data between FILE streams

Also, minor whitespace and coding style cleanup.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2014-04-12 15:08:56 +02:00
Joachim Nilsson 1d98647c54 Add missing include for system header file
Only affects externally built plugins.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2014-04-12 14:31:31 +02:00
Joachim Nilsson 7cd52b36a1 Always print service start/stop at start of line
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2014-04-12 14:30:34 +02:00
Joachim Nilsson b033052647 TODO: Further simplify example inetd syntax.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2014-04-10 10:34:06 +02:00
Joachim Nilsson 4fcf2533a6 Minor indentation fix to TODO.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2014-04-10 10:29:06 +02:00
Joachim Nilsson a8a103a521 Update TODO with inetd proposal, and minor README cleanup.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2014-04-10 10:26:46 +02:00
Joachim Nilsson 12b09bb80b Improve CI status integration in README and minor cleanup.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2014-02-25 09:23:16 +01:00
Joachim Nilsson 49aaffcf9a Update README with CI status. 2014-02-25 00:00:43 +01:00
Joachim Nilsson afbe628f17 Travis CI integration
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2014-02-24 23:46:28 +01:00
Joachim Nilsson 1d6cbe31fe Initial support for restarting lost processes during norespawn
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2014-02-24 23:33:38 +01:00
Jonas Johansson cb874d7a94 Handle SIGHUP requst from service when switching runlevel
Signed-off-by: Jonas Johansson <jonasj76@gmail.com>
2014-02-24 23:33:38 +01:00
Joachim Nilsson d7598ca672 Update URL of example to new download FTP. 2013-06-08 15:37:31 +02:00
Joachim Nilsson ff8e494abd Update README with a slightly more clear and catchy intro. 2013-06-08 14:49:28 +02:00
Joachim Nilsson dfaa6dd3f8 Minor ReST syntax fix for improved display in GitHub
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2013-06-08 11:23:24 +02:00
25 changed files with 652 additions and 369 deletions
+6
View File
@@ -0,0 +1,6 @@
# Travis CI integration
language: c
compiler:
- gcc
script: make
+1 -1
View File
@@ -1,5 +1,5 @@
Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com> Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
Copyright (c) 2008-2012 Joachim Nilsson <troglobit@gmail.com> Copyright (c) 2008-2014 Joachim Nilsson <troglobit@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
+5 -2
View File
@@ -1,7 +1,7 @@
# Finit - Extremely fast /sbin/init replacement w/ I/O, hook & service plugins # Finit - Extremely fast /sbin/init replacement w/ I/O, hook & service plugins
# #
# Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com> # Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
# Copyright (c) 2008-2012 Joachim Nilsson <troglobit@gmail.com> # Copyright (c) 2008-2014 Joachim Nilsson <troglobit@gmail.com>
# #
# Permission is hereby granted, free of charge, to any person obtaining a copy # Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal # of this software and associated documentation files (the "Software"), to deal
@@ -26,7 +26,7 @@
uninstall-exec uninstall-data uninstall-dev uninstall-exec uninstall-data uninstall-dev
#VERSION ?= $(shell git tag -l | tail -1) #VERSION ?= $(shell git tag -l | tail -1)
VERSION ?= 1.8 VERSION ?= 1.9
NAME = finit NAME = finit
PKG = $(NAME)-$(VERSION) PKG = $(NAME)-$(VERSION)
DEV = $(NAME)-dev DEV = $(NAME)-dev
@@ -141,6 +141,9 @@ distclean: clean
$(MAKE) -C libite $@ $(MAKE) -C libite $@
$(MAKE) -C plugins $@ $(MAKE) -C plugins $@
check:
$(CHECK) *.c plugins/*.c libite/*.c
dist: dist:
@echo "Building xz tarball of $(PKG) in parent dir..." @echo "Building xz tarball of $(PKG) in parent dir..."
git archive --format=tar --prefix=$(PKG)/ $(VERSION) | xz >../$(ARCHIVE) git archive --format=tar --prefix=$(PKG)/ $(VERSION) | xz >../$(ARCHIVE)
+10
View File
@@ -2,6 +2,16 @@
NEWS NEWS
============================================================================== ==============================================================================
1.9 (2014-04-21)
----------------
* Bug fixes, code cleanup
* Add support for an include directive to .conf files
* Fallback to ``/bin/sh`` if user forgets tty setting
* Handle ``SIGHUP`` from service callback properly when switching runlevel
* Initial support for restarting lost services during ``norespwan``
* Misc. major (memleak) and minor fixes and additions to libite/lite.h
1.8 (2013-06-07) 1.8 (2013-06-07)
---------------- ----------------
* Support for runlevels, with a bootstrap runlevel 'S' * Support for runlevels, with a bootstrap runlevel 'S'
+89 -66
View File
@@ -1,60 +1,66 @@
============================================================================== ==============================================================================
Finit — A fast plugin-based /sbin/init with service monitoring Finit | Fast Init Replacement
============================================================================== ==============================================================================
|cistatus|
Welcome to finit! Finit is a small `SysV init`_ replacement with `process supervision`_
similar to that of `daemontools`_ and `runit`_. Its focus is on small
and embedded GNU/Linux systems, although fully functional on standard
server and desktop installations. It should also work on other UNIX
systems, but this has yet to be proven.
This is an extremely fast /sbin/init replacement with focus on small Finit is fast because it starts services in parallel, it then supervises
embedded GNU/Linux systems. Based on Claudio Matsuoka's original finit_ and automatically restarts them if they fail. This can be extended upon
with I/O, service and hook plugin extensions. The original was a with custom callbacks for all services, hooks into the boot process, or
reimplementation of the EeePC fastinit_ daemon based on its system calls plugins to extend the functionality and adapt Finit to your needs.
with gaps filled with frog DNA.
In the world of finit we write C plugins that hook into and extend the Finit is not only fast, it's arguably one of the easiest to get started
``main()`` loop of ``/sbin/init``, this is what gives the system its raw with. A complete system can be booted with one simple configuration
performance and the user full control. file, ``/etc/finit.conf``, see below for syntax.
If you chose finit you know what you want, a fast no hassles boot!
Features Features
-------- --------
**Service monitoring** **Process Supervision**
Restarting a service when it exits Start, monitor and restarting services if they fail.
**Runlevels**
Finit supports standard runlevels if you want, but you don't need them
for simple installations.
**Plugins** **Plugins**
Extend and modify finit behavior. See examples in plugins/ directory. Extend and modify finit behavior. See examples in plugins/ directory.
Plugin capabilities: Plugin capabilities:
* Service callbacks — should the service run/restart/stop? * Service callbacks — modify service arguments, run/restart/stop
* Task/Run callbacks — a one-shot command, should it run in sequence? * Task/Run callbacks — a one-shot commands, executed in sequence
* Hooks — hook into the boot at predefined points to extend finit * Hooks — hook into the boot at predefined points to extend finit
* I/O — listen to external events and control finit behaviour/services * I/O — listen to external events and control finit behavior/services
Most extensions and functionality not purely related to what an /sbin/init Extensions and functionality not purely related to what an /sbin/init
needs to start a system from the original finit_ has been reactored into needs to start a system are available as a set of plugins that either
plugins with either hooks or I/O demands. hook into the boot process or respond to various I/O.
/etc/finit.conf /etc/finit.conf
--------------- ---------------
Contrary to most script based init alternatives (`SysV init`_, upstart_, Contrary to most script based init alternatives (`SysV init`_, upstart_,
OpenRC_ and the likes) finit instead reads its configuration from systemd_, OpenRC_ and the likes) finit instead reads its configuration
``/etc/finit.conf``. Below is a brief list, see the source code for the from ``/etc/finit.conf``. Below is a brief list, see the source code
full list: for the full list:
check check <DEV>
Run fsck on a file system before mounting it Run fsck on a file system before mounting it
module module <MODULE>
Load a kernel module, with optional arguments Load a kernel module, with optional arguments
network network <PATH>
Script or program to bringup networking, with optional arguments Script or program to bring up networking, with optional arguments
runlevel N runlevel <N>
N is the runlevel number 1-9, where 6 is reserved for reboot N is the runlevel number 1-9, where 6 is reserved for reboot
run [RUN_LVLS] /path/to/cmd ARGS -- Optional description run [RUN_LVLS] /path/to/cmd ARGS -- Optional description
@@ -71,16 +77,24 @@ service [RUN_LVLS] /path/to/daemon ARGS -- Optional description
a --foreground or --no-background argument to most daemons to a --foreground or --no-background argument to most daemons to
prevent them from forking off to the background. prevent them from forking off to the background.
runparts runparts <PATH>
Call run-parts(8) on a directory other than the default /etc/finit.d Call run-parts(8) on a directory other than default ``/etc/finit.d``
tty [RUN_LVLS] DEV include <CONF>
Run getty on the listed TTY device, in the given runlevels Include another configuration file, ``/etc/finit.d``, or runparts
path is prepended to file if the file is not found or an absolute
path is not given
console DEV tty [RUN_LVLS] <DEV | /bin/sh>
Start a getty on the given TTY device, in the given runlevels. When
no tty setting is given in ``finit.conf``, or if /bin/sh is given as
argument instead of a device path, a single shell is started on the
default console. Useful for really bare-bones systems
console <DEV>
Some embedded systems have a dedicated console port. This command Some embedded systems have a dedicated console port. This command
tells finit to not start getty, but instead print a friendly message tells finit to not start getty, but instead print a friendly message
and wait for the user to activate the console with a keypress before and wait for the user to activate the console with a key press before
starting getty. starting getty.
When running ``make install`` no default ``/etc/finit.conf`` will be When running ``make install`` no default ``/etc/finit.conf`` will be
@@ -96,9 +110,9 @@ getty!
At the end of the boot, when networking and all services are up, finit At the end of the boot, when networking and all services are up, finit
calls its built-in run-parts(8) on the ``/etc/finit.d/`` directory, if calls its built-in run-parts(8) on the ``/etc/finit.d/`` directory, if
it exists. Similar to how the ``/ec/rc.local`` file works in most other it exists. Similar to how the ``/ec/rc.local`` file works in most other
inits, only finit runs a directory of scripts. This replaces the init daemons, only finit runs a directory of scripts. This replaces the
earlier support for a ``/usr/sbin/services.sh`` script in the original earlier support for a ``/usr/sbin/services.sh`` script in the original
finit_. finit.
Runlevels Runlevels
@@ -109,23 +123,23 @@ services, tasks, run commands and TTYs listed without a set of runlevels
get a default set [234] assigned. The default runlevel after boot is 2. get a default set [234] assigned. The default runlevel after boot is 2.
To specify an allowed set of runlevels for a service, run command, task, To specify an allowed set of runlevels for a service, run command, task,
or tty, add [NNN] to it in finit.conf, like this: or tty, add [NNN] to it in finit.conf, like this::
run [S] /etc/init.d/acpid start -- Starting ACPI Daemon run [S] /etc/init.d/acpid start -- Starting ACPI Daemon
task [S] /etc/init.d/kbd start -- Preparing console task [S] /etc/init.d/kbd start -- Preparing console
service [S12345] /sbin/klogd -n -x -- Kernel log daemon service [S12345] /sbin/klogd -n -x -- Kernel log daemon
tty [12345] /dev/tty1 tty [12345] /dev/tty1
tty [2] /dev/tty2 tty [2] /dev/tty2
tty [2] /dev/tty3 tty [2] /dev/tty3
tty [2] /dev/tty4 tty [2] /dev/tty4
tty [2] /dev/tty5 tty [2] /dev/tty5
tty [2] /dev/tty6 tty [2] /dev/tty6
In this example acpid is started once at bootstrap using a conventional In this example acpid is started once at bootstrap using a conventional
SysV init script. Here the run command was used, meaning the following SysV init script. Here the run command was used, meaning the following
task command is not run until the init script has fully completed. task command is not run until the init script has fully completed.
Tasks and services are started in parallell, while run commands are run Tasks and services are started in parallel, while run commands are run
in the order listed and subsequent commands are not started until a run in the order listed and subsequent commands are not started until a run
command has completed. command has completed.
@@ -163,16 +177,16 @@ what is built and where resulting binaries are installed.
be overridden by packages to add a suffix or completely alter the version. be overridden by packages to add a suffix or completely alter the version.
**CFLAGS=** **CFLAGS=**
Standard CFLAGS are inherited from the build enviornmant. Standard CFLAGS are inherited from the build environment.
**CPPFLAGS=** **CPPFLAGS=**
Standard CPPFLAGS are inherited from the build enviornmant. Standard CPPFLAGS are inherited from the build environment.
**LDFLAGS=** **LDFLAGS=**
Standard LDFLAGS are inherited from the build enviornmant. Standard LDFLAGS are inherited from the build environment.
**LDLIBS=** **LDLIBS=**
Standard LIBLIBS are inherited from the build enviornmant. Standard LIBLIBS are inherited from the build environment.
**prefix=** **prefix=**
Base prefix path for all files, except ``sbinbdir`` and ``sysconfdir``. Base prefix path for all files, except ``sbinbdir`` and ``sysconfdir``.
@@ -197,7 +211,7 @@ what is built and where resulting binaries are installed.
**DESTDIR=** **DESTDIR=**
Used by packagers and distributions when building a relocatable Used by packagers and distributions when building a relocatable
bundle of files. Alwawys prepended to the ``prefix`` destination bundle of files. Always prepended to the ``prefix`` destination
directory. directory.
**Example**:: **Example**::
@@ -225,7 +239,7 @@ what is built and where resulting binaries are installed.
In this example the `finit-1.3.tar.xz`_ archive is unpacked to the In this example the `finit-1.3.tar.xz`_ archive is unpacked to the
user's home directory, built and installed to a temporary staging user's home directory, built and installed to a temporary staging
directory. The enviroment variables ``DESTDIR`` and ``PLUGINS`` are directory. The environment variables ``DESTDIR`` and ``PLUGINS`` are
changed to suit this particular build. changed to suit this particular build.
@@ -248,7 +262,7 @@ Debugging
Add ``finit_debug``, or ``--debug``, to the kernel command line to Add ``finit_debug``, or ``--debug``, to the kernel command line to
enable trace messages. A console getty is always started, see the file enable trace messages. A console getty is always started, see the file
``finit.h`` for more useful comile-time tweaks:: ``finit.h`` for more useful compile-time tweaks::
init=/sbin/finit --debug init=/sbin/finit --debug
@@ -256,17 +270,26 @@ enable trace messages. A console getty is always started, see the file
Contact Contact
------- -------
Finit is maintained collaborativly at http://github.com/troglobit/finit — This is the continuation of the `original finit`_ by Claudio Matsuoka,
please file a bug report, clone it, or send pull requests for bug fixes and which in turn was reverse engineered from syscalls of the `EeePC
proposed extensions, or become a co-maintainer by contacting the main author. fastinit`_ -- "gaps filled with frog DNA ...". It is currently being
developed and maintained by `Joachim Nilsson`_ at `GitHub`_. Please
file bug reports, clone it, or send pull requests for bug fixes and
proposed extensions.
Regards .. _`SysV init`: https://en.wikipedia.org/wiki/Init
/Joachim Nilsson <troglobit@gmail.com> .. _`Joachim Nilsson`: http://troglobit.com
.. _GitHub: http://github.com/troglobit/finit
.. _finit: http://helllabs.org/finit/ .. _`process supervision`: https://en.wikipedia.org/wiki/Process_supervision
.. _fastinit: http://wiki.eeeuser.com/boot_process:the_boot_process .. _`daemontools`: http://cr.yp.to/daemontools.html
.. _`SysV init`: http://savannah.nongnu.org/projects/sysvinit .. _`runit`: http://smarden.org/runit/
.. _`original finit`: http://helllabs.org/finit/
.. _`EeePC fastinit`: http://wiki.eeeuser.com/boot_process:the_boot_process
.. _upstart: http://upstart.ubuntu.com/ .. _upstart: http://upstart.ubuntu.com/
.. _runlevels: http://en.wikipedia.org/wiki/Runlevel .. _runlevels: http://en.wikipedia.org/wiki/Runlevel
.. _systemd: http://www.freedesktop.org/wiki/Software/systemd/
.. _openrc: http://www.gentoo.org/proj/en/base/openrc/ .. _openrc: http://www.gentoo.org/proj/en/base/openrc/
.. _`finit-1.3.tar.xz`: http://github.com/downloads/troglobit/finit/finit-1.3.tar.xz .. _`finit-1.3.tar.xz`: ftp://troglobit.com/finit/finit-1.3.tar.xz
.. |cistatus| image:: https://travis-ci.org/troglobit/finit.png?branch=master
:target: https://travis-ci.org/troglobit/finit
+19 -6
View File
@@ -14,6 +14,22 @@ similiar to launchd, the goal of finit is to be a FAST replacement for:
The main goal is to be FAST. Secondary goals are to be: small, simple The main goal is to be FAST. Secondary goals are to be: small, simple
and with a very low dependency on external packages. and with a very low dependency on external packages.
Inetd
-----
Simple way of running Internet services on demand, like the old inetd::
inetd SVC [RUNLVL] /path/to/daemon args -- description
Example::
# Inetd services, launched on demand
inetd ssh [2345] /usr/sbin/sshd -i -- SSH Daemon
In keeping with the finit tradition, an optional callback can be setup
to each inetd service. When a client connects the finit will call the
callback with a `struct in_pktinfo` argument which the callback then can
allowed or deny.
Priority Priority
-------- --------
@@ -24,13 +40,10 @@ processes that declare themselves to be finit compliant.
* Integrate the ingenious libev to handle all events: signals, polling * Integrate the ingenious libev to handle all events: signals, polling
fd's, etc. Because "Event driven software improves concurrency" -- fd's, etc. Because "Event driven software improves concurrency" --
Dave Zarzycki, Apple. See the `launchd video`_ for more info! Dave Zarzycki, Apple. See the `launchd video`_ for more info!
* Add support for process and system supervision. Which could
be an API wrapping, e.g., TIPC and loadavg.
* Add support for a /dev/watchdog plugin to replace watchdogd * Add support for a /dev/watchdog plugin to replace watchdogd
* Integrate watchdog plugin with process/system supervisor to * Integrate watchdog plugin with process/system supervisor to optionally
reboot the system when a process stops responding, or when reboot the system when a process stops responding, or when a respawn
restarting it is imposible, as well as when system load gets limit has been reached, as well as when system load gets too high.
too high.
Configuration Configuration
+1
View File
@@ -5,6 +5,7 @@ ROOTDIR ?= $(TOPDIR)
JUNK = *~ *.bak *.aux *.dvi *.idx *.ind *.log *.ps *.map .*.d DEADJOE semantic.cache *.gdb *.elf core core.* JUNK = *~ *.bak *.aux *.dvi *.idx *.ind *.log *.ps *.map .*.d DEADJOE semantic.cache *.gdb *.elf core core.*
MAKE := @$(MAKE) MAKE := @$(MAKE)
MAKEFLAGS = --no-print-directory --silent MAKEFLAGS = --no-print-directory --silent
CHECK := cppcheck $(CPPFLAGS) --quiet --enable=all
INSTALL := install --backup=off INSTALL := install --backup=off
STRIPINST := $(INSTALL) -s --strip-program=$(CROSS)strip -m 0755 STRIPINST := $(INSTALL) -s --strip-program=$(CROSS)strip -m 0755
+178 -126
View File
@@ -86,141 +86,193 @@ int parse_runlevels(char *runlevels)
return bitmask; return bitmask;
} }
void parse_finit_conf(char *file) static int parse_conf(char *file)
{ {
FILE *fp; FILE *fp;
char line[LINE_SIZE]; char line[LINE_SIZE] = "";
char cmd[CMD_SIZE]; char cmd[CMD_SIZE];
char *x;
const char *err = NULL;
fp = fopen(file, "r");
if (!fp)
return 1;
/*
* If not standard finit.conf, then we want to show just the base name
* Loading configuration ............. vs
* Loading services configuration ....
*/
if (!string_match (file, FINIT_CONF)) {
/* Remove leading path */
x = strrchr(file, '/');
if (!x) x = file;
else x++;
/* Remove ending .conf */
strlcpy(line, x, sizeof(line));
x = strstr(line, ".conf");
if (x) *x = 0;
/* Add empty space. */
strcat(line, " ");
}
print(0, "Loading %sconfiguration", line);
while (!feof(fp)) {
if (!fgets(line, sizeof(line), fp))
continue;
chomp(line);
_d("conf: %s", line);
/* Skip comments. */
if (MATCH_CMD(line, "#", x))
continue;
/* Do this before mounting / read-write
* XXX: Move to plugin which checks /etc/fstab instead */
if (MATCH_CMD(line, "check ", x)) {
char *dev = strip_line(x);
strcpy(cmd, "/sbin/fsck -C -a ");
strlcat(cmd, dev, sizeof(cmd));
run_interactive(cmd, "Checking file system %s", dev);
continue;
}
if (MATCH_CMD(line, "user ", x)) {
if (username) free(username);
username = strdup(strip_line(x));
continue;
}
if (MATCH_CMD(line, "host ", x)) {
if (hostname) free(hostname);
hostname = strdup(strip_line(x));
continue;
}
if (MATCH_CMD(line, "module ", x)) {
char *mod = strip_line(x);
strcpy(cmd, "/sbin/modprobe ");
strlcat(cmd, mod, sizeof(cmd));
run_interactive(cmd, "Loading kernel module %s", mod);
continue;
}
if (MATCH_CMD(line, "mknod ", x)) {
char *dev = strip_line(x);
strcpy(cmd, "/bin/mknod ");
strlcat(cmd, dev, sizeof(cmd));
run_interactive(cmd, "Creating device node %s", dev);
continue;
}
if (MATCH_CMD(line, "network ", x)) {
if (network) free(network);
network = strdup(strip_line(x));
continue;
}
/* This is the directory from which executable scripts and
* any finit include files are read, default /etc/finit.d/ */
if (MATCH_CMD(line, "runparts ", x)) {
if (rcsd) free(rcsd);
rcsd = strdup(strip_line(x));
continue;
}
/* Parse any include file, use rcsd if absolute path not given */
if (MATCH_CMD(line, "include ", x)) {
char *file = strip_line(x);
strlcpy(cmd, file, sizeof(cmd));
if (!fexist(cmd)) {
/* ... try /etc/finit.d/ as prefix */
snprintf(cmd, sizeof(cmd), "%s/%s", rcsd, file);
if (!fexist(cmd))
continue;
}
parse_conf(cmd);
continue;
}
if (MATCH_CMD(line, "startx ", x)) {
svc_register(SVC_CMD_SERVICE, strip_line(x), username);
continue;
}
if (MATCH_CMD(line, "shutdown ", x)) {
if (sdown) free(sdown);
sdown = strdup(strip_line(x));
continue;
}
/* The desired runlevel to start when leaving
* bootstrap (S). Finit supports 1-9, but most
* systems only use 1-6, where 6 is reserved for
* reboot */
if (MATCH_CMD(line, "runlevel ", x)) {
char *token = strip_line(x);
cfglevel = strtonum(token, 1, 9, &err);
if (err)
cfglevel = RUNLEVEL;
if (cfglevel < 1 || cfglevel > 9 || cfglevel == 6)
cfglevel = 2; /* Fallback */
continue;
}
/* Monitored daemon, will be respawned on exit, as
* long as the (optional) service callback returns
* non-zero */
if (MATCH_CMD(line, "service ", x)) {
svc_register(SVC_CMD_SERVICE, x, NULL);
continue;
}
/* One-shot task, will not be respawned. Only runs if
* the (optional) service callback returns true */
if (MATCH_CMD(line, "task ", x)) {
svc_register(SVC_CMD_TASK, x, NULL);
continue;
}
/* Like task but waits for completion, useful w/ [S] */
if (MATCH_CMD(line, "run ", x)) {
svc_register(SVC_CMD_RUN, x, NULL);
continue;
}
if (MATCH_CMD(line, "console ", x)) {
if (console) free(console);
console = strdup(strip_line(x));
continue;
}
if (MATCH_CMD(line, "tty ", x)) {
tty_register(strip_line(x));
continue;
}
}
fclose(fp);
return 0;
}
int parse_finit_conf(char *file)
{
int result;
username = strdup(DEFUSER); username = strdup(DEFUSER);
hostname = strdup(DEFHOST); hostname = strdup(DEFHOST);
rcsd = strdup(FINIT_RCSD); rcsd = strdup(FINIT_RCSD);
if ((fp = fopen(file, "r")) != NULL) { result = parse_conf(file);
char *x; if (!tty_num())
const char *err = NULL; tty_register(FALLBACK_SHELL);
_d("Parse %s ...", file); return result;
while (!feof(fp)) {
if (!fgets(line, sizeof(line), fp))
continue;
chomp(line);
_d("conf: %s", line);
/* Skip comments. */
if (MATCH_CMD(line, "#", x))
continue;
/* Do this before mounting / read-write
* XXX: Move to plugin which checks /etc/fstab instead */
if (MATCH_CMD(line, "check ", x)) {
char *dev = strip_line(x);
strcpy(cmd, "/sbin/fsck -C -a ");
strlcat(cmd, dev, sizeof(cmd));
run_interactive(cmd, "Checking file system %s", dev);
continue;
}
if (MATCH_CMD(line, "user ", x)) {
if (username) free(username);
username = strdup(strip_line(x));
continue;
}
if (MATCH_CMD(line, "host ", x)) {
if (hostname) free(hostname);
hostname = strdup(strip_line(x));
continue;
}
if (MATCH_CMD(line, "module ", x)) {
char *mod = strip_line(x);
strcpy(cmd, "/sbin/modprobe ");
strlcat(cmd, mod, sizeof(cmd));
run_interactive(cmd, "Loading kernel module %s", mod);
continue;
}
if (MATCH_CMD(line, "mknod ", x)) {
char *dev = strip_line(x);
strcpy(cmd, "/bin/mknod ");
strlcat(cmd, dev, sizeof(cmd));
run_interactive(cmd, "Creating device node %s", dev);
continue;
}
if (MATCH_CMD(line, "network ", x)) {
if (network) free(network);
network = strdup(strip_line(x));
continue;
}
if (MATCH_CMD(line, "runparts ", x)) {
if (rcsd) free(rcsd);
rcsd = strdup(strip_line(x));
continue;
}
if (MATCH_CMD(line, "startx ", x)) {
svc_register(SVC_CMD_SERVICE, strip_line(x), username);
continue;
}
if (MATCH_CMD(line, "shutdown ", x)) {
if (sdown) free(sdown);
sdown = strdup(strip_line(x));
continue;
}
/* The desired runlevel to start when leaving
* bootstrap (S). Finit supports 1-9, but most
* systems only use 1-6, where 6 is reserved for
* reboot */
if (MATCH_CMD(line, "runlevel ", x)) {
char *token = strip_line(x);
cfglevel = strtonum(token, 1, 9, &err);
if (err)
cfglevel = RUNLEVEL;
if (cfglevel < 1 || cfglevel > 9 || cfglevel == 6)
cfglevel = 2; /* Fallback */
continue;
}
/* Monitored daemon, will be respawned on exit, as
* long as the (optional) service callback returns
* non-zero */
if (MATCH_CMD(line, "service ", x)) {
svc_register(SVC_CMD_SERVICE, x, NULL);
continue;
}
/* One-shot task, will not be respawned. Only runs if
* the (optional) service callback returns true */
if (MATCH_CMD(line, "task ", x)) {
svc_register(SVC_CMD_TASK, x, NULL);
continue;
}
/* Like task but waits for completion, useful w/ [S] */
if (MATCH_CMD(line, "run ", x)) {
svc_register(SVC_CMD_RUN, x, NULL);
continue;
}
if (MATCH_CMD(line, "console ", x)) {
if (console) free(console);
console = strdup(strip_line(x));
continue;
}
if (MATCH_CMD(line, "tty ", x)) {
tty_register(strip_line(x));
continue;
}
}
fclose(fp);
}
} }
+2 -2
View File
@@ -1,7 +1,7 @@
/* Finit - Extremely fast /sbin/init replacement w/ I/O, hook & service plugins /* Finit - Extremely fast /sbin/init replacement w/ I/O, hook & service plugins
* *
* Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com> * Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
* Copyright (c) 2008-2012 Joachim Nilsson <troglobit@gmail.com> * Copyright (c) 2008-2014 Joachim Nilsson <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@@ -207,7 +207,7 @@ int main(int argc, char* argv[])
* all services, or service plugins won't have anything to * all services, or service plugins won't have anything to
* hook on to. * hook on to.
*/ */
print_desc("", "Loading Finit plugins"); print_desc("Loading plugins", NULL);
print_result(plugin_load_all(PLUGIN_PATH)); print_result(plugin_load_all(PLUGIN_PATH));
/* /*
+6 -7
View File
@@ -24,15 +24,14 @@ tty /dev/tty3
# Alternative method instead of runparts # Alternative method instead of runparts
#task [S] /etc/init.d/keyboard-setup start -- Setting up preliminary keymap #task [S] /etc/init.d/keyboard-setup start -- Setting up preliminary keymap
#task [S] /etc/init.d/acpid start -- Starting ACPI Daemon #task [S] /etc/init.d/acpid start -- Starting ACPI Daemon
#task [S] /etc/init.d/kbd start -- Preparing console #task [S] /etc/init.d/kbd start -- Preparing console
#run [2] /etc/init.d/networking start -- Start networking #run [2] /etc/init.d/networking start -- Start networking
# Services to be monitored and respawned as needed # Services to be monitored and respawned as needed
service [2345] /sbin/klogd -n -- Kernel logging server service [2345] /sbin/klogd -n -- Kernel logging server
service [2345] /sbin/syslogd -n -- Syslog server service [2345] /sbin/syslogd -n -- Syslog server
service [2345] /usr/sbin/sshd -D -- OpenSSH server service [3] /usr/sbin/gdm -- GNOME Display Manager
service [3] /usr/sbin/gdm -- GNOME Display Manager
# By default Finit looks for /etc/finit.d # By default Finit looks for /etc/finit.d
# runparts /etc/finit.d # runparts /etc/finit.d
+27 -22
View File
@@ -27,6 +27,7 @@
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <paths.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/types.h> #include <sys/types.h>
@@ -35,41 +36,45 @@
/* Distribution specific configuration */ /* Distribution specific configuration */
#if defined EMBEDDED_SYSTEM #if defined EMBEDDED_SYSTEM
# define CONSOLE "/dev/console" # define CONSOLE _PATH_CONSOLE
# define SETUP_DEVFS "/sbin/mdev -s" # define SETUP_DEVFS "/sbin/mdev -s"
# define GETTY "/sbin/getty -L" # define GETTY "/sbin/getty -L"
# define GETTY_BUSYBOX # define GETTY_BUSYBOX
# define BAUDRATE 115200 # define BAUDRATE 115200
# define RUNLEVEL 2 # define RUNLEVEL 2
#else /* Debian/Ubuntu based distributions */ #else /* Debian/Ubuntu based distributions */
# define CONSOLE "/dev/tty1" # define CONSOLE "/dev/tty1"
# define SETUP_DEVFS "/sbin/udevd --daemon" # define SETUP_DEVFS "/sbin/udevd --daemon"
# define GETTY "/sbin/getty -8" # define GETTY "/sbin/getty -8"
# define GETTY_AGETTY # define GETTY_AGETTY
# define BAUDRATE 38400 # define BAUDRATE 38400
# define RUNLEVEL 2 # define RUNLEVEL 2
# define RANDOMSEED "/var/lib/urandom/random-seed" # define RANDOMSEED "/var/lib/urandom/random-seed"
# define REMOUNT_ROOTFS_RW # define REMOUNT_ROOTFS_RW
# define HAVE_DBUS # define HAVE_DBUS
#endif #endif
#ifndef FALLBACK_SHELL
# define FALLBACK_SHELL _PATH_BSHELL
#endif
#ifndef DEFUSER #ifndef DEFUSER
# define DEFUSER "root" # define DEFUSER "root"
#endif #endif
#ifndef DEFHOST #ifndef DEFHOST
# define DEFHOST "noname" # define DEFHOST "noname"
#endif #endif
/* Delay start of GETTY at boot. Must be > 0 */ /* Delay start of GETTY at boot. Must be > 0 */
#define DELAY_TTY 2 #define DELAY_TTY 2
#define CMD_SIZE 256 #define CMD_SIZE 256
#define LINE_SIZE 1024 #define LINE_SIZE 1024
#define BUF_SIZE 4096 #define BUF_SIZE 4096
#define INIT_MAGIC 0x03091969 #define INIT_MAGIC 0x03091969
#define INIT_CMD_RUNLVL 1 #define INIT_CMD_RUNLVL 1
#define INIT_CMD_DEBUG 2 #define INIT_CMD_DEBUG 2
struct init_request { struct init_request {
int magic; /* Magic number */ int magic; /* Magic number */
@@ -91,8 +96,8 @@ extern char *console;
extern char *__progname; extern char *__progname;
/* conf.c */ /* conf.c */
int parse_runlevels (char *runlevels); int parse_runlevels (char *runlevels);
void parse_finit_conf (char *file); int parse_finit_conf (char *file);
#endif /* FINIT_H_ */ #endif /* FINIT_H_ */
+53 -19
View File
@@ -1,7 +1,7 @@
/* Misc. utility functions and C-library extensions for finit and its plugins /* Misc. utility functions and C-library extensions for finit and its plugins
* *
* Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com> * Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
* Copyright (c) 2008-2012 Joachim Nilsson <troglobit@gmail.com> * Copyright (c) 2008-2014 Joachim Nilsson <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@@ -151,7 +151,7 @@ pid_t pidfile_read(char *pidfile)
errno = 0; errno = 0;
pid = strtoul(buf, NULL, 0); pid = strtoul(buf, NULL, 0);
if (errno) if (errno)
pid = 0; /* Failed conversion. */ pid = 0; /* Failed conversion. */
} }
fclose(fp); fclose(fp);
@@ -330,25 +330,55 @@ static int print_timestamp(void)
return 0; return 0;
} }
void print_desc(char *action, char *desc) void print(int action, const char *fmt, ...)
{ {
char buf[80];
size_t len;
va_list ap;
const char success[] = " \e[1m[ OK ]\e[0m\n";
const char failure[] = " \e[7m[FAIL]\e[0m\n";
const char pending[] = " \e[1m[ \\/ ]\e[0m\n";
const char dots[] = " ....................................................................."; const char dots[] = " .....................................................................";
delline(); if (fmt) {
print_timestamp(); va_start(ap, fmt);
len = vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
write(STDERR_FILENO, action, strlen(action)); delline();
write(STDERR_FILENO, desc, strlen(desc)); print_timestamp();
write(STDERR_FILENO, dots, 60 - strlen(desc) - strlen(action)); /* pad with dots. */
write(STDERR_FILENO, "\r", 1);
write(STDERR_FILENO, buf, len);
write(STDERR_FILENO, dots, 60 - len); /* pad with dots. */
}
switch (action) {
case -1:
break;
case 0:
write(STDERR_FILENO, success, sizeof(success));
break;
case 1:
write(STDERR_FILENO, failure, sizeof(failure));
break;
default:
write(STDERR_FILENO, pending, sizeof(pending));
break;
}
}
void print_desc(char *action, char *desc)
{
print(-1, "%s%s", action ?: "", desc ?: "");
} }
int print_result(int fail) int print_result(int fail)
{ {
if (fail) print(!!fail, NULL);
fprintf(stderr, " \e[7m[FAIL]\e[0m\n");
else
fprintf(stderr, " \e[1m[ OK ]\e[0m\n");
return fail; return fail;
} }
@@ -421,7 +451,7 @@ int run(char *cmd)
struct sigaction sa; struct sigaction sa;
/* Reset signal handlers that were set by the parent process */ /* Reset signal handlers that were set by the parent process */
for (i = 1; i < NSIG; i++) for (i = 1; i < NSIG; i++)
DFLSIG(sa, i, 0); DFLSIG(sa, i, 0);
/* Redirect stdio if the caller requested so. */ /* Redirect stdio if the caller requested so. */
@@ -510,7 +540,7 @@ pid_t run_getty(char *cmd, char *args[], int console)
pid_t pid = fork(); pid_t pid = fork();
if (!pid) { if (!pid) {
int i; int i, fd;
char c; char c;
sigset_t nmask; sigset_t nmask;
struct sigaction sa; struct sigaction sa;
@@ -519,12 +549,13 @@ pid_t run_getty(char *cmd, char *args[], int console)
/* Detach from initial controlling TTY */ /* Detach from initial controlling TTY */
vhangup(); vhangup();
close(2); close(STDERR_FILENO);
close(1); close(STDOUT_FILENO);
close(0); close(STDIN_FILENO);
/* Attach TTY to console */ /* Attach TTY to console */
if (open(CONSOLE, O_RDWR) != 0) fd = open(CONSOLE, O_RDWR);
if (fd != STDIN_FILENO)
exit(1); exit(1);
dup2(0, STDIN_FILENO); dup2(0, STDIN_FILENO);
@@ -560,6 +591,9 @@ pid_t run_getty(char *cmd, char *args[], int console)
execv(cmd, args); execv(cmd, args);
} }
if (console)
close(fd);
exit(0); exit(0);
} }
+2 -1
View File
@@ -1,7 +1,7 @@
/* Misc. utility functions and C-library extensions for finit and its plugins /* Misc. utility functions and C-library extensions for finit and its plugins
* *
* Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com> * Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
* Copyright (c) 2008-2012 Joachim Nilsson <troglobit@gmail.com> * Copyright (c) 2008-2014 Joachim Nilsson <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@@ -93,6 +93,7 @@ char *pid_get_name (pid_t pid, char *name, size_t len);
void procname_set (char *name, char *args[]); void procname_set (char *name, char *args[]);
int procname_kill (char *name, int signo); int procname_kill (char *name, int signo);
void print (int action, const char *fmt, ...);
void print_desc (char *action, char *desc); void print_desc (char *action, char *desc);
int print_result (int fail); int print_result (int fail);
int start_process (char *cmd, char *args[], int console); int start_process (char *cmd, char *args[], int console);
+1 -1
View File
@@ -1,6 +1,6 @@
# Finit libite -- Light-weight utility functions and C-library extensions # Finit libite -- Light-weight utility functions and C-library extensions
# #
# Copyright (c) 2008-2012 Joachim Nilsson <troglobit@gmail.com> # Copyright (c) 2008-2014 Joachim Nilsson <troglobit@gmail.com>
# #
# Permission is hereby granted, free of charge, to any person obtaining a copy # Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal # of this software and associated documentation files (the "Software"), to deal
+107 -48
View File
@@ -34,13 +34,14 @@
#include "lite.h" #include "lite.h"
static int __isdir_and_append_filename(char *src, char **dst); static int adjust_target(char *src, char **dst);
/** /**
* copyfile - Copy a file to another. * copyfile - Copy a file to another.
* @src: Source file. * @src: Source file.
* @dst: Target file. * @dst: Target file.
* @len: Number of bytes to copy, zero (0) for entire file. * @len: Number of bytes to copy, zero (0) for entire file.
* @sym: Should symlinks be recreated (1) or followed (0)
* *
* This is a C implementation of the command line cp(1) utility. It is one * This is a C implementation of the command line cp(1) utility. It is one
* of the classic missing links in the UNIX C library. This version is from * of the classic missing links in the UNIX C library. This version is from
@@ -54,58 +55,70 @@ static int __isdir_and_append_filename(char *src, char **dst);
* may also indicate that @src was empty. If @src is a directory errno * may also indicate that @src was empty. If @src is a directory errno
* will be set to %EISDIR since copyfile() is not recursive. * will be set to %EISDIR since copyfile() is not recursive.
*/ */
ssize_t copyfile(char *src, char *dst, int len) ssize_t copyfile(char *src, char *dst, int len, int sym)
{ {
char *buffer; char *buffer;
int s, d, n, isdir = 0, saved_errno = 0; int in, out, isdir = 0, saved_errno = 0;
ssize_t size = 0; ssize_t num, size = 0;
errno = 0; /* Reset before leaving this function. */ errno = 0;
// fprintf (stderr, "%s() src: %s, dst: %s, len: %d\n", __func__, src, dst, len);
buffer = malloc(BUFSIZ); buffer = malloc(BUFSIZ);
if (!buffer) if (!buffer)
return 0; return 0;
if (fisdir(src)) { if (fisdir(src)) {
errno = EISDIR; /* Error: source is a directory */ saved_errno = EISDIR; /* Error: source is a directory */
return 0; goto exit;
} }
/* Check if target is a directory, then append the src base filename. */ /* Check if target is a directory, then append src filename. */
isdir = __isdir_and_append_filename(src, &dst); isdir = adjust_target(src, &dst);
/* Len == 0 means copy entire file */ if (sym) {
if (len == 0) { size = readlink(src, buffer, BUFSIZ);
/* XXX: This feels a bit unsafe, but 2047 MiB may be sufficient for us. if (size > 0) {
* --Jocke 2008-08-11 */ if (size >= (ssize_t) BUFSIZ) {
len = INT_MAX; saved_errno = ENOBUFS;
} goto exit;
if ((s = open(src, O_RDONLY)) >= 0) {
if ((d =
open(dst, O_WRONLY | O_CREAT | O_TRUNC,
fmode(src))) >= 0) {
do {
int clen = len > BUFSIZ ? BUFSIZ : len;
if ((n = read(s, buffer, clen)) > 0) {
size += write(d, buffer, n);
}
len -= clen;
} }
while (len > 0 && n == BUFSIZ);
close(d); buffer[size] = 0;
} else { size = !symlink(buffer, dst);
saved_errno = errno; goto exit;
} }
close(s);
} else {
saved_errno = errno;
} }
/* 0: copy entire file */
if (len == 0)
len = INT_MAX; /* XXX: 2047 MiB should sufficient ... */
in = open(src, O_RDONLY);
if (in < 0) {
saved_errno = errno;
goto exit;
}
out = open(dst, O_WRONLY | O_CREAT | O_TRUNC, fmode(src));
if (out < 0) {
close(in);
saved_errno = errno;
goto exit;
}
do {
int clen = len > BUFSIZ ? BUFSIZ : len;
num = read(in, buffer, clen);
if (num > 0)
size += write(out, buffer, num);
len -= clen;
} while (len > 0 && num == BUFSIZ);
close(out);
close(in);
exit:
free(buffer); free(buffer);
if (isdir) if (isdir)
free(dst); free(dst);
@@ -135,12 +148,12 @@ int movefile(char *src, char *dst)
int isdir, result = 0; int isdir, result = 0;
/* Check if target is a directory, then append the src base filename. */ /* Check if target is a directory, then append the src base filename. */
isdir = __isdir_and_append_filename(src, &dst); isdir = adjust_target(src, &dst);
if (rename(src, dst)) { if (rename(src, dst)) {
if (errno == EXDEV) { if (errno == EXDEV) {
errno = 0; errno = 0;
copyfile(src, dst, 0); copyfile(src, dst, 0, 0);
if (errno) if (errno)
result = 1; result = 1;
else else
@@ -170,27 +183,30 @@ int movefile(char *src, char *dst)
int copy_filep(FILE *src, FILE *dst) int copy_filep(FILE *src, FILE *dst)
{ {
int result = 0; int result = 0;
char *buf = (char *)malloc(BUFSIZ); char *buf;
if (!src || !dst) if (!src || !dst)
return EINVAL; return EINVAL;
buf = (char *)malloc(BUFSIZ);
if (!buf) if (!buf)
return errno; return errno;
while (1) { while (1) {
errno = 0; errno = 0;
if (!fgets(buf, BUFSIZ, src)) { if (!fgets(buf, BUFSIZ, src)) {
if (errno == EINTR) { if (errno == EINTR) {
clearerr(src); clearerr(src);
continue; continue;
} }
if (feof(src)) if (feof(src))
break; break;
result = errno; result = errno;
goto exit; goto exit;
} }
while (EOF == fputs(buf, dst)) { while (EOF == fputs(buf, dst)) {
if (errno == EINTR) { if (errno == EINTR) {
clearerr(dst); clearerr(dst);
@@ -202,13 +218,58 @@ int copy_filep(FILE *src, FILE *dst)
} }
} }
exit: exit:
free(buf); free(buf);
return errno = result; return errno = result;
} }
/**
* fsendfile - copy data between file streams
* @out: Destination stream
* @in: Source stream
* @sz: Size in bytes to copy.
*
* @out may be NULL, in which case @sz bytes are read and discarded
* from @in. This is useful for streams where seeks are not
* permitted. Additionally @sz may be the special value zero (0) in
* which case fsendfile will copy until EOF is seen on @src.
*
* Returns:
* The number of bytes copied. If there was an error, -1 is returned
* and errno will be set accordingly.
*/
size_t fsendfile (FILE *out, FILE *in, size_t sz)
{
char *buf;
size_t blk = BUFSIZ, num = 0, tot = 0;
buf = (char *)malloc(BUFSIZ);
if (!buf)
return -1;
while (!sz || tot < sz) {
if (sz && ((sz - tot) < BUFSIZ))
blk = sz - tot;
num = fread(buf, 1, blk, in);
if (num == 0)
break;
if (out && (fwrite(buf, num, 1, out) != 1)) {
num = -1;
break;
}
tot += num;
}
free(buf);
return (num == (size_t)-1) ? (size_t)-1 : tot;
}
/* Tests if dst is a directory, if so, reallocates dst and appends src filename returning 1 */ /* Tests if dst is a directory, if so, reallocates dst and appends src filename returning 1 */
static int __isdir_and_append_filename(char *src, char **dst) static int adjust_target(char *src, char **dst)
{ {
int isdir = 0; int isdir = 0;
@@ -221,7 +282,6 @@ static int __isdir_and_append_filename(char *src, char **dst)
else else
ptr++; ptr++;
// fprintf (stderr, "Yes %s is a dir --> add %s\n", *dst, ptr);
tmp = malloc(strlen(*dst) + strlen(ptr) + 2); tmp = malloc(strlen(*dst) + strlen(ptr) + 2);
if (!tmp) { if (!tmp) {
errno = EISDIR; errno = EISDIR;
@@ -233,7 +293,6 @@ static int __isdir_and_append_filename(char *src, char **dst)
sprintf(tmp, "%s%s%s", *dst, slash ? "" : "/", ptr); sprintf(tmp, "%s%s%s", *dst, slash ? "" : "/", ptr);
*dst = tmp; *dst = tmp;
// fprintf (stderr, "NEW DST:%s\n", *dst);
} }
return isdir; return isdir;
@@ -254,7 +313,7 @@ int main(int argc, char *argv[])
printf("Copying file %s to %s\n", argv[1], argv[2]); printf("Copying file %s to %s\n", argv[1], argv[2]);
return copyfile(argv[1], argv[2], 0); return copyfile(argv[1], argv[2], 0, 0);
} }
#else #else
int main(void) int main(void)
@@ -293,7 +352,7 @@ int main(void)
i = 0; i = 0;
while (files[i]) { while (files[i]) {
fprintf(stderr, "copyfile(%s, %s)\t", files[i], files[i + 1]); fprintf(stderr, "copyfile(%s, %s)\t", files[i], files[i + 1]);
if (!copyfile(files[i], files[i + 1], 0)) if (!copyfile(files[i], files[i + 1], 0, 0))
perror("Failed"); perror("Failed");
if (fexist(files[i + 2])) if (fexist(files[i + 2]))
@@ -312,7 +371,7 @@ int main(void)
* Local Variables: * Local Variables:
* compile-command: "gcc -g -I../include -o unittest -DUNITTEST copyfile.c && ./unittest" * compile-command: "gcc -g -I../include -o unittest -DUNITTEST copyfile.c && ./unittest"
* version-control: t * version-control: t
* kept-new-versions: 2 * indent-tabs-mode: t
* c-file-style: "ellemtel" * c-file-style: "linux"
* End: * End:
*/ */
+1 -1
View File
@@ -1,6 +1,6 @@
/* Functions for operating on files in directories. /* Functions for operating on files in directories.
* *
* Copyright (c) 2008-2012 Joachim Nilsson <troglobit@gmail.com> * Copyright (c) 2008-2014 Joachim Nilsson <troglobit@gmail.com>
* *
* Permission to use, copy, modify, and/or distribute this software for any * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
+33 -2
View File
@@ -1,7 +1,7 @@
/* Collection of utility funcs and C library extensions for finit & its plugins /* Collection of utility funcs and C library extensions for finit & its plugins
* *
* Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com> * Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
* Copyright (c) 2008-2012 Joachim Nilsson <troglobit@gmail.com> * Copyright (c) 2008-2014 Joachim Nilsson <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@@ -29,15 +29,17 @@
#include <string.h> #include <string.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/param.h> /* MAX(), isset(), setbit(), TRUE, FALSE, et consortes. :-) */
#include <unistd.h> #include <unistd.h>
int fexist (char *file); int fexist (char *file);
int fisdir (char *file); int fisdir (char *file);
mode_t fmode (char *file); mode_t fmode (char *file);
ssize_t copyfile (char *src, char *dst, int len); ssize_t copyfile (char *src, char *dst, int len, int sym);
int movefile (char *src, char *dst); int movefile (char *src, char *dst);
int copy_filep (FILE *src, FILE *dst); int copy_filep (FILE *src, FILE *dst);
size_t fsendfile (FILE *out, FILE *in, size_t sz);
int dir (const char *dir, const char *type, int (*filter) (const char *file), char ***list, int strip); int dir (const char *dir, const char *type, int (*filter) (const char *file), char ***list, int strip);
int rsync (char *src, char *dst, int delete, int (*filter) (const char *file)); int rsync (char *src, char *dst, int delete, int (*filter) (const char *file));
@@ -59,6 +61,35 @@ static inline int fisslashdir(char *dir)
return 0; return 0;
} }
/* Validate string, non NULL and not zero length */
static inline int string_valid (const char *s)
{
return s && strlen (s);
}
/* Relaxed comparison, e.g., sys_string_match("small", "smaller") => TRUE */
static inline int string_match (const char *a, const char *b)
{
size_t min = MIN(strlen (a), strlen (b));
return !strncasecmp (a, b, min);
}
/* Strict comparison, e.g., sys_string_match("small", "smaller") => FALSE */
static inline int string_compare (const char *a, const char *b)
{
return strlen (a) == strlen (b) && !strcmp (a, b);
}
/* Strict comparison, like sys_string_compare(), but case insensitive,
* e.g., sys_string_match("small", "SmAlL") => TRUE
*/
static inline int string_case_compare (const char *a, const char *b)
{
return strlen (a) == strlen (b) && !strcasecmp (a, b);
}
#endif /* FINIT_LITE_H_ */ #endif /* FINIT_LITE_H_ */
/** /**
+18 -13
View File
@@ -61,7 +61,7 @@ int rsync(char *src, char *dst, int delete, int (*filter) (const char *file))
void copy(char *src, char *dst) void copy(char *src, char *dst)
{ {
errno = 0; errno = 0;
copyfile(src, dst, 0); copyfile(src, dst, 0, 1);
if (errno) { if (errno) {
if (errno == EEXIST) if (errno == EEXIST)
errno = 0; errno = 0;
@@ -142,26 +142,31 @@ static int makedir(char *buf, size_t buf_len, char *dir, char *name, mode_t mode
return 0; return 0;
} }
static int find(char *file, char **files, int num)
{
int n;
for (n = 0; n < num; n++)
if (!strncmp (files[n], file, MAX(strlen(files[n]), strlen(file))))
return 1;
return 0;
}
/* Prune old files, no longer existing on source, from destination directory. */ /* Prune old files, no longer existing on source, from destination directory. */
static int prune(char *dst, char **new_files, int new_num) static int prune(char *dst, char **new_files, int new_num)
{ {
int i, num, result = 0; int num, result = 0;
char **files; char **files;
int find(char *file) {
int n;
for (n = 0; n < new_num; n++)
if (!strncmp (new_files[n], file, MAX(strlen(new_files[n]), strlen(file))))
return 1;
return 0;
}
num = dir(dst, "", NULL, &files, 0); num = dir(dst, "", NULL, &files, 0);
if (num) { if (num) {
int i;
for (i = 0; i < num; i++) { for (i = 0; i < num; i++) {
if (!find(files[i])) { if (!find(files[i], new_files, new_num)) {
char *name; char *name;
size_t len = strlen(files[i]) + 2 + strlen(dst); size_t len = strlen(files[i]) + 2 + strlen(dst);
+1 -1
View File
@@ -1,7 +1,7 @@
/* Optional /dev/initctl FIFO monitor /* Optional /dev/initctl FIFO monitor
* *
* Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com> * Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
* Copyright (c) 2008-2012 Joachim Nilsson <troglobit@gmail.com> * Copyright (c) 2008-2014 Joachim Nilsson <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,7 +1,7 @@
/* Signal management - Be conservative with what finit responds to! /* Signal management - Be conservative with what finit responds to!
* *
* Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com> * Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
* Copyright (c) 2008-2012 Joachim Nilsson <troglobit@gmail.com> * Copyright (c) 2008-2014 Joachim Nilsson <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,7 +1,7 @@
/* Signal management - Be conservative with what finit responds to! /* Signal management - Be conservative with what finit responds to!
* *
* Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com> * Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
* Copyright (c) 2008-2012 Joachim Nilsson <troglobit@gmail.com> * Copyright (c) 2008-2014 Joachim Nilsson <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+41 -17
View File
@@ -37,6 +37,7 @@
/* The registered services are kept in shared memory for easy read-only access /* The registered services are kept in shared memory for easy read-only access
* by 3rd party APIs. Mostly because of the ability to, from the outside, query * by 3rd party APIs. Mostly because of the ability to, from the outside, query
* liveness state of all daemons that should run. */ * liveness state of all daemons that should run. */
static int was_stopped = 0;
static int svc_counter = 0; /* Number of registered services to monitor. */ static int svc_counter = 0; /* Number of registered services to monitor. */
static svc_t *services = NULL; /* List of registered services, in shared memory. */ static svc_t *services = NULL; /* List of registered services, in shared memory. */
@@ -132,11 +133,11 @@ svc_t *svc_iterator(int restart)
void svc_bootstrap(void) void svc_bootstrap(void)
{ {
svc_t *svc; svc_t *svc;
svc_cmd_t cmd;
_d("Bootstrapping all services in runlevel S from %s", FINIT_CONF); _d("Bootstrapping all services in runlevel S from %s", FINIT_CONF);
for (svc = svc_iterator(1); svc; svc = svc_iterator(0)) { for (svc = svc_iterator(1); svc; svc = svc_iterator(0)) {
cmd = svc_enabled(svc, 0, NULL); svc_cmd_t cmd = svc_enabled(svc, 0, NULL);
if (SVC_START == cmd || (SVC_RELOAD == cmd)) if (SVC_START == cmd || (SVC_RELOAD == cmd))
svc_start(svc); svc_start(svc);
} }
@@ -188,6 +189,8 @@ void svc_runlevel(int newlevel)
if (svc->pid) { if (svc->pid) {
if (run == SVC_STOP) if (run == SVC_STOP)
svc_stop(svc); svc_stop(svc);
else if (run == SVC_RELOAD)
svc_reload(svc);
} else { } else {
if (run == SVC_START) if (run == SVC_START)
svc_start(svc); svc_start(svc);
@@ -345,11 +348,29 @@ static int is_norespawn(void)
fexist("/tmp/norespawn"); fexist("/tmp/norespawn");
} }
static void restart_any_lost_procs(void)
{
svc_t *svc;
for (svc = svc_iterator(1); svc; svc = svc_iterator(0)) {
if (svc->pid > 0 && pid_alive(svc->pid))
continue;
svc_start(svc);
}
}
void svc_monitor(void) void svc_monitor(void)
{ {
pid_t lost; pid_t lost;
svc_t *svc; svc_t *svc;
if (was_stopped && !is_norespawn()) {
was_stopped = 0;
restart_any_lost_procs();
return;
}
lost = waitpid(-1, NULL, WNOHANG); lost = waitpid(-1, NULL, WNOHANG);
if (lost < 1) if (lost < 1)
return; return;
@@ -358,8 +379,10 @@ void svc_monitor(void)
return; return;
/* Power user at the console, don't respawn tasks. */ /* Power user at the console, don't respawn tasks. */
if (is_norespawn()) if (is_norespawn()) {
was_stopped = 1;
return; return;
}
if (tty_respawn(lost)) if (tty_respawn(lost))
return; return;
@@ -400,13 +423,13 @@ void svc_monitor(void)
/* Remember: svc_enabled() must be called before calling svc_start() */ /* Remember: svc_enabled() must be called before calling svc_start() */
int svc_start(svc_t *svc) int svc_start(svc_t *svc)
{ {
int respawn = svc->pid != 0; int respawn;
pid_t pid; pid_t pid;
sigset_t nmask, omask; sigset_t nmask, omask;
char *args[MAX_NUM_SVC_ARGS];
if (!svc) if (!svc)
return 0; return 0;
respawn = svc->pid != 0;
/* Don't try and start service if it doesn't exist. */ /* Don't try and start service if it doesn't exist. */
if (!fexist(svc->cmd)) { if (!fexist(svc->cmd)) {
@@ -428,24 +451,25 @@ int svc_start(svc_t *svc)
else if (!respawn) else if (!respawn)
print_desc("Starting ", svc->desc); print_desc("Starting ", svc->desc);
/* Block sigchild while forking. */ /* Block sigchild while forking. */
sigemptyset(&nmask); sigemptyset(&nmask);
sigaddset(&nmask, SIGCHLD); sigaddset(&nmask, SIGCHLD);
sigprocmask(SIG_BLOCK, &nmask, &omask); sigprocmask(SIG_BLOCK, &nmask, &omask);
pid = fork(); pid = fork();
sigprocmask(SIG_SETMASK, &omask, NULL); sigprocmask(SIG_SETMASK, &omask, NULL);
if (pid == 0) { if (pid == 0) {
int i = 0; int i = 0;
int uid = getuser(svc->username); int uid = getuser(svc->username);
struct sigaction sa; struct sigaction sa;
char *args[MAX_NUM_SVC_ARGS];
sigemptyset(&nmask); sigemptyset(&nmask);
sigaddset(&nmask, SIGCHLD); sigaddset(&nmask, SIGCHLD);
sigprocmask(SIG_UNBLOCK, &nmask, NULL); sigprocmask(SIG_UNBLOCK, &nmask, NULL);
/* Reset signal handlers that were set by the parent process */ /* Reset signal handlers that were set by the parent process */
for (i = 1; i < NSIG; i++) for (i = 1; i < NSIG; i++)
DFLSIG(sa, i, 0); DFLSIG(sa, i, 0);
/* Set desired user */ /* Set desired user */
@@ -453,7 +477,7 @@ int svc_start(svc_t *svc)
setuid(uid); setuid(uid);
/* Serve copy of args to process in case it modifies them. */ /* Serve copy of args to process in case it modifies them. */
for (i = 0; svc->args[i][0] != 0 && i < MAX_NUM_SVC_ARGS; i++) for (i = 0; i < MAX_NUM_SVC_ARGS && svc->args[i][0] != 0; i++)
args[i] = svc->args[i]; args[i] = svc->args[i];
args[i] = NULL; args[i] = NULL;
@@ -467,7 +491,7 @@ int svc_start(svc_t *svc)
dup2(STDERR_FILENO, fd); dup2(STDERR_FILENO, fd);
} }
for (i = 0; args[i] && i < MAX_NUM_SVC_ARGS; i++) { for (i = 0; i < MAX_NUM_SVC_ARGS && args[i]; i++) {
char arg[MAX_ARG_LEN]; char arg[MAX_ARG_LEN];
snprintf(arg, sizeof(arg), "%s ", args[i]); snprintf(arg, sizeof(arg), "%s ", args[i]);
+21 -20
View File
@@ -1,7 +1,7 @@
/* Finit service monitor and generic API for managing svc_t structures /* Finit service monitor and generic API for managing svc_t structures
* *
* Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com> * Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
* Copyright (c) 2008-2012 Joachim Nilsson <troglobit@gmail.com> * Copyright (c) 2008-2014 Joachim Nilsson <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@@ -27,6 +27,7 @@
#include <errno.h> #include <errno.h>
#include <string.h> /* strerror() */ #include <string.h> /* strerror() */
#include <sys/ipc.h> /* IPC_CREAT */
#include <sys/shm.h> /* shmat() */ #include <sys/shm.h> /* shmat() */
#include <sys/types.h> /* pid_t */ #include <sys/types.h> /* pid_t */
@@ -57,21 +58,21 @@ typedef struct svc {
pid_t pid; pid_t pid;
svc_type_t type; svc_type_t type;
int reload; int reload;
int runlevels; int runlevels;
unsigned int restart_counter; /* Incremented for each restart by service monitor. */ unsigned int restart_counter; /* Incremented for each restart by service monitor. */
char cmd[MAX_ARG_LEN]; char cmd[MAX_ARG_LEN];
char args[MAX_NUM_SVC_ARGS][MAX_ARG_LEN]; char args[MAX_NUM_SVC_ARGS][MAX_ARG_LEN];
char desc[MAX_STR_LEN]; char desc[MAX_STR_LEN];
char username[MAX_USER_LEN]; char username[MAX_USER_LEN];
/* For external plugins. If @cb is set a plugin is loaded. /* For external plugins. If @cb is set a plugin is loaded.
* @dynamic: Set by plugins that want dynamic events. * @dynamic: Set by plugins that want dynamic events.
* @dynamic_stop: Set by plugins that allow dyn. events to stop it as well. * @dynamic_stop: Set by plugins that allow dyn. events to stop it as well.
* @private: Can be used freely by plugin, e.g., to store "states". * @private: Can be used freely by plugin, e.g., to store "states".
*/ */
int dynamic; int dynamic;
int dynamic_stop; int dynamic_stop;
int private; int private;
svc_cmd_t (*cb)(struct svc *svc, int event, void *event_arg); svc_cmd_t (*cb)(struct svc *svc, int event, void *event_arg);
} svc_t; } svc_t;
@@ -80,11 +81,11 @@ typedef struct svc_map svc_map_t;
/* Put services array in shm */ /* Put services array in shm */
static inline svc_t *finit_svc_connect(void) static inline svc_t *finit_svc_connect(void)
{ {
const long ID = FINIT_SHM_ID;
static void *ptr = (void *)-1; static void *ptr = (void *)-1;
if ((void *)-1 == ptr) { if ((void *)-1 == ptr) {
ptr = shmat (shmget (ID, sizeof(svc_t) * MAX_NUM_SVC, 0600 | IPC_CREAT), NULL, 0); ptr = shmat (shmget (FINIT_SHM_ID, sizeof(svc_t) * MAX_NUM_SVC,
0600 | IPC_CREAT), NULL, 0);
if ((void *)-1 == ptr) if ((void *)-1 == ptr)
return NULL; return NULL;
} }
@@ -92,18 +93,18 @@ static inline svc_t *finit_svc_connect(void)
return (svc_t *)ptr; return (svc_t *)ptr;
} }
svc_t *svc_new (void); svc_t *svc_new (void);
svc_t *svc_find (char *name); svc_t *svc_find (char *name);
svc_t *svc_iterator (int restart); svc_t *svc_iterator (int restart);
void svc_runlevel (int newlevel); void svc_runlevel (int newlevel);
int svc_register (int type, char *line, char *username); int svc_register (int type, char *line, char *username);
int svc_id_by_name (char *name); int svc_id_by_name (char *name);
svc_cmd_t svc_enabled (svc_t *svc, int event, void *arg); svc_cmd_t svc_enabled (svc_t *svc, int event, void *arg);
int svc_start (svc_t *svc); int svc_start (svc_t *svc);
int svc_start_by_name (char *name); int svc_start_by_name (char *name);
int svc_stop (svc_t *svc); int svc_stop (svc_t *svc);
int svc_reload (svc_t *svc); int svc_reload (svc_t *svc);
#endif /* FINIT_SVC_H_ */ #endif /* FINIT_SVC_H_ */
+18 -3
View File
@@ -102,6 +102,17 @@ tty_node_t *tty_find(char *dev)
return NULL; return NULL;
} }
size_t tty_num(void)
{
size_t num = 0;
tty_node_t *entry;
LIST_FOREACH(entry, &tty_list, link)
num++;
return num;
}
tty_node_t *tty_find_by_pid(pid_t pid) tty_node_t *tty_find_by_pid(pid_t pid)
{ {
tty_node_t *entry; tty_node_t *entry;
@@ -127,13 +138,17 @@ void tty_start(finit_tty_t *tty)
if (console && !strcmp(tty->name, console)) if (console && !strcmp(tty->name, console))
is_console = 1; is_console = 1;
if (!strncmp(tty->name, _PATH_DEV, strlen(_PATH_DEV))) {
#if defined(GETTY_AGETTY) #if defined(GETTY_AGETTY)
snprintf(line, sizeof(line), "%s %s %d %s", GETTY, tty->name, tty->baud, tty->term ?: ""); snprintf(line, sizeof(line), "%s %s %d %s", GETTY, tty->name, tty->baud, tty->term ?: "");
#elif defined(GETTY_BUSYBOX) #elif defined(GETTY_BUSYBOX)
snprintf(line, sizeof(line), "%s %d %s %s", GETTY, tty->baud, tty->name, tty->term ?: ""); snprintf(line, sizeof(line), "%s %d %s %s", GETTY, tty->baud, tty->name, tty->term ?: "");
#else #else
#error No GETTY defined! strlcpy(line, FALLBACK_CONSOLE, sizeof(line));
#endif #endif
} else {
strlcpy(line, tty->name, sizeof(line));
}
cmd = strtok(line, " "); cmd = strtok(line, " ");
args[i++] = basename(cmd); args[i++] = basename(cmd);
while ((arg = strtok(NULL, " "))) while ((arg = strtok(NULL, " ")))
+9 -8
View File
@@ -32,7 +32,7 @@
typedef struct { typedef struct {
char *name; char *name;
int baud; int baud;
char *term; char *term;
int runlevels; int runlevels;
int pid; int pid;
@@ -45,14 +45,15 @@ typedef struct tty_node {
//extern LIST_HEAD(, tty_node) tty_list; //extern LIST_HEAD(, tty_node) tty_list;
int tty_register (char *line); int tty_register (char *line);
tty_node_t *tty_find (char *dev); tty_node_t *tty_find (char *dev);
size_t tty_num (void);
tty_node_t *tty_find_by_pid (pid_t pid); tty_node_t *tty_find_by_pid (pid_t pid);
void tty_start (finit_tty_t *tty); void tty_start (finit_tty_t *tty);
void tty_stop (finit_tty_t *tty); void tty_stop (finit_tty_t *tty);
int tty_enabled (finit_tty_t *tty, int runlevel); int tty_enabled (finit_tty_t *tty, int runlevel);
int tty_respawn (pid_t pid); int tty_respawn (pid_t pid);
void tty_runlevel (int runlevel); void tty_runlevel (int runlevel);
#endif /* FINIT_TTY_H_ */ #endif /* FINIT_TTY_H_ */