mirror of
https://github.com/troglobit/finit.git
synced 2026-10-12 10:12:32 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
757911f149 | ||
|
|
35b771fb42 | ||
|
|
720f1b0e5b | ||
|
|
292a3be515 | ||
|
|
5ed407e493 | ||
|
|
40988b901c | ||
|
|
26d49b2027 | ||
|
|
10386ee4de | ||
|
|
773d2e65d6 | ||
|
|
3e29d883fa | ||
|
|
f6f2895524 | ||
|
|
62287f8fcc | ||
|
|
be3257f805 | ||
|
|
1bf3aa528a | ||
|
|
056236c9f8 | ||
|
|
71fff76111 | ||
|
|
1095724e5c | ||
|
|
e81c2f2f90 | ||
|
|
9f91b4c050 | ||
|
|
7ada824e3e | ||
|
|
7cf7591f0a | ||
|
|
143a257c25 | ||
|
|
1d98647c54 | ||
|
|
7cd52b36a1 | ||
|
|
b033052647 | ||
|
|
4fcf2533a6 | ||
|
|
a8a103a521 | ||
|
|
12b09bb80b | ||
|
|
49aaffcf9a | ||
|
|
afbe628f17 | ||
|
|
1d6cbe31fe | ||
|
|
cb874d7a94 | ||
|
|
d7598ca672 | ||
|
|
ff8e494abd | ||
|
|
dfaa6dd3f8 |
@@ -0,0 +1,6 @@
|
||||
# Travis CI integration
|
||||
language: c
|
||||
compiler:
|
||||
- gcc
|
||||
|
||||
script: make
|
||||
@@ -1,5 +1,5 @@
|
||||
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
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Finit - Extremely fast /sbin/init replacement w/ I/O, hook & service plugins
|
||||
#
|
||||
# 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
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -26,7 +26,7 @@
|
||||
uninstall-exec uninstall-data uninstall-dev
|
||||
|
||||
#VERSION ?= $(shell git tag -l | tail -1)
|
||||
VERSION ?= 1.8
|
||||
VERSION ?= 1.9
|
||||
NAME = finit
|
||||
PKG = $(NAME)-$(VERSION)
|
||||
DEV = $(NAME)-dev
|
||||
@@ -141,6 +141,9 @@ distclean: clean
|
||||
$(MAKE) -C libite $@
|
||||
$(MAKE) -C plugins $@
|
||||
|
||||
check:
|
||||
$(CHECK) *.c plugins/*.c libite/*.c
|
||||
|
||||
dist:
|
||||
@echo "Building xz tarball of $(PKG) in parent dir..."
|
||||
git archive --format=tar --prefix=$(PKG)/ $(VERSION) | xz >../$(ARCHIVE)
|
||||
|
||||
@@ -2,6 +2,16 @@
|
||||
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)
|
||||
----------------
|
||||
* Support for runlevels, with a bootstrap runlevel 'S'
|
||||
|
||||
+89
-66
@@ -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
|
||||
embedded GNU/Linux systems. Based on Claudio Matsuoka's original finit_
|
||||
with I/O, service and hook plugin extensions. The original was a
|
||||
reimplementation of the EeePC fastinit_ daemon based on its system calls
|
||||
with gaps filled with frog DNA.
|
||||
Finit is fast because it starts services in parallel, it then supervises
|
||||
and automatically restarts them if they fail. This can be extended upon
|
||||
with custom callbacks for all services, hooks into the boot process, or
|
||||
plugins to extend the functionality and adapt Finit to your needs.
|
||||
|
||||
In the world of finit we write C plugins that hook into and extend the
|
||||
``main()`` loop of ``/sbin/init``, this is what gives the system its raw
|
||||
performance and the user full control.
|
||||
|
||||
If you chose finit you know what you want, a fast no hassles boot!
|
||||
Finit is not only fast, it's arguably one of the easiest to get started
|
||||
with. A complete system can be booted with one simple configuration
|
||||
file, ``/etc/finit.conf``, see below for syntax.
|
||||
|
||||
|
||||
Features
|
||||
--------
|
||||
|
||||
**Service monitoring**
|
||||
Restarting a service when it exits
|
||||
**Process Supervision**
|
||||
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**
|
||||
Extend and modify finit behavior. See examples in plugins/ directory.
|
||||
Extend and modify finit behavior. See examples in plugins/ directory.
|
||||
Plugin capabilities:
|
||||
|
||||
* Service callbacks — should the service run/restart/stop?
|
||||
* Task/Run callbacks — a one-shot command, should it run in sequence?
|
||||
* Service callbacks — modify service arguments, run/restart/stop
|
||||
* Task/Run callbacks — a one-shot commands, executed in sequence
|
||||
* 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
|
||||
needs to start a system from the original finit_ has been reactored into
|
||||
plugins with either hooks or I/O demands.
|
||||
Extensions and functionality not purely related to what an /sbin/init
|
||||
needs to start a system are available as a set of plugins that either
|
||||
hook into the boot process or respond to various I/O.
|
||||
|
||||
|
||||
/etc/finit.conf
|
||||
---------------
|
||||
|
||||
Contrary to most script based init alternatives (`SysV init`_, upstart_,
|
||||
OpenRC_ and the likes) finit instead reads its configuration from
|
||||
``/etc/finit.conf``. Below is a brief list, see the source code for the
|
||||
full list:
|
||||
systemd_, OpenRC_ and the likes) finit instead reads its configuration
|
||||
from ``/etc/finit.conf``. Below is a brief list, see the source code
|
||||
for the full list:
|
||||
|
||||
check
|
||||
check <DEV>
|
||||
Run fsck on a file system before mounting it
|
||||
|
||||
module
|
||||
module <MODULE>
|
||||
Load a kernel module, with optional arguments
|
||||
|
||||
network
|
||||
Script or program to bringup networking, with optional arguments
|
||||
network <PATH>
|
||||
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
|
||||
|
||||
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
|
||||
prevent them from forking off to the background.
|
||||
|
||||
runparts
|
||||
Call run-parts(8) on a directory other than the default /etc/finit.d
|
||||
runparts <PATH>
|
||||
Call run-parts(8) on a directory other than default ``/etc/finit.d``
|
||||
|
||||
tty [RUN_LVLS] DEV
|
||||
Run getty on the listed TTY device, in the given runlevels
|
||||
include <CONF>
|
||||
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
|
||||
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.
|
||||
|
||||
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
|
||||
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
|
||||
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
|
||||
finit_.
|
||||
finit.
|
||||
|
||||
|
||||
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.
|
||||
|
||||
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
|
||||
task [S] /etc/init.d/kbd start -- Preparing console
|
||||
service [S12345] /sbin/klogd -n -x -- Kernel log daemon
|
||||
tty [12345] /dev/tty1
|
||||
tty [2] /dev/tty2
|
||||
tty [2] /dev/tty3
|
||||
tty [2] /dev/tty4
|
||||
tty [2] /dev/tty5
|
||||
tty [2] /dev/tty6
|
||||
run [S] /etc/init.d/acpid start -- Starting ACPI Daemon
|
||||
task [S] /etc/init.d/kbd start -- Preparing console
|
||||
service [S12345] /sbin/klogd -n -x -- Kernel log daemon
|
||||
tty [12345] /dev/tty1
|
||||
tty [2] /dev/tty2
|
||||
tty [2] /dev/tty3
|
||||
tty [2] /dev/tty4
|
||||
tty [2] /dev/tty5
|
||||
tty [2] /dev/tty6
|
||||
|
||||
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.
|
||||
|
||||
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
|
||||
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.
|
||||
|
||||
**CFLAGS=**
|
||||
Standard CFLAGS are inherited from the build enviornmant.
|
||||
Standard CFLAGS are inherited from the build environment.
|
||||
|
||||
**CPPFLAGS=**
|
||||
Standard CPPFLAGS are inherited from the build enviornmant.
|
||||
Standard CPPFLAGS are inherited from the build environment.
|
||||
|
||||
**LDFLAGS=**
|
||||
Standard LDFLAGS are inherited from the build enviornmant.
|
||||
Standard LDFLAGS are inherited from the build environment.
|
||||
|
||||
**LDLIBS=**
|
||||
Standard LIBLIBS are inherited from the build enviornmant.
|
||||
Standard LIBLIBS are inherited from the build environment.
|
||||
|
||||
**prefix=**
|
||||
Base prefix path for all files, except ``sbinbdir`` and ``sysconfdir``.
|
||||
@@ -197,7 +211,7 @@ what is built and where resulting binaries are installed.
|
||||
|
||||
**DESTDIR=**
|
||||
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.
|
||||
|
||||
**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
|
||||
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.
|
||||
|
||||
|
||||
@@ -248,7 +262,7 @@ Debugging
|
||||
|
||||
Add ``finit_debug``, or ``--debug``, to the kernel command line to
|
||||
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
|
||||
|
||||
@@ -256,17 +270,26 @@ enable trace messages. A console getty is always started, see the file
|
||||
Contact
|
||||
-------
|
||||
|
||||
Finit is maintained collaborativly at http://github.com/troglobit/finit —
|
||||
please file a bug report, clone it, or send pull requests for bug fixes and
|
||||
proposed extensions, or become a co-maintainer by contacting the main author.
|
||||
This is the continuation of the `original finit`_ by Claudio Matsuoka,
|
||||
which in turn was reverse engineered from syscalls of the `EeePC
|
||||
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
|
||||
/Joachim Nilsson <troglobit@gmail.com>
|
||||
|
||||
.. _finit: http://helllabs.org/finit/
|
||||
.. _fastinit: http://wiki.eeeuser.com/boot_process:the_boot_process
|
||||
.. _`SysV init`: http://savannah.nongnu.org/projects/sysvinit
|
||||
.. _`SysV init`: https://en.wikipedia.org/wiki/Init
|
||||
.. _`Joachim Nilsson`: http://troglobit.com
|
||||
.. _GitHub: http://github.com/troglobit/finit
|
||||
.. _`process supervision`: https://en.wikipedia.org/wiki/Process_supervision
|
||||
.. _`daemontools`: http://cr.yp.to/daemontools.html
|
||||
.. _`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/
|
||||
.. _runlevels: http://en.wikipedia.org/wiki/Runlevel
|
||||
.. _systemd: http://www.freedesktop.org/wiki/Software/systemd/
|
||||
.. _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
|
||||
|
||||
|
||||
@@ -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
|
||||
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
|
||||
--------
|
||||
@@ -24,13 +40,10 @@ processes that declare themselves to be finit compliant.
|
||||
* Integrate the ingenious libev to handle all events: signals, polling
|
||||
fd's, etc. Because "Event driven software improves concurrency" --
|
||||
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
|
||||
* Integrate watchdog plugin with process/system supervisor to
|
||||
reboot the system when a process stops responding, or when
|
||||
restarting it is imposible, as well as when system load gets
|
||||
too high.
|
||||
* Integrate watchdog plugin with process/system supervisor to optionally
|
||||
reboot the system when a process stops responding, or when a respawn
|
||||
limit has been reached, as well as when system load gets too high.
|
||||
|
||||
|
||||
Configuration
|
||||
|
||||
@@ -5,6 +5,7 @@ ROOTDIR ?= $(TOPDIR)
|
||||
JUNK = *~ *.bak *.aux *.dvi *.idx *.ind *.log *.ps *.map .*.d DEADJOE semantic.cache *.gdb *.elf core core.*
|
||||
MAKE := @$(MAKE)
|
||||
MAKEFLAGS = --no-print-directory --silent
|
||||
CHECK := cppcheck $(CPPFLAGS) --quiet --enable=all
|
||||
INSTALL := install --backup=off
|
||||
STRIPINST := $(INSTALL) -s --strip-program=$(CROSS)strip -m 0755
|
||||
|
||||
|
||||
@@ -86,141 +86,193 @@ int parse_runlevels(char *runlevels)
|
||||
return bitmask;
|
||||
}
|
||||
|
||||
void parse_finit_conf(char *file)
|
||||
static int parse_conf(char *file)
|
||||
{
|
||||
FILE *fp;
|
||||
char line[LINE_SIZE];
|
||||
char line[LINE_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);
|
||||
hostname = strdup(DEFHOST);
|
||||
rcsd = strdup(FINIT_RCSD);
|
||||
|
||||
if ((fp = fopen(file, "r")) != NULL) {
|
||||
char *x;
|
||||
const char *err = NULL;
|
||||
result = parse_conf(file);
|
||||
if (!tty_num())
|
||||
tty_register(FALLBACK_SHELL);
|
||||
|
||||
_d("Parse %s ...", file);
|
||||
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);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* Finit - Extremely fast /sbin/init replacement w/ I/O, hook & service plugins
|
||||
*
|
||||
* 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
|
||||
* 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
|
||||
* hook on to.
|
||||
*/
|
||||
print_desc("", "Loading Finit plugins");
|
||||
print_desc("Loading plugins", NULL);
|
||||
print_result(plugin_load_all(PLUGIN_PATH));
|
||||
|
||||
/*
|
||||
|
||||
+6
-7
@@ -24,15 +24,14 @@ tty /dev/tty3
|
||||
|
||||
# Alternative method instead of runparts
|
||||
#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/kbd start -- Preparing console
|
||||
#run [2] /etc/init.d/networking start -- Start networking
|
||||
#task [S] /etc/init.d/acpid start -- Starting ACPI Daemon
|
||||
#task [S] /etc/init.d/kbd start -- Preparing console
|
||||
#run [2] /etc/init.d/networking start -- Start networking
|
||||
|
||||
# Services to be monitored and respawned as needed
|
||||
service [2345] /sbin/klogd -n -- Kernel logging 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 [2345] /sbin/klogd -n -- Kernel logging server
|
||||
service [2345] /sbin/syslogd -n -- Syslog server
|
||||
service [3] /usr/sbin/gdm -- GNOME Display Manager
|
||||
|
||||
# By default Finit looks for /etc/finit.d
|
||||
# runparts /etc/finit.d
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <paths.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
@@ -35,41 +36,45 @@
|
||||
|
||||
/* Distribution specific configuration */
|
||||
#if defined EMBEDDED_SYSTEM
|
||||
# define CONSOLE "/dev/console"
|
||||
# define SETUP_DEVFS "/sbin/mdev -s"
|
||||
# define GETTY "/sbin/getty -L"
|
||||
# define CONSOLE _PATH_CONSOLE
|
||||
# define SETUP_DEVFS "/sbin/mdev -s"
|
||||
# define GETTY "/sbin/getty -L"
|
||||
# define GETTY_BUSYBOX
|
||||
# define BAUDRATE 115200
|
||||
# define RUNLEVEL 2
|
||||
# define BAUDRATE 115200
|
||||
# define RUNLEVEL 2
|
||||
#else /* Debian/Ubuntu based distributions */
|
||||
# define CONSOLE "/dev/tty1"
|
||||
# define SETUP_DEVFS "/sbin/udevd --daemon"
|
||||
# define GETTY "/sbin/getty -8"
|
||||
# define CONSOLE "/dev/tty1"
|
||||
# define SETUP_DEVFS "/sbin/udevd --daemon"
|
||||
# define GETTY "/sbin/getty -8"
|
||||
# define GETTY_AGETTY
|
||||
# define BAUDRATE 38400
|
||||
# define RUNLEVEL 2
|
||||
# define RANDOMSEED "/var/lib/urandom/random-seed"
|
||||
# define BAUDRATE 38400
|
||||
# define RUNLEVEL 2
|
||||
# define RANDOMSEED "/var/lib/urandom/random-seed"
|
||||
# define REMOUNT_ROOTFS_RW
|
||||
# define HAVE_DBUS
|
||||
#endif
|
||||
|
||||
#ifndef FALLBACK_SHELL
|
||||
# define FALLBACK_SHELL _PATH_BSHELL
|
||||
#endif
|
||||
|
||||
#ifndef DEFUSER
|
||||
# define DEFUSER "root"
|
||||
# define DEFUSER "root"
|
||||
#endif
|
||||
#ifndef DEFHOST
|
||||
# define DEFHOST "noname"
|
||||
# define DEFHOST "noname"
|
||||
#endif
|
||||
|
||||
/* Delay start of GETTY at boot. Must be > 0 */
|
||||
#define DELAY_TTY 2
|
||||
#define DELAY_TTY 2
|
||||
|
||||
#define CMD_SIZE 256
|
||||
#define LINE_SIZE 1024
|
||||
#define BUF_SIZE 4096
|
||||
#define CMD_SIZE 256
|
||||
#define LINE_SIZE 1024
|
||||
#define BUF_SIZE 4096
|
||||
|
||||
#define INIT_MAGIC 0x03091969
|
||||
#define INIT_CMD_RUNLVL 1
|
||||
#define INIT_CMD_DEBUG 2
|
||||
#define INIT_MAGIC 0x03091969
|
||||
#define INIT_CMD_RUNLVL 1
|
||||
#define INIT_CMD_DEBUG 2
|
||||
|
||||
struct init_request {
|
||||
int magic; /* Magic number */
|
||||
@@ -91,8 +96,8 @@ extern char *console;
|
||||
extern char *__progname;
|
||||
|
||||
/* conf.c */
|
||||
int parse_runlevels (char *runlevels);
|
||||
void parse_finit_conf (char *file);
|
||||
int parse_runlevels (char *runlevels);
|
||||
int parse_finit_conf (char *file);
|
||||
|
||||
#endif /* FINIT_H_ */
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* Misc. utility functions and C-library extensions for finit and its plugins
|
||||
*
|
||||
* 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
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -112,7 +112,7 @@ void ifconfig(char *ifname, char *addr, char *mask, int up)
|
||||
ifr.ifr_flags &= ~IFF_UP;
|
||||
|
||||
ioctl(sock, SIOCSIFFLAGS, &ifr);
|
||||
|
||||
|
||||
close(sock);
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ pid_t pidfile_read(char *pidfile)
|
||||
errno = 0;
|
||||
pid = strtoul(buf, NULL, 0);
|
||||
if (errno)
|
||||
pid = 0; /* Failed conversion. */
|
||||
pid = 0; /* Failed conversion. */
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
@@ -330,25 +330,55 @@ static int print_timestamp(void)
|
||||
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[] = " .....................................................................";
|
||||
|
||||
delline();
|
||||
print_timestamp();
|
||||
if (fmt) {
|
||||
va_start(ap, fmt);
|
||||
len = vsnprintf(buf, sizeof(buf), fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
write(STDERR_FILENO, action, strlen(action));
|
||||
write(STDERR_FILENO, desc, strlen(desc));
|
||||
write(STDERR_FILENO, dots, 60 - strlen(desc) - strlen(action)); /* pad with dots. */
|
||||
delline();
|
||||
print_timestamp();
|
||||
|
||||
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)
|
||||
{
|
||||
if (fail)
|
||||
fprintf(stderr, " \e[7m[FAIL]\e[0m\n");
|
||||
else
|
||||
fprintf(stderr, " \e[1m[ OK ]\e[0m\n");
|
||||
|
||||
print(!!fail, NULL);
|
||||
return fail;
|
||||
}
|
||||
|
||||
@@ -421,7 +451,7 @@ int run(char *cmd)
|
||||
struct sigaction sa;
|
||||
|
||||
/* 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);
|
||||
|
||||
/* 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();
|
||||
|
||||
if (!pid) {
|
||||
int i;
|
||||
int i, fd;
|
||||
char c;
|
||||
sigset_t nmask;
|
||||
struct sigaction sa;
|
||||
@@ -519,12 +549,13 @@ pid_t run_getty(char *cmd, char *args[], int console)
|
||||
/* Detach from initial controlling TTY */
|
||||
vhangup();
|
||||
|
||||
close(2);
|
||||
close(1);
|
||||
close(0);
|
||||
close(STDERR_FILENO);
|
||||
close(STDOUT_FILENO);
|
||||
close(STDIN_FILENO);
|
||||
|
||||
/* Attach TTY to console */
|
||||
if (open(CONSOLE, O_RDWR) != 0)
|
||||
fd = open(CONSOLE, O_RDWR);
|
||||
if (fd != STDIN_FILENO)
|
||||
exit(1);
|
||||
|
||||
dup2(0, STDIN_FILENO);
|
||||
@@ -560,6 +591,9 @@ pid_t run_getty(char *cmd, char *args[], int console)
|
||||
execv(cmd, args);
|
||||
}
|
||||
|
||||
if (console)
|
||||
close(fd);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* Misc. utility functions and C-library extensions for finit and its plugins
|
||||
*
|
||||
* 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
|
||||
* 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[]);
|
||||
int procname_kill (char *name, int signo);
|
||||
|
||||
void print (int action, const char *fmt, ...);
|
||||
void print_desc (char *action, char *desc);
|
||||
int print_result (int fail);
|
||||
int start_process (char *cmd, char *args[], int console);
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
# 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
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
+107
-48
@@ -34,13 +34,14 @@
|
||||
|
||||
#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.
|
||||
* @src: Source file.
|
||||
* @dst: Target 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
|
||||
* 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
|
||||
* 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;
|
||||
int s, d, n, isdir = 0, saved_errno = 0;
|
||||
ssize_t size = 0;
|
||||
int in, out, isdir = 0, saved_errno = 0;
|
||||
ssize_t num, size = 0;
|
||||
|
||||
errno = 0; /* Reset before leaving this function. */
|
||||
// fprintf (stderr, "%s() src: %s, dst: %s, len: %d\n", __func__, src, dst, len);
|
||||
errno = 0;
|
||||
|
||||
buffer = malloc(BUFSIZ);
|
||||
if (!buffer)
|
||||
return 0;
|
||||
|
||||
if (fisdir(src)) {
|
||||
errno = EISDIR; /* Error: source is a directory */
|
||||
return 0;
|
||||
saved_errno = EISDIR; /* Error: source is a directory */
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* Check if target is a directory, then append the src base filename. */
|
||||
isdir = __isdir_and_append_filename(src, &dst);
|
||||
/* Check if target is a directory, then append src filename. */
|
||||
isdir = adjust_target(src, &dst);
|
||||
|
||||
/* Len == 0 means copy entire file */
|
||||
if (len == 0) {
|
||||
/* XXX: This feels a bit unsafe, but 2047 MiB may be sufficient for us.
|
||||
* --Jocke 2008-08-11 */
|
||||
len = INT_MAX;
|
||||
}
|
||||
|
||||
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;
|
||||
if (sym) {
|
||||
size = readlink(src, buffer, BUFSIZ);
|
||||
if (size > 0) {
|
||||
if (size >= (ssize_t) BUFSIZ) {
|
||||
saved_errno = ENOBUFS;
|
||||
goto exit;
|
||||
}
|
||||
while (len > 0 && n == BUFSIZ);
|
||||
|
||||
close(d);
|
||||
} else {
|
||||
saved_errno = errno;
|
||||
buffer[size] = 0;
|
||||
size = !symlink(buffer, dst);
|
||||
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);
|
||||
if (isdir)
|
||||
free(dst);
|
||||
@@ -135,12 +148,12 @@ int movefile(char *src, char *dst)
|
||||
int isdir, result = 0;
|
||||
|
||||
/* 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 (errno == EXDEV) {
|
||||
errno = 0;
|
||||
copyfile(src, dst, 0);
|
||||
copyfile(src, dst, 0, 0);
|
||||
if (errno)
|
||||
result = 1;
|
||||
else
|
||||
@@ -170,27 +183,30 @@ int movefile(char *src, char *dst)
|
||||
int copy_filep(FILE *src, FILE *dst)
|
||||
{
|
||||
int result = 0;
|
||||
char *buf = (char *)malloc(BUFSIZ);
|
||||
char *buf;
|
||||
|
||||
if (!src || !dst)
|
||||
return EINVAL;
|
||||
|
||||
buf = (char *)malloc(BUFSIZ);
|
||||
if (!buf)
|
||||
return errno;
|
||||
|
||||
while (1) {
|
||||
errno = 0;
|
||||
errno = 0;
|
||||
if (!fgets(buf, BUFSIZ, src)) {
|
||||
if (errno == EINTR) {
|
||||
clearerr(src);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (feof(src))
|
||||
break;
|
||||
|
||||
result = errno;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
while (EOF == fputs(buf, dst)) {
|
||||
if (errno == EINTR) {
|
||||
clearerr(dst);
|
||||
@@ -202,13 +218,58 @@ int copy_filep(FILE *src, FILE *dst)
|
||||
}
|
||||
}
|
||||
|
||||
exit:
|
||||
exit:
|
||||
free(buf);
|
||||
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 */
|
||||
static int __isdir_and_append_filename(char *src, char **dst)
|
||||
static int adjust_target(char *src, char **dst)
|
||||
{
|
||||
int isdir = 0;
|
||||
|
||||
@@ -221,7 +282,6 @@ static int __isdir_and_append_filename(char *src, char **dst)
|
||||
else
|
||||
ptr++;
|
||||
|
||||
// fprintf (stderr, "Yes %s is a dir --> add %s\n", *dst, ptr);
|
||||
tmp = malloc(strlen(*dst) + strlen(ptr) + 2);
|
||||
if (!tmp) {
|
||||
errno = EISDIR;
|
||||
@@ -233,7 +293,6 @@ static int __isdir_and_append_filename(char *src, char **dst)
|
||||
|
||||
sprintf(tmp, "%s%s%s", *dst, slash ? "" : "/", ptr);
|
||||
*dst = tmp;
|
||||
// fprintf (stderr, "NEW DST:%s\n", *dst);
|
||||
}
|
||||
|
||||
return isdir;
|
||||
@@ -254,7 +313,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
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
|
||||
int main(void)
|
||||
@@ -293,7 +352,7 @@ int main(void)
|
||||
i = 0;
|
||||
while (files[i]) {
|
||||
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");
|
||||
|
||||
if (fexist(files[i + 2]))
|
||||
@@ -312,7 +371,7 @@ int main(void)
|
||||
* Local Variables:
|
||||
* compile-command: "gcc -g -I../include -o unittest -DUNITTEST copyfile.c && ./unittest"
|
||||
* version-control: t
|
||||
* kept-new-versions: 2
|
||||
* c-file-style: "ellemtel"
|
||||
* indent-tabs-mode: t
|
||||
* c-file-style: "linux"
|
||||
* End:
|
||||
*/
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/* 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
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
|
||||
+33
-2
@@ -1,7 +1,7 @@
|
||||
/* Collection of utility funcs and C library extensions for finit & its plugins
|
||||
*
|
||||
* 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
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -29,15 +29,17 @@
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h> /* MAX(), isset(), setbit(), TRUE, FALSE, et consortes. :-) */
|
||||
#include <unistd.h>
|
||||
|
||||
int fexist (char *file);
|
||||
int fisdir (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 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 rsync (char *src, char *dst, int delete, int (*filter) (const char *file));
|
||||
@@ -59,6 +61,35 @@ static inline int fisslashdir(char *dir)
|
||||
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_ */
|
||||
|
||||
/**
|
||||
|
||||
+18
-13
@@ -61,7 +61,7 @@ int rsync(char *src, char *dst, int delete, int (*filter) (const char *file))
|
||||
void copy(char *src, char *dst)
|
||||
{
|
||||
errno = 0;
|
||||
copyfile(src, dst, 0);
|
||||
copyfile(src, dst, 0, 1);
|
||||
if (errno) {
|
||||
if (errno == EEXIST)
|
||||
errno = 0;
|
||||
@@ -142,26 +142,31 @@ static int makedir(char *buf, size_t buf_len, char *dir, char *name, mode_t mode
|
||||
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. */
|
||||
static int prune(char *dst, char **new_files, int new_num)
|
||||
{
|
||||
int i, num, result = 0;
|
||||
int num, result = 0;
|
||||
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);
|
||||
if (num) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < num; i++) {
|
||||
if (!find(files[i])) {
|
||||
if (!find(files[i], new_files, new_num)) {
|
||||
char *name;
|
||||
size_t len = strlen(files[i]) + 2 + strlen(dst);
|
||||
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
/* Optional /dev/initctl FIFO monitor
|
||||
*
|
||||
* 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
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* Signal management - Be conservative with what finit responds to!
|
||||
*
|
||||
* 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
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* Signal management - Be conservative with what finit responds to!
|
||||
*
|
||||
* 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
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
/* 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
|
||||
* 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 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)
|
||||
{
|
||||
svc_t *svc;
|
||||
svc_cmd_t cmd;
|
||||
|
||||
_d("Bootstrapping all services in runlevel S from %s", FINIT_CONF);
|
||||
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))
|
||||
svc_start(svc);
|
||||
}
|
||||
@@ -188,6 +189,8 @@ void svc_runlevel(int newlevel)
|
||||
if (svc->pid) {
|
||||
if (run == SVC_STOP)
|
||||
svc_stop(svc);
|
||||
else if (run == SVC_RELOAD)
|
||||
svc_reload(svc);
|
||||
} else {
|
||||
if (run == SVC_START)
|
||||
svc_start(svc);
|
||||
@@ -345,11 +348,29 @@ static int is_norespawn(void)
|
||||
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)
|
||||
{
|
||||
pid_t lost;
|
||||
svc_t *svc;
|
||||
|
||||
if (was_stopped && !is_norespawn()) {
|
||||
was_stopped = 0;
|
||||
restart_any_lost_procs();
|
||||
return;
|
||||
}
|
||||
|
||||
lost = waitpid(-1, NULL, WNOHANG);
|
||||
if (lost < 1)
|
||||
return;
|
||||
@@ -358,8 +379,10 @@ void svc_monitor(void)
|
||||
return;
|
||||
|
||||
/* Power user at the console, don't respawn tasks. */
|
||||
if (is_norespawn())
|
||||
if (is_norespawn()) {
|
||||
was_stopped = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
if (tty_respawn(lost))
|
||||
return;
|
||||
@@ -400,13 +423,13 @@ void svc_monitor(void)
|
||||
/* Remember: svc_enabled() must be called before calling svc_start() */
|
||||
int svc_start(svc_t *svc)
|
||||
{
|
||||
int respawn = svc->pid != 0;
|
||||
int respawn;
|
||||
pid_t pid;
|
||||
sigset_t nmask, omask;
|
||||
char *args[MAX_NUM_SVC_ARGS];
|
||||
sigset_t nmask, omask;
|
||||
|
||||
if (!svc)
|
||||
return 0;
|
||||
respawn = svc->pid != 0;
|
||||
|
||||
/* Don't try and start service if it doesn't exist. */
|
||||
if (!fexist(svc->cmd)) {
|
||||
@@ -428,24 +451,25 @@ int svc_start(svc_t *svc)
|
||||
else if (!respawn)
|
||||
print_desc("Starting ", svc->desc);
|
||||
|
||||
/* Block sigchild while forking. */
|
||||
sigemptyset(&nmask);
|
||||
sigaddset(&nmask, SIGCHLD);
|
||||
sigprocmask(SIG_BLOCK, &nmask, &omask);
|
||||
/* Block sigchild while forking. */
|
||||
sigemptyset(&nmask);
|
||||
sigaddset(&nmask, SIGCHLD);
|
||||
sigprocmask(SIG_BLOCK, &nmask, &omask);
|
||||
|
||||
pid = fork();
|
||||
sigprocmask(SIG_SETMASK, &omask, NULL);
|
||||
sigprocmask(SIG_SETMASK, &omask, NULL);
|
||||
if (pid == 0) {
|
||||
int i = 0;
|
||||
int uid = getuser(svc->username);
|
||||
struct sigaction sa;
|
||||
char *args[MAX_NUM_SVC_ARGS];
|
||||
|
||||
sigemptyset(&nmask);
|
||||
sigaddset(&nmask, SIGCHLD);
|
||||
sigprocmask(SIG_UNBLOCK, &nmask, NULL);
|
||||
sigemptyset(&nmask);
|
||||
sigaddset(&nmask, SIGCHLD);
|
||||
sigprocmask(SIG_UNBLOCK, &nmask, NULL);
|
||||
|
||||
/* 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);
|
||||
|
||||
/* Set desired user */
|
||||
@@ -453,7 +477,7 @@ int svc_start(svc_t *svc)
|
||||
setuid(uid);
|
||||
|
||||
/* 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] = NULL;
|
||||
|
||||
@@ -467,7 +491,7 @@ int svc_start(svc_t *svc)
|
||||
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];
|
||||
|
||||
snprintf(arg, sizeof(arg), "%s ", args[i]);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* Finit service monitor and generic API for managing svc_t structures
|
||||
*
|
||||
* 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
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h> /* strerror() */
|
||||
#include <sys/ipc.h> /* IPC_CREAT */
|
||||
#include <sys/shm.h> /* shmat() */
|
||||
#include <sys/types.h> /* pid_t */
|
||||
|
||||
@@ -57,21 +58,21 @@ typedef struct svc {
|
||||
pid_t pid;
|
||||
svc_type_t type;
|
||||
int reload;
|
||||
int runlevels;
|
||||
int runlevels;
|
||||
unsigned int restart_counter; /* Incremented for each restart by service monitor. */
|
||||
char cmd[MAX_ARG_LEN];
|
||||
char args[MAX_NUM_SVC_ARGS][MAX_ARG_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.
|
||||
* @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.
|
||||
* @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_stop;
|
||||
int private;
|
||||
int dynamic;
|
||||
int dynamic_stop;
|
||||
int private;
|
||||
svc_cmd_t (*cb)(struct svc *svc, int event, void *event_arg);
|
||||
} svc_t;
|
||||
|
||||
@@ -80,11 +81,11 @@ typedef struct svc_map svc_map_t;
|
||||
/* Put services array in shm */
|
||||
static inline svc_t *finit_svc_connect(void)
|
||||
{
|
||||
const long ID = FINIT_SHM_ID;
|
||||
static void *ptr = (void *)-1;
|
||||
|
||||
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)
|
||||
return NULL;
|
||||
}
|
||||
@@ -92,18 +93,18 @@ static inline svc_t *finit_svc_connect(void)
|
||||
return (svc_t *)ptr;
|
||||
}
|
||||
|
||||
svc_t *svc_new (void);
|
||||
svc_t *svc_find (char *name);
|
||||
svc_t *svc_iterator (int restart);
|
||||
void svc_runlevel (int newlevel);
|
||||
svc_t *svc_new (void);
|
||||
svc_t *svc_find (char *name);
|
||||
svc_t *svc_iterator (int restart);
|
||||
void svc_runlevel (int newlevel);
|
||||
|
||||
int svc_register (int type, char *line, char *username);
|
||||
int svc_id_by_name (char *name);
|
||||
int svc_register (int type, char *line, char *username);
|
||||
int svc_id_by_name (char *name);
|
||||
svc_cmd_t svc_enabled (svc_t *svc, int event, void *arg);
|
||||
int svc_start (svc_t *svc);
|
||||
int svc_start_by_name (char *name);
|
||||
int svc_stop (svc_t *svc);
|
||||
int svc_reload (svc_t *svc);
|
||||
int svc_start (svc_t *svc);
|
||||
int svc_start_by_name (char *name);
|
||||
int svc_stop (svc_t *svc);
|
||||
int svc_reload (svc_t *svc);
|
||||
|
||||
#endif /* FINIT_SVC_H_ */
|
||||
|
||||
|
||||
@@ -102,6 +102,17 @@ tty_node_t *tty_find(char *dev)
|
||||
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 *entry;
|
||||
@@ -127,13 +138,17 @@ void tty_start(finit_tty_t *tty)
|
||||
if (console && !strcmp(tty->name, console))
|
||||
is_console = 1;
|
||||
|
||||
if (!strncmp(tty->name, _PATH_DEV, strlen(_PATH_DEV))) {
|
||||
#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)
|
||||
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
|
||||
#error No GETTY defined!
|
||||
strlcpy(line, FALLBACK_CONSOLE, sizeof(line));
|
||||
#endif
|
||||
} else {
|
||||
strlcpy(line, tty->name, sizeof(line));
|
||||
}
|
||||
cmd = strtok(line, " ");
|
||||
args[i++] = basename(cmd);
|
||||
while ((arg = strtok(NULL, " ")))
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
typedef struct {
|
||||
char *name;
|
||||
int baud;
|
||||
char *term;
|
||||
char *term;
|
||||
int runlevels;
|
||||
|
||||
int pid;
|
||||
@@ -45,14 +45,15 @@ typedef struct tty_node {
|
||||
|
||||
//extern LIST_HEAD(, tty_node) tty_list;
|
||||
|
||||
int tty_register (char *line);
|
||||
tty_node_t *tty_find (char *dev);
|
||||
int tty_register (char *line);
|
||||
tty_node_t *tty_find (char *dev);
|
||||
size_t tty_num (void);
|
||||
tty_node_t *tty_find_by_pid (pid_t pid);
|
||||
void tty_start (finit_tty_t *tty);
|
||||
void tty_stop (finit_tty_t *tty);
|
||||
int tty_enabled (finit_tty_t *tty, int runlevel);
|
||||
int tty_respawn (pid_t pid);
|
||||
void tty_runlevel (int runlevel);
|
||||
void tty_start (finit_tty_t *tty);
|
||||
void tty_stop (finit_tty_t *tty);
|
||||
int tty_enabled (finit_tty_t *tty, int runlevel);
|
||||
int tty_respawn (pid_t pid);
|
||||
void tty_runlevel (int runlevel);
|
||||
|
||||
#endif /* FINIT_TTY_H_ */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user