Compare commits

..
496 Commits
Author SHA1 Message Date
Joachim Nilsson 55479cc511 Bump version for first -rc, v3.1-rc1
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-23 11:52:40 +01:00
Joachim Nilsson b702f7eeef Update ChangeLog for upcoming v3.1 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-23 11:52:40 +01:00
Joachim Nilsson 0e37bb0924 Follow-up to b0663d0, cond_init() must run before first hooks
The new condition triggered hooks requrie /var/run/finit/cond to
be set up before calling the first user-configurable hooks.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-23 11:19:35 +01:00
Joachim Nilsson 360f3e72bc Audit b0663d0, add newline to generation ID in cond files
- Add newline to cond generation ID, like PID files, easier when
  debugging.  Does not affect fscanf() in cond_get_gen()
- Update copyright years

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-23 10:05:45 +01:00
Joachim Nilsson c1023c03c7 Merge pull request #89 from westermo/cond-generation
Cond generation
2017-12-23 09:37:16 +01:00
Joachim Nilsson e94d2a8c08 Merge branch 'master' into cond-generation 2017-12-23 09:31:41 +01:00
Joachim Nilsson f7c0366fa2 Fix segfault on X86_64, call va_end()+va_start() for each vfprintf()
... varargs is a special kind of hell.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-23 00:38:01 +01:00
Joachim Nilsson 8992e7bf2b Refactor svc_iterator() into a proper iterator, add first flag
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-22 23:56:14 +01:00
Joachim Nilsson 95518df62d Some systems rely on /dev/shm being there for mount -a
This was accidentally removed in d7401b2, when svc_t was refactored
from using shared memory.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-22 16:44:52 +01:00
Joachim Nilsson 85fe95835a doc/build.md: Mention required library versions
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-22 13:17:39 +01:00
Joachim Nilsson baf9c4f61f Travis-CI: Update build deps, libite v1.9.2 --> v2.0.1
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-22 13:12:04 +01:00
Joachim Nilsson b439ac670d .conf: don't rely on mtime to determine if service needs reloading
Until now Finit has used mtime to determine if a file has been changed,
or simply touched to request reload, when `initctl reload` is called.
Using mtime for this purpose is a monumentally bad idea since time can
be changed at any point: a user may adjust the time, NTP continously
tunes the clock, and time stamps are stored as the walltime.  So if we
compare timestamps against the last time we (booted or) did reload, we
would miss .conf file changes.

This patch replaces the mtime mistake with an inotify watcher for the
following files: /etc/finit.d/*.conf, /etc/finit.d/available/*.conf,
and /etc/finit.conf.  All file changes between (bootstraps and) calls
to `initctl reload` are tracked, like the mtime backend it replaces.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-22 13:08:38 +01:00
Joachim Nilsson bb3d9c8670 initctl: Add support for touch <CONF>, mark .conf for reload
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-22 12:50:18 +01:00
Joachim Nilsson 2f9b97b3a7 Update libite (-lite) requried version: 1.9.2 --> 2.0.1
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-22 12:49:04 +01:00
Joachim Nilsson c59f7d23f4 Add and improve debug messages, clean out old dev. comments
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-22 12:40:43 +01:00
Tobias Waldekranz b0663d04e4 cond: don't rely on mtime for condition management
TIL, using mtimes for tracking event orderings is a monumentally bad
idea (queue the nodding UNIX-beards). Mtimes are in wallclock time which
is not necessarily monotonically increasing. A user may adjust the time,
an NTP daemon will continously tune the clock and so on.

Instead, store an explicit generation number in each condition file,
which will be monotonically increased by finit on each reconf.
2017-12-21 11:10:47 +01:00
Joachim Nilsson 6f26f2f9d0 TODO: Idea about addding support for an optional rescue mode
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-20 09:30:49 +01:00
Joachim Nilsson e7cca05fe3 Reserve certain configuration directives for bootstrap only
The following configuration directives, previously only allowed
in /etc/finit.conf, are now also only allowed in runlevel S, i.e.
at bootstrap:

- host
- mknod
- network
- runparts
- runlevel

This change is in preparation for allowing reload of finit.conf
as well as /etc/finit.d/*.conf, which we already support.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-20 09:16:55 +01:00
Joachim Nilsson f3669c7537 svc: Remove svc_dynamic_iterator(), soon no difference between svc's
This is a prelude to a major behavioral change.  The difference between
a static and dynamic service will be removed in Finit v3.1.  This means
all .conf files, including /etc/finit.conf, will be re-read on reload.

However, not all configuration directives will be re-read, some will
only be applicable at bootstrap, i.e. runlevel S.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-20 09:04:14 +01:00
Joachim Nilsson a9456cec41 svc: Remove unused function, svc_foreach_dynamic()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-20 09:02:38 +01:00
Joachim Nilsson 61a9926442 Minor, staticify
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-20 00:13:21 +01:00
Joachim Nilsson 7784480abe Postpone networking stuff, + hooks, a bit to the finalize() step
This patch moves the networking bit to the latter part of bootstrap,
called finalize(), in favor of starting the event loop earlier.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-20 00:10:29 +01:00
Joachim Nilsson db50c09ec5 initctl: Improve show SVC command output a bit, provide summary
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-18 21:04:17 +01:00
Joachim Nilsson 0f1f51b5ad Refactor, change from static array of svc_t to linked list
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-18 17:50:02 +01:00
Joachim Nilsson d7401b2a96 Follow-up to issue #81: remove SysV shared memory IPC altogether
This change removes a long standing kernel requirement and architectural
mishap in the design of Finit v1.  It is no longer necessary to include
CONFIG_SYSVIPC in the kernel to use Finit and its command line tool
initctl.  It is also no longer possible to connect to the internals of
PID 1 using shmat(), the initctl tool has already been updated to use
the domain socket API.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-18 11:20:21 +01:00
Joachim Nilsson c0515d112e New client side API to access svc_t entries without shared memory
This change is one of the required intermediate steps to remove the
shared memory store for all svc_t, this in turn to avoid any external
programs manipulating the internal memory of PID 1.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-18 11:06:19 +01:00
Joachim Nilsson 9a8b55737f Move svc_status() + svc_dirtystr() to header file as static inline
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-18 11:03:15 +01:00
Joachim Nilsson d7d8b8487d Refactor other iterators to use new re-entrant svc_iterator1() API
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-18 07:49:45 +01:00
Joachim Nilsson 7f04382eee Refactor, use new re-entrant svc_iterator1() API
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-18 00:21:07 +01:00
Joachim Nilsson bf004d9ec4 svc: Re-entrant replacement to svc_iterator() --> svc_iterator1()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-18 00:18:13 +01:00
Joachim Nilsson 23e0928e5c Minor, unused arguments no longer need magic tricks or hand waving
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-18 00:17:00 +01:00
Joachim Nilsson d6b2ac94dd Fix regression in 32b9096, only pick next :ID for inetd services
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-17 14:54:46 +01:00
Joachim Nilsson 7362e6d00a initctl: Fix error handling for intictl start/stop if missing arg
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-17 12:12:57 +01:00
Joachim Nilsson d94d11e00a initctl: Allow short forms of commands
For ease of use, allow short forms of commands, like:

   initctl h
   initctl c d
   initctl l

Also, default to show conditions if no argument to cond is given.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-17 12:09:41 +01:00
Joachim Nilsson f06a0fcb71 initctl: Support printing previous runlevel
This patch adds support for "PREVLEVEL RUNLEVEL" output to the initctl
runlevel command.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-17 10:54:06 +01:00
Joachim Nilsson cae61ad6df initctl refactor, break out domain socket/client API
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-16 12:15:28 +01:00
Joachim Nilsson 27e4af5ed8 Rename, client.c --> telinit.c
We need the name client.c for the client side of api.c, so let's rename
the client to its traditional name.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-15 14:00:11 +01:00
Joachim Nilsson f10a724503 Add mention of dropping UDP connections from blocked interfaces
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-14 17:23:54 +01:00
Joachim Nilsson 33037b012a Merge pull request #88 from ccb3/master
Drop UDP packets from unwanted interfaces
2017-12-14 10:44:29 +01:00
Lennart Eriksson 0c75e59b77 Drop UDP packets from unwanted interfaces
Previously UDP packets were never dropped and if a request came
from a not valid interface inetd got stuck in an inifinite
loop looking at the same packet every time and not dropping it.

Signed-off-by: Lennart Eriksson <lennart.eriksson@westermo.se>
2017-12-14 10:34:07 +01:00
Joachim Nilsson 8e55a76732 Initial draft of v3.1 release notes
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-14 09:13:13 +01:00
Joachim Nilsson 32b9096e31 Fix #87: Allow inetd services to be registered with an id != 1
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-13 22:20:30 +01:00
Joachim Nilsson f51723e8b7 Fix #86: Ensure that run/tasks are run at least once per runlevel
This patch fixes the problem with run/task jobs with conditions, run at
runlevel S (bootstrap), not being given enough time to actually start
and run even once.

The new svc counter 'once' is now inspected before transitioning away
from runlevel S to the configured runlevel.  A global (currently hard
coded) timeout of 10 sec is given to all run/tasks.

As a spin-off, this patch starts up the event loop much earlier than
before.  Meaning the initial runlevel change at boot is now done in
a finalize() callback when all run/tasks have completed, or when the
global timeout has expired.  Starting the event loop earlier gives us
the possibility to rely on the pidfile plugin to provide our run/tasks
with the conditions necessary to start.

TODO: What remains is to add similar handling to all runlevel
      transitions, not just the initial one at boot.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-13 17:58:48 +01:00
Joachim Nilsson 9e31bd8a23 Fix #18: Add support for calling run/tasks on HOOK points
This patch implements support for calling run/task jobs on the built-in
`HOOK_*` points in Finit.  To map each HOOK point to a condition a new
classification was made, as shown in plugin.h and in the example below.

task <hook/mount/root> /sbin/attachubi.sh      # run in parallel with other tasks/services
run  <hook/net/up>     /sbin/dosomething.sh    # run in sequence with other commands

Please note, only rudimentary tested.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-13 17:58:48 +01:00
Joachim Nilsson e841984a4e service_step(): Fix problem with double start of service/run/tasks
Make svc state transition to RUNNING *before* service_start(), because
in that function we may call service_step() as well, which would start
the svc again (since it was still in READY).

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-13 17:58:48 +01:00
Joachim Nilsson 594476c4fc Fix progress print-out ordering bug, and run HOOK_SVC_START only on success
Only run HOOK_SVC_START on successful start, and *after* having printed
the result of the started service, otherwise any print-outs from plugins
or tasks we start may overwrite the started service's progress.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-13 17:58:48 +01:00
Joachim Nilsson 9c423dfca4 Disable toggling of log/debug in fsck() loop
Don't really see the point of this code anymore, was possibly an issue
before we refactored the logging subsystem.  Comment out for now, and
remove later.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-13 17:58:48 +01:00
Joachim Nilsson 77cd0f0243 Fix problem with duplicate log messages before syslogd has started
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-13 17:58:48 +01:00
Joachim Nilsson 5dc4e7c058 cond_update(): Minor, log service description as well as cmd
If you have lots of service/run/tasks using the same cmd it's impossible
to tell them apart in debug mode.  This patch logs description as well
as cmd to improve on this situation a bit.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-13 17:58:48 +01:00
Joachim Nilsson 3c015f384d Track run/tasks, should run at least once per declared runlevel
This patch adds a 'once' counter to the svc_t for run/task jobs.  This
counter is incremented when Finit calls service_start() and is reset on
runlevel changes.

Also, at the end of a runlevel each run/task have their state reset to
SVC_HALTED_STATE so they can be launched again for the new runlevel, if
so declared.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-13 17:58:48 +01:00
Joachim Nilsson 5117b723c2 Minor, fix missing rlim2str() declaration
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-13 17:58:48 +01:00
Joachim Nilsson b55a609834 Handle /etc overlayfs: reload /etc/finit.d/*.conf after mount -a
Systems running OverlayFS, or similar, on /etc may have new/modified
.conf files in /etc/finit.d.  This patch makes sure to reload them
after `mount -a` has run so any configured bootstrap tasks and the
new hook callback scripts may run as expected.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-13 17:58:48 +01:00
Joachim Nilsson 60eccbac31 Refactor, relocate+rename service_enabled() --> svc_enabled()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-13 17:58:48 +01:00
Joachim Nilsson b182e6bcc5 Minor update and refactor, use kernel doc style comments
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-13 17:58:48 +01:00
Joachim Nilsson b8bf26b107 Refactor, rename restart counter and change type to char, MAX=10
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-13 17:58:48 +01:00
Joachim Nilsson 14c0d80f63 Merge pull request #85 from reverendhomer/doc-fix-typo
doc: fix couple of typos in config.md
2017-12-01 18:45:20 +01:00
Reverend Homer 1f55f677d1 doc: fix couple of typos in config.md 2017-12-01 20:07:58 +03:00
Joachim Nilsson 40267a5f0f Minor, comment fixes and additions
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-28 08:07:06 +01:00
Joachim Nilsson 9f50b033d9 Abort service kill if already terminated, otherwise kill(0, SIGKILL)
This patch fixes a rather nasty bug in the SIGTERM+SIGKILL logic
employed by Finit when stopping tasks, e.g. at a runlevel change.

When a process terminates, after Finit having sent it SIGTERM, and the
SIGKILL timer expires *before* the timer has been cancelled, then the
timer callback would cause kill(0, SIGKILL).

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-28 08:00:46 +01:00
Joachim Nilsson bbaa7a1403 TODO: Process callbacks replaced with conditions in Finit 3.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-27 22:37:38 +01:00
Joachim Nilsson b68c5c1291 Fix #45: add support for rlimit per service/run/task/inetd/tty
This patch extends the existing rlimit implementation to support setting
limits per service, run/task, inetd, and tty.

Use rlimit in /etc/finit.conf to change the global setting, which is
then inherited to each /etc/finit.d/*.conf.  For each .conf file the
rlimit is reinitialized to the global finit.conf settings.

Also, add `unlimited` keyword, to replace the now deprecated `infinity`
keyword.  The latter is however kept, for compatibility with previous
releases, for the foreseeable future.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-26 16:35:37 +01:00
Joachim Nilsson 44007c86f2 initctl: Fix problem with start/stop using job ID
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-24 08:51:50 +01:00
Joachim Nilsson cd73c1c951 Replace libite:fmode() with stat(), removed in libite v2
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-22 14:40:02 +01:00
Joachim Nilsson 5406af2054 watchdog: Adjust WDT timeout (30 sec), use half that as kick period
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-19 16:51:33 +01:00
Joachim Nilsson 3c800f6508 Refactor, simplify registration of built-in watchdog daemon
This patch not only greatly simplifies the registration of the built-in
watchdog daemon, it also fixes a nasty race condition with an external
watchdog daemon.  The INIT_CMD_WDOG_HELLO could reach finit in reversed
order, leading to the built-in daemon shutting down, but finit killing
the just registered external daemon.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-19 16:48:32 +01:00
Joachim Nilsson e0fb2b036d Improve debug of initctl api
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-19 16:45:07 +01:00
Joachim Nilsson 0ee4657f1c Follow-up to 6c563a2, clean up unused variables
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-19 16:39:27 +01:00
Joachim Nilsson ec2382b6d4 Silence, remove "Starting ..." of inetd services from boot progress
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-19 12:30:04 +01:00
Joachim Nilsson 0fc2df1a65 Silence, remove "Loading %sconfiguration ..." from boot progress
Most Linux distributions, embedded or otherwise, do not need this
and only confuses the user of an OS with Finit.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-19 12:29:31 +01:00
Joachim Nilsson 6c563a2b22 Silence, remove "Loading plugins ..." from boot progress
Most Linux distributions, embedded or otherwise, do not need this
and only confuses the user of an OS with Finit.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-19 12:27:57 +01:00
Joachim Nilsson 6a2911223d Fix screen_init() regression introduced in a6290da
A simple missing semicolon caused initscr() to not be called properly.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-19 12:26:45 +01:00
Joachim Nilsson 7f499ed1d0 watchdog: Kick one last time before handover to external watchdogd
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-18 14:48:46 +01:00
Joachim Nilsson 2d2807bc65 Change log message for crashing services, remove dev. debug info
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-18 14:48:08 +01:00
Joachim Nilsson 4af7974fb9 Travis-CI: Install new required version of libuEv, v2.1.0
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-14 15:26:12 +01:00
Joachim Nilsson 3fd45eac7c bootmisc: Handle _PATH_VARDB inconsistency gracefully
Some systems use /var/db while others use /var/lib/misc, we need to
support both and cannot rely on _PATH_VARDB, since it too might not
be set properly.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-14 15:24:25 +01:00
Joachim Nilsson bb4578292f Bump version for v3.1 release cycle
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-14 15:01:02 +01:00
Joachim Nilsson 656fa3d0e7 Bump required libuEv version to v2.1.0, fixed failure mode support
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-14 15:00:36 +01:00
Joachim Nilsson 9a75813350 api.c: Handle domain socket errors more gracefully, restart socket
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-14 15:00:05 +01:00
Joachim Nilsson 5af1f05606 plugin: Only close() PID file descriptors >0, skip -1
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-14 14:34:08 +01:00
Joachim Nilsson fcdb5c2965 initctl: Refactor, reduce code duplication
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-12 22:58:50 +01:00
Joachim Nilsson af3e560d79 tty.c: Refactor, move LIST_REMOVE() to tty_unregister()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-12 21:33:22 +01:00
Joachim Nilsson b6e695b656 Bump required libuEv version to v2.0.0, with failure mode support
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-12 19:40:54 +01:00
Joachim Nilsson 123df18847 Travis-CI: Bump required libuEv version to v2.0
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-12 19:40:28 +01:00
Joachim Nilsson dae21d9d64 Simplify rlimit documentation a bit
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-12 19:18:32 +01:00
Joachim Nilsson bf4a0abe5c conf_parse_rlimit(): Refactor, replace 'new' with 'cfg'
'new' is a reserved keyword in C++, it is recommnded to avoid it also in C.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-12 14:57:22 +01:00
Joachim Nilsson 6826d7ee3f Handle event loop watcher failure modes
When alibuEv event watcher callback has `UEV_ERROR` in the events mask
we must handle the error.  Unfortunately, in most cases there is not
much we can do but ignore it or log the error.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-12 11:18:12 +01:00
Joachim Nilsson 168da2a5c6 plugin: Update list of available events for I/O plugins
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-12 02:47:33 +01:00
Joachim Nilsson c82dc54205 initctl: Minor refactor, handle errors first
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-12 02:46:19 +01:00
Joachim Nilsson eb0a759371 TTY: If parsing speed argument fails, do NOT default to B38400
If the speed argument to the `tty` stanza is invalid we should not
default to some other random speed.  Instead, leave the line speed
as-is, like we do when starting an external getty.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-02 10:48:04 +01:00
Joachim Nilsson 830abc1971 getty: Remove leading \n in do_issue(), not needed
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-31 20:57:36 +01:00
Joachim Nilsson 4c3a11131f Minor cleanup + use strlen() rather than sizeof() on const strings
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-31 20:56:48 +01:00
Joachim Nilsson 796701c854 getty: Ignore SIGINT & C:o earlier
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-31 20:54:56 +01:00
Joachim Nilsson ab760aa3ff Mention @console TTYs in top-level README
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-29 17:21:21 +01:00
Joachim Nilsson 2b9eecbef3 Spell check and mention use of logger tool in service stanza
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-29 17:17:21 +01:00
Joachim Nilsson b8190c8a2a Refactor, move speed parser from getty() to prepare_tty()
This patch relocates the speed parser so that exec.c can set the TTY
speed properly as soon as possible.  For external getty we make sure
to not touch the TTY speed.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-29 16:53:26 +01:00
Joachim Nilsson adb4670d2f Clear current line before printing \nPlease press Enter ...
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-29 16:52:14 +01:00
Joachim Nilsson d31575538c getty: Disable VINTR + VEOF, re-enable before calling /bin/login
This patch makes the Finit built-in getty behave a bit more like other
getty implementations.  We now not only disable ISIG but also VEOF and
VINTR when prearing the TTY for the getty (built-in or external).

Like before, it is up to the getty process to leave the TTY in a
usable state to /bin/login, so we also move the stty() call to
just before calling /bin/login in getty.c

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-29 16:11:59 +01:00
Joachim Nilsson faf0c680b8 getty: Disable ECHO, XON/OFF while waiting for initial <CR>
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-29 12:14:04 +01:00
Joachim Nilsson 250e26f2f6 Fix #84: Reset TTY w/ stty() before taking any pre-getty action
This patch moves the stty() function from getty.c to a separate file so
it can be called from exec.c as well.  The fix to #84 is simply to call
stty() in prepare_tty(), which is shared by run_getty() and run_getty2()
and called before "Please press Enter ...".

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-29 11:59:48 +01:00
Joachim Nilsson b45c3d5cb8 timespec_newer(): time a should be > or >= to b
Time comparision should be >= not just >.  May seem a bit silly to
nitpick like this since we're comparing nano seconds, but on systems
with no high-res timers this happens more often than you would like.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-24 16:04:18 +02:00
Joachim Nilsson 6b2678c2ed pidfile: On HOOK_SVC_RECONF the netlink plugin must run first
When performing an `initctl reload` with one (unchanged) service
depending on, e.g. `net/iface/lo`, its condition will not be set
to ON by the pidfile plugin unless the netlink plugin hook runs
first.

Example:

    service <net/iface/lo> /sbin/dropbear ...

Which provides the <svc/sbin/dropbear> condition, will not be
set by pidfile.so during `initctl reload` because dropbear is
still SIGSTP:ed waiting for <net/iface/lo>.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-24 15:55:35 +02:00
Joachim Nilsson 0d6f203e0b tty_reload(): When reloading a single TTY dev, remember to clean it
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-24 13:48:25 +02:00
Joachim Nilsson 781ba66905 Revert "Remove reconf condition when .conf reload completes"
This reverts commit 06479aa5f1.
2017-10-24 13:07:48 +02:00
Joachim Nilsson 9a97ab29dc Revert "cond_reassert(): Use cond_set_path(), not cond_clear(), for reconf"
This reverts commit afb3fada50.
2017-10-24 13:07:15 +02:00
Joachim Nilsson b2b17ea4fb doc/config.md: Document new tty @console support in finit.conf
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-23 19:30:24 +02:00
Joachim Nilsson bfa99266e7 Minor, cleanup old unused function prototype
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-23 19:30:04 +02:00
Joachim Nilsson c76a58ef7a Remove long since deprecated finit.conf: console <DEV> support
All this code did was trigger prctl() to set process name to "console",
which you could use as a simple means of figuring out if a process was
started from the system console.

There are other ways to do this, which Finit should not be involved in.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-23 19:28:11 +02:00
Joachim Nilsson 51c5f3cbfa Length of the ANSI escaped runlevels string is 20 chars, need 21
Problem reported by @wkz

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-23 19:20:25 +02:00
Joachim Nilsson a6290da210 screen_init(): Verify that STDOUT is a TTY
Before we call screen_init(), which in turn calls libite:initscr(),
which in turn does a lot of tcgetattr() and termios to STDOUT to figure
out the size, we need to check that we're not backgrounded, or don't
actually have a TTY.  Problem reported by @wkz

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-23 19:16:51 +02:00
Joachim Nilsson 949f02eff4 tty: Add support for auto-detecting serial console from SysFS
This patch adds support for a new TTY device keyword `@console` which
auto-detects the system console by reading the SysFS file:

    /sys/class/tty/console/active

Embedded systems with one of /dev/ttyAMA0, /tty/ttyMXC0 or the original
/dev/ttyS0, as their active serial console can now instead use a single
line to /etc/finit.d/getty.conf to start the built-in getty on the same
TTY as the kernel already runs on:

    tty [12345789] @console 115200 noclear

With no TTY defined Finit will either do nothing (default), or start a
fallback shell if enabled in the configure script.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-23 17:24:46 +02:00
Joachim Nilsson 7970e45f45 Follow-up to cf60cdd, make sure to disable ISIG before calling getty
Disable INTR, QUIT, SUSP, and DSUSP while handing over to getty.  It is
up to the getty process to allow ISIG again.

This patch is due to the differences in control line setup between ARM,
x86/x86_64, and most notably PPC.  PPC in particular seem to have ISIG
set by default from the kernel.

Without this patch pressing Ctrl-C before getty is started will lead to
Finit receiving SIGINT and defaulting to a reboot, as introduced in the
BusyBox init signal adoption in eeb59eb.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-23 11:57:58 +02:00
Joachim Nilsson a36dafaa6c README: Update initctl usage
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-19 20:16:37 +02:00
Joachim Nilsson c092d22d48 initctl: Default to show services listing, not usage text
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-19 20:01:15 +02:00
Joachim Nilsson e4401f92ad Bump version for v3.0 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-19 09:58:05 +02:00
Joachim Nilsson 0197a9427c Update ChangeLog for v3.0 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-19 09:58:05 +02:00
Joachim Nilsson 49481053a4 Fix GCC 7 string truncation warning, too small temporary buffer
In GCC 7 the -Wall infers the new -Wformat-truncation which finds
problems with string truncation in functions like snprintf().

This patch suppresses the warning by allowing only a subset of the
parent inetd service description to be copied to the child connection.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-19 09:58:05 +02:00
Joachim Nilsson 13887f323a Fix GCC 7 string truncation warning, too small temporary buffer
In GCC 7 the -Wall infers the new -Wformat-truncation which finds
problems with string truncation in functions like snprintf().

This patch fixes a possibly problem in path name creation which,
combined with the scandir() function, might cause loss of .conf
files, failure to call run-parts properly, and kill services at
shutdown.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-19 09:58:05 +02:00
Joachim Nilsson faca84a590 Fix GCC 7 string truncation warning, too small temporary buffer
In GCC 7 the -Wall infers the new -Wformat-truncation which finds
problems with string truncation in functions like snprintf().

This patch fixes a problem in condition parsing for very long
PID filenames which might be truncated in internal buffers
causing a mismatch in Finit condition tracking.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-19 09:58:05 +02:00
Joachim Nilsson 920df09cd5 Fix GCC 7 warning, convert "Fall through" to "fallthrough" comment
In GCC 7 the -Wextra infers the new -Wimplicit-fallthrough which can be
suppressed by adding a simple comment

    /* fallthrough */

Which we had, but was too verbose (and misspelled) for GCC to notice.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-19 09:58:05 +02:00
Joachim Nilsson 3e71d43bff Follow-up to 22192ac, missing semicolon
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 23:19:41 +02:00
Joachim Nilsson 5c3a07e8e6 tty_exist(): Simplify, no need to call access() and then open()
Found by Coverity Scan, classified as security issue but was just
unnecessary overhead.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 23:06:04 +02:00
Joachim Nilsson 11dd877484 initctl: Fix possible divide by zero, found by Coverity Scan
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 23:01:07 +02:00
Joachim Nilsson 921fd1e363 service_start(): Don't fclose() invalid file pointer, found by Coverity Scan
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 22:58:31 +02:00
Joachim Nilsson f949017596 logrotate(): Ignore any error from rename(), file may not exist
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 22:57:18 +02:00
Joachim Nilsson 03a33fc0ee Check stat() return value, found by Coverity Scan
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 22:56:02 +02:00
Joachim Nilsson 22192acce4 initctl: Make sure to NUL terminate info string from Finit
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 22:53:23 +02:00
Joachim Nilsson 500d301700 tty_unregister(): Fix possible out-of-bounds access, found by Coverity Scan
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 22:45:02 +02:00
Joachim Nilsson e8f26709e2 service_register(): Fix possible memory leak, found by Coverity Scan
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 22:41:13 +02:00
Joachim Nilsson 91b3e5eeb4 inetd: Fix possible tcp socket leaks, found by Coverity Scan
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 22:37:21 +02:00
Joachim Nilsson 71026adf03 tty_register(): Fix possible memory leak, found by Coverity Scan
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 22:32:26 +02:00
Joachim Nilsson 978beb8e7e Don't log if failed to remove non-existing condition
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 22:05:00 +02:00
Joachim Nilsson 3ef75ac176 debian: Mention the possibility to change the default init to Finit
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 21:49:19 +02:00
Joachim Nilsson 83b613581a void: Clean up README
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 21:48:58 +02:00
Joachim Nilsson d4c28f87d1 void: Update installation instruction, recommend manual edit of grub
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 19:15:28 +02:00
Joachim Nilsson 5b53f001a2 Revert parts of c2bf7d3, core-services scripts not executable
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 11:24:29 +02:00
Joachim Nilsson f1c9581da9 service_start(): Must set GID before dropping user privs, obvs
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 11:05:59 +02:00
Joachim Nilsson 5301bcb4f1 void: Drop-privs to correct @username:group
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 10:51:39 +02:00
Joachim Nilsson c2bf7d3a50 void: Call runit core startup scripts using run-parts at bootstrap
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 10:30:21 +02:00
Joachim Nilsson 685771aef2 void: Simplify uuidd service description
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 10:29:53 +02:00
Joachim Nilsson 3ebb697910 Install a proper #!/bin/sh style rc.local on Void Linux
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 10:18:11 +02:00
Joachim Nilsson bacaea0e02 bootmisc: Fix misspelled uuidd
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 10:14:56 +02:00
Joachim Nilsson 07d6e69c30 bootmisc: Check return value from getgroup()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 10:10:13 +02:00
Joachim Nilsson d2053bd07d bootmisc: Follow-up to f4662d8
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 10:09:15 +02:00
Joachim Nilsson 1e8a45cbe2 void: Remove non-working hack to create /run/uuid in <service>.conf
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 10:06:12 +02:00
Joachim Nilsson f4662d8c06 boomisc: Create /run/uuid for Void Linux if uuid user exists
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 10:05:46 +02:00
Joachim Nilsson 38ba9930d0 helpers.c:getuser() - Make @home an optional argument
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 10:03:54 +02:00
Joachim Nilsson 00fe37174d Refactor initial /dev popoulation
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 09:57:38 +02:00
Joachim Nilsson 33916a2097 Fix #82: Revert parts of 34a1524 and add workaround from Void Linux
In commit 34a1524 the start of udevd was refactored to allow it to be a
properly monitored service caused systems using eudev to malfunction.

This patch reverts part of that commit and adds a workaround found when
trying to reproduce issue #82 on Void Linux:

   - Start a temporary udevd in the background
   - Call udevadm to trigger bringup of all subsystems and devices
   - Wait for everything to settle
   - Tell temporary udevd to exit (new)

In the world of `mdev` this song and dance act is not required.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 09:43:37 +02:00
Joachim Nilsson dd8dd67106 void: Create /run/uuid directory and start uuidd as @uuid:uuid
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 09:14:22 +02:00
Joachim Nilsson eb870efaff Add support for setting effective group ID of services
Finit has long since supported an @user:group syntax to services, tasks,
and run stanzas.  Setting UID was implemented at that time, but setting
GID never was.  This patch fixes that oversight.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 09:11:23 +02:00
Joachim Nilsson 84369ab8b5 void: No syslogd to wait for in Void Linux
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 08:54:24 +02:00
Joachim Nilsson 7ef3959a45 Minor, consistency in presentation
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 08:14:29 +02:00
Joachim Nilsson 858f793ad2 Initial support for Void Linux
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-17 23:53:24 +02:00
Joachim Nilsson 8749459206 doc/condiitions.md: Update and simplify, hopefully more readable
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-16 17:07:52 +02:00
Joachim Nilsson 1c9f2e9b55 initctl: Fix set/clear condition
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-16 16:49:35 +02:00
Joachim Nilsson 9b8e7a0793 Minor, update documentation on raw condition dumps
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-16 14:54:48 +02:00
Joachim Nilsson 3f150901fe initctl: Align STATUS output from cond show and dump
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-16 11:26:43 +02:00
Joachim Nilsson fd090a6785 initctl: Fix 'cond dump/set/clear' commands, only show worked
This patch fixes an invalid use of strpbrk() causing all cond
sub-commands, except initctl cond show, to fail.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-16 11:23:57 +02:00
Joachim Nilsson 83445f1ebe initctl: show, use '-' for runlevels service is not member of
This patch adds a '-' for each runlevel a service/task is not part of.
The resulting listings are easier to read and also makes it clearer to
the user what happens when changing runlevels.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-16 09:43:58 +02:00
Joachim Nilsson e88241316b Prune bootstrap tasks/services that never ran
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-16 09:42:08 +02:00
Joachim Nilsson f91205cbad initctl: list, only print whitespace separator between services
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-16 08:43:29 +02:00
Joachim Nilsson 94aec26e8c initctl: shoow, adjust width of runlevels column, needs 12 chars
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-16 08:42:47 +02:00
Joachim Nilsson 11026d9da3 initctl: Minor, use local screen_cols rather than SCREEN_WIDTH
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-16 08:42:03 +02:00
Joachim Nilsson a6a3299f08 Free cmd from which() after having registered the udevd service
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-15 23:10:42 +02:00
Joachim Nilsson 34a15241ca Convert udevd to a regular system service
This patch, similar to the work done in the d-bus plugin, converts the
udevd service from a non-monitored run_interactive() task that forks
itself into the background, to a proper Finit monitored service.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-15 23:10:18 +02:00
Joachim Nilsson 7a2667d34c plugins/dbus: Free cmd returned from which() when done
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-15 23:01:10 +02:00
Joachim Nilsson f39cd50762 plugins/dbus: Use cmd found by which() to start dbus-daemon
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-15 22:48:04 +02:00
Joachim Nilsson ddeed15191 plugins/dbus: Start dbus-daemon with absolut path
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-15 22:45:01 +02:00
Joachim Nilsson 2b173e831f service_start(): Redirect service output to /dev/null by default
This patch prevents output of stderr/stdout from services to leak to the
console.  Use the 'log' keyword to service/run/task stanza to redirect
output to syslog.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-15 21:39:58 +02:00
Joachim Nilsson b02f241e5e plugin/dbus.c: Minor, documentation
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-15 21:18:21 +02:00
Joachim Nilsson 1a45045a0f service_register(): Do not modify input string, may be read-only
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-15 21:17:00 +02:00
Joachim Nilsson e131b20a6c service_register(): Make sure to initialize username to NULL
Follow-up to 7d9f873, which converted this from a function argument to a
local variable.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-15 20:47:18 +02:00
Joachim Nilsson 888ce56f3e plugin/dbus.c: Register dbus-daemon as a service
This patch changes how the D-Bus plugin starts dbus-daemon, from being
started in the background to letting Finit start and monitor it.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-15 20:46:22 +02:00
Joachim Nilsson 7d9f873b7c Follow-up to a2f4b35, remove username arg from service_register()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-15 20:32:11 +02:00
Joachim Nilsson cf60cdd9c9 Fix termios regression on PPC introduced in 907595d
For some reason PPC is much more sensitive than ARM when it comes to
termios changes.  This patch fixes a regression in Ctrl-C handling
after login introduced in 907595d when blocking of Ctrl-C was added
to prevent breaking the login-prompt.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-15 20:12:37 +02:00
Joachim Nilsson bb27dde3ca Nope, keep original logo to home page instead, this is Finit3
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-15 13:34:39 +02:00
Joachim Nilsson 6d02c6a71c New logo on top maybe?
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-15 13:33:17 +02:00
Joachim Nilsson f0c5c2d7f2 Play around a bit with altering logo
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-15 13:32:23 +02:00
Joachim Nilsson 29357acf18 Update bootstrap.md to match Finit3 changes
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-15 13:09:26 +02:00
Joachim Nilsson a32d3b0c87 Update ChangeLog upcoming v3.0 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-15 12:41:55 +02:00
Joachim Nilsson 510b53e62d Add simple ToC
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-14 16:35:51 +02:00
Joachim Nilsson 23481b197b build.md: Simplify and sectionalize better
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-14 16:34:09 +02:00
Joachim Nilsson 4782b1dc54 conditions.md: Remove ToC heading and rewrite introduction
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-14 16:30:31 +02:00
Joachim Nilsson 1ee1b9cec4 signals.md: Clarify and update slightly
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-14 16:22:45 +02:00
Joachim Nilsson cef2ef82b6 Add mini ToC for overview
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-14 16:20:46 +02:00
Joachim Nilsson cafa759edb distro.md: Clarify vague leading paragraph
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-14 16:18:15 +02:00
Joachim Nilsson cf0554405b bootstrap.md: Start updating, needs more work ...
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-14 16:17:42 +02:00
Joachim Nilsson f6071d6701 contrib: Rename tty.conf to getty.conf to reduce confusion
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-14 16:09:35 +02:00
Joachim Nilsson 7104296396 Remove ToC heading and audit grammar + wording in Limitations section
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-14 16:04:56 +02:00
Joachim Nilsson 38a274114d Allow registering TTYs that are not yet available
This patch removes the following very annoying warning for TTY devices
not yet available, i.e. plugged-in to the system.

Loading configuration ............................................................................. [ OK ]
[   11.097414] finit[1]:tty_register():Incomplete or non-existing TTY device given, cannot register.
[   11.101457] finit[1]:tty_register():Incomplete or non-existing TTY device given, cannot register.
Mounting filesystems .............................................................................. [ OK ]

Finit will not start a getty (built-in or external) if the TTY does not
exist, but having the configuration enabled makes it possible to do a
simple `initctl reload` to activate a plugged in TTY.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-14 13:14:48 +02:00
Joachim Nilsson 97eca563b6 Reduce indent and remove non-matching keyword conf
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-13 08:34:32 +02:00
Joachim Nilsson 0174347039 Use Apache .conf highlighting for finit.conf sample
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-13 08:32:43 +02:00
Joachim Nilsson 02cc426f05 Update Alpine screenshot, removed failing/missing D-Bus service
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-13 08:17:37 +02:00
Joachim Nilsson 06d9d95723 Minor updates, linking to scripts, grammar
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-13 08:11:59 +02:00
Joachim Nilsson b8a7f3e0cc Link to Alpine Linux home page
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-13 08:08:18 +02:00
Joachim Nilsson 7db0e265ad Link to Alpine Linux home page
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-13 08:07:06 +02:00
Joachim Nilsson 6818813ff8 plugins/dbus: Conditionalize, don't run if dbus-daemon is missing
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-13 08:02:59 +02:00
Joachim Nilsson 5b8f7ce2a3 Update screenshot, TroglOS Linux --> Alpine Linux
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-13 07:59:33 +02:00
Joachim Nilsson 1f9a6a42c1 Push badges even further down
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-13 07:37:22 +02:00
Joachim Nilsson 1c2d987bea Place logo first, then badges
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-13 07:36:06 +02:00
Joachim Nilsson 906827cc88 Move documentation to doc/ sub-directory, all except README
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-13 07:35:09 +02:00
Joachim Nilsson b2d98dc010 Update path to sample finit.conf
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 23:10:47 +02:00
Joachim Nilsson d027b4ff9c Relocate old sample finit.conf to contrib/
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 23:09:32 +02:00
Joachim Nilsson 843621aded Move documentation to doc/ sub-directory, all except README + TODO
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 23:07:21 +02:00
Joachim Nilsson da5ac16670 Minor
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 23:05:27 +02:00
Joachim Nilsson 2c68183045 Clarify actions of Alpine Linux install script
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 22:51:15 +02:00
Joachim Nilsson c40cd06d60 Update Alpine README, we now have an install script
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 22:44:56 +02:00
Joachim Nilsson c901b65581 Simplify
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 22:44:00 +02:00
Joachim Nilsson 27abcb5682 Add option to install Finit as system default init
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 22:41:20 +02:00
Joachim Nilsson b7617248ce Simple install script for Alpine Linux
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 22:35:17 +02:00
Joachim Nilsson c400d35f83 Also include /usr/lib/pkgconfig in PKG_CONFIG_LIBDIR
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 22:26:37 +02:00
Joachim Nilsson d236709457 Minor, script output updates
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 22:26:24 +02:00
Joachim Nilsson 07790f4044 Debian/REDAME: Clarify last paragraph, add reminder of /etc/rc.local
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 19:03:53 +02:00
Joachim Nilsson 3d5128be77 Remove Emacs Local Variables, not really needed and looks bad
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 19:01:25 +02:00
Joachim Nilsson b37ea48e5d Debian/README: Update, modernize, simplify, and clarify
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 18:54:34 +02:00
Joachim Nilsson 92616d2ac0 README: Add URLs for the various RFC inetd services available
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 18:46:14 +02:00
Joachim Nilsson 46bc75e7f3 README: Add more examples on conditions and multiple dependencies
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 18:43:47 +02:00
Joachim Nilsson 5f81404162 xdm.conf: Remove lightdm, now has its own .conf
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 18:25:51 +02:00
Joachim Nilsson 6ba7cfc851 Rename Debian xdm.com --> xdm.conf
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 18:24:41 +02:00
Joachim Nilsson 09d2243eba Add Debian .conf for LightDM
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 18:23:19 +02:00
Joachim Nilsson e97c5e5860 Increase log level for poweroff/reboot/halt
In case the kernel is incapable of handling a reboot,
power-off, or halt request we want to be able to let
the user perform some basic diagnose of the system.

The existing debug messages are good enough, and use
the correct grammar form, to be enabled always.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 09:03:24 +02:00
Joachim Nilsson 660a09c7c1 Reduce log level when skipping re-register of boostrap tasks
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 09:02:05 +02:00
Joachim Nilsson 41c003b221 Don't reload *.conf files when changing to runlevel reboot
... or if someone manages (regression) to change to runlevel bootstrap.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 08:56:08 +02:00
Joachim Nilsson 12d8ac2399 service_register(): Skip bootstrap services if not in bootstrap
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 08:55:42 +02:00
Joachim Nilsson 8dc263d508 Revert live logging of state machine
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 01:28:38 +02:00
Joachim Nilsson afb3fada50 cond_reassert(): Use cond_set_path(), not cond_clear(), for reconf
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 01:23:43 +02:00
Joachim Nilsson 227dda34f7 cond_set_path(): Log error if unlink() fails
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 01:23:16 +02:00
Joachim Nilsson 06479aa5f1 Remove reconf condition when .conf reload completes
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 01:07:09 +02:00
Joachim Nilsson 75d29de3cc initctl: Use entire screen width for task/service description
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 00:19:10 +02:00
Joachim Nilsson 40fc95047d Prevent 100% CPU, allow bootstrap tasks to fully complete
When collecting a bootstrap task we need to allow its state machine to
complete before cleaning them out.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-11 23:53:34 +02:00
Joachim Nilsson 5551324291 Minor, comment style
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-11 23:52:20 +02:00
Joachim Nilsson 46cef811d6 Make sure to step state machine when collecting bootstrap tasks
During the runlevel change from S --> 2 the state machine will pause,
waiting to collect all S-only tasks/services, before continuing.

When an S-only task/service is collected we therefore need to call the
state machine again so that it can reassert all conditions properly.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-11 23:02:13 +02:00
Joachim Nilsson 52ccd6d662 Use correct grammar form
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-11 22:54:48 +02:00
Joachim Nilsson 70afaa16f5 sm_step(): Log pending stopped svc if we exit state machine
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-11 22:05:33 +02:00
Joachim Nilsson 8a1015cf3e API refactor, allow svc_stop_completed() to return the pending svc
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-11 22:04:17 +02:00
Joachim Nilsson 586f0a7799 Live debug stopped but not yet collected tasks
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-11 21:56:49 +02:00
Joachim Nilsson 474bd2f361 Minor, comment style
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-11 21:56:31 +02:00
Joachim Nilsson 0caa8330b7 Increase live debugging of main state machine
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-11 21:41:42 +02:00
Joachim Nilsson c8d8c817e7 Minor, cleanup
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-11 21:29:21 +02:00
Joachim Nilsson 0d9542c222 Live debug
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-11 21:29:15 +02:00
Joachim Nilsson b6be354508 Minor, whitespace
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-10 23:39:22 +02:00
Joachim Nilsson 448c6749d6 Add missing debug calls to RTM_NEWLINK and RTM_DELLINK
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-10 22:53:19 +02:00
Joachim Nilsson 0f09c1b0dc Minor, comment fix
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-10 22:53:05 +02:00
Joachim Nilsson 7db6611593 Debian GNU/Linux: Minor caveats
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-10 22:15:27 +02:00
Joachim Nilsson c9b13759a2 Debian GNU/Linux: Install finit.* using install and cp
A recursive cp is requried for finit.d

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-10 18:50:58 +02:00
Joachim Nilsson 449c712329 Remove old symlinks and install finit.d directory instead
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-10 16:15:36 +02:00
Joachim Nilsson e27283c5e6 Add extra spacing
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-10 16:14:27 +02:00
Joachim Nilsson f337efcc35 Debian GNU/Linux: Update install script
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-10 16:13:22 +02:00
Joachim Nilsson 3c7eaff7b3 Debian GNU/Linux: Update and sync build instructions with Alpine
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-10 12:00:04 +02:00
Joachim Nilsson d4d42a7a75 Debian GNU/Linux: Convert finit.conf to finit.d/*.conf
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-10 11:59:29 +02:00
Joachim Nilsson 3c1c5621a5 Alpine Linux: Slight update + sync with Debian
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-10 11:46:02 +02:00
Joachim Nilsson 2d9c147e0e Minor, fix comment within comment GCC warning
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-09 09:03:58 +02:00
Joachim Nilsson 53de1c8575 Follow-up to issue #81, don't append error message again.
Also, when called multiple times, return workaround immediately instead
of warning again.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-01 22:07:21 +02:00
Joachim Nilsson 3d4e3c99ed Fix #81: Workaround for systems without SYSV shm IPC support
We should not let PID 1 fail on systems where Linux is built without
CONFIG_SYSVIPC, or the libc does not support shmget()/shmat().

This workaround implements a fallback to using calloc() for PID 1,
which means the initctl tool will not work properly.  A better fix
would be to refactor the shm implementation to instead have initctl
call Finit using api.c for each svc_t.  This has been added to the
TODO file as future work.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-01 20:52:01 +02:00
Joachim Nilsson c1b6c7e840 TODO: Remove shm, as soon as possible
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-01 20:01:57 +02:00
Joachim Nilsson f17515d791 Merge pull request #80 from joerg-krause/patch-1
helpers.h: fix build error: unknown type name ‘va_list’
2017-10-01 18:56:45 +02:00
Jörg Krause 48262e4250 helpers.h: fix build error: unknown type name ‘va_list’
Building finit with a uclibc-ng-toolchain fails with:
```
../src/helpers.h:53:43: error: unknown type name ‘va_list’
 void    printv          (const char *fmt, va_list ap);
```
2017-10-01 16:50:39 +02:00
Joachim Nilsson 9d9dc74768 Minor corrections
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-01 01:26:43 +02:00
Joachim Nilsson e1d1d1c795 Makefile: Remove service script wrapper from distribution as well
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-30 12:16:33 +02:00
Joachim Nilsson fcfef0af47 Initial cleanup + refactor of Debian contrib files
We should no longer need to rely on runparts to handle initial set up of
keyboard and console.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-30 10:26:03 +02:00
Joachim Nilsson c44c217c4a Clean up unused and long since deprecated contrib files/patches
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-30 10:23:21 +02:00
Joachim Nilsson d60fc1ce62 Refactor, simplify
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-29 01:22:10 +02:00
Joachim Nilsson 0a12997d32 Try right aligning Finit3 logo
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-29 01:21:07 +02:00
Joachim Nilsson dce8031c83 Clarify, early on, that conditions also stop services.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-28 08:22:41 +02:00
Joachim Nilsson bd9d9c8303 Add early example of conditions in service stanza
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-28 08:22:28 +02:00
Joachim Nilsson 956acc4b93 Update getty overview
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-28 08:10:31 +02:00
Joachim Nilsson 5ed54d79fc Update configure flags
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-27 09:27:15 +02:00
Joachim Nilsson acc77c27c3 Add URL to initctl reference
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-27 09:23:54 +02:00
Joachim Nilsson bcb9fe039a Move running and debugging to doc/build.md
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-27 09:22:04 +02:00
Joachim Nilsson 55f44386d1 Clarify focus, refer to examples and tell what the screenshot is
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-27 09:09:23 +02:00
Joachim Nilsson 37983e69c4 Clarify service stanza and simplify text further
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-27 09:08:32 +02:00
Joachim Nilsson a45a872c28 Simplify introduction a lot, focus on screenshot and example
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-27 08:43:53 +02:00
Joachim Nilsson 152b2be8ea Clarify warning
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-27 08:43:27 +02:00
Joachim Nilsson 1677436137 initctl: Allow C99 style
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-26 10:39:45 +02:00
Joachim Nilsson c69ca6847a Update ToC and move references to alternative init systems here
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-25 19:06:07 +02:00
Joachim Nilsson f8147214f1 doc/config.md: Significant update, less limitations for /etc/finit.d
- Detail limitations in separate section
- Focus on syntax early in document
- Overhaul and simplify introduction

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-25 19:03:22 +02:00
Joachim Nilsson 56eec5164d Minor, update code comment
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-25 19:02:19 +02:00
Joachim Nilsson e58f84f3fb Update introduction, much system config can be done using finit.d
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-24 20:54:27 +02:00
Joachim Nilsson d22ffa05bd initctl: Refactor initctl list slightly
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-24 20:41:40 +02:00
Joachim Nilsson 2e66db3fea helpers.c:printv() - Iterate over size of buffer
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-24 20:40:44 +02:00
Joachim Nilsson 376811c1a7 doc/config.md: Update run and task, mention pipes + redirects
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-21 22:52:48 +02:00
Joachim Nilsson 9b5f2388c1 Alpine Linux: Add LXDM service .conf
Enable LXDM using:

    initctl enable lxdm
    initctl reload

The latter command reloads all /etc/finit.d/*.conf files and starts lxdm
in runlevels 2-5.

Remember to first edit /etc/lxdm/lxdm.conf, necessary to get a session.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-10 15:33:56 +02:00
Joachim Nilsson 686193b701 Only load modules at bootstrap
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-10 14:03:56 +02:00
Joachim Nilsson b43bca529c Minor, fix build error
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-10 13:57:23 +02:00
Joachim Nilsson 545171a8b2 Minor, improve comments in parse_dynamic()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-10 13:50:44 +02:00
Joachim Nilsson d54d5b7f20 Allow kernel modules to be loaded from /etc/finit.d/*.conf
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-10 13:48:07 +02:00
Joachim Nilsson e52d952ca5 Alpine: Move bootstrap services and setup from finit.conf to finit.d/*.conf
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-10 13:30:36 +02:00
Joachim Nilsson 633a56054b Add support for boot[S]trap services in /etc/finit.d/*.conf
This patch enables support for bootstrap services in /etc/finit.d/

Please note, however, that this does not mean that all configuration
directives are now allowed in /etc/finit.d/*.conf -- the intention is
only to simplify distribution setups.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-10 13:21:11 +02:00
Joachim Nilsson 3eeb966f15 Alpine Linux: Simplify build instructions by referencing script
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-10 12:55:32 +02:00
Joachim Nilsson d09253bdbd Make Alpine build script executable
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-10 12:50:36 +02:00
Joachim Nilsson 0052793a46 Update Alpine Linux README
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-10 11:41:05 +02:00
Joachim Nilsson 333871caf2 Minor, reorder
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-10 11:40:56 +02:00
Joachim Nilsson ef9d0c479e Load mousedev kernel driver for Alpine installs
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-10 01:40:24 +02:00
Joachim Nilsson d5cce03a76 Enable D-Bus plugin for Alpine installs
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-10 01:39:23 +02:00
Joachim Nilsson 744903d455 Alpine Linux finit.conf, clear space at end for easy script append
Restore original file layout somewhat, it's better if we clear the space
at the end of the file for easy `cat BOOTSTRAP.conf >>/etc/finit.conf`

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-06 08:12:44 +02:00
Joachim Nilsson cc00be48b5 Move runlevel stanza to the end, possibly more intuitive
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-04 21:24:59 +02:00
Joachim Nilsson b45a37ca47 Add simple build script for targeting Alpine
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-04 21:20:32 +02:00
Joachim Nilsson f1f9ee712a Refactor Alpine example to use /etc/finit.d/*.conf for services
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-04 21:15:11 +02:00
Joachim Nilsson 7c4a9ad5af alpine: Migrate rc.local bootstrap tasks to finit.conf
Finit now supports pipes and redirects in run/task stanzas.  Hence, we
can reduce rc.local to an example template.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-04 20:16:54 +02:00
Joachim Nilsson f3a000560f exec_runtask(): Refactor, remove GLIBC:isms to build with musl
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-04 20:05:22 +02:00
Joachim Nilsson fdd13c1ae1 README: New shell redirect + pipe possibilities with task + run
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-04 16:35:22 +02:00
Joachim Nilsson 0585767258 README: Update tty configuration examples with noclear + nowait
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-04 16:35:04 +02:00
Joachim Nilsson 9e7e92b4b7 run stanzas are never caught in service_monitor()
A run stanza blocks operation by calling waitpid(), so it will never be
caught by the service_monitor() function.  Hence, we need to clean up
any bootsrap calls after waitpid(), or at least perform a manual state
change.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-04 16:02:23 +02:00
Joachim Nilsson 29822ef0f7 Always collect bootstrap tasks, regardless of previous runlevel
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-04 16:02:01 +02:00
Joachim Nilsson 718e82bc10 svc_clean_dynamic(): Actually clean dirty services ...
Add missing call to svc_mark_clean() in while() loop.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-04 16:01:05 +02:00
Joachim Nilsson 684314db0f Allow pipe + redirect in task/run stanzas, exec() in /bin/sh
This patch extends the capabilities of task and run .conf stanzas by
enabling pipes and redirects.

Example:

    task [s] echo "foo" | cat >/tmp/bar
    run  [s] echo "$HOME" >/tmp/secret

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-04 16:00:49 +02:00
Joachim Nilsson 442598282f Update Alpine Linux sample to latest Finit dev.
- Show progress when booting
- Use noclear + nowait on TTY's
- Update `loadkmap` args

Works on Alpine Linux 3.4 .. 3.6

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-04 07:19:12 +02:00
Joachim Nilsson 3e2b78305d Update finit.conf tty documentation
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-01 06:45:29 +02:00
Joachim Nilsson 8eea64cebf getty: Set $TERM environment variable if given in tty config
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-01 06:41:22 +02:00
Joachim Nilsson b8a7cb6b93 tty-register(): Fix regression in built-in TTY baud + term parser
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-01 06:40:52 +02:00
Joachim Nilsson 529b39ebba tty: Add 'noclear' + 'nowait' options to built-in and external tty's
This patch aligns the two tty configuration stanzas, thus clear and wait
are now the default for both.

    tty [LVLS] <DEV> [BAUD] [noclear] [nowait] [TERM]
    tty [LVLS] <CMD> <ARGS> [noclear] [nowait]

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-01 06:10:08 +02:00
Joachim Nilsson f029ba2111 Reorder functions a bit, group run_getty*() family
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-01 05:50:50 +02:00
Joachim Nilsson 277c3dbb14 getty: Remove TTY clear from built-in getty, delegate to run_getty()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-01 05:47:53 +02:00
Joachim Nilsson f273ecc135 Fix #79: Add 'nowait' option to tty setting, external getty
This patch makes it possible to disable the "Please press Enter" prompt
when using an external getty. Simply append `nowait` to the .conf entry
and Finit will spawn the getty immediately.

A future patch will add support for `noclear` as well to external getty,
as well as a change in default (=> `wait`) for the built-in getty.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-08-31 00:51:11 +02:00
Joachim Nilsson 2fe257b7af getty.c: Handle Ctrl-U properly, erase line to beginning
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-08-30 17:19:43 +02:00
Joachim Nilsson 907595d9ed getty.c: Ignore signals like SIGINT, SIGHUP
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-08-30 17:19:12 +02:00
Joachim Nilsson 55c12aa6f6 Remove developer debug message
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-08-30 15:08:14 +02:00
Joachim Nilsson 04891d3e5b Update and align service descriptions in finit.conf example
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-08-30 15:05:31 +02:00
Joachim Nilsson 9973cd22a5 Update sample .conf files after purge of startx and user settings
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-08-30 15:02:39 +02:00
Joachim Nilsson a2f4b35e4e Fix #77: Remove deprecated startx and user .conf settings
It is strongly recommended to instead use the service stanza to start
XDM/GDM, or use startx after a regular login.

Note: the `user NAME` setting was always reserved for use with startx

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-08-30 15:01:05 +02:00
Joachim Nilsson 1de540dd67 Update external getty TTY documentation, remove limitations
Also, provide an agetty example.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-08-30 14:47:15 +02:00
Joachim Nilsson dec21e758a Fix #78: Support agetty cmd line format for external getty
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-08-30 14:44:10 +02:00
Joachim Nilsson 513f03b897 Merge branch 'external-getty-support' 2017-08-27 17:08:21 +02:00
Joachim Nilsson 371fb3d0d0 Add example for using an external getty
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-08-27 17:07:12 +02:00
Joachim Nilsson f9f1846c8b Document alternative tty ... config option for external getty
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-08-27 17:03:39 +02:00
Joachim Nilsson f7b9b7be96 tty.c: Free memory for external getty on tty_unregister()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-08-27 16:57:26 +02:00
Joachim Nilsson 74affb32d3 tty_register(): Fix parser for external getty
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-08-27 16:43:01 +02:00
Joachim Nilsson 675f82a6b9 run_getty2(): Minor fixes only, whitespace + cautionary _exit()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-08-27 16:41:58 +02:00
Joachim Nilsson 19fcfcfef4 Initial support for external getty
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-08-27 15:02:55 +02:00
Joachim Nilsson 7c50d86a55 Restore pre built-in run_getty() as run_getty2()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-08-27 15:01:42 +02:00
Joachim Nilsson b629348973 Refactor TTY exec, prepare for external getty
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-08-27 15:00:43 +02:00
Joachim Nilsson 7c185b4575 Fix really bizarre inetd builtin example ...
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-08-21 21:23:51 +02:00
Joachim Nilsson fefa6a93ca Merge branch 'emergency-shell-improvements' 2017-08-19 20:17:31 +02:00
Joachim Nilsson 299962118a Update debug section with info on rescue shell, issue #76 2017-08-19 20:16:44 +02:00
Joachim Nilsson 054baed134 Reap zombie processes in emergency shell mode, issue #76
The emergency shell is just a Finit debug mode.  This patch adresses a
concern from GitHub issue #76, with zombie processes in this mode.

Emergency shell could be further improved, e.g. informing the real Finit
process of each collected child (zombie) to be restarted if needed.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-08-15 08:09:19 +02:00
Joachim Nilsson b20fafd9fa tty.c: Add support for reloading a single TTY
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-14 11:03:59 +02:00
Joachim Nilsson 62081d9525 tty.c: Refactor, break out enabled check + stop/start
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-14 11:03:10 +02:00
Joachim Nilsson 100b4c70e4 tty_enabled(): Simplify, tty_exists() checks for existence
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-14 10:54:51 +02:00
Joachim Nilsson 5631849ced Travis-CI: Update build dependency, libite --> v1.9.2
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-10 17:48:14 +02:00
Joachim Nilsson 14ee218443 Refactor, use libite (-lite) version of initscr()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-09 16:25:22 +02:00
Joachim Nilsson 52fe525442 Update version requirement for libite, v1.9.2
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-09 16:25:01 +02:00
Joachim Nilsson fec00377e5 Update documentation for tty .conf option
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-09 15:36:31 +02:00
Joachim Nilsson c9ab70e30f Update section on built-in getty, add info on noclear option
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-09 15:18:16 +02:00
Joachim Nilsson 8aef1e76c3 Follow-up to eec32e2: Support for removing TTYs at runtime
In commit eec32e2 support for reloading TTY configurations was added.
This patch is a follow-up to that with support for cleaning up and
removing allocated TTYs.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-09 15:05:32 +02:00
Joachim Nilsson 44f69bd575 Check if symlink with lstat(), mtime with stat()
With the new scheme using /etc/finit.d/available/, and symlinks from
there to the enabled directory, we need to check mtime of .conf files
using stat(), not lstat() which we need to check if .conf is a symlink.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-09 15:05:32 +02:00
Joachim Nilsson 963b736d8b tty: Refactor, remove useless runlevel argument
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-09 15:05:32 +02:00
Joachim Nilsson 4cc3aed139 Avoid 2 sec block of Finit when stopping TTYs
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-09 15:05:32 +02:00
Joachim Nilsson e791e3dbe9 Make silent bootup the default, use --enable-progress for old style
This patch disables console heading and bootup progress messages by
default. Use --enable-progress to get the old behavior back, or try
the new HOOK_BANNER and HOOK_SVC_UP to run a custom progress.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-09 15:05:32 +02:00
Joachim Nilsson d34ee62f77 Update copyright years
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-08 15:32:24 +02:00
Joachim Nilsson e48901b90f tty: Clear tty before login: prompt by default, add 'noclear' option
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-08 15:31:59 +02:00
Joachim Nilsson 60f73dc952 tty.c: Refactor parsing of tty .conf stanza in tty_register()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-08 15:30:51 +02:00
Joachim Nilsson eec32e299b Allow loading TTYs from /etc/finit.d rather than /etc/finit.conf
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-08 15:28:22 +02:00
Joachim Nilsson fe362341dc finit.conf: Remove check config, replaced by fsck over /etc/fstab
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-08 15:01:31 +02:00
Joachim Nilsson 8505db24b7 Refactor, rename local variables
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-08 12:28:52 +02:00
Joachim Nilsson 560adb2065 Remove debug message(s) from tty_fallback()
When the TTY fallback mechanism is enabled tty_fallback() prints this
annoying debug message whenever *any* is process is collected by PID 1:

   "Not starting fallback (%d) shell, lost pid %d", fallback, lost"

This patch removes it, and a two other useless debug messages.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-08 11:06:28 +02:00
Joachim Nilsson 6676d4b50c Silence service start/stop *before* launching TTYs
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-08 11:04:50 +02:00
Joachim Nilsson c1bd3961cf log_init(): If called with debug disbled set (or restore) LOG_NOTICE
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-08 00:11:24 +02:00
Joachim Nilsson 4fa47eaf71 log_init(): If debug mode enabled, set loglevel LOG_DEBUG
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-08 00:08:27 +02:00
Joachim Nilsson e5f47024af early_logit(): If debug mode enable, also print to stderr
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-08 00:07:49 +02:00
Joachim Nilsson 115b5f1ca7 Add HOOK_BANNER for plugins to override the default Finit banner()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-08 00:07:21 +02:00
Joachim Nilsson 878885e2b2 Load plugins much earlier, for future banner plugin
This patch moves the plugin loader much earlier, making it possible to
provide a custom banner/logo in a plugin.

To facilitate this move we need to also move banner later and parsing
of the kernel cmdline earlier, right after mouting /proc.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-08 00:05:07 +02:00
Joachim Nilsson 709e4230c8 plugin: Add private method plugin_exists() to check for HOOKs
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-07 23:33:43 +02:00
Joachim Nilsson 46c5e41b68 README: Reduce indentation of code blocks, use ``` instead
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-07 23:18:06 +02:00
Joachim Nilsson 0b43d0dc70 Refactor screen_init(), preparing for migration to libite
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-07 23:00:27 +02:00
Joachim Nilsson 99f3f0291a Makefile.am: Fix cut-and-paste error
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-04 21:48:16 +02:00
Joachim Nilsson 6d3d190134 reboot: Add search path to libite (-lite) headers and .so
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-04 21:40:46 +02:00
Joachim Nilsson 769659767c Minor, comment fixes only
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-04 21:12:54 +02:00
Joachim Nilsson 99818f9ce0 Convert banner() and printv() to use new screen_init() values
This patch changes the traditional look of the Finit boot sequence.
Now we stick to the screen width probed by screen_init(), or max
132 chars.

Also, some minor cleanup of the currently unused print_timestamp()
method used by printv() when showing [ OK ] or [FAIL] of services
at boot.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-04 20:59:49 +02:00
Joachim Nilsson be6f0de0df Add util.c:screen_init() to probe screen size once per boot
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-04 20:58:43 +02:00
Joachim Nilsson 405cf4d997 initctl: Use actual terminal/screen width for table listings
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-04 12:55:34 +02:00
Joachim Nilsson 91480a0f02 configure: Check for termios.h, needed by screen_width()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-04 12:55:10 +02:00
Joachim Nilsson 90793c71a2 util: Import screen_width() developed for the SMCRoute project
This patch introduces the screen_width() method from the SMCRoute
project.  The code is hereby also available under MIT/X11.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-04 12:53:19 +02:00
Joachim Nilsson 9bcb3e5778 initctl: top:ify table headings, i.e. use captial letters
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-04 12:39:41 +02:00
Joachim Nilsson c97e23bd58 initctl: Remove currently unused -d debug flag
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-04 12:38:22 +02:00
Joachim Nilsson 73f1b986dd initctl: Fix regression in initctl utmp
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-04 12:37:59 +02:00
Joachim Nilsson b06502b0cb initctl: Use printheader() from libite for table headings
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-04 12:37:20 +02:00
Joachim Nilsson c4b6fab3f3 Travis-CI: Update with latest version of libite, v1.9.1
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-03 16:46:52 +02:00
Joachim Nilsson 109b5bb9df Update TODO, some completed and some deprecated features
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-03 15:16:36 +02:00
Joachim Nilsson 6f61e8e915 Remove hard-coded paths to system tools available in $PATH
Since at least a44daf2 both run() and run_interactive() can access all
system tools in _PATH_STDPATH.  A system that uses non-standard paths,
e.g. /system/bin and /apps/bin, should update _PATH_STDPATH.

For reference, see issue #69 and PRs #70 and #72.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-03 13:18:42 +02:00
Joachim Nilsson 9c6e046d93 Remove hard-coded paths to system tools available in $PATH
This patch implemements a new feature of libite v1.9.1, whichp(), which
instead of fexist() that requires an absolute path, searches $PATH.

For reference, see issue #69 and PRs #70 and #72.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-03 13:13:55 +02:00
Joachim Nilsson 30822f0d68 Remove UNUSED() macro and disable the compiler warning instead
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-02 21:59:23 +02:00
Joachim Nilsson e46e3cdcb6 log.c: Filter debug messages by default, like before refactor
Ways to log:
- Set debug, using kernel cmdline, or edit the sources
- Change loglevel severity, default blocks > LOG_NOTICE

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-02 21:56:19 +02:00
Joachim Nilsson 260335a19f Usability, a servivce stopped by a user is stopped, not blocked
The generic term for a non-running service is blocked, but a service may
be blocked for several different reasons.  When a user stops a service
with `initctl stop` the intuitive expected output from `initctl show` is
"stopped" not "blocked".

When the user later restarts the service with `initctl start` it may of
course be blocked due to wrong runlevel or a missing condition.  As can
be expected from the service's configuration.

The rest of the patch refactors the internal API names a bit to reflect
this change.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-02 15:42:44 +02:00
Joachim Nilsson 516dbcc512 Remove --disable-quiet and quiet mode, default to a sane behavior
This patch is a follow-up to 1f1c2e0 which introduced the new semantics
for the very confusing quiet and silent modes.

The initial idea was to loosely follow the kernel cmdline 'quiet' option
and as a working concept this was good.  The resulting code, however,
became unnecessarily complex and the configure options impossible to
explain.

With this patch the quiet mode, and thus the --disable-quiet configure
option, is removed.  Finit now defaults to a sane behavior: services are
shown only at startup.   The --enable-silent option works like it did
before, silencing everything.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-02 13:40:54 +02:00
Joachim Nilsson 7a48240856 log.c: Do reopen syslog() when toggling debug => LOG_PERROR
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-02 13:19:22 +02:00
Joachim Nilsson cda5938215 helpers.c: New function, printv()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-02 12:43:41 +02:00
Joachim Nilsson cd947a69a8 log.c: New functions to hide access to quiet and silent flags
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-02 12:42:44 +02:00
Joachim Nilsson 60df2f2ea9 Minor, cleanup old requirement for clients to set silent
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-02 12:41:23 +02:00
Joachim Nilsson 51e1a907e6 log.c: New log_is_debug() function, hide access to debug variable
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-02 12:40:50 +02:00
Joachim Nilsson e9d5512e1a Refactor, simplify ... print() APIs already check if silent
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-02 12:38:35 +02:00
Joachim Nilsson bd54cf6dee log.c: New log_init() function, called at initial bootstrap
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-02 12:34:12 +02:00
Joachim Nilsson 1036c365b8 log.c: New log_exit() function, called at shutdown
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-02 12:31:38 +02:00
Joachim Nilsson 8ce330bcdb log.c: Rename log_toggle_debug() --> log_debug()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-02 12:28:16 +02:00
Joachim Nilsson 8161e8d153 Simplify log message from kernel cmdline parser
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-02 01:26:36 +02:00
Joachim Nilsson ec52a6a240 Set correct syslog() log level based on debug flag
Also, refactor logging to /dev/kmsg to separate function.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-01 22:23:53 +02:00
Joachim Nilsson 9a4f46dba4 Install log.h for external plugins
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-01 20:36:47 +02:00
Joachim Nilsson 5e8cb63f9a Refactor, _d() et al to use logit() instead of err.h
This patch is the first in a series of changes to clean up the internal
logging APIs of Finit:

  1. Convert log macros to use logit() for everything (this patch)
  2. Set correct syslog() log level based on debug flag
  3. Do closelog()/openlog() when toggling debug flag to control LOG_PERROR

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-01 20:34:37 +02:00
Joachim Nilsson d1df837d04 Refactor, move debug toggle to log.c:log_toggle_debug()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-01 20:34:37 +02:00
Joachim Nilsson 670f08ce51 Refactor, move logit() and log macros to log.c + log.h
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-01 20:34:37 +02:00
Joachim Nilsson 82661346b7 Follow-up to 885056a, collapse and simplify code
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-01 20:34:26 +02:00
Joachim Nilsson b2ac81540f Merge branch 'enable-disable-services'
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-01 18:02:52 +02:00
Joachim Nilsson fd861e1691 conf.c: Log warning for dangling .conf symlinks in /etc/finit.d/
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-01 17:52:15 +02:00
Joachim Nilsson 76b5bdc2c4 conf.c: Simplify .conf load/parse debug messages
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-01 16:06:01 +02:00
Joachim Nilsson 0ec5ad6961 TODO: Remember the idea of creating service stanzas using initctl
See issue #69 for a background.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-01 12:18:46 +02:00
Joachim Nilsson 1c2dcd9acc doc: Add distribution recommendations and tips, issue #71
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-01 12:17:57 +02:00
Joachim Nilsson 018a87286c initctl: Sort commands in usage according to topic
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-06-30 12:12:13 +02:00
Joachim Nilsson d0a3b4b019 Note neat feature of Solaris SMF, enable service temporarily
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-06-30 10:41:24 +02:00
Joachim Nilsson 3428cd48b7 Fix #71: Add support for enabling/disabling services in /etc/finit.d
This patch adds support for enabling and disabling services in
/etc/finit.d/ by adding another subdirectory:

    /etc/finit.d/available

Enabled service/run/task stanzas are by convention symlinked
to the parent dir.  The initctl tool has three new convenience
commands to facilitate operating with this:

   initctl list
   initctl enable  <CONF>
   initctl disable <CONF>

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-06-29 22:23:38 +02:00
Joachim Nilsson 023a881fb9 Enable more compiler warnings by default, except unused parameters
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-06-29 22:23:09 +02:00
Joachim Nilsson 36f38d5a13 initctl: Only append space between args, not at last arg
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-06-29 22:21:33 +02:00
Joachim Nilsson d4001064a0 configure: Fix hard coded FIFO path, found by previous commit
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-06-11 22:52:09 +02:00
Joachim Nilsson fffdad7645 configure: Add neat summary of settings, from lldpd
Hat tip to @vincentbernat

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-06-11 22:19:54 +02:00
Joachim Nilsson 32612929d9 doc/conditions.md: Attempt to clarify PID file dependency handling
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-06-10 19:49:36 +02:00
Joachim Nilsson d49683cfb6 TODO: Update and clarify introduction a bit
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-06-10 19:46:19 +02:00
Joachim Nilsson 9ca5ec16af doc/config.md: Minor refactor to add an Introduction section
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-06-10 19:44:48 +02:00
Joachim Nilsson 7041813966 Update Makefile after service script move
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-06-05 01:08:46 +02:00
Joachim Nilsson a31ecb32e1 Fix problem with building from a separate build directory
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-06-05 01:07:47 +02:00
Joachim Nilsson b1ea279940 Move helper script 'service' to contrib/
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-06-05 01:00:40 +02:00
Joachim Nilsson 82172e65fa Fix indentation
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-06-05 00:56:24 +02:00
Joachim Nilsson dfedb231dc Add MIT license badge to README
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-06-05 00:54:45 +02:00
Joachim Nilsson 5f5be8d74e Merge pull request #73 from westermo/wmo/inetd-remove-ntoh-on-proto
inetd: remove ntoh on proto
2017-04-25 13:34:19 +02:00
Petrus Hellgren fafeaf661a inetd: remove ntoh on proto
getprotobyname() returns p_proto in host endian, so it should not be
converted with ntoh. (Note: getservbyname() on the other hand does
return s_port in network endian)

Signed-off-by: Petrus Hellgren <petrus.hellgren@westermo.se>
2017-04-25 10:39:09 +02:00
Joachim Nilsson 06d3161ffe Merge pull request #72 from abucodonosor/master
Some cleanup

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-03-28 18:43:32 +02:00
crazy 885056a6c9 networking(): check first ifup exists
Check first ifup exists before using it since
   this is really something only exits on some
   distros an in different ways. Debian/Ubunu has
   an package for this while others have it in the
   initscripts package(s) , meaning the file can be
   around even without the prog.

Signed-off-by: crazy <crazy@frugalware.org>
2017-03-28 13:21:20 +02:00
crazy a44daf20cb finit.c: set _PATH_STDPATH much earlier
This should allow us to run 'prog' without
     absolute paths.  Eg:

     run("/bin/foo"); -> run("foo");

     However we still need absolute PATH for
     checking since fexist() need full path right now.

Signed-off-by: crazy <crazy@frugalware.org>
2017-03-28 13:21:18 +02:00
crazy 67435d2034 finit.h: added fallback for _PATH_{STDPATH,VARRUN} in case is not defined
That should never be needed , however I saw
  already systems with broken paths.h so better
  have something around in case something breaks.

Signed-off-by: crazy <crazy@frugalware.org>
2017-03-28 13:21:14 +02:00
Joachim Nilsson cd5348dffd Add a set of contributing guidelines
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-03-21 07:58:57 +01:00
Joachim Nilsson 6e4b698fac Add Code of Conduct document
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-03-21 07:49:19 +01:00
Joachim Nilsson c135a83cb3 Check if /proc/bus/usb exists before trying to mount it
Most newer kernels have usbfs disabled by default.
See issue #69 for details.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-03-20 20:41:09 +01:00
Joachim Nilsson 37d391d53a doc/build.md: Remove mention of --enable-embedded configure option
As suggested in GitHub issue #68.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-03-17 16:55:02 +01:00
Joachim Nilsson d335c9833c It is difficult to write readable technical text.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-03-08 16:25:14 +01:00
Joachim Nilsson ab7df43ccb Clarify link target a bit
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-03-08 16:17:05 +01:00
Joachim Nilsson ead92b3a27 Fix Markdown link
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-03-08 16:15:52 +01:00
Joachim Nilsson 647a79ffbd README: Add explanation of service early and link to doc/config.md
Also, update the service help text in doc/config.md to include info on
both runlevels and explain the condition in the listed example.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-03-08 16:09:40 +01:00
Joachim Nilsson 47793dcdf2 sm.c: Add missing header
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-03-08 08:26:13 +01:00
Joachim Nilsson 9df0454b64 initctl: Support for utmp show FILE
This patch adds support for showing a log rotated (uncompressed)
UTMP/WTMP file in initctl.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-02-10 11:44:57 +01:00
Joachim Nilsson 5ea1ac7582 Followup to #66: Gzip log files >= .2
This patch to the logrotate() function extends the log rotattion of a
file with a gzip of .2 and older log files.  If gzip is not available
in $PATH then @num files are left uncompressed.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-02-10 11:00:17 +01:00
Joachim Nilsson 9f7604848c initctl: Remove no longer neede source files from build
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-02-10 10:21:27 +01:00
Joachim Nilsson bbbaba7b47 Minor cleanup
initctl: Replace daemon-only API from user tool
utmp-api.c: Remove not needed header

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-02-10 10:20:29 +01:00
Joachim Nilsson d56031db7d svc.c: Replace daemon-only logging API with API from err.h
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-02-10 10:19:00 +01:00
Joachim Nilsson 0f64e18f27 Relocate utmp_show() to initctl.c
Only used by this tool, no need to keep it in the shared utmp-api.c

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-02-10 10:17:41 +01:00
Joachim Nilsson 958cab8cc7 Relocate runlevel_string() to initctl.c
Only used by this tool, no need to keep it in helpers.c

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-02-10 10:11:52 +01:00
Joachim Nilsson 9974d65756 Fix #66: Rotate /var/log/wtmp log max:2, size:100k
This patch adds a simple log-rotate function to the UTMP, WTMP, BTMP,
and lastlog files.  Enabled by default, disable with:

    configure --disable-logrotate

Even though it can rotate /run/utmp it is unlikely this file will grow
that much during a system's uptime.

The hard-coded defaults are to keep up to two (2) previous versions
of the files and rotate on file size >= 100k.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-25 19:40:06 +01:00
Joachim Nilsson a0e17c8f47 Relocate create() from bootmisc plugin to helpers.h
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-25 19:40:06 +01:00
Joachim Nilsson f76268dec9 initctl: Fix build warnings after de4bf53
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-24 09:15:30 +01:00
Joachim Nilsson 8d74a12628 Fix #64: Skip fsck of already mounted devices
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-24 08:03:53 +01:00
Joachim Nilsson 33ae64495a finit.c: Mount /proc and /sys before fsck()
For issue #64 we need to have /proc/mounts, or /etc/mtab but that's
usually symlinked to /proc/mounts.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-24 07:57:19 +01:00
Joachim Nilsson 750712d28d Merge pull request #63 from mattiaswal/add-cond-dump
initctl: Add 'initctl cond dump' to show all conditions in the system
2017-01-18 19:06:48 +01:00
Mattias Walström de4bf53536 initctl: Add 'initctl cond dump' to show all conditions in the system
Remove verbose of initctl cond, and replace it with 'initctl cond dump'
Show all conditions if they are in flux/on even if there are no other
services depending on this condition.

Signed-off-by: Mattias Walström <lazzer@gmail.com>
2017-01-18 16:15:52 +01:00
Joachim Nilsson 205db919f5 Move service script: $PREFIX/bin --> $PREFIX/sbin
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-16 07:43:24 +01:00
Joachim Nilsson 9b5d12bf22 Install service script wrapper in $PREFIX/bin
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-16 07:37:55 +01:00
Joachim Nilsson 3b53dfcaed configure: Simplify description
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-16 07:37:34 +01:00
Joachim Nilsson 1d39decaf1 Update .gitignore files
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-16 07:32:09 +01:00
Joachim Nilsson 8129ea32aa Remnant of GIT submodule era
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-16 07:25:03 +01:00
Joachim Nilsson 2bf024d3c3 Remnant of the old build system
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-16 07:23:44 +01:00
Joachim Nilsson 19d89d627b Add src/.gitignore
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-16 01:35:06 +01:00
Joachim Nilsson fff68b7b06 Relocate source files to an src/ subdirectory
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-16 01:31:02 +01:00
Joachim Nilsson 044ded3045 Fix #61: Reassert net/* conditions after initctl reload
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-16 01:09:06 +01:00
Joachim Nilsson 0cccc629bf pidfile: Ensure svc is always followed by a slash
A service need no longer be fully qualified path.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-16 01:02:40 +01:00
Joachim Nilsson 57181264e9 pidfile: Make sure to set a default name for plugin
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-16 01:02:16 +01:00
Joachim Nilsson 0b5888ed22 cond.c: Use utimensat() instead of utime() for nanosecond precision
We have repeatedly seen use-cases when sub-second resolution for
updatating the mtime of files have been needed.  Yes, all those
cases have been Autobots.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-16 01:00:10 +01:00
Joachim Nilsson 4321038518 bootmisc: Minor refactor
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-16 00:59:32 +01:00
Joachim Nilsson b84e32a6fe Add initctl log [SVC] command
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-15 23:21:19 +01:00
Joachim Nilsson 21a293beae Fix #60: initctl start/stop/restart ignores non-existing services
This patch improves the error handling of initctl so that it returns
non-zero if a service does not exist.

    $ initctl <start|stop|restart> SVC
    $ echo $?
    1

In verbose mode an error message is also returned:

    $ initctl -v <start|stop|restart> SVC
    No such service SVC
    $ echo $?
    1

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-15 23:15:10 +01:00
Joachim Nilsson 47b4850aa8 api.c: Factor out SVC|JOB:ID string parser
This patch breaks out the JOB:ID parser from api.c, placing it in a new
function called svc_parse_jobstr().

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-15 23:12:53 +01:00
Joachim Nilsson 1999956d91 fixup! API: Show debug level in log after initctl debug
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-15 23:07:27 +01:00
Joachim Nilsson 698f736b65 Relocate and export sanitize() function
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-15 23:06:45 +01:00
Joachim Nilsson 618744cc52 fixup! Fix compiler warnings after do_sleep() relocation
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-15 23:05:06 +01:00
Joachim Nilsson 67125fedab API: Show debug level in log after initctl debug
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-15 21:16:31 +01:00
Joachim Nilsson f7cd46abc9 API: Check input argument
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-15 21:15:58 +01:00
Joachim Nilsson 9f62153966 Whitespace: reindent and relocate function declaration(s)
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-15 20:53:13 +01:00
Joachim Nilsson 978771a3fb Fix compiler warnings after do_sleep() relocation
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-15 20:19:44 +01:00
Joachim Nilsson adc340e4c3 reboot: Use do_sleep() instead of sleep() to prevent wakeups due to SIGTERM
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-13 07:56:48 +01:00
Joachim Nilsson 50668161ad Move do_sleep() from helper.c --> util.c
This move makes it possible to share the code between the Finit daemon
and its client tools.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-13 07:55:44 +01:00
Joachim Nilsson 6507136bdd reboot: Mention why CMD_SUSPEND is not managed in regular flow
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-13 07:54:48 +01:00
Joachim Nilsson 5cdbd57875 reboot: Ignore SIGTERM at halt/poweroff
We want to emulate the behavior of the reboot() syscall on success.
Primarily for a coherency/symmetry, but also to prevent printing
a new shell prompt in the middle of system shutdown messages.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-13 07:48:00 +01:00
Joachim Nilsson 1550c34d65 reboot: Simplify applet transformation.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-13 07:47:29 +01:00
Joachim Nilsson ec6e3bc9e7 TODO: Minor update/clarification
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-11 17:45:13 +01:00
Joachim Nilsson d5942f3267 Minor whitespace fixes
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-11 17:40:10 +01:00
Joachim Nilsson e272710e36 Merge pull request #62 from mattiaswal/fix-fluxstate
Fix fluxstate
2017-01-11 17:21:27 +01:00
Mattias Walström a95df9d64b svc: The timestamp should have subsecond resolution
When finit completes quicker than one second it will
not find if any configurations has been changed.

Signed-off-by: Mattias Walström <mattias.walstrom@westermo.se>
2017-01-11 16:28:03 +01:00
Mattias Walström 816aa9a17c pidfile: Run the reconf-callback again until no application are in flux
If a service depend on the service last in the list the application
will be kept in flux state forever.

Signed-off-by: Mattias Walström <mattias.walstrom@westermo.se>
2017-01-11 16:25:04 +01:00
Joachim Nilsson f95cd38ddb Refactor #ifndef INETD_DISABLED --> #ifdef INETD_ENABLED
This patch changes the confusing logic in all #ifndef INETD_DISABLED
statements to instead be #ifdef INETD_ENABLED, which is quite a bit
more readable.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-12-30 13:34:31 +01:00
Joachim Nilsson d9de2717a2 Merge pull request #59 from reverendhomer/master
run: fix array overflow
2016-12-30 11:40:11 +01:00
Reverend Homer 11d5019103 run: fix array overflow 2016-12-29 14:31:28 +03:00
Joachim Nilsson 0946dbb287 Merge pull request #58 from reverendhomer/master
Another typo fix :)
2016-12-29 10:52:00 +01:00
Reverend Homer cfcdedd508 doc: fix typo in signals.md 2016-12-29 12:43:01 +03:00
Joachim Nilsson 3fac6ed6af Merge pull request #57 from reverendhomer/master
fix typo in config.md
2016-12-26 20:13:42 +01:00
Reverend Homer ef7497094c doc: fix typo 2016-12-26 20:44:08 +03:00
Joachim Nilsson de05070ccc tty: Debug messages when TTY is not started
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-12-25 10:35:51 +01:00
Joachim Nilsson f68daf1b14 Update ChangeLog with -rc2 fixes
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-12-24 09:43:09 +01:00
Joachim Nilsson 88039f3d65 Fix #56: Check TTY before trying to start getty
This (initial) patch for issue #56 adds a very basic validation of the
device before attempting to start a getty on it.

TODO: Verify a USB/serial device can be plugged in at any point at
      runtime, either automatically start getty or by `initctl reload`

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-12-23 23:11:53 +01:00
Joachim Nilsson 2c0421f2e6 Fix #54: Allow halt and poweroff despite --enable-watchdog
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-12-13 20:36:34 +01:00
Joachim Nilsson a672988e35 Merge branch 'fix-mpc85xx-getty-regression'
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-12-12 22:30:08 +01:00
Mattias Walström 74f3a3f5c8 Actually disable modem specific flags
Signed-off-by: Mattias Walström <lazzer@gmail.com>
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-12-12 22:29:02 +01:00
Joachim Nilsson f335e74cb8 Add missing #include <signal.h>, non GLIBC targets
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-12-09 07:29:45 +01:00
168 changed files with 6576 additions and 4071 deletions
+16 -16
View File
@@ -2,34 +2,34 @@
*.o
*.so
*.gz
*.map
configure
Makefile
Makefile.in
/.deps/*
/.libs/*
/finit
/initctl
/reboot
/config.h
/config.mk
/GPATH
/GRTAGS
/GSYMS
/GTAGS
GPATH
GRTAGS
GSYMS
GTAGS
# GNU configure and build system
/autom4te.cache/*
/aclocal.m4
/ar-lib
/compile
/config.h
/config.mk
/config.guess
/config.h.in
/config.log
/config.status
/config.sub
/configure
/depcomp
/install-sh
/libtool
/ltmain.sh
/missing
/Makefile
/Makefile.in
/stamp-h1
# TroglOS build system
/.config
/.stamp
/.unpacked
+6 -6
View File
@@ -33,12 +33,12 @@ addons:
branch_pattern: dev
install:
- wget https://github.com/troglobit/libuev/releases/download/v1.5.2/libuev-1.5.2.tar.xz
- wget https://github.com/troglobit/libite/releases/download/v1.8.2/libite-1.8.2.tar.xz
- tar xf libuev-1.5.2.tar.xz
- tar xf libite-1.8.2.tar.xz
- (cd libuev-1.5.2 && ./configure --prefix=/tmp && make && make install-strip)
- (cd libite-1.8.2 && ./configure --prefix=/tmp && make && make install-strip)
- wget https://github.com/troglobit/libuev/releases/download/v2.1.0/libuev-2.1.0.tar.xz
- wget https://github.com/troglobit/libite/releases/download/v2.0.1/libite-2.0.1.tar.xz
- tar xf libuev-2.1.0.tar.xz
- tar xf libite-2.0.1.tar.xz
- (cd libuev-2.1.0 && ./configure --prefix=/tmp && make && make install-strip)
- (cd libite-2.0.1 && ./configure --prefix=/tmp && make && make install-strip)
# Custom build script for the time being, no "make test" yet
script:
+161 -7
View File
@@ -3,14 +3,136 @@ Change Log
All relevant changes are documented in this file.
[3.0][UNRELEASED] - 2016-XX-YY
------------------------------
[3.1][] - 2017-12-xx
--------------------
Finit v3.1 require libuEv v2.1.0, or later, and libite v2.0.1, or later.
### Changes
* Support for `rlimit` per service/run/task/inetd/tty, issue #45
* Support for auto-detecting serial console using Linux SysFS, the new
`tty @console` eliminates the need to keep track of different console
devices across embedded platforms: `/dev/ttyS0`, `/dev/ttyAMA0`, etc.
* Support for calling run/tasks on Finit internal HOOK points, issue #18
* Removed support for long-since deprecated `console DEV` setting
* Cosmetic change to login, pressing enter at the `Press enter to ...`
prompt will now replace that line with the login issue text
* Calling `initctl` without any arguments or options now defaults to
show status of all enabled services, and run/task/inetd jobs
* Cosmetic change to boot messages, removed `Loading plugins ...`, start
of inetd services, and `Loading configuration ...`. No end user knows
what those plugins and configurations are, i.e. internal state+config
* Change kernel WDT timeout (3 --> 30 sec) for built-in watchdog daemon
* Handle `/etc/` OverlayFS, reload /etc/finit.d/*.conf after `mount -a`
* initctl: Add support for printing previous runlevel
* initctl: Support short forms of all commands
* initctl: Support for `initctl touch <CONF>` to be used with `reload`
* initctl: Improved output of `initctl show <SVC>`
* Support reloading `/etc/finit.conf`. The main finit.conf file
previously did not support reloading at runtime, as of v3.1 all
configuration directives supported in `/etc/finit.d/*.conf` are now
supported in `/etc/finit.conf`
* Change `.conf` dependency + reload handling. Finit no longer relies
on mtime of `.conf` files, instead an inotify handler tracks file
changes for time *insensitive* dependency tracking
* Change condition handling to not rely on mtime but a generation id.
### Fixes
* Reset TTY before restarting it. A program may manipulate the TTY in
various ways before the user logs out, Finit needs to reset the TTY to
a sane state before restarting it. Issue #84
* On .conf parse errors, do *not* default to set TTY speed 38400, reuse
current TTY speed instead
* Fix run/tasks, must be guaranteed to run once per declared runlevel.
All run/tasks on `[S]` with a condition `<...>` failed to run. Finit
now tracks run/tasks more carefully, waiting for them to finish before
switching to the configured runlevel at boot. Issue #86
* Allow inetd services to be registered with a unique ID, e.g. `:161`,
issue #87. Found by Westermo
* inetd: drop UDP packets from blocked interfaces, issue #88
* Handle obscure inter-plugin dependency issue by calling the netlink
plugin before the pidfile plugin on `HOOK_SVC_RECONF` events
* Handle event loop failure modes, issue found by Westermo
* Handle API socket errors more gracefully, restart socket
* Fix regression in condition handling, reconf condition must be kept
as a reference point to previous reconfiguration, or bootstrap.
* Fix nasty race condition with internal service stop, abort kill if the
service has already terminated, otherwise we may do `kill(0, SIGKILL)`
* Fix reconfiguration issue with (very quick) systems that don't have
highres timers
* Fix formatting of runlevel string in `initctl show`
* Allow running `initctl` with `STDOUT` redirected
* Fix regression in `initctl start/stop <ID>`, using name worked not id
* Fix error handling in `initctl start/stop` without any argument
* Fix issue #81 properly, remove use of SYSV shm IPC completely. Finit
now use the API socket for all communication between PID 1 and initctl
* Fix segfault on x86_64 when started with kernel cmdline `--debug`
[3.0][] - 2017-10-19
--------------------
Major release, support for conditions/dependencies between services,
optional built-in watchdog daemon, optional built-in getty, optional
built-in standard inetd services like echo server, rdate, etc.
Also, native support for Debian/BusyBox `/etc/network/interfaces`,
overhauled new configure based build system, logging to `/dev/kmsg`
before syslogd has started, massively improved support for Linux
distributions.
### Changes
* Added basic code of conduct covenant to project
* Added contribution guidelines document
* Removed `finit.conf` option `check DEV`, replaced entirely by automated
call to `fsck` for each device listed in `/etc/fstab`
* Removed deprecated and confusing `startx` and `user` settings. It is
strongly recommended to instead use xdm/gdb/lightdm etc.
* Add support for `initctl log <SVC>`, shows last 10 lines from syslog
* Add `initctl cond dump` for debugging conditions
* Ensure plugins always have a default name, file name
* Reorganization, move all source files to a `src/` sub-directory
* Add support for `initctl <list|enable|disable> <SVC>`, much needed by
distributions. See [doc/distro.md](doc/distro.md) for details
* Remove `UNUSED()` macro, mentioned here because it may have been used
by external plugin developers. Set `-Wno-unused-parameter` instead
* New table headings in `initctl`, using `top` style inverted text
* Allow `initctl show` to use full screen width for service descriptions
* New `HOOK_BANNER` for plugins to override the default `banner()`
* Allow loading TTYs from `/etc/finit.d`
* Improvements to built-in getty, ignore signals like `SIGINT`,
`SIGHUP`, support Ctrl-U to erase to beginning of line
* Add TTY `nowait` and `noclear` options
* Allow using both built-in getty and external getty:
tty [12345] /dev/ttyAMA0 115200 noclear vt220
tty [12345] /sbin/getty -L 115200 /dev/ttyAMA0 vt100
tty [12345] /sbin/agetty -L ttyAMA0 115200 vt100 nowait
* Silent boot is now the default, use `--enable-progress` to get the old
Finit style process progress. I.e., `--enable-silent` is no more
* Support for `configure --enable-emergency-shell`, debug-only mode
* Support for a fallback shell on console if none of the configured TTYs
can be started, `configure --enable-fallback-shell`
* All debug messages to console when Finit `--debug` is enabled
* Prevent login, by touching `/etc/nologin`, during runlevel changes
* A more orderly shutdown. On reboot/halt/poweroff Finit now properly
goes to runlevel 0/6 to first stop all processes.
* Perform sync before remounting as read-only, at shutdown
* Clean up `/tmp`, `/var/run`, and `/var/lock` at boot on systems which
have these directories on persistent storage
* Call udev triggers at boot, on systems with udev
* Add missing `/var/lock/subsys` directory for dbus
* Add support for `poweroff`
* Add support for a built-in miniature watchdog daemon
* Remove GLIBC:isms like `__progname`
* Manage service states based on user defined conditions
* Manage dependencies between services, w/ conditions (pidfile plugin)
* Manage service dependenceis on network events (netlink plugin)
* Manage service dependencies on network events (netlink plugin)
* Support for dynamically reloading Finit configuration at runtime
* Refactor to use GNU configure and build system
* New hooks for for detecting lost and started services (lost plugin)
@@ -22,8 +144,7 @@ All relevant changes are documented in this file.
* Add simple built-in getty
* Greatly improved accounting support, both UTMP and WTMP fixes+features
* Improved udev support, on non-embedded systems
* Improvide shutdown and file-system unmount support (Debian)
* Added `--enable-emergency-shell` (configure) fallback debug mode
* Improved shutdown and file-system unmount support (Debian)
* Support SysV init `/etc/rc.local`
* Inetd protection against UDP looping attacks
* Support systems with `/run` instead of `/var/run` (bootmisc plugin)
@@ -33,7 +154,39 @@ All relevant changes are documented in this file.
* Add OpenRC-like support for sysctl.d/*.conf
* Add support for Debian/BusyBox `/etc/network/interfaces`
* Add support for running fsck on file systems in `/etc/fstab`
* Added example configs + HowTos for Debian (Jessie) and Alpine Linux
* Added example configs + HowTos for Debian and Alpine Linux
to support latest releases of both distributions
* Lots of documentation updates
### Fixes
* Fix race-condition at configuration reload due to too low resolution.
Thanks to Mattias Walström, Westermo
* Fix to handle long process (PID) dependency chains, re-run reconf
callback until no more applications are in flux.
Thanks to Mattias Walström, Westermo
* Clear `reconf` condition when `initctl reload` has finished
* Skip automatic reload of `/etc/finit.d/*.conf` files when changing
runlevel to halt or reboot
* Fix issue #54: Allow halt and poweroff commands even if watchdog is enabled
* Fix issue #56: Check existence of device before trying to start getty
* Fix issue #60: `initctl` should display error and return error code
for non-existing services should the operator try to start/stop them.
* Fix issue #61: Reassert `net/*` conditions after `initctl reload`
* Fix issue #64: Skip `fsck` on already mounted devices
* Fix issue #66: Log rotate and gzip `/var/log/wtmp`, created by Finit
* Fix issue #72: Check `ifup` exists before trying to bring up networking,
also set `$PATH` earlier to simplify `run()` et al -- no longer any need
to use absolute paths for system tools called from Finit. Thanks to crazy
* Fix issue #73: Remove double `ntohl()` in inetd handling, prevents matches.
Thanks to Petrus Hellgren, Westermo
* Fix issue #76: Reap zombie processes in emergency shell mode
* Fix issue #80: FTBFS on Arch Linux, missing `stdarg.h` in `helpers.h`,
thanks to Jörg Krause
* Fix issue #81: Workaround for systems w/o SYSV shm IPC support in kernel
* Always collect bootstrap-only tasks when done, we will never re-run them.
Also, make sure to never reload bootstrap-only tasks at runtime
* Remove two second block (!) of Finit when stopping TTYs
[2.4][] - 2015-12-04
@@ -514,7 +667,8 @@ Major bug fix release.
* Initial release
[UNRELEASED]: https://github.com/troglobit/finit/compare/2.4...HEAD
[UNRELEASED]: https://github.com/troglobit/finit/compare/3.0...HEAD
[3.0]: https://github.com/troglobit/finit/compare/2.4...3.0
[2.4]: https://github.com/troglobit/finit/compare/2.3...2.4
[2.3]: https://github.com/troglobit/finit/compare/2.2...2.3
[2.2]: https://github.com/troglobit/finit/compare/2.1...2.2
+5 -99
View File
@@ -1,105 +1,11 @@
ACLOCAL_AMFLAGS = -I m4
sbin_PROGRAMS = finit initctl reboot
finit_SOURCES = api.c \
cond.c cond-w.c cond.h \
client.c \
conf.c conf.h \
exec.c finit.c finit.h \
getty.c \
helpers.c helpers.h \
mdadm.c mount.c pid.c \
plugin.c plugin.h private.h \
service.c service.h \
sig.c sig.h \
sm.c sm.h \
svc.c svc.h \
tty.c tty.h \
util.c util.h \
utmp-api.c utmp-api.h
pkginclude_HEADERS = cond.h finit.h helpers.h inetd.h plugin.h svc.h
if INETD
finit_SOURCES += inetd.c inetd.h
endif
if WATCHDOGD
finit_SOURCES += watchdog.c watchdog.h
endif
finit_CFLAGS = -W -Wall -Wextra -std=gnu99 $(lite_CFLAGS) $(uev_CFLAGS)
finit_LDADD = $(lite_LIBS) $(uev_LIBS)
if STATIC
finit_LDADD += plugins/libplug.la
else
finit_LDADD += -ldl
endif
initctl_SOURCES = initctl.c svc.c svc.h helpers.c helpers.h cond.c cond.h \
util.c util.h utmp-api.c utmp-api.h
initctl_CFLAGS = $(lite_CFLAGS)
initctl_LDADD = $(lite_LIBS)
reboot_SOURCES = reboot.c util.c util.h
INIT_LNKS = telinit init
REBOOT_LNKS = shutdown halt poweroff suspend
SUBDIRS = plugins
doc_DATA = README.md LICENSE finit.conf
EXTRA_DIST = README.md LICENSE ChangeLog.md finit.conf
AM_CPPFLAGS = -U_FORTIFY_SOURCE
AM_CPPFLAGS += -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE
if STATIC
AM_CPPFLAGS += -DENABLE_STATIC
AM_LDFLAGS = -static-libtool-libs
else
AM_CPPFLAGS += -DPLUGIN_PATH=\"$(pkglibdir)\"
AM_LDFLAGS = -export-dynamic
endif
SUBDIRS = plugins src
doc_DATA = README.md LICENSE contrib/finit.conf
EXTRA_DIST = README.md LICENSE ChangeLog.md contrib/finit.conf
# Compat hook
install-dev: install-pkgincludeHEADERS
# Hook in install to add finit and reboot symlink(s)
install-exec-hook:
@for file in $(INIT_LNKS); do \
lnk=$(DESTDIR)$(sbindir)/$$file; \
if [ -e $$lnk ]; then \
echo "Skipping $$lnk exists already."; \
else \
$(LN_S) finit $$lnk; \
fi; \
done
@if [ -L $(DESTDIR)$(sbindir)/reboot ]; then \
echo "Non-finit reboot, skipping install."; \
else \
for file in $(REBOOT_LNKS); do \
link=$(DESTDIR)$(sbindir)/$$file; \
if [ -e $$link ]; then \
echo "$$link exists, skipping.";\
else \
$(LN_S) reboot $$link; \
fi; \
done; \
fi
uninstall-hook:
@for file in $(INIT_LNKS); do \
lnk=`readlink $(DESTDIR)$(sbindir)/$$file`; \
if [ "$$lnk" != "finit" ]; then \
echo "Skipping non-finit $$file."; \
continue; \
fi; \
$(RM) $(DESTDIR)$(sbindir)/$$file; \
done
@if [ -L $(DESTDIR)$(sbindir)/reboot ]; then \
echo "Non-finit reboot, skipping uninstall."; \
else \
for file in $(REBOOT_LNKS); do \
if [ "`readlink $$file`" != "reboot" ]; \
then continue; \
fi; \
$(RM) $(DESTDIR)$(sbindir)/$$file; \
done; \
fi
install-dev:
@make -C src install-pkgincludeHEADERS
# Target to run when building a release
release: dist
+256 -195
View File
@@ -1,99 +1,145 @@
<p align="center"><img src="images/finit3.png" alt="Finit: Fast Init" /></p>
Table of Contents
-----------------
[![Travis Status]][Travis] [![Coverity Status]][Coverity Scan]
<img align="right" src="images/finit3.png" alt="Finit: Fast Init">
* [Introduction](#introduction)
* [Features](#features)
* [/etc/finit.conf](doc/config.md#etcfinitconf)
* [/etc/finit.d](doc/config.md#etcfinitd)
* [Runparts & /etc/rc.local](#runparts--etcrclocal)
* [Bootstrap](doc/bootstrap.md#bootstrap)
* [Runlevels](#runlevels)
* [Inetd](doc/inetd.md#inetd)
* [Hooks, Callbacks & Plugins](doc/plugins.md#hooks-callbacks--plugins)
* [Syntax](doc/config.md#syntax)
* [Inetd](doc/inetd.md#inetd)
* [Runparts & /etc/rc.local](#runparts--etcrclocal)
* [Hooks, Callbacks & Plugins](doc/plugins.md#hooks-callbacks--plugins)
* [Rebooting & Halting](#rebooting--halting)
* [Commands & Status](#commands--status)
* [Building](doc/build.md#building)
* [Running](doc/build.md#running)
* [Debugging](doc/build.md#debugging)
* [Requirements](#requirements)
* [Running](#running)
* [Debugging](#debugging)
* [Origin & References](#origin--references)
Introduction
------------
[![License Badge][]][License] [![Travis Status]][Travis] [![Coverity Status]][Coverity Scan]
Finit is an EeePC Fastinit inspired clone with [process supervision][1]
similar to that of D.J. Bernstein's [daemontools][2] and Gerrit Pape's
[runit][3]. It also supports free-form conditions based on events, e.g.
triggering on PID file creation, Netlink events like a default route or
interfaces coming up, or even custom events. Similar to [systemd][6].
Finit is a simple alternative to [SysV init][4] and [systemd][6]. It
was reverse engineered from the [EeePC fastinit][] ten years ago by
[Claudio Matsuoka][] — "gaps filled with frog DNA …"
Finit focuses on small and embedded Linux systems, although fully usable
on servers and desktops as well. See the [contrib section](contrib/)
for Debian and Alpine Linux examples.
Focus is on small and embedded systems, although Finit is fully usable
on server and desktop systems as well. For working examples, see the
[contrib/](contrib/) section where both [Debian](contrib/debian/) and
up to date [Alpine Linux](contrib/alpine/) tutorials can be found.
Traditional [SysV init][4] style systems are scripted. For low-resource
embedded systems this is quite resource intensive and often leads to
long boot times. Finit reduces context switches and forking of shell
scripts to provide a swift [system bootstrap](doc/bootstrap.md) written
entirely in C.
![Alpine screenshot](images/alpine-screenshot.png)
The screenshot shows [Alpine Linux](https://www.alpinelinux.org/).
Configuration is read from [/etc/finit.conf](doc/config.md#etcfinitconf)
which details kernel modules to load, services and TTYs to start. When
initial [bootstrap](doc/bootstrap.md) is done, including setting up
networking, [/etc/finit.d/](doc/config.md#etcfinitd) and the familiar
[/etc/rc.local](#runparts--etcrclocal) are run.
**Example /etc/finit.conf:**
Example
-------
```
# Fallback if /etc/hostname is missing
host wopr
# Runlevel to start after bootstrap, runlevel 'S'
runlevel 2
# Services to be monitored and respawned as needed
service [S12345] /sbin/watchdogd -L -f -- System watchdog daemon
service [S12345] /sbin/syslogd -n -b 3 -D -- System log daemon
service [S12345] /sbin/klogd -n -- Kernel log daemon
service [2345] /sbin/lldpd -d -c -M1 -H0 -i -- LLDP daemon (IEEE 802.1ab)
# For multiple instances of the same service, add :ID somewhere between
# the service/run/task keyword and the command.
service :1 [2345] /sbin/merecat -n -p 80 /var/www -- Web server
service :2 [2345] /sbin/merecat -n -p 8080 /var/www -- Old web server
This example `/etc/finit.conf` can also be split up in multiple `.conf`
files in `/etc/finit.d`. Available, but not yet enabled, services can
be placed in `/etc/finit.d/available` and enabled by an operator using
the [initctl](#commands--status) tool.
# Alternative method instead of below runparts, can also use /etc/rc.local
#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
```ApacheConf
# Fallback if /etc/hostname is missing
host default
# Inetd services to start on demand, with alternate ports and filtering
inetd ftp/tcp nowait [2345] /sbin/uftpd -i -f -- FTP daemon
inetd tftp/udp wait [2345] /sbin/uftpd -i -y -- TFTP daemon
inetd time/udp wait [2345] internal -- UNIX rdate service
inetd time/tcp nowait [2345] internal -- UNIX rdate service
inetd 3737/tcp nowait [2345] internal.time -- UNIX rdate service
inetd telnet/tcp nowait [2345] /sbin/telnetd -i -F -- Telnet daemon
inetd 2323/tcp nowait [2345] /sbin/telnetd -i -F -- Telnet daemon
inetd 222/tcp@eth0 nowait [2345] /sbin/dropbear -i -R -F -- SSH service
inetd ssh/tcp@*,!eth0 nowait [2345] /sbin/dropbear -i -R -F -- SSH service
# Run start scripts from this directory
# runparts /etc/start.d
# Virtual consoles to start built-in getty on
tty [12345] /dev/tty1 115200 linux
tty [12345] /dev/ttyAMA0 115200 vt100
# Runlevel to start after bootstrap, 'S', default: 2
runlevel 2
# Services to be monitored and respawned as needed
service [S12345] /sbin/watchdogd -L -f -- System watchdog daemon
service [S12345] /sbin/syslogd -n -b 3 -D -- System log daemon
service [S12345] /sbin/klogd -n -- Kernel log daemon
service [2345] /sbin/lldpd -d -c -M1 -H0 -i -- LLDP daemon (IEEE 802.1ab)
# For multiple instances of the same service, add :ID somewhere between
# the service/run/task keyword and the command.
service :1 [2345] /sbin/merecat -n -p 80 /var/www -- Web server
service :2 [2345] /sbin/merecat -n -p 8080 /var/www -- Old web server
# Alternative method instead of below runparts, can also use /etc/rc.local
#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
# Inetd services to start on demand, with alternate ports and filtering
inetd ftp/tcp nowait [2345] /sbin/in.ftpd -- FTP daemon
inetd tftp/udp wait [2345] /sbin/in.tftpd -- TFTP daemon
inetd time/udp wait [2345] internal -- UNIX rdate service
inetd time/tcp nowait [2345] internal -- UNIX rdate service
inetd 3737/tcp nowait [2345] internal.time -- UNIX rdate service
inetd telnet/tcp nowait [2345] /sbin/telnetd -i -F -- Telnet daemon
inetd 2323/tcp nowait [2345] /sbin/telnetd -i -F -- Telnet daemon
inetd 222/tcp@eth0 nowait [2345] /sbin/dropbear -i -R -F -- SSH service
inetd ssh/tcp@*,!eth0 nowait [2345] /sbin/dropbear -i -R -F -- SSH service
# Run start scripts from this directory
# runparts /etc/start.d
# Virtual consoles run BusyBox getty
tty [12345] /sbin/getty -L 115200 /dev/tty1 linux
tty [12345] /sbin/getty -L 115200 /dev/tty2 linux
tty [12345] /sbin/getty -L 115200 /dev/tty3 linux
# Use built-in getty for serial port and USB serial
tty [12345] /dev/ttyAMA0 115200 noclear nowait
tty [12345] /dev/ttyUSB0 115200 noclear
```
For an example of a full blown embedded Linux, see [TroglOS][9], or take
a look at the `contrib/` section with [Alpine Linux](contrib/alpine/),
[Debian](contrib/debian/), support and more.
The `service` stanza, as well as `task`, `run`, `inetd` and others are
described in full in [doc/config.md](doc/config.md). Here's a quick
overview of some of the most common components needed to start a UNIX
daemon:
```
service [LVLS] <COND> /path/to/daemon ARGS -- Some text
^ ^ ^ ^ ^ ^
| | | | | `-- Optional description
| | | | `---------- Daemon arguments
| | | `-------------------------- Path to daemon
| | `--------------------------------- Optional conditions
| `---------------------------------------- Optional Runlevels
`------------------------------------------------ Monitored application
```
Some components are optional: runlevel(s), condition(s) and description,
making it easy to create simple start scripts and still possible for more
advanced uses as well:
service /usr/sbin/sshd -D
Dependencies are handled using [conditions](doc/conditions.md). One of
the most common conditions is to wait for basic networking to become
available:
service <net/route/default> /usr/sbin/nginx -- High performace HTTP server
Here is another example where we instruct Finit to not start BusyBox
`ntpd` until `syslogd` has started properly. Finit waits for `syslogd`
to create its PID file, by default `/var/run/syslogd.pid`.
service [2345] log <svc/sbin/syslogd> /usr/sbin/ntpd -n -N -p pool.ntp.org
service [S12345] /sbin/syslogd -n -- Syslog daemon
Notice the `log` keyword, BusyBox `ntpd` uses `stderr` for logging when
run in the foreground. With `log` Finit redirects `stdout` + `stderr`
to the system log daemon using the command line `logger(1)` tool.
A service, or task, can have multiple dependencies listed. Here we wait
for *both* `syslogd` to have started and basic networking to be up:
service [2345] log <svc/sbin/syslogd,net/route/default> /usr/sbin/ntpd -n -N -p pool.ntp.org
If either condition fails, e.g. loss of networking, `ntpd` is stopped
and as soon as it comes back up again `ntpd` is restarted automatically.
**Note:** Make sure daemons *do not* fork and detach themselves from the
controlling TTY, usually an `-n` or `-f` flag, or `-D` as in the case
of OpenSSH above. If it detaches itself, Finit cannot monitor it and
will instead try to restart it.
Features
@@ -103,6 +149,7 @@ Features
Start, monitor and restart services should they fail.
**Inetd**
Finit comes with a built-in [inetd server](doc/inetd.md). No need to
@@ -114,23 +161,39 @@ interface, reducing the need for a full blown firewall.
Built-in optional inetd services:
- echo RFC862
- chargen RFC864
- daytime RFC867
- discard RFC863
- time (rdate) RFC868
- echo [RFC862][]
- chargen [RFC864][]
- daytime [RFC867][]
- discard [RFC863][]
- time (rdate) [RFC868][]
For more information, see [doc/inetd.md](doc/inetd.md).
**Getty**
Finit also comes with a built-in Getty for Linux console TTYs. It can
parse `/etc/inittab` and set the speed. Then `/bin/login` handles all
nasty bits with PAM etc.
Finit supports external getty but also comes with a limited built-in
Getty, useful for really small systems. A getty sets up the TTY and
waits for user input before handing over to `/bin/login`, which is
responsible for handling the actual authentication.
```conf
tty [12345] /dev/tty1 38400 nowait linux
tty [12345] /dev/ttyAMA0 115200 noclear vt100
tty [12345] /sbin/getty -L 115200 /dev/ttyAMA0 vt100
```
Users of embedded systems may want to enable automatic serial console
with the special `@console` device. This works regardless weather the
system uses `ttyS0`, `ttyAMA0`, `ttyMXC0`, or anything else. Finit
figures it out by querying sysfs: `/sys/class/tty/console/active`.
```conf
tty [12345] @console 115200 linux noclear
```
For more information, see [doc/config.md](doc/config.md#syntax).
# /etc/finit.conf
tty [12345] /dev/tty1 38400 linux
tty [12345] /dev/ttyAMA0 115200 vt100
**Runlevels**
@@ -177,7 +240,7 @@ calls its built-in [run-parts(8)][] on the `runparts <DIR>` directory,
and `/etc/rc.local`, in that order if they exist.
```shell
runparts /etc/rc.d/
runparts /etc/rc.d/
```
No configuration stanza in `/etc/finit.conf` is required for `rc.local`.
@@ -205,16 +268,17 @@ To specify an allowed set of runlevels for a `service`, `run` command,
`task`, or `tty`, add `[NNN]` to your `/etc/finit.conf`, like this:
```
service [S12345] /sbin/syslogd -n -x -- System log daemon
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
service [S12345] /sbin/syslogd -n -x -- System log daemon
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 syslogd is first started, in parallel, and then acpid is
@@ -226,16 +290,27 @@ service.
Again, tasks and services are started in parallel, while run commands
are called in the order listed and subsequent commands are not started
until a run command has completed.
until a run command has completed. Also, task and run commands are run
in a shell, so pipes and redirects can be used.
The following examples illustrate this. Bootstrap task and run commands
are also removed when they have completed, `initctl show` will not list
them.
```
task [S] echo "foo" | cat >/tmp/bar
run [S] echo "$HOME" >/tmp/secret
```
Switching between runlevels can be done by calling init with a single
argument, e.g. <kbd>init 5</kbd> switches to runlevel 5. When changing
runlevels Finit also automatically reloads all `.conf` files in the
`/etc/finit.d/` directory. So if you want to set a new system config,
switch to runlevel 1, change all config files in the system, and touch
all `.conf` files in `/etc/finit.d` before switching back to the
previous runlevel again — that way Finit can both stop old services and
start any new ones for you, without rebooting the system.
argument, e.g. <kbd>init 5</kbd>, or using `initctl runlevel 5`, both
switch to runlevel 5. When changing runlevels Finit also automatically
reloads all `.conf` files in the `/etc/finit.d/` directory. So if you
want to set a new system config, switch to runlevel 1, change all config
files in the system, and touch all `.conf` files in `/etc/finit.d`
before switching back to the previous runlevel again — that way Finit
can both stop old services and start any new ones for you, without
rebooting the system.
Rebooting & Halting
@@ -256,21 +331,23 @@ Finit also listens to the classic SysV init FIFO, used by `telinit`.
Support for this is implemented by the `initctl.so` plugin. Hence,
`telinit q` will work as the UNIX beards intended.
~ # telinit -h
Usage: telinit [OPTIONS] [q | Q | 0-9]
Options:
-h, --help This help text
-V, --version Show Finit version
Commands:
0 Power-off the system, same as initctl poweroff
6 Reboot the system, same as initctl reboot
2, 3, 4, 5 Change runlevel. Starts services in new runlevel, stops any
services in prev. runlevel that are not allowed in new.
q, Q Reload *.conf in /etc/finit.d/, same as initctl reload or
sending SIGHUP to PID 1
1, s, S Enter system rescue mode, runlevel 1
```shell
~ # telinit -h
Usage: telinit [OPTIONS] [q | Q | 0-9]
Options:
-h, --help This help text
-V, --version Show Finit version
Commands:
0 Power-off the system, same as initctl poweroff
6 Reboot the system, same as initctl reboot
2, 3, 4, 5 Change runlevel. Starts services in new runlevel, stops any
services in prev. runlevel that are not allowed in new.
q, Q Reload *.conf in /etc/finit.d/, same as initctl reload or
sending SIGHUP to PID 1
1, s, S Enter system rescue mode, runlevel 1
```
Commands & Status
@@ -280,29 +357,42 @@ Finit also implements a more modern API to query status, and start/stop
services, called `initctl`. Unlike `telinit` the `initctl` tool does
not return until the given command has fully completed.
~ $ initctl -h
Usage: initctl [OPTIONS] <COMMAND>
Options:
-d, --debug Debug initctl (client)
-v, --verbose Verbose output
-h, --help This help text
Commands:
debug Toggle Finit (daemon) debug
help This help text
reload Reload *.conf in /etc/finit.d/ and activate changes
runlevel [0-9] Show or set runlevel: 0 halt, 6 reboot
status | show Show status of services
cond set <COND> Set (assert) condition => +COND
cond clear <COND> Clear (deassert) condition => -COND
cond flux <COND> Emulate flux condition => ~COND
cond show Show condition status
start <JOB|NAME>[:ID] Start service by job# or name, with optional ID
stop <JOB|NAME>[:ID] Stop/Pause a running service by job# or name
restart <JOB|NAME>[:ID] Restart (stop/start) service by job# or name
reload <JOB|NAME>[:ID] Reload (SIGHUP) service by job# or name
version Show Finit version
```shell
~ $ initctl -h
Usage: initctl [OPTIONS] [COMMAND]
Options:
-v, --verbose Verbose output
-h, --help This help text
Commands:
debug Toggle Finit (daemon) debug
help This help text
version Show Finit version
list List all .conf in /etc/finit.d/
enable <CONF> Enable .conf in /etc/finit.d/available/
disable <CONF> Disable .conf in /etc/finit.d/[enabled/]
reload Reload *.conf in /etc/finit.d/ (activates changes)
cond set <COND> Set (assert) condition => +COND
cond clear <COND> Clear (deassert) condition => -COND
cond show Show condition status
cond dump Dump all conditions and their status
log [NAME] Show ten last Finit, or NAME, messages from syslog
start <JOB|NAME>[:ID] Start service by job# or name, with optional ID
stop <JOB|NAME>[:ID] Stop/Pause a running service by job# or name
restart <JOB|NAME>[:ID] Restart (stop/start) service by job# or name
status | show Show status of services, default command
runlevel [0-9] Show or set runlevel: 0 halt, 6 reboot
reboot Reboot system
halt Halt system
poweroff Halt and power off system
utmp show Raw dump of UTMP/WTMP db
```
For services *not* supporting `SIGHUP` the `<!>` notation in the .conf
file must be used to tell Finit to stop and start it on `reload` and
@@ -314,17 +404,18 @@ the current runlevel these services will not be respawned automatically
by Finit if they exit (crash). Hence, if the runlevel is 2, the below
Dropbear SSH service will not be restarted if it is killed or exits.
~ $ initctl status -v
1 running 476 [S12345] /sbin/watchdog -T 16 -t 2 -F /dev/watchdog
2 running 477 [S12345] /sbin/syslogd -n -b 3 -D
3 running 478 [S12345] /sbin/klogd -n
4:1 inetd 0 [2345] internal time allow *:37
4:2 inetd 0 [2345] internal time allow *:37
4:3 inetd 0 [2345] internal 3737 allow *:3737
5:1 inetd 0 [2345] /sbin/telnetd allow *:23 deny eth0,eth1
5:2 inetd 0 [2345] /sbin/telnetd allow eth0:2323,eth2:2323,eth1:2323
6:1 inetd 0 [345] /sbin/dropbear allow eth0:222
6:2 inetd 0 [345] /sbin/dropbear allow *:22 deny eth0
```shell
~ $ initctl status -v
1 running 476 [S12345] /sbin/watchdog -T 16 -t 2 -F /dev/watchdog
2 running 477 [S12345] /sbin/syslogd -n -b 3 -D
3 running 478 [S12345] /sbin/klogd -n
4:1 inetd 0 [2345] internal time allow *:37,!eth0
4:2 inetd 0 [2345] internal time allow eth0:3737
5:1 inetd 0 [2345] /sbin/telnetd allow *:23 deny eth0,eth1
5:2 inetd 0 [2345] /sbin/telnetd allow eth0:2323,eth2:2323,eth1:2323
6:1 inetd 0 [345] /sbin/dropbear allow eth0:222
6:2 inetd 0 [345] /sbin/dropbear allow *:22 deny eth0
```
Requirements
@@ -341,7 +432,9 @@ At boot Finit calls either `mdev` or `udevd` to populate `/dev`, this is
done slightly differently and on systems with udev you might want to add
the following one-shot task early in your `/etc/finit.conf`:
run [S] /sbin/udevadm settle --timeout=120 -- Waiting for udev
```conf
run [S] /sbin/udevadm settle --timeout=120 -- Waiting for udev
```
Finit has a built-in Getty for TTYs, but requires a working `/bin/login`
or `/bin/sh`, if no TTYs are configured in `/etc/finit.conf`.
@@ -353,43 +446,6 @@ The built-in Inetd requires `/etc/services` and `/etc/protocols` to work
with port names rather than numbers.
Running
-------
Having successfully [built Finit](doc/build.md) it may now be time to
take it for a test drive. The `make install` attempts to set up finit
as the system system init, `/sbin/init`, but this is usually a symlink
pointing to the current init.
So either change the symlink, or change your boot loader (GRUB, LOADLIN,
LILO, U-Boot/Barebox or RedBoot) configuration to append the following
to the kernel command line:
```shell
append="init=/sbin/finit"
```
Remember to also set up an initial `/etc/finit.conf` before rebooting!
![Finit starting TroglOS](images/finit3-screenshot.png "Finit screenshot")
Debugging
---------
Add `finit_debug`, or `--debug`, to the kernel command line to enable
debug messages.
```shell
append="init=/sbin/finit --debug"
```
To debug startup issues, in particular issues with getty/login, try
`configure --enable-fallback-shell`. When no TTYs are detected, and
Finit is configured with this option, Finit will try to start a bare
`/bin/sh` on the boot console.
Origin & References
-------------------
@@ -409,19 +465,24 @@ and proposed extensions.
[5]: http://en.wikipedia.org/wiki/Runlevel
[6]: https://www.freedesktop.org/wiki/Software/systemd/
[9]: https://github.com/troglobit/troglos
[RFC862]: https://tools.ietf.org/html/rfc862
[RFC863]: https://tools.ietf.org/html/rfc863
[RFC864]: https://tools.ietf.org/html/rfc864
[RFC867]: https://tools.ietf.org/html/rfc867
[RFC868]: https://tools.ietf.org/html/rfc868
[init]: http://en.wikipedia.org/wiki/Init
[upstart]: http://upstart.ubuntu.com/
[systemd]: http://www.freedesktop.org/wiki/Software/systemd/
[openrc]: http://www.gentoo.org/proj/en/base/openrc/
[run-parts(8)]: http://manpages.debian.org/cgi-bin/man.cgi?query=run-parts
[original finit]: http://helllabs.org/finit/
[EeePC fastinit]: http://wiki.eeeuser.com/boot_process:the_boot_process
[Claudio Matsuoka]: https://github.com/cmatsuoka
[Joachim Nilsson]: http://troglobit.com
[GitHub]: https://github.com/troglobit/finit
[License]: https://en.wikipedia.org/wiki/MIT_License
[License Badge]: https://img.shields.io/badge/License-MIT-yellow.svg
[Travis]: https://travis-ci.org/troglobit/finit
[Travis Status]: https://travis-ci.org/troglobit/finit.png?branch=master
[Coverity Scan]: https://scan.coverity.com/projects/3545
[Coverity Status]: https://scan.coverity.com/projects/3545/badge.svg
<!--
-- Local Variables:
-- mode: markdown
-- End:
-->
-30
View File
@@ -1,30 +0,0 @@
# Top directory for building complete system, fall back to this directory
ROOTDIR ?= $(TOPDIR)
# Strip binaries unless user explicitly disables it
STRIPARGS ?= -s --strip-program=$(CROSS)strip -m 0755
# Some junk files we always want to be removed when doing a make clean.
JUNK = *~ *.bak *.map .*.d *.d DEADJOE semantic.cache *.gdb *.elf core core.*
MAKE := @$(MAKE)
MAKEFLAGS = --no-print-directory --silent
CHECK := cppcheck $(CPPFLAGS) --quiet --enable=all
INSTALL := install --backup=off
STRIPINST := $(INSTALL) $(STRIPARGS)
ARFLAGS := crus
export libdir plugindir incdir ROOTDIR CPPFLAGS LDFLAGS LDLIBS STATIC
# Override default implicit rules
%.o: %.c
@printf " CC $(subst $(ROOTDIR)/,,$(shell pwd)/$@)\n"
@$(CC) $(CFLAGS) $(CPPFLAGS) -c -MMD -MP -o $@ $<
%: %.o
@printf " LINK $(subst $(ROOTDIR)/,,$(shell pwd)/$@)\n"
@$(CC) $(CFLAGS) $(LDFLAGS) -Wl,-Map,$@.map -o $@ $^ $(LDLIBS$(LDLIBS-$(@)))
%.so: %.o
@printf " PLUGIN $(subst $(ROOTDIR)/,,$(shell pwd)/$@)\n"
@$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS)
-524
View File
@@ -1,524 +0,0 @@
/* Parser for /etc/finit.conf and /etc/finit.d/<SVC>.conf
*
* Copyright (c) 2012-2015 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
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "config.h" /* Generated by configure script */
#include <dirent.h>
#include <string.h>
#include <sys/resource.h>
#include <lite/lite.h>
#include "finit.h"
#include "cond.h"
#include "service.h"
#include "tty.h"
#include "helpers.h"
#define MATCH_CMD(l, c, x) \
(!strncasecmp(l, c, strlen(c)) && (x = (l) + strlen(c)))
static int parse_conf(char *file);
void conf_parse_cmdline(void)
{
FILE *fp;
char line[LINE_SIZE];
fp = fopen("/proc/cmdline", "r");
if (fp) {
fgets(line, sizeof(line), fp);
_d("Kernel command line: %s", line);
if (strstr(line, "finit_debug") || strstr(line, "--debug"))
debug = 1;
if (!debug && strstr(line, "quiet"))
quiet = 1;
fclose(fp);
}
}
/* Convert optional "[!123456789S]" string into a bitmask */
int conf_parse_runlevels(char *runlevels)
{
int i, not = 0, bitmask = 0;
if (!runlevels)
runlevels = "[234]";
i = 1;
while (i) {
int level;
char lvl = runlevels[i++];
if (']' == lvl || 0 == lvl)
break;
if ('!' == lvl) {
not = 1;
bitmask = 0x3FE;
continue;
}
if ('s' == lvl || 'S' == lvl)
lvl = '0';
level = lvl - '0';
if (level > 9 || level < 0)
continue;
if (not)
CLRBIT(bitmask, level);
else
SETBIT(bitmask, level);
}
return bitmask;
}
void conf_parse_cond(svc_t *svc, char *cond)
{
size_t i = 0;
char *ptr;
if (!svc) {
_e("Invalid service pointer");
return;
}
/* By default we assume UNIX daemons support SIGHUP */
if (svc_is_daemon(svc))
svc->sighup = 1;
if (!cond)
return;
/* First character must be '!' if SIGHUP is not supported. */
ptr = cond;
if (ptr[i] == '!') {
svc->sighup = 0;
ptr++;
}
while (ptr[i] != '>' && ptr[i] != 0)
i++;
ptr[i] = 0;
if (i >= sizeof(svc->cond)) {
logit(LOG_WARNING, "Too long event list in declaration of %s: %s", svc->cmd, ptr);
return;
}
strlcpy(svc->cond, ptr, sizeof(svc->cond));
}
struct rlimit_name {
char *name;
int val;
};
static const struct rlimit_name rlimit_names[] = {
{ "as", RLIMIT_AS },
{ "core", RLIMIT_CORE },
{ "cpu", RLIMIT_CPU },
{ "data", RLIMIT_DATA },
{ "fsize", RLIMIT_FSIZE },
{ "locks", RLIMIT_LOCKS },
{ "memlock", RLIMIT_MEMLOCK },
{ "msgqueue", RLIMIT_MSGQUEUE },
{ "nice", RLIMIT_NICE },
{ "nofile", RLIMIT_NOFILE },
{ "nproc", RLIMIT_NPROC },
{ "rss", RLIMIT_RSS },
{ "rtprio", RLIMIT_RTPRIO },
#ifdef RLIMIT_RTTIME
{ "rttime", RLIMIT_RTTIME },
#endif
{ "sigpending", RLIMIT_SIGPENDING },
{ "stack", RLIMIT_STACK },
{ NULL, 0 }
};
void conf_parse_rlimit(char *line)
{
struct rlimit rlim;
rlim_t new, *set;
const struct rlimit_name *name;
int resource = -1;
char *tok = strtok(line, " \t");
if (tok && !strcmp(tok, "soft"))
set = &rlim.rlim_cur;
else if (tok && !strcmp(tok, "hard"))
set = &rlim.rlim_max;
else
goto error;
tok = strtok(NULL, " \t");
if (!tok)
goto error;
for (name = rlimit_names; name->name; name++) {
if (!strcmp(tok, name->name))
resource = name->val;
}
if (resource < 0)
goto fail;
tok = strtok(NULL, " \t");
if (!tok)
goto fail;
if (!strcmp(tok, "infinity")) {
new = RLIM_INFINITY;
} else {
const char *err = NULL;
new = strtonum(tok, 0, (long long)2 << 31, &err);
if (err)
goto fail;
}
if (getrlimit(resource, &rlim))
goto fail;
*set = new;
if (setrlimit(resource, &rlim))
goto fail;
return;
fail:
logit(LOG_WARNING, "rlimit: Failed setting rlimit %s", name->name ? : "unknown");
return;
error:
logit(LOG_WARNING, "rlimit: parse error");
}
static void parse_static(char *line)
{
char *x;
char cmd[CMD_SIZE];
/* 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);
return;
}
if (MATCH_CMD(line, "user ", x)) {
if (username) free(username);
username = strdup(strip_line(x));
return;
}
if (MATCH_CMD(line, "host ", x)) {
if (hostname) free(hostname);
hostname = strdup(strip_line(x));
return;
}
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);
return;
}
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);
return;
}
if (MATCH_CMD(line, "network ", x)) {
if (network) free(network);
network = strdup(strip_line(x));
return;
}
if (MATCH_CMD(line, "runparts ", x)) {
if (runparts) free(runparts);
runparts = strdup(strip_line(x));
return;
}
if (MATCH_CMD(line, "include ", x)) {
char *file = strip_line(x);
strlcpy(cmd, file, sizeof(cmd));
if (!fexist(cmd)) {
_e("Cannot find include file %s, absolute path required!", x);
return;
}
parse_conf(cmd);
return;
}
if (MATCH_CMD(line, "startx ", x)) {
service_register(SVC_TYPE_SERVICE, strip_line(x), 0, username);
return;
}
if (MATCH_CMD(line, "shutdown ", x)) {
if (sdown) free(sdown);
sdown = strdup(strip_line(x));
return;
}
/* 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);
const char *err = NULL;
cfglevel = strtonum(token, 1, 9, &err);
if (err)
cfglevel = RUNLEVEL;
if (cfglevel < 1 || cfglevel > 9 || cfglevel == 6)
cfglevel = 2; /* Fallback */
return;
}
/* TODO: Make console & tty dynamically loadable from /etc/finit.d */
if (MATCH_CMD(line, "console ", x)) {
if (console) free(console);
console = strdup(strip_line(x));
return;
}
/* TODO: Make console & tty dynamically loadable from /etc/finit.d */
if (MATCH_CMD(line, "tty ", x)) {
tty_register(strip_line(x));
return;
}
}
static void parse_dynamic(char *line, time_t mtime)
{
char *x;
/* Skip comments, i.e. lines beginning with # */
if (MATCH_CMD(line, "#", x))
return;
/* Monitored daemon, will be respawned on exit */
if (MATCH_CMD(line, "service ", x)) {
service_register(SVC_TYPE_SERVICE, x, mtime, NULL);
return;
}
/* One-shot task, will not be respawned */
if (MATCH_CMD(line, "task ", x)) {
service_register(SVC_TYPE_TASK, x, mtime, NULL);
return;
}
/* Like task but waits for completion, useful w/ [S] */
if (MATCH_CMD(line, "run ", x)) {
service_register(SVC_TYPE_RUN, x, mtime, NULL);
return;
}
/* Classic inetd service */
if (MATCH_CMD(line, "inetd ", x)) {
#ifndef INETD_DISABLED
service_register(SVC_TYPE_INETD, x, mtime, NULL);
#else
_e("Finit built with inetd support disabled, cannot register service inetd %s!", x);
#endif
return;
}
if (MATCH_CMD(line, "rlimit ", x)) {
conf_parse_rlimit(x);
return;
}
}
static void tabstospaces(char *line)
{
if (!line)
return;
for (int i = 0; line[i]; i++) {
if (line[i] == '\t')
line[i] = ' ';
}
}
static int parse_conf_dynamic(char *file, time_t mtime)
{
FILE *fp = fopen(file, "r");
if (!fp) {
_pe("Failed opening %s", file);
return 1;
}
while (!feof(fp)) {
char line[LINE_SIZE] = "";
if (!fgets(line, sizeof(line), fp))
continue;
chomp(line);
tabstospaces(line);
_d("dyn conf: %s", line);
parse_dynamic(line, mtime);
}
fclose(fp);
return 0;
}
static int parse_conf(char *file)
{
FILE *fp;
char line[LINE_SIZE] = "";
char *x;
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, " ");
}
if (!silent)
print(0, "Loading %sconfiguration", line);
while (!feof(fp)) {
if (!fgets(line, sizeof(line), fp))
continue;
chomp(line);
tabstospaces(line);
_d("conf: %s", line);
parse_static(line);
parse_dynamic(line, 0);
}
fclose(fp);
return 0;
}
/* Reload all *.conf in /etc/finit.d/ */
void conf_reload_dynamic(void)
{
int i, num;
char *dir = rcsd;
struct dirent **e;
/* Mark and sweep */
svc_mark_dynamic();
num = scandir(dir, &e, NULL, alphasort);
if (num < 0) {
_d("No files found in %s, skipping ...", dir);
return;
}
for (i = 0; i < num; i++) {
char *name = e[i]->d_name;
char path[CMD_SIZE];
struct stat st;
snprintf(path, sizeof(path), "%s/%s", dir, name);
/* Check that it's an actual file ... */
if (stat(path, &st)) {
_d("Cannot even read .conf file %s, skipping ...", path);
continue;
}
if (S_ISEXEC(st.st_mode) || S_ISDIR(st.st_mode))
continue;
/* Check that file ends with '.conf' */
if (strcmp(&path[strlen(path) - 5], ".conf")) {
_d("File %s is not a .conf, skipping ... ", path);
continue;
}
parse_conf_dynamic(path, st.st_mtime);
}
while (num--)
free(e[num]);
free(e);
set_hostname(&hostname);
}
int conf_parse_config(void)
{
username = strdup(DEFUSER);
hostname = strdup(DEFHOST);
return parse_conf(FINIT_CONF);
}
/**
* Local Variables:
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/
+85 -47
View File
@@ -1,10 +1,10 @@
AC_INIT(Finit, 3.0-rc2, https://github.com/troglobit/finit/issues, finit, http://troglobit.com/finit.html)
AC_INIT(Finit, 3.1-rc1, https://github.com/troglobit/finit/issues, finit, http://troglobit.com/finit.html)
AM_INIT_AUTOMAKE([1.11 foreign no-dist-gzip dist-xz subdir-objects])
AM_SILENT_RULES([yes])
AC_CONFIG_SRCDIR([finit.c])
AC_CONFIG_SRCDIR([src/finit.c])
AC_CONFIG_HEADER([config.h])
AC_CONFIG_FILES([Makefile plugins/Makefile])
AC_CONFIG_FILES([Makefile plugins/Makefile src/Makefile])
# Older versions of autoconf (<2.58) do not have AC_CONFIG_MACRO_DIR()
#m4_include([m4/plugin.m4])
@@ -24,8 +24,8 @@ AC_PROG_INSTALL
# Configuration.
AC_HEADER_STDC
AC_CHECK_HEADERS(fstaby.h)
AC_CHECK_FUNCS(strstr getopt getfsenty)
AC_CHECK_HEADERS([fstaby.h termios.h])
AC_CHECK_FUNCS([strstr getopt getfsenty])
# Check for uint[8,16,32]_t
AC_TYPE_UINT8_T
@@ -33,31 +33,38 @@ AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
# Check for required libraries
PKG_CHECK_MODULES([uev], [libuev >= 1.5.2])
PKG_CHECK_MODULES([lite], [libite >= 1.8.2])
PKG_CHECK_MODULES([uev], [libuev >= 2.1.0])
PKG_CHECK_MODULES([lite], [libite >= 2.0.1])
# Check for configured Finit features
AC_ARG_ENABLE(emergency_shell,
AS_HELP_STRING([--enable-emergency-shell], [Experimental emergency fallback at boot.
Only use this for debugging very early boot problems with Finit.]))
Use only for debugging very early boot problems with Finit]),,[
enable_emergency_shell=no])
AC_ARG_ENABLE(fallback_shell,
AS_HELP_STRING([--enable-fallback-shell], [Start a shell if no TTYs can start.]))
AS_HELP_STRING([--enable-fallback-shell], [Start a shell if no TTYs can start]),,[
enable_fallback_shell=no])
AC_ARG_ENABLE(rw-rootfs,
AS_HELP_STRING([--enable-rw-rootfs], [Remount / R/W at boot, usually not for embedded]))
AS_HELP_STRING([--enable-rw-rootfs], [Remount / R/W at boot, usually not for embedded]),,[
enable_rw_rootfs=no])
AC_ARG_ENABLE(silent,
AS_HELP_STRING([--enable-silent], [Completely silent operation, not even boot messages]))
AC_ARG_ENABLE(progress,
AS_HELP_STRING([--enable-progress], [Pre Finit v3 bootup progress and heading]),,[
enable_progress=no])
AC_ARG_ENABLE(watchdog,
AS_HELP_STRING([--enable-watchdog], [Enable built-in watchdog, uses /dev/watchdog]))
AS_HELP_STRING([--enable-watchdog], [Enable built-in watchdog, uses /dev/watchdog]),,[
enable_watchdog=no])
AC_ARG_ENABLE(inetd,
AS_HELP_STRING([--disable-inetd], [Disable built-in inetd super server, default enabled]))
AS_HELP_STRING([--disable-inetd], [Disable built-in inetd super server, default enabled]),,[
enable_inetd=yes])
AC_ARG_ENABLE(quiet,
AS_HELP_STRING([--disable-quiet], [Default Finit obeys the kernel quiet option]))
AC_ARG_ENABLE(logrotate,
AS_HELP_STRING([--disable-logrotate], [Disable built-in rotation of /var/log/wtmp, default enabled]),,[
enable_logrotate=yes])
# Check for extra plugins to enable
enable_all_plugins=auto
@@ -80,7 +87,7 @@ AC_ARG_WITH(heading,
AC_ARG_WITH(fifo,
AS_HELP_STRING([--with-fifo=FIFO], [FIFO for init/telinit clients, default /var/run/initctl]),
[fifo=$withval], [fifo=/var/run/initctl])
[fifo=$withval], [fifo=$localstatedir/run/initctl])
AC_ARG_WITH(plugindir,
AS_HELP_STRING([--with-plugindir=DIR], [Finit plugin directory, default /lib/finit/plugins]),
@@ -103,10 +110,6 @@ AC_ARG_WITH(console,
AS_HELP_STRING([--with-console=DEV], [Console to use, default: /dev/console]),
[console=$withval], [console=/dev/console])
AC_ARG_WITH(username,
AS_HELP_STRING([--with-username=USER], [User for 'startx' .conf option, default: root]),
[username=$withval], [username=root])
AC_ARG_WITH(hostname,
AS_HELP_STRING([--with-hostname=NAME], [If /etc/hostname is missing, default: noname]),
[hostname=$withval], [hostname=noname])
@@ -132,48 +135,46 @@ AS_IF([test "x$enable_fallback_shell" = "xyes"], [
AS_IF([test "x$enable_rw_rootfs" = "xyes"], [
AC_DEFINE(REMOUNT_ROOTFS, 1, [Remount / as rw at boot])])
AS_IF([test "x$enable_silent" = "xyes"], [
AC_DEFINE(SILENT_MODE, 1, [Completely silent operation, not even boot messages])
AS_IF([test "x$enable_progress" = "xyes"], [
AC_DEFINE(SILENT_MODE, 0, [Pre Finit v3 bootup messages and heading])
], [
AC_DEFINE(SILENT_MODE, 0, [Normal output, default])])
AC_DEFINE(SILENT_MODE, 1, [Completely silent until login prompt])])
AS_IF([test "x$enable_watchdog" = "xyes"], [
AC_DEFINE(BUILTIN_WATCHDOG, 1, [Enable built-in watchdog, kicks on /dev/watchdog])])
### Disable features ###########################################################################
AS_IF([test "x$enable_inetd" != "xno"],
enable_inetd="yes", [
AC_DEFINE(INETD_DISABLED, 1, [Disable built-in inetd])])
AS_IF([test "x$enable_inetd" != "xno"], [
enable_inetd="yes"
AC_DEFINE(INETD_ENABLED, 1, [Enable built-in inetd])])
AS_IF([test "x$enable_quiet" != "xno"], [
AC_DEFINE(QUIET_MODE, 1, [Silent, after initial boot, no stopping/starting messages. Default: 1])
], [
AC_DEFINE(QUIET_MODE, 0, [Silent, after initial boot, no stopping/starting messages. Default: 1])])
AS_IF([test "x$enable_logrotate" != "xno"], [
AC_DEFINE(LOGROTATE_ENABLED, 1, [Enable built-in rotation of /var/log/wtmp et al.])])
### With features ##############################################################################
AS_IF([test "x$with_fifo" != "xno"], [
AS_IF([test "x$fifo" = "xyes"], [
fifo='/var/run/initctl'])])
AC_EXPAND_DIR(lurvig, "$fifo")
AC_DEFINE_UNQUOTED(FINIT_FIFO, "$lurvig", [FIFO for old style init/telinit client programs])
fifo='$localstatedir/run/initctl'])])
AC_EXPAND_DIR(fifo_path, "$fifo")
AC_DEFINE_UNQUOTED(FINIT_FIFO, "$fifo_path", [FIFO for old style init/telinit client programs])
AS_IF([test "x$with_config" != "xno"], [
AS_IF([test "x$config" = "xyes"], [
conf=$sysconfdir/finit.conf])])
AC_EXPAND_DIR(lurvig, "$conf")
AC_DEFINE_UNQUOTED(FINIT_CONF, "$lurvig", [Main Finit configuration file, default /etc/finit.conf])
AC_EXPAND_DIR(conf_path, "$conf")
AC_DEFINE_UNQUOTED(FINIT_CONF, "$conf_path", [Main Finit configuration file, default /etc/finit.conf])
AS_IF([test "x$with_rcsd" != "xno"], [
AS_IF([test "x$rcsd" = "xyes"], [
rcsd=$sysconfdir/finit.d])])
AC_EXPAND_DIR(lurvig, "$rcsd")
AC_DEFINE_UNQUOTED(FINIT_RCSD, "$lurvig", [Finit rcS.d/, default /etc/finit.d])
AC_EXPAND_DIR(rcsd_path, "$rcsd")
AC_DEFINE_UNQUOTED(FINIT_RCSD, "$rcsd_path", [Finit rcS.d/, default /etc/finit.d])
AS_IF([test "x$with_rc_local" != "xno"], [
AS_IF([test "x$rclocal" = "xyes"], [
rclocal=$sysconfdir/rc.local])])
AC_EXPAND_DIR(lurvig, "$rclocal")
AC_DEFINE_UNQUOTED(FINIT_RC_LOCAL, "$lurvig", [Compat SysV /etc/rc.local file to run last at boot.])
AC_EXPAND_DIR(rclocal_path, "$rclocal")
AC_DEFINE_UNQUOTED(FINIT_RC_LOCAL, "$rclocal_path", [Compat SysV /etc/rc.local file to run last at boot.])
AS_IF([test "x$with_heading" != "xno"], [
AS_IF([test "x$heading" = "xyes"], [
@@ -185,11 +186,6 @@ AS_IF([test "x$with_console" != "xno"], [
console=/dev/console])])
AC_DEFINE_UNQUOTED(CONSOLE, "$console", [Default console to use])
AS_IF([test "x$with_username" != "xno"], [
AS_IF([test "x$username" = "xyes"], [
username=root])])
AC_DEFINE_UNQUOTED(DEFUSER, "$username", [Used for startx .conf option])
AS_IF([test "x$with_hostname" != "xno"], [
AS_IF([test "x$hostname" = "xyes"], [
hostname=noname])])
@@ -203,8 +199,8 @@ AS_IF([test "x$with_runlevel" != "xno"], [
AS_IF([test "x$with_random_seed" != "xno"], [
AS_IF([test "x$random_seed" = "xyes"], [
random_seed=/var/lib/misc/random-seed])
AC_EXPAND_DIR(lurvig, "$random_seed")
AC_DEFINE_UNQUOTED(RANDOMSEED, "$lurvig", [Improve random at boot by seeding it with sth from before.])])
AC_EXPAND_DIR(random_path, "$random_seed")
AC_DEFINE_UNQUOTED(RANDOMSEED, "$random_path", [Improve random at boot by seeding it with sth from before.])])
# Control build with automake flags
AM_CONDITIONAL(STATIC, [test "x$enable_static" = "xyes"])
@@ -213,3 +209,45 @@ AM_CONDITIONAL(WATCHDOGD, [test "x$enable_watchdog" = "xyes"])
# Generate all files
AC_OUTPUT
cat <<EOF
------------------ Summary ------------------
$PACKAGE_NAME version $PACKAGE_VERSION
Prefix................: $prefix
Sysconfdir............: `eval echo $sysconfdir`
Localstatedir.........: `eval echo $localstatedir`
FIFO path.............: $fifo_path
Finit config file.....: $conf_path
Finit config.d path...: $rcsd_path
Compat rc.local path..: $rclocal_path
Random seed path......: $random_path
C Compiler............: $CC $CFLAGS $CPPFLAGS $LDFLAGS $LIBS
Linker................: $LD $LLDP_LDFLAGS $LLDP_BIN_LDFLAGS $LDFLAGS $LIBS
Behavior:
Boot heading..........: $heading
Plugins...............: $plugins
Optional features:
Built-in inetd........: $enable_inetd
Built-in watchdogd....: $enable_watchdog
Built-in logrotate....: $enable_logrotate
Emergency shell.......: $enable_emergency_shell
Fallback shell........: $enable_fallback_shell
Remount / RW at boot..: $enable_rw_rootfs
Traditional progress..: $enable_progress
Default console dev...: $console
Default hostname......: $hostname
Default runlevel......: $runlevel
------------- Compiler version --------------
$($CC --version || true)
-------------- Linker version ---------------
$($LD --version || true)
---------------------------------------------
Check the above options and compile with:
${MAKE-make}
EOF
+32 -30
View File
@@ -1,46 +1,48 @@
HowTo: Finit on Alpine Linux 3.4
================================
HowTo: Finit on Alpine Linux 3.4-3.6
====================================
Mini HowTo using Finit to boot an Alpine Linux system. It is assumed
that the user has already installed a compiler, C library header files,
HowTo use Finit to boot an [Alpine Linux][] system. It is assumed that
the user has already installed make, a compiler, C library header files,
and other tools needed to build a GNU configure based project.
To start with you need to first install [libuEv][] and [libite][], by
default they install to `/usr/local` and Alpine's `pkg-config` does not
look for libraries and header files there. So the `PKG_CONFIG_LIBDIR`
environment variable has to be used:
To start with you need to first install [libuEv][] and [libite][]. They
default to install to `/usr/local`, but unlike Debian and Ubuntu based
distros, Alpine's `pkg-config` does not look for libraries and header
files there. So the `PKG_CONFIG_LIBDIR` environment variable must be
used, or change the install prefix to `/usr`.
alpine:~/finit# PKG_CONFIG_LIBDIR=/usr/local/lib/pkgconfig ./configure \
--enable-rw-rootfs --enable-x11-common-plugin \
--enable-alsa-utils-plugin --enable-inetd-echo-plugin \
--enable-inetd-chargen-plugin --enable-inetd-daytime-plugin \
--enable-inetd-discard-plugin --enable-inetd-time-plugin \
--with-heading="Alpine Linux 3.4" --with-hostname=alpine
The bundled [build.sh](build.sh) script can be used to configure and
build finit:
The plugins are optional, but the other configure flags are *not*.
alpine:~# cd finit
alpine:~/finit# ./contrib/alpine/build.sh
alpine:~/finit# make all install
Then run the [install.sh](install.sh) script to install all necessary
files, including the sample `finit.conf` and `finit.d/*.conf` files.
More on that below.
The installation skips `/sbin/init`, because it already exists, and
Alpine is hard coded to use it. So you have to change the symlink
yourself to point to `finit` instead of `/bin/busybox`.
alpine:~/finit# ./contrib/alpine/install.sh
The install script is non-destructive by default, you have to answer
*Yes* twice to set up Finit as the system default init. Pay close
attention to the last question:
*** Install Finit as the system default Init (y/N)?
If you answer `No`, simply by pressing enter, you can change the symlink
yourself later on, to point to `finit` instead of `/bin/busybox`:
alpine:~/finit# cd /sbin
alpine:/sbin# rm init
alpine:/sbin# ln -s finit init
Before rebooting, make sure to set up a [/etc/finit.conf](finit.conf),
and possibly also an [/etc/rc.local](rc.local) for one-shot set up and
initialization like keyboard language etc. You can use the files in
this directory as templates -- check them both if they need to be
tweaked for your installation, you may not run Dropbear SSH or speak
Swedish ...
and [/etc/finit.d/](finit.d/) for your services. Samples are included
in this directory. Notice the symlinks in `/etc/finit.d/`, which can be
managed by the operator at runtime using `initctl enable SERVICE`. You
can also use a standard [/etc/rc.local](rc.local) for one-shot tasks and
initialization like keyboard language etc.
[libuEv]: https://github.com/troglobit/libuev
[libite]: https://github.com/troglobit/libite
<!--
-- Local Variables:
-- mode: markdown
-- End:
-->
[Alpine Linux]: https://www.alpinelinux.org/
+1
View File
@@ -0,0 +1 @@
3.6.2
+39
View File
@@ -0,0 +1,39 @@
#!/bin/sh -e
echo
echo "*** Configuring Finit for Alpine Linux"
if [ ! -e configure ]; then
echo " The configure script is missing, maybe you're using a version from GIT?"
echo " Attempting to run the autogen.sh script, you will need these tools:"
echo " autoconf, automake, libtool, pkg-config ..."
echo
./autogen.sh
fi
# The plugins are optional, but you may need D-Bus and X11 if you want
# to run X-Window, the other configure flags are however required.
PKG_CONFIG_LIBDIR=/usr/lib/pkgconfig:/usr/local/lib/pkgconfig ./configure \
--enable-rw-rootfs --enable-progress \
--enable-dbus-plugin --enable-x11-common-plugin \
--enable-alsa-utils-plugin --enable-inetd-echo-plugin \
--enable-inetd-chargen-plugin --enable-inetd-daytime-plugin \
--enable-inetd-discard-plugin --enable-inetd-time-plugin \
--with-heading="Alpine Linux 3.6" --with-hostname=alpine
echo
echo "*** Building ..."
echo
make
if [ $? -ne 0 ]; then
echo
echo "*** The build failed for some reason"
echo
exit 1
fi
echo
echo "*** Done"
echo
+7 -37
View File
@@ -1,40 +1,10 @@
# /etc/finit.conf: Example for Alpine Linux 3.4
# /etc/finit.conf: Example for Alpine Linux
# See /etc/finit.d/*.conf and `initctl list` for other services
# Modules to load
#module qxl
#module fbcon
module button
module evdev
## Runlevel to start after bootstrap, runlevel 'S'
# Default is 2
#runlevel 2
# Runlevel to start after bootstrap, runlevel 'S'
runlevel 2
## Bootstrap services and tasks
# Can be listed here or in /etc/finit.d/*.conf
# Services to be monitored and respawned as needed
service [S12345] /sbin/klogd -n -- Kernel log daemon
service [S12345] /sbin/syslogd -n -- Syslog daemon
# Network bringup script, blocks boot like run stanza, use below task instead
#network /sbin/ifup -a
### Every line below can be a service/task per file in /etc/finit.d/*.conf ###
# Network bringup not needed if /etc/network/interfaces is used.
task [2345] log <svc/sbin/syslogd> /sbin/ifup -a -- Networking
# Depends on syslogd having started. Redirect any output to log.
service [2345] log <svc/sbin/syslogd> /usr/sbin/acpid -f -- ACPI daemon
# Silly Busybox ntpd has no option to use syslog when running in foreground
service [2345] log <svc/sbin/syslogd> /usr/sbin/ntpd -n -N -p pool.ntp.org
# Start SSH daemon as soon as basic networking comes up
service [2345] <net/lo/up> /usr/sbin/dropbear -R -F -p 22 -- Dropbear SSH daemon
service [2345] <svc/sbin/syslogd> /usr/sbin/crond -f -S -c /etc/crontabs -- Cron daemon
# Handle PWR button to shutdown/reboot -- useful in Qemu (virt-manager)
service [2345] /sbin/acpid -f -- ACPI daemon
# Consoles to start getty on when system is up
tty /dev/tty1
tty /dev/tty2
tty /dev/tty3
@@ -0,0 +1,3 @@
# Handle PWR button to shutdown/reboot -- useful in Qemu (virt-manager)
# Depends on syslogd having started. Redirect any output to log.
service [2345] log <svc/sbin/syslogd> /sbin/acpid -f -- ACPI daemon
@@ -0,0 +1 @@
service [2345] <svc/sbin/syslogd> /usr/sbin/crond -f -S -c /etc/crontabs -- Cron daemon
@@ -0,0 +1,2 @@
# Start SSH daemon as soon as basic networking comes up
service [2345] <net/lo/up> /usr/sbin/dropbear -R -F -p 22 -- Dropbear SSH daemon
@@ -0,0 +1,4 @@
# Consoles to start getty on when system is up
tty /dev/tty1 noclear nowait
tty /dev/tty2 noclear nowait
tty /dev/tty3 noclear nowait
@@ -0,0 +1,2 @@
# Oneshot task to run once at bootstrap
task [S] zcat /etc/keymap/se.bmap.gz | loadkmap -- Loading keymap
@@ -0,0 +1,2 @@
# Start klogd as soon as possible, should always run
service [S12345] /sbin/klogd -n -- Kernel log daemon
@@ -0,0 +1 @@
service [2345] /usr/sbin/lxdm -- Lightweight Login Manager
@@ -0,0 +1,6 @@
## Linux kernel modules to load
#module fbcon
module button
module evdev
module mousedev
module 8139cp
@@ -0,0 +1,2 @@
# Silly Busybox ntpd has no option to use syslog when running in foreground
service [2345] log <svc/sbin/syslogd> /usr/sbin/ntpd -n -N -p pool.ntp.org -- NTP daemon
@@ -0,0 +1,2 @@
# Start syslogd as soon as possible, should always run
service [S12345] /sbin/syslogd -n -- Syslog daemon
+1
View File
@@ -0,0 +1 @@
available/dropbear.conf
+1
View File
@@ -0,0 +1 @@
available/getty.conf
+1
View File
@@ -0,0 +1 @@
available/keymap.conf
+1
View File
@@ -0,0 +1 @@
available/klogd.conf
+1
View File
@@ -0,0 +1 @@
available/modules.conf
+1
View File
@@ -0,0 +1 @@
available/syslogd.conf
+51
View File
@@ -0,0 +1,51 @@
#!/bin/sh
if [ "x`id -u`" != "x0" ]; then
echo
echo "*** This script must run as root"
echo
exit 1
fi
# Adjust base directory
if [ -e alpine-release ]; then
cd ../..
elif [ ! -e autogen.sh ]; then
echo "*** Please run this script from the Finit base directory."
exit 1
fi
echo
echo "*** Install Finit on Alpine Linux"
echo "========================================================================"
echo "/sbin/finit - PID 1"
echo "/lib/finit/plugins/* - All enabled Finit plugins"
echo "/etc/finit.conf - Finit configuration file"
echo "/etc/finit.d/ - Finit services"
echo
read -p "Do you want to continue (y/N)? " yorn
if [ "x$yorn" = "xy" -o "x$yorn" = "xY" ]; then
echo
echo "*** Installing Finit files ..."
make install
cd `dirname $0`
for file in finit.conf rc.local; do
install -vbD $file /etc/$file
done
cp -va finit.d /etc/
read -p "*** Install Finit as the system default Init (y/N)? " yorn
if [ "x$yorn" = "xy" -o "x$yorn" = "xY" ]; then
echo "*** Updating /sbin/init symlink --> finit ..."
cd /sbin
rm init
ln -s finit init
fi
echo "*** Done"
echo
else
echo
echo "*** Aborting install."
echo
fi
+7 -1
View File
@@ -1,2 +1,8 @@
#!/bin/sh
zcat /etc/keymap/sv-latin1.bmap.gz | loadkmap
# This script is executed once at boot, at the very end,
# right before starting the TTYs.
#
# Each line is run in sequence.
#
# NOTE: Remeber to set the executable bit!
#
+31 -33
View File
@@ -1,20 +1,12 @@
HowTo: Finit on Debian Jessie
=============================
HowTo: Finit on Debian GNU/Linux
================================
Mini HowTo using Finit to boot Debian GNU/Linux 8.5 (Jessie). It is
assumed that the user has already installed a compiler, C library header
files, and other tools needed to build a GNU configure based project.
HowTo use Finit to boot a Debian GNU/Linux system. It is assumed that
the user has already installed a compiler, C library header files, and
other tools needed to build a GNU configure based project. I.e., at
the very least:
Also, Finit has only been verified to work with the Debian *Server* ed.
I.e., during install — skip GNOME and other X stuff to get a plain and
usable Debian server install, which we can add X-Window to later :-)
Now, I started off by replacing systemd from the base install with the
old SysV init, using [this HowTo][1], you may not need to do that, but
for me it was easier — and also a great rebuttal to all the systemd
haters out there (yeah, even though I speak for the alternative PID 1
movement I don't hate systemd :P) it is possible to still run Debian
without systemd! Anyway, this text was based on that experience.
root@debian:~# apt install build-essential
Like the [Alpine HowTo](../alpine/), you need to install [libuEv][] and
[libite][], but since this is Debian — which takes infinite care of its
@@ -23,30 +15,36 @@ it installed so it can locate the uEv and lite libraries.
> With Debian everything just works!™
The following build and install script can be used to configure, build,
install and set up your system to run Finit:
... just make sure to install the following, so `ifup` and other basic
tools pre-systemd work as intended.
debian:~/finit$ contrib/debian/build.sh
root@debian:~# apt install initscripts console-setup
Since `/sbin/init` already exists on your system the script creates
another entry in your GRUB config, in `/etc/grub.d/40_custom`, where
`init=/sbin/finit` is added to your kernel line. You could of course
also change the `/sbin/init` symlink and uninstall systemd/SysV init if
everything works fine, but that's up to you.
The following script can then be used to configure, build, install and
set up your system to run Finit:
Before rebooting, read up on [/etc/finit.conf](finit.conf) and notice
how `/etc/start.d/` and `/etc/rc.local` can be used to extend the boot
with simpler setup tasks on your system — see the docu for details.
user@debian:~/finit$ contrib/debian/build.sh
However, since `/sbin/init` already exists on your system, the script
creates another entry in your GRUB config, in `/etc/grub.d/40_custom`,
where `init=/sbin/finit` is added to your kernel line. It is of course
also possible to change the default init to Finit, if you do you can
remove the custom Grub entry:
user@debian:~/finit# cd /sbin
user@debian:/sbin# sudo rm init
user@debian:/sbin# sudo ln -s finit init
Before rebooting, check the default [/etc/finit.conf](finit.conf) and
`/etc/finit.d/*.conf` files. The build + install script above provides
a few sample `.conf` files. See `initctl list` after boot for a list of
enabled and available services.
You can also use a standard [/etc/rc.local](rc.local) for one-shot tasks
and initialization like keyboard language etc.
Have fun!
/Joachim ツ
[1]: http://without-systemd.org/wiki/index.php/How_to_remove_systemd_from_a_Debian_jessie/sid_installation
[libuEv]: https://github.com/troglobit/libuev
[libite]: https://github.com/troglobit/libite
<!--
-- Local Variables:
-- mode: markdown
-- End:
-->
+13 -9
View File
@@ -11,24 +11,28 @@ echo
echo "*** Configuring Finit for Debian"
if [ ! -e configure ]; then
echo " The configure script is missing, maybe you're using a GIT checkout?"
echo " Attempting to run the autogen.sh script, you need these tools:"
echo " The configure script is missing, maybe you're using a version from GIT?"
echo " Attempting to run the autogen.sh script, you will need these tools:"
echo " autoconf, automake, libtool, pkg-config ..."
echo
./autogen.sh
fi
echo
./configure --enable-rw-rootfs --enable-dbus-plugin --enable-x11-common-plugin \
--enable-alsa-utils-plugin --with-random-seed=/var/lib/urandom/random-seed \
--with-heading="Debian GNU/Linux 8.5" --with-hostname=jessie \
--enable-inetd-echo-plugin --enable-inetd-chargen-plugin \
--enable-inetd-daytime-plugin --enable-inetd-discard-plugin \
--enable-inetd-time-plugin
# The plugins are optional, but you may need D-Bus and X11 if you want
# to run X-Window, the other configure flags are however required.
./configure \
--enable-rw-rootfs --enable-progress \
--enable-dbus-plugin --enable-x11-common-plugin \
--enable-alsa-utils-plugin --enable-inetd-echo-plugin \
--enable-inetd-chargen-plugin --enable-inetd-daytime-plugin \
--enable-inetd-discard-plugin --enable-inetd-time-plugin \
--with-random-seed=/var/lib/urandom/random-seed \
--with-heading="Debian GNU/Linux" --with-hostname="stretch"
if [ $? -ne 0 ]; then
echo
echo "*** Configure script failed, have you installed libuEV and libite?"
echo "*** Configure script failed, have you installed libuEv and libite?"
echo
exit 1
fi
+7 -57
View File
@@ -1,60 +1,10 @@
# /etc/finit.conf: Example for Debian GNU/Linux 8.5
# Here we use one big (?) finit.conf, but all non-bootstrap services
# can just as easily be listed in a separate /etc/finit.d/*.conf
# /etc/finit.conf: Example for Debian GNU/Linux
# See /etc/finit.d/*.conf and `initctl list` for other services
# The host directive is a fallback if /etc/hostname is missing
host jessie
## Runlevel to start after bootstrap, runlevel 'S'
# Default is 2
#runlevel 2
# The user directive is only for the startx directive, which in turn is
# just like a service but with a different user. Services can also run
# with a different user, using the @username syntax
user root
## Bootstrap services and tasks
# Can be listed here or in /etc/finit.d/*.conf
# Linux kernel modules to load, /etc/modprobe is not used
module button
module evdev
module loop
module psmouse
# Runlevel to start after bootstrap, runlevel 'S'.
# Change this to 3 to start XDM at boot.
runlevel 2
# Some services may need to start very early, e.g. a watchdog daemon.
# Runlevel [S] (bootStrap) is useful for that. It cannot be switched
# to at runtime either, so tasks and run directives usually live here.
# Please note, the run directive is blocking, so be careful!
#service [S12345] /sbin/watchdogd -n -- Watchdog daemon
#run [S] /sbin/probe -- system probe
#run [S] /sbin/setupd --bootstrap -- system bootstrap
service [S12345] /usr/sbin/rsyslogd -n -- Syslog daemon
# Network bringup script not needed if /etc/network/interfaces is used
#network service networking start
# Regular services to be monitored and respawned as needed. Here we use
# a (svc) condition, the listed service must be started (waits for the
# PID file to be created in /run/*.pid) before starting either service,
# (net) conditions are also available.
service [2345] <svc/usr/sbin/rsyslogd> log /usr/sbin/acpid -f -- ACPI daemon
service [2345] <svc/usr/sbin/rsyslogd> /usr/sbin/sshd -D -- SSH daemon
# Here we use XDM since it has few dependencies (relatively speaking).
# It is also an example of a service (startx is an alias for service)
# that does not have a -- description.
#service [3] /usr/sbin/lightdm -- X-Window Display Manager
startx [3] /usr/bin/xdm -nodaemon
# Run old-style start scripts from this directory. Very similar to how
# SysV init works: 01first, 02second, etc. see run-parsts(8) for details
runparts /etc/start.d
# |-- S03keyboard-setup
# |-- S17kbd
# `- S18console-setup
# Virtual consoles to start getty on. Runlevels, speed & $TERM optional
# TTYs are also services, sort of, but they are guaranteed to start at
# the very end of the boot sequence. Finit comes with a built-in getty.
tty [12345] /dev/tty1 115200 vt100
tty [2345] /dev/tty2 38400 linux
tty [2345] /dev/tty3 38400 linux
@@ -0,0 +1,3 @@
# Handle PWR button to shutdown/reboot -- useful in Qemu (virt-manager)
# Depends on rsyslogd having started. Redirect any output to log.
service [2345] <svc/usr/sbin/rsyslogd> log /usr/sbin/acpid -f -- ACPI daemon
@@ -0,0 +1,2 @@
# Oneshot task to run once at bootstrap
task [S] /lib/console-setup/console-setup.sh -- Setting up console font and keymap
@@ -0,0 +1,4 @@
# Consoles to start getty on when system is up
tty [12345] /dev/tty1 115200 vt100 noclear nowait
tty [2345] /dev/tty2 38400 linux noclear nowait
tty [2345] /dev/tty3 38400 linux noclear nowait
@@ -0,0 +1,2 @@
# Oneshot task to run once at bootstrap
task [S] /lib/console-setup/keyboard-setup.sh -- Setting up console keyboard layout
@@ -0,0 +1 @@
service [3] /usr/sbin/lightdm -- Light Display Manager
@@ -0,0 +1,8 @@
## Linux kernel modules to load
#module fbcon
module button
module evdev
module loop
module psmouse
module mousedev
module 8139cp
@@ -0,0 +1,2 @@
# Simple NTP client (SNTP)
service [2345] <net/route/default> /usr/sbin/ntpclient -n -L pool.ntp.org -- SNTP client
@@ -0,0 +1,2 @@
# Start rsyslogd as soon as possible, should always run
service [S12345] /usr/sbin/rsyslogd -n -- Reliable and extended syslog daemon
@@ -0,0 +1,2 @@
# Start SSH daemon as soon as basic networking comes up
service [2345] <net/lo/up> /usr/sbin/sshd -D -- OpenSSH daemon
@@ -0,0 +1,4 @@
# Here we use XDM since it has few dependencies (relatively speaking).
# It is also an example of a service without a -- description.
# service [3] /usr/sbin/lxdm -- Lightweight Login Manager
service [3] /usr/bin/xdm -nodaemon
+1
View File
@@ -0,0 +1 @@
available/console-setup.conf
+1
View File
@@ -0,0 +1 @@
available/getty.conf
+1
View File
@@ -0,0 +1 @@
available/keyboard-setup.conf
+1
View File
@@ -0,0 +1 @@
available/modules.conf
+1
View File
@@ -0,0 +1 @@
available/rsyslogd.conf
+1
View File
@@ -0,0 +1 @@
available/sshd.conf
+17 -19
View File
@@ -1,8 +1,5 @@
#!/bin/sh
SYMLINKS="start.d/*"
FILES="finit.conf"
if [ "x`id -u`" != "x0" ]; then
echo
echo "=> Unfortunately this script must run as root (sudo) <="
@@ -14,19 +11,18 @@ fi
grep -q Debian os-release 2>/dev/null
if [ $? -eq 0 ]; then
cd ../..
elif [ ! -e finit.c ]; then
echo "Please run this script from the Finit base directory."
elif [ ! -e autogen.sh ]; then
echo "*** Please run this script from the Finit base directory."
exit 1
fi
echo "Install Finit on Debian 8 (jessie)"
echo
echo "*** Install Finit on Debian GNU/Linux"
echo "========================================================================"
echo "/sbin/finit - PID 1"
echo "/lib/finit/plugins/* - All enabled Finit plugins"
echo "/etc/finit.conf - Instead of units or /etc/init.d Finit can have"
echo " one config for your system. Or you can split"
echo " it in service(s) per file in /etc/finit.d/"
echo "/etc/start.d/ - Simple Debian setup scripts run with run-parts(8)"
echo "/etc/finit.conf - Finit configuration file"
echo "/etc/finit.d/ - Finit services"
echo "/etc/grub.d/40_custom - Add menu entry to the Grub boot loader"
echo
read -p "Do you want to continue (y/N)? " yorn
@@ -36,20 +32,22 @@ if [ "x$yorn" = "xy" -o "x$yorn" = "xY" ]; then
echo "Installing Finit files ..."
make install
cd `dirname $0`
mkdir -p /etc/start.d
for file in $FILES; do
install -vbD $file /etc/$file
done
for link in $SYMLINKS; do
cp -va $link /etc/$link
done
echo "Setting up a GRUB boot entry ..."
install -vbD finit.conf /etc/finit.conf
cp -va finit.d /etc/
echo "*** Setting up a GRUB boot entry ..."
MENU=`grep gnu-linux /boot/grub/grub.cfg |head -1 |sed "s/menuentry '\([^']*\).*/\1/"`
TYPE=`grep gnu-linux /boot/grub/grub.cfg |head -1 |sed "s/.*' --class \([a-z]*\).*/\1/"`
BOOT=`grep set=root /boot/grub/grub.cfg |head -1 |sed 's/.* \([a-f0-9]*-[a-f0-9]*-[a-f0-9]*-[a-f0-9]*-[a-f0-9]*\).*/\1/'`
ROOT=`grep root=UUID /boot/grub/grub.cfg |head -1 |sed 's/.*UUID=\([a-f0-9]*-[a-f0-9]*-[a-f0-9]*-[a-f0-9]*-[a-f0-9]*\).*/\1/'`
cat grub.d/40_custom | sed "s,\$BOOT,$BOOT,;s,\$ROOT,$ROOT,;s,\$TYPE,$TYPE,;s,\$MENU,$MENU," >/etc/grub.d/40_custom
update-grub
echo
echo "*** Done"
echo
else
echo "Aborting install."
echo
echo "*** Aborting install."
echo
fi
-1
View File
@@ -1 +0,0 @@
../init.d/keyboard-setup
-1
View File
@@ -1 +0,0 @@
../init.d/kbd
-1
View File
@@ -1 +0,0 @@
../init.d/console-setup
-1
View File
@@ -1,6 +1,5 @@
# Sample finit.conf to demonstrate the syntax
#
user admin
host testbed
# Devices to fsck at boot
-65
View File
@@ -1,65 +0,0 @@
#!/bin/sh
### BEGIN INIT INFO
# Provides: keyboard-setup
# Required-Start: mountkernfs
# Required-Stop:
# Should-Start: keymap udev
# X-Start-Before: checkroot
# Default-Start: S
# Default-Stop:
# X-Interactive: true
# Short-Description: Set preliminary keymap
# Description: Set the console keyboard as early as possible
# so during the file systems checks the administrator
# can interact. At this stage of the boot process
# only the ASCII symbols are supported.
### END INIT INFO
set -e
# This script is not used by keyboard-configuration. It is used
# jointly by console-setup and console-setup-mini
test -f /bin/setupcon || exit 0
if [ -f /lib/lsb/init-functions ]; then
. /lib/lsb/init-functions
else
log_action_begin_msg () {
echo -n "$@... "
}
log_action_end_msg () {
if [ "$1" -eq 0 ]; then
echo done.
else
echo failed.
fi
}
fi
case "$1" in
stop)
# keyboard-setup isn't a daemon
;;
start|force-reload|restart|reload)
case `readlink /proc/self/fd/2` in
/dev/tty[0-9]*|/dev/vc/[0-9]*|/dev/console)
log_action_begin_msg "Setting preliminary keymap"
if setupcon -k; then
log_action_end_msg 0
else
log_action_end_msg $?
fi
;;
*)
exit 0
;;
esac
;;
*)
echo 'Usage: /etc/init.d/keyboard-setup {start|reload|restart|force-reload|stop}'
exit 1
;;
esac
-81
View File
@@ -1,81 +0,0 @@
#!/bin/sh
### BEGIN INIT INFO
# Provides: acpid
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# X-Start-Before: kdm gdm xdm hal
# X-Stop-After: kdm gdm xdm hal
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: Start the Advanced Configuration and Power Interface daemon
# Description: Provide a socket for X11, hald and others to multiplex
# kernel ACPI events.
### END INIT INFO
set -e
ACPID="/usr/sbin/acpid"
DEFAULTS="/etc/default/acpid"
# Check for daemon presence
[ -x "$ACPID" ] || exit 0
OPTIONS=""
MODULES=""
# Include acpid defaults if available
[ -r "$DEFAULTS" ] && . "$DEFAULTS"
# Get lsb functions
. /lib/lsb/init-functions
# As the name says. If the kernel supports modules, it'll try to load
# the ones listed in "MODULES".
load_modules() {
[ -f /proc/modules ] || return 0
if [ "$MODULES" = "all" ]; then
MODULES="$(sed -rn 's#^(/lib/modules/[^/]+/)?kernel/(drivers|ubuntu)/acpi/([^/]+/)*(.*)\.ko:.*#\4#p' "/lib/modules/$(uname -r)/modules.dep")"
fi
if [ -z "$MODULES" ]; then
return
fi
log_begin_msg "Loading ACPI kernel modules..."
# work around a bug in initramfs which leaks this env var Launchpad #291619
# and a bug in modprobe --all --quiet which doesn't load all modules and
# exits with non-zero exit status Debian #504088
unset MODPROBE_OPTIONS
modprobe --all --use-blacklist $MODULES 2>/dev/null
log_end_msg $?
}
case "$1" in
start)
load_modules || true
log_begin_msg "Starting ACPI services..."
start-stop-daemon --start --quiet --oknodo --exec "$ACPID" -- $OPTIONS
log_end_msg $?
;;
stop)
log_begin_msg "Stopping ACPI services..."
start-stop-daemon --stop --quiet --oknodo --retry 2 --exec "$ACPID"
log_end_msg $?
;;
restart)
$0 stop
sleep 1
$0 start
;;
reload|force-reload)
log_begin_msg "Reloading ACPI services..."
start-stop-daemon --stop --signal 1 --exec "$ACPID"
log_end_msg $?
;;
status)
status_of_proc "$ACPID" acpid
;;
*)
log_success_msg "Usage: /etc/init.d/acpid {start|stop|restart|reload|force-reload|status}"
exit 1
esac
-259
View File
@@ -1,259 +0,0 @@
#!/bin/sh
### BEGIN INIT INFO
# Provides: kbd
# Required-Start: $remote_fs
# Required-Stop:
# Default-Start: S
# Default-Stop:
# X-Interactive: true
# Description: Set console screen modes and fonts
# Short-Description: Prepare console
### END INIT INFO
# This is the boot script for the `kbd' package.
# It loads parameters from /etc/kbd/config and maybe loads
# default font and map.
# (c) 1997 Yann Dirson
PKG=kbd
if [ -r /etc/$PKG/config ]; then
. /etc/$PKG/config
fi
if [ -d /etc/$PKG/config.d ]; then
for i in `run-parts --list /etc/$PKG/config.d `; do
. $i
done
fi
# do some magic with the variables for compatibility with the config
# file of console-tools
for vc in '' `set | grep "^.*_vc[0-9][0-9]*=" | sed 's/^.*\(_vc[0-9][0-9]*\)=.*/\1/'`
do
eval [ '"'\${SCREEN_FONT$vc}'"' ] && eval CONSOLE_FONT$vc=\${CONSOLE_FONT$vc:-\${SCREEN_FONT$vc}}
eval [ '"'\${SCREEN_FONT_MAP$vc}'"' ] && eval FONT_MAP$vc=\${FONT_MAP$vc:-\${SCREEN_FONT_MAP$vc}}
eval [ '"'\${APP_CHARSET_MAP$vc}'"' ] && eval CONSOLE_MAP$vc=\${CONSOLE_MAP$vc:-\${APP_CHARSET_MAP$vc}}
done
. /lib/lsb/init-functions
PATH=/sbin:/bin:/usr/sbin:/usr/bin
SETFONT_OPT="-v"
if which setupcon >/dev/null
then
HAVE_SETUPCON=yes
fi
# set DEVICE_PREFIX depending on devfs/udev
if [ -d /dev/vc ]; then
DEVICE_PREFIX="/dev/vc/"
else
DEVICE_PREFIX="/dev/tty"
fi
# determine the system charmap
ENV_FILE=''
[ -r /etc/environment ] && ENV_FILE="/etc/environment"
[ -r /etc/default/locale ] && ENV_FILE="/etc/default/locale"
[ "$ENV_FILE" ] && CHARMAP=$(set -a && . "$ENV_FILE" && locale charmap)
if [ "$CHARMAP" = "UTF-8" -a -z "$CONSOLE_MAP" ]
then
UNICODE_MODE=yes
fi
reset_vga_palette ()
{
if [ -f /proc/fb ]; then
# They have a framebuffer device.
# That means we have work to do...
echo -n "]R"
fi
}
unicode_start_stop ()
{
vc=$1
if [ -n "$UNICODE_MODE" -a -z "`eval echo \\$CONSOLE_MAP_vc$vc`" ]; then
action=unicode_start
else
action=unicode_stop
fi
if [ "${CONSOLE_FONT}" ]; then
$action "${CONSOLE_FONT}" < ${DEVICE_PREFIX}$vc > ${DEVICE_PREFIX}$vc 2> /dev/null || true
else
$action < ${DEVICE_PREFIX}$vc > ${DEVICE_PREFIX}$vc 2> /dev/null || true
fi
}
setup ()
{
# be sure the main program is installed
which setfont >/dev/null || return
VT="no"
# If we can't access the console, quit
CONSOLE_TYPE=`fgconsole 2>/dev/null` || return
if [ ! $CONSOLE_TYPE = "serial" ]; then
readlink /proc/self/fd/0 | grep -q -e /dev/vc -e '/dev/tty[^p]' -e /dev/console
if [ $? -eq 0 ]; then
VT="yes"
reset_vga_palette
fi
fi
[ $VT = "no" ] && return
# start vcstime
if [ "${DO_VCSTIME}" = "yes" ] && which vcstime >/dev/null; then
[ "$VERBOSE" != "no" ] && log_action_begin_msg "Starting clock on text console"
vcstime &
[ "$VERBOSE" != "no" ] && log_action_end_msg 0
fi
if [ -d /etc/init ] && which initctl >/dev/null; then
# Upstart
LIST_CONSOLES=`cd /etc/init; find -name 'tty*.conf' -printf '%f ' | sed -e 's/[^0-9 ]//g'`
else
# traditional SysV init
LIST_CONSOLES=`sed -e '/^ *#/d' /etc/inittab | grep -e '\<tty[0-9]*\>' | awk -F: '{printf "%s ", $1}'`
fi
# Global default font+map
if [ -z "${HAVE_SETUPCON}" -a "${CONSOLE_FONT}" ]; then
[ "$VERBOSE" != "no" ] && log_action_begin_msg "Setting up general console font"
sfm="${FONT_MAP}" && [ "$sfm" ] && sfm="-u $sfm"
acm="${CONSOLE_MAP}" && [ "$acm" ] && acm="-m $acm"
# Set for the first 6 VCs (as they are allocated in /etc/inittab)
for vc in $LIST_CONSOLES
do
if ! ( unicode_start_stop $vc \
&& setfont -C ${DEVICE_PREFIX}$vc ${SETFONT_OPT} $sfm ${CONSOLE_FONT} $acm )
then
[ "$VERBOSE" != "no" ] && log_action_end_msg 1
break
fi
done
[ "$VERBOSE" != "no" ] && log_action_end_msg 0
fi
# Default to Unicode mode for new VTs?
if [ -f /sys/module/vt/parameters/default_utf8 ]; then
if [ -n "$UNICODE_MODE" ]; then
echo 1
else
echo 0
fi > /sys/module/vt/parameters/default_utf8
fi
# Per-VC font+sfm
PERVC_FONTS="`set | grep "^CONSOLE_FONT_vc[0-9]*=" | tr -d \' `"
if [ -z "${HAVE_SETUPCON}" -a "${PERVC_FONTS}" ]; then
[ "$VERBOSE" != "no" ] && log_action_begin_msg "Setting up per-VC fonts"
for font in ${PERVC_FONTS}
do
# extract VC and FONTNAME info from variable setting
vc=`echo $font | cut -b16- | cut -d= -f1`
eval font=\$CONSOLE_FONT_vc$vc
# eventually find an associated SFM
eval sfm=\${FONT_MAP_vc${vc}}
[ "$sfm" ] && sfm="-u $sfm"
if ! ( unicode_start_stop $vc \
&& setfont -C ${DEVICE_PREFIX}$vc ${SETFONT_OPT} $sfm $font )
then
[ "$VERBOSE" != "no" ] && log_action_end_msg 1
break
fi
done
[ "$VERBOSE" != "no" ] && log_action_end_msg 0
fi
# Per-VC ACMs
PERVC_ACMS="`set | grep "^CONSOLE_MAP_vc[0-9]*=" | tr -d \' `"
if [ -z "${HAVE_SETUPCON}" -a "${PERVC_ACMS}" ]; then
[ "$VERBOSE" != "no" ] && log_action_begin_msg "Setting up per-VC ACM's"
for acm in ${PERVC_ACMS}
do
# extract VC and ACM_FONTNAME info from variable setting
vc=`echo $acm | cut -b15- | cut -d= -f1`
eval acm=\$CONSOLE_MAP_vc$vc
if ! setfont -C "${DEVICE_PREFIX}$vc" ${SETFONT_OPT} -m "$acm"; then
[ "$VERBOSE" != "no" ] && log_action_end_msg 1
break
fi
done
[ "$VERBOSE" != "no" ] && log_action_end_msg 0
fi
# screensaver stuff
setterm_args=""
if [ "$BLANK_TIME" ]; then
setterm_args="$setterm_args -blank $BLANK_TIME"
fi
if [ "$BLANK_DPMS" ]; then
setterm_args="$setterm_args -powersave $BLANK_DPMS"
fi
if [ "$POWERDOWN_TIME" ]; then
setterm_args="$setterm_args -powerdown $POWERDOWN_TIME"
fi
if [ "$setterm_args" ]; then
setterm $setterm_args
fi
# Keyboard rate and delay
KBDRATE_ARGS=""
if [ -n "$KEYBOARD_RATE" ]; then
KBDRATE_ARGS="-r $KEYBOARD_RATE"
fi
if [ -n "$KEYBOARD_DELAY" ]; then
KBDRATE_ARGS="$KBDRATE_ARGS -d $KEYBOARD_DELAY"
fi
if [ -n "$KBDRATE_ARGS" ]; then
[ "$VERBOSE" != "no" ] && log_action_begin_msg "Setting keyboard rate and delay"
kbdrate -s $KBDRATE_ARGS
[ "$VERBOSE" != "no" ] && log_action_end_msg 0
fi
# Inform gpm if present, of potential changes.
if [ -f /var/run/gpm.pid ]; then
kill -s WINCH `cat /var/run/gpm.pid` 2> /dev/null
fi
# Allow user to remap keys on the console
if [ -z "${HAVE_SETUPCON}" -a -r /etc/$PKG/remap ]; then
dumpkeys < ${DEVICE_PREFIX}1 | sed -f /etc/$PKG/remap | loadkeys --quiet
fi
# Set LEDS here
if [ -n "$LEDS" ]; then
for i in $LIST_CONSOLES
do
setleds -D $LEDS < $DEVICE_PREFIX$i
done
fi
}
case "$1" in
start|reload|restart|force-reload)
if [ -n "$HAVE_SETUPCON" ]
then
log_action_msg "Setting console screen modes"
else
log_action_msg "Setting console screen modes and fonts"
fi
setup
[ -z "$HAVE_SETUPCON" ] || log_action_msg "Skipping font and keymap setup (handled by console-setup)"
;;
stop)
;;
*)
setup
;;
esac
:
@@ -1,14 +0,0 @@
Prevent nash-hotplug to keep running after boot using 100% of cpu
diff -rud mkinitrd-6.0.34-orig/nash/hotplug.c mkinitrd-6.0.34/nash/hotplug.c
--- mkinitrd-6.0.34-orig/nash/hotplug.c 2008-03-06 21:20:34.000000000 -0300
+++ mkinitrd-6.0.34/nash/hotplug.c 2008-03-12 18:48:46.000000000 -0300
@@ -547,7 +547,7 @@
nashLogger(nc, NASH_ERROR, "parent exited without telling us\n");
close(nc->hp_childfd);
nc->hp_childfd = -1;
- break;
+ exit(1);
}
count += rc;
}
-20
View File
@@ -1,20 +0,0 @@
#!/bin/sh
# Alternative boot method for other distributions than Debian 6.0
# Place this file in a /etc/start.d/ directory and add the following
# line to /etc/finit.conf:
#
# runparts /etc/start.d
#
# At boot finit will run all files, using its built-in run_parts(),
# in that directory.
#
# Here we chain load Debian /etc/rcS.d and /etc/rc2.d directories
# in sequence using the standard run-parts tool.
run-parts /etc/rcS.d --arg=start
run-parts /etc/rc2.d --arg=start
# You can also place other commands in this services file, akin to
# the old finit /usr/sbin/services.sh (not supported anymore).
#service acpid start
#service networking start
#service ssh start
+62
View File
@@ -0,0 +1,62 @@
HowTo: Finit on Void Linux
==========================
HowTo use Finit to boot an [Void Linux][] system. It is assumed that
the user has already installed make, a compiler, C library header files,
and other tools needed to build a GNU configure based project.
To start with you need to first install [libuEv][] and [libite][]. They
default to install to `/usr/local`, but unlike Debian and Ubuntu based
distros, Void's `pkg-config` does not look for libraries and header
files there. So the `PKG_CONFIG_LIBDIR` environment variable must be
used, or change the install prefix to `/usr`.
The bundled [build.sh](build.sh) script can be used to configure and
build finit:
void:~# cd finit
void:~/finit# ./contrib/void/build.sh
Then run the [install.sh](install.sh) script to install all necessary
files, including the sample `finit.conf` and `finit.d/*.conf` files.
More on that below.
void:~/finit# ./contrib/void/install.sh
The install script is (supposed to be) non-destructive by default, you
have to answer *Yes* twice to set up Finit as the system default init.
Pay close attention to the last question:
*** Install Finit as the system default Init (y/N)?
If you answer `No`, simply by pressing enter, you can change the symlink
yourself later on, to point to `finit` instead of `runit`:
void:~/finit# cd /sbin
void:/sbin# rm init
void:/sbin# ln -s finit init
Another option is to change the Grub defaults, in `/etc/default/grub`:
#GRUB_CMDLINE_LINUX_DEFAULT="loglevel=4 slub_debug=P page_poison=1"
GRUB_CMDLINE_LINUX_DEFAULT="loglevel=4 init=/sbin/finit"
Alternatively, you can simply modify the default Grub entry at boot, or
set up an alternative Grub entry to include:
linux /boot/vmlinuz-X.YY.Z ... init=/sbin/finit
If you modify a Grub configuration file, remember to run:
update-grub
Before rebooting, make sure to set up a [/etc/finit.conf](finit.conf),
and [/etc/finit.d/](finit.d/) for your services. Samples are included
in this directory. Notice the symlinks in `/etc/finit.d/`, which can be
managed by the operator at runtime using `initctl enable SERVICE`. You
can also use a standard [/etc/rc.local](rc.local) for one-shot tasks and
initialization like keyboard language etc.
[libuEv]: https://github.com/troglobit/libuev
[libite]: https://github.com/troglobit/libite
[Void Linux]: https://www.voidlinux.eu/
+39
View File
@@ -0,0 +1,39 @@
#!/bin/sh -e
echo
echo "*** Configuring Finit for Void Linux"
if [ ! -e configure ]; then
echo " The configure script is missing, maybe you're using a version from GIT?"
echo " Attempting to run the autogen.sh script, you will need these tools:"
echo " autoconf, automake, libtool, pkg-config ..."
echo
./autogen.sh
fi
# The plugins are optional, but you may need D-Bus and X11 if you want
# to run X-Window, the other configure flags are however required.
PKG_CONFIG_LIBDIR=/usr/lib/pkgconfig:/usr/local/lib/pkgconfig ./configure \
--enable-rw-rootfs --enable-progress \
--enable-dbus-plugin --enable-x11-common-plugin \
--enable-alsa-utils-plugin --enable-inetd-echo-plugin \
--enable-inetd-chargen-plugin --enable-inetd-daytime-plugin \
--enable-inetd-discard-plugin --enable-inetd-time-plugin \
--with-heading="Void Linux" --with-hostname=void
echo
echo "*** Building ..."
echo
make
if [ $? -ne 0 ]; then
echo
echo "*** The build failed for some reason"
echo
exit 1
fi
echo
echo "*** Done"
echo
+9
View File
@@ -0,0 +1,9 @@
# /etc/finit.conf: Example for Void Linux
# See /etc/finit.d/*.conf and `initctl list` for other services
## Runlevel to start after bootstrap, runlevel 'S'
# Default is 2
#runlevel 2
## Bootstrap services and tasks
# Can be listed here or in /etc/finit.d/*.conf
+1
View File
@@ -0,0 +1 @@
available/acpid.conf
@@ -0,0 +1,3 @@
# Handle PWR button to shutdown/reboot -- useful in Qemu (virt-manager)
# Depends on syslogd having started. Redirect any output to log.
service [2345] /sbin/acpid -f -- ACPI daemon
@@ -0,0 +1 @@
service [2345] <svc/sbin/syslogd> /usr/sbin/crond -f -S -c /etc/crontabs -- Cron daemon
@@ -0,0 +1 @@
service [2345] /usr/sbin/dhcpcd -B -M -- DHCP client
@@ -0,0 +1 @@
service [S12345] /sbin/dmeventd -f -- Device mapper event daemon
@@ -0,0 +1,4 @@
# Consoles to start Finit built-in getty on when system is up
tty /dev/tty1 noclear nowait
tty /dev/tty2 noclear nowait
tty /dev/tty3 noclear nowait
@@ -0,0 +1,2 @@
# Oneshot task to run once at bootstrap
task [S] zcat /etc/keymap/se.bmap.gz | loadkmap -- Loading keymap
@@ -0,0 +1,2 @@
# Start klogd as soon as possible, should always run
service [S12345] /sbin/klogd -n -- Kernel log daemon
+1
View File
@@ -0,0 +1 @@
service [2345] /usr/sbin/lxdm -- Lightweight Login Manager
@@ -0,0 +1,6 @@
## Linux kernel modules to load
#module fbcon
module button
module evdev
module mousedev
module 8139cp
+2
View File
@@ -0,0 +1,2 @@
# Silly Busybox ntpd has no option to use syslog when running in foreground
service [2345] log <svc/sbin/syslogd> /usr/sbin/ntpd -n -N -p pool.ntp.org -- NTP daemon
+2
View File
@@ -0,0 +1,2 @@
# Start SSH daemon as soon as basic networking comes up
service [2345] <net/lo/up> /usr/sbin/sshd -D -- OpenSSH daemon
@@ -0,0 +1,2 @@
# Start syslogd as soon as possible, should always run
service [S12345] /sbin/syslogd -n -- Syslog daemon
@@ -0,0 +1 @@
service @uuidd:uuidd [2345] /sbin/uuidd -F -- UUID generation daemon
+1
View File
@@ -0,0 +1 @@
available/dhcpcd.conf
+1
View File
@@ -0,0 +1 @@
available/getty.conf
+1
View File
@@ -0,0 +1 @@
available/sshd.conf
+1
View File
@@ -0,0 +1 @@
available/uuidd.conf
+53
View File
@@ -0,0 +1,53 @@
#!/bin/sh
if [ "x`id -u`" != "x0" ]; then
echo
echo "*** This script must run as root"
echo
exit 1
fi
# Adjust base directory
if [ -e xbps ]; then
cd ../..
elif [ ! -e autogen.sh ]; then
echo "*** Please run this script from the Finit base directory."
exit 1
fi
echo
echo "*** Install Finit on Void Linux"
echo "========================================================================"
echo "/sbin/finit - PID 1"
echo "/lib/finit/plugins/* - All enabled Finit plugins"
echo "/etc/finit.conf - Finit configuration file"
echo "/etc/finit.d/ - Finit services"
echo "/etc/grub.d/40_custom - Add menu entry to the Grub boot loader"
echo
read -p "Do you want to continue (y/N)? " yorn
if [ "x$yorn" = "xy" -o "x$yorn" = "xY" ]; then
echo
echo "*** Installing Finit files ..."
make install
cd `dirname $0`
for file in finit.conf rc.local; do
install -vbD $file /etc/$file
done
cp -va finit.d /etc/
read -p "*** Install Finit as the system default Init (y/N)? " yorn
if [ "x$yorn" = "xy" -o "x$yorn" = "xY" ]; then
echo "*** Updating /sbin/init symlink --> finit ..."
cd /sbin
rm init
ln -s finit init
fi
echo "*** Done"
echo
else
echo
echo "*** Aborting install."
echo
fi
+7
View File
@@ -0,0 +1,7 @@
#!/bin/sh
# This script is executed once at boot, at the very end,
# right before starting the TTYs.
#
# Each line is run in sequence.
#
# NOTE: Remeber to set the executable bit!
View File
+44
View File
@@ -0,0 +1,44 @@
# Contributor Code of Conduct
As contributors and maintainers of this project, and in the interest of
fostering an open and welcoming community, we pledge to respect all
people who contribute through reporting issues, posting feature
requests, updating documentation, submitting pull requests or patches,
and other activities.
We are committed to making participation in this project a
harassment-free experience for everyone, regardless of level of
experience, gender, gender identity and expression, sexual orientation,
disability, personal appearance, body size, race, ethnicity, age,
religion, or nationality.
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery
* Personal attacks
* Trolling or insulting/derogatory comments
* Public or private harassment
* Publishing other's private information, such as physical or electronic
addresses, without explicit permission
* Other unethical or unprofessional conduct.
Project maintainers have the right and responsibility to remove, edit,
or reject comments, commits, code, wiki edits, issues, and other
contributions that are not aligned to this Code of Conduct. By adopting
this Code of Conduct, project maintainers commit themselves to fairly
and consistently applying these principles to every aspect of managing
this project. Project maintainers who do not follow or enforce the Code
of Conduct may be permanently removed from the project team.
This code of conduct applies both within project spaces and in public
spaces when an individual is representing the project or its community.
Instances of abusive, harassing, or otherwise unacceptable behavior may
be reported by opening an issue or contacting one or more of the project
maintainers.
This Code of Conduct is adapted from the [Contributor Covenant][1],
[version 1.2.0][2].
[1]: http://contributor-covenant.org
[2]: http://contributor-covenant.org/version/1/2/0/
+89
View File
@@ -0,0 +1,89 @@
Contributing to Finit
=====================
We welcome any and all help in the form of bug reports, fixes, patches
for new features -- *preferably as GitHub pull requests*. Other methods
are of course also possible: emailing the maintainer a patch or even a
raw file, or simply emailing a feature request or an alert of a problem.
For email questions/requests/alerts there is always the risk of memory
exhaustion on the part of the maintainer(s).
If you are unsure of what to do, or how to implement an idea or bugfix,
open an issue with `"[RFC: Unsure if this is a bug ... ?"`, or similar,
so we can discuss it. Talking about the code first is the best way to
get started before submitting a pull request.
Either way, when sending an email, patch, or pull request, start by
stating the version the change is made against, what it does, and why.
Please take care to ensure you follow the project coding style and the
commit message format. If you follow these recommendations you help
the maintainer(s) and make it easier for them to include your code.
Coding Style
------------
> **Tip:** Always submit code that follows the style of surrounding code!
First of all, lines are allowed to be longer than 72 characters these
days. In fact, there exist no enforced maximum, but keeping it around
100 chars is OK.
The coding style itself is strictly Linux [KNF][].
Commit Messages
---------------
Commit messages exist to track *why* a change was made. Try to be as
clear and concise as possible in your commit messages, and always, be
proud of your work and set up a proper GIT identity for your commits:
git config --global user.name "Jane Doe"
git config --global user.email jane.doe@example.com
Example commit message from the [Pro Git][gitbook] online book, notice
how `git commit -s` is used to automatically add a `Signed-off-by`:
Brief, but clear and concise summary of changes
More detailed explanatory text, if necessary. Wrap it to about 72
characters or so. In some contexts, the first line is treated as
the subject of an email and the rest of the text as the body. The
blank line separating the ummary from the body is critical (unless
you omit the body entirely); tools like rebase can get confused if
you run the two together.
Further paragraphs come after blank lines.
- Bullet points are okay, too
- Typically a hyphen or asterisk is used for the bullet, preceded
by a single space, with blank lines in between, but conventions
vary here
Signed-off-by: Jane Doe <jane.doe@example.com>
Another good *counter* example [is this][rambling] ...
Code of Conduct
---------------
It is expected of everyone engaging in the project to, in the words of
Bill & Ted; [be excellent to each other][conduct].
[github]: https://github.com/troglobit/finit/
[KNF]: https://en.wikipedia.org/wiki/Kernel_Normal_Form
[gitbook]: https://git-scm.com/book/ch5-2.html
[rambling]: http://stopwritingramblingcommitmessages.com/
[conduct]: https://github.com/troglobit/finit/blob/master/CODE-OF-CONDUCT.md
<!--
-- Local Variables:
-- mode: markdown
-- End:
-->
+22 -13
View File
@@ -12,14 +12,18 @@ finit is to be a replacement for:
* watchdogd
A small and simple replacement, primarily for embedded systems, with a
very low dependency on external packages.
low dependency on external packages. A compliant software is one that
can run as a damon in the foreground. If it can also touch its PID file
after a reconfiguration (`initctl reload`), the Finit dependency system
can also be used.
General
-------
* Add halt/poweroff/shutdown symlinks to finit and convert reboot, but
only install symlinks if these tools don't already exist.
* Add support for `rescue` on the kernel command line, start rescue mode
if enabled with `configure` script. Could mean skip `/etc/finit.conf`
et al and jump straight to a single getty login on console.
* Add support for timed shutdown in Finit, including cancelled shutdown.
* SysV init and systemd use SIGUSR1 to restart their FIFO/D-Bus. Add
API restart to SIGHUP callback for the same functionality in Finit.
@@ -28,19 +32,23 @@ General
* Add `finit.conf` support for ctrl-alt-delete (SIGINT) and kbrequest,
i.e. KeyboardSignal, (SIGWINCH) behavior. Using conditions to a task,
e.g, <sys/key/ctrlaltdel> and <sys/key/signal> like SIGPWR handling.
* Add `IFF_RUNNING` support to netlink plugin along `IFF_IUP`
* Allow process callbacks to be scripts.
* Add support for a pipe/popen where we can listen for `STOP`, `START`
and `RELOAD` on `STDOUT` from a script ... call it for example
`.monitor=` in `svc_t` ... the script named as the basename of the
service it monitors + `.sh`.
* Add `IFF_RUNNING` support to netlink plugin along `IFF_UP`
* Implement `initctl stop|start|restart|reload|status <SVC>` and
`service <SVC> stop|start|restart|reload|status` on top
* Add support for JSON output, or similar, from `initctl show`, e.g.
`initctl show --json`
* Improve output of `initctl show SVC`, list service uptime, last
ten relevant logs, etc. Similar to `systemctl show SVC`
* Add PRE and POST hooks for when switching between runlevels
* Improve `initctl show SVC` output. Add service uptime, last ten SVC
logs/history (historian), etc. Similar to `systemctl show SVC`
* [Solaris SMF][] (Service Management Facility) has some interesting
features that may be well worth looking into adopting:
svcs enable -rt svc:/network/ssh:default
That is: (r)esolve dependencies and only enable ssh (t)emporary
in the default runlevel when networking is available.
* `initctl add /sbin/service -n -- Service description`, for details
see above [Solaris SMF][] featuer, issue #55 and issue #69,
https://github.com/troglobit/finit/issues/69#issuecomment-287907610
Init
@@ -105,8 +113,9 @@ Documentation
how close Finit3 still is to the original easy-to-use Finit0 :)
[libwdt]: http://www.wehavemorefun.de/fritzbox/Libwdt.so
[libwdt]: http://www.wehavemorefun.de/fritzbox/Libwdt.so
[Fritz!Box source dump]: ftp://ftp.avm.de/fritz.box/fritzbox.fon_wlan_7170/x_misc/opensrc/
[Solaris SMF]: http://www.oracle.com/technetwork/articles/servers-storage-admin/intro-smf-basics-s11-1729181.html
<!--
-- Local Variables:
+37 -34
View File
@@ -1,41 +1,51 @@
Bootstrap
=========
1. Populate `/dev`
2. Parse `/etc/finit.conf`
3. Load all `.so` plugins
4. Remount/Pivot `/` to get R+W
5. Call 1st level hooks, `HOOK_ROOTFS_UP`
6. Mount `/etc/fstab` and swap, if available
7. Cleanup stale files from `/tmp/*` et al
8. Enable SysV init signals
9. Call 2nd level hooks, `HOOK_BASEFS_UP`
10. Start all 'S' runlevel tasks and services
11. Load kernel params from `/etc/sysctl.d/*.conf`, `/etc/sysctl.conf`
et al. (Supports all locations that SysV init does.)
12. Set hostname and bring up loopback interface
13. Call `network` script, if set in `/etc/finit.conf`
14. Call 3rd level hooks, `HOOK_NETWORK_UP`
15. Switch to the configured runlevel from `/etc/finit.conf`, default 2.
1. Prepare emergency shell, if enabled
2. Set up initial signal handlers
3. Set up default $PATH early
4. Mount `/proc` and `/sys`
5. Check kernel command line for `--debug` to figure out log level
6. Load all `.so` plugins
7. Call `fsck` on file systems listed in `/etc/fstab`
8. Populate `/dev` using either udev or mdev, depending on system type
9. Parse `/etc/finit.conf` and all `/etc/finit.d/*.conf` files
10. Start built-in watchdog, if enabled
11. Set hostname
12. Pivot root, or remount `/` read-write, depending on system type
13. Call 1st level hooks, `HOOK_ROOTFS_UP`
14. Mount all file systems listed in `/etc/fstab` and swap, if available
15. Enable SysV init signals
16. Call 2nd level hooks, `HOOK_BASEFS_UP`
17. Cleanup stale files from `/tmp/*` et al, handled by `bootmisc` plugin
18. Load kernel params from `/etc/sysctl.d/*.conf`, `/etc/sysctl.conf`
et al. (Supports all locations that SysV init does.), handled by
`procps` plugin
19. Start all 'S' runlevel tasks and services
20. Bring up loopback interface and all `/etc/network/interfaces`, if
the `.conf` setting `network <SCRIPT>` is set, it is called instead
21. Call 3rd level hooks, `HOOK_NETWORK_UP`
22. Switch to the configured runlevel from `/etc/finit.conf`, default 2.
At every runlevel change all `*.conf` files in `/etc/finit.d/` are
(re)loaded and new services, tasks, and blocking run commands are
started. Provided they are allowed in the new runlevel and all of
their conditions, if any, are set.
16. Call 4th level hooks, `HOOK_SVC_UP`
17. If `runparts <DIR>` is set, [run-parts(8)][] is called on `<DIR>`
18. Call `/etc/rc.local`, if it exists and is an executable shell script
19. Call 5th level (last) hooks, `HOOK_SYSTEM_UP`
20. Start TTYs defined in `/etc/finit.conf`, or rescue on `/dev/console`
23. Call 4th level hooks, `HOOK_SVC_UP`
24. If `runparts <DIR>` is set, [run-parts(8)][] is called on `<DIR>`
25. Call `/etc/rc.local`, if it exists and is an executable shell script
26. Call 5th level (last) hooks, `HOOK_SYSTEM_UP`
27. Start all configured TTYs, or a fallback shell on `/dev/console`
In (10) and (15) tasks and services defined in `/etc/finit.conf` are
started. Remember, all `service` and `task` stanzas are started in
parallel and `run` in sequence, and in the order listed. Hence, to
emulate a SysV `/etc/init.d/rcS` one could write a long file with only
`run` statements.
In (19) and (22) tasks and services defined in `/etc/finit.conf` and
`/etc/sysctl.d/*.conf` are started. Remember, all `service` and `task`
stanzas are started in parallel and `run` in sequence, and in the order
listed. Hence, to emulate a SysV `/etc/init.d/rcS` one could write a
long `finit.conf` with only `run` statements.
Notice the five hook points that are called at various point in the
bootstrap process. This is where plugins can extend the boot in any way
they please.
they please. There are other hook points, e.g. `HOOK_MOUNT_ERROR`, for
more on this see [plugins.md](plugins.md).
For instance, at `HOOK_BASEFS_UP` a plugin could read an XML file from a
USB stick, convert/copy its contents to the system's `/etc/` directory,
@@ -43,11 +53,4 @@ well before all 'S' runlevel tasks are started. This could be used with
system images that are created read-only and all configuration is stored
on external media.
[run-parts(8)]: http://manpages.debian.org/cgi-bin/man.cgi?query=run-parts
<!--
-- Local Variables:
-- mode: markdown
-- End:
-->
+87 -32
View File
@@ -1,30 +1,45 @@
Building
========
* [Introduction](#introduction)
* [Configure](#configure)
* [Example](#example)
* [Running](#running)
* [Debugging](#debugging)
Introduction
------------
Finit comes with a traditional configure script to control features and
optional plugins to enable. It does however depend on two external
libraries that provide some frog DNA needed:
optional plugins to enable. It depends on two external libraries:
- [libuEv][]
- [libite][] (-lite)
- [libuEv][], the event loop
- [libite][] (-lite), much needed frog DNA
Like most free/open source software that uses `configure` they deafult
to install to `/usr/local`. However, some Linux distributions do no
longer search that path for installed software, e.g. Fedora and Alpine
Linux. To get finit's configure script to find its dependencies you
have to help the `pkg-config` tool a bit if you do not change the
default prefix path:
**NOTE:** Most free/open source software that uses `configure` default
to install to `/usr/local`. However, some Linux distributions do no
longer search that path for installed software, e.g. Fedora and Alpine
Linux. To get finit's configure script to find its dependencies you
have to help the `pkg-config` tool a bit if you do not change the
default prefix path:
PKG_CONFIG_LIBDIR=/usr/local/lib/pkgconfig ./configure
Below are a few of the main switches to
configure:
The configure script checks for all dependencies, including the correct
version of the above mentioned libraries. Currently requried versions:
- libite v2.0.1
- libuEv v2.1.0
Configure
---------
Below are a few of the main switches to configure:
* `--disable-inetd`: Disable the built-in inetd server.
* `--enable-embedded`: Target finit for BusyBox getty and mdev instead
of a standard Linux distribution with GNU tools and udev.
* `--enable-rw-rootfs`: Most desktop and server systems boot with the
root file stystem read-only. With this setting Finit will remount it
as read-write early at boot so the `bootmisc.so` plugin can run.
@@ -34,19 +49,21 @@ configure:
built-ins (.o files) and all external libraries, except the C library
will be linked statically.
* `--enable-alsa-utils`: Enable the optional `alsa-utils.so` sound plugin.
* `--enable-alsa-utils-plugin`: Enable the optional `alsa-utils.so` sound plugin.
* `--enable-dbus`: Enable the optional D-Bus `dbus.so` plugin.
* `--enable-dbus-plugin`: Enable the optional D-Bus `dbus.so` plugin.
* `--enable-lost`: Enable noisy example plugin for `HOOK_SVC_LOST`.
* `--enable-lost-plugin`: Enable noisy example plugin for `HOOK_SVC_LOST`.
* `--enable-resolvconf`: Enable the `resolvconf.so` optional plugin.
* `--enable-resolvconf-plugin`: Enable the `resolvconf.so` optional plugin.
* `--enable-x11-common`: Enable the optional X Window `x11-common.so` plugin.
* `--enable-x11-common-plugin`: Enable the optional X Window `x11-common.so` plugin.
For more configure flags, see <kbd>./configure --help</kbd>
**Example**
Example
-------
First, unpack the archive:
@@ -58,7 +75,7 @@ First, unpack the archive:
Then configure, build and install:
```shell
$ ./configure --enable-embedded --enable-rw-rootfs --enable-inetd-echo-plugin \
$ ./configure --enable-rw-rootfs --enable-inetd-echo-plugin \
--enable-inetd-chargen-plugin --enable-inetd-daytime-plugin \
--enable-inetd-discard-plugin --enable-inetd-time-plugin \
--with-heading="Alpine Linux 3.4" --with-hostname=alpine
@@ -75,10 +92,10 @@ staging directory. The environment variable `DESTDIR` controls the
destination directory when installing, very useful for building binary
standalone packages.
To target an embedded Linux system, usally a system that use BusyBox
tools instead of udev & C:o, add <kbd>--enable-embedded</kbd> to the
configure command above. This enables `mdev` instead of `udev` and the
BusyBox `getty` syntax. Remember to also change the Linux config to:
Finit 3.0 and later can detect if it runs on an embedded system, or a
system that use BusyBox tools instead of udev & C:o. On such systems
`mdev` instead of `udev` is used. However, remember to also change the
Linux config to:
CONFIG_UEVENT_HELPER_PATH="/sbin/mdev"
@@ -88,12 +105,50 @@ BusyBox `getty` syntax. Remember to also change the Linux config to:
system `/etc/fstab`.
Running
-------
Having successfully built Finit it is now be time to take it for a test
drive. The `make install` attempts to set up finit as the system system
init, `/sbin/init`, but this is usually a symlink pointing to the
current init.
So either change the symlink, or change your boot loader (GRUB, LOADLIN,
LILO, U-Boot/Barebox or RedBoot) configuration to append the following
to the kernel command line:
```shell
append="init=/sbin/finit"
```
Remember to also set up an initial `/etc/finit.conf` before rebooting!
Debugging
---------
Add `finit_debug`, or `--debug`, to the kernel command line to enable
debug messages.
```shell
append="init=/sbin/finit --debug"
```
To debug startup issues, in particular issues with getty/login, try
`configure --enable-fallback-shell`. When no TTYs are detected, and
Finit is configured with this option, Finit will try to start a bare
`/bin/sh` on the boot console. Remember, this is only for debugging
and would leave your production system potentially wide open.
There is also a rescue shell available, in case Finit crashes and the
kernel usually reboots: `configure --enable-emergency-shell`. However,
the behavior of Finit is severely limited when this is enabled, so use
it only for debugging start up issues when Finit crashes.
**NOTE:** Neither of these two configure options should be enabled on
production systems since they can potentially give a user root access.
[1]: ftp://troglobit.com/finit/finit-3.0.tar.xz
[libuEv]: https://github.com/troglobit/libuev
[libite]: https://github.com/troglobit/libite
<!--
-- Local Variables:
-- mode: markdown
-- End:
-->
+47 -34
View File
@@ -3,10 +3,6 @@ Finit Conditions
![The service state machine](svc-machine.png "The service state machine")
Table of Contents
-----------------
* [Introduction](#introduction)
* [Triggering](#triggering)
* [Built-in Conditions](#built-in--conditions)
@@ -17,15 +13,22 @@ Table of Contents
Introduction
------------
In addition to declaring allowed runlevels per service, it is also
possible to declare user-defined conditions as dependencies. Conditions
are specified within angle brackets (<>) in the service stanza.
Multiple conditions may be specified separated by comma. Conditions are
AND'ed during evaluation, i.e. all conditions must be satisfied in order
for a service to run.
Conditions are a new addition to Finit, introduced in v3, with the
intention of providing a mechanism for common synchronization problems.
For example:
- *"do not start this service until another process has started"*, or
- *"do not starty until basic network access is available"*
Conditions are similar in syntax to declaring runlevels per service.
They are specified within angle brackets `<>` and can be applied to any
of the `service`, `task`, or `run` stanza. Multiple conditions may be
specified separated by comma. Multiple conditions are logically AND'ed
during evaluation, i.e. all conditions must be satisfied in order for a
service to run.
**Example:**
### Example
```shell
service [2345] <svc/sbin/setupd,svc/sbin/zebra> /sbin/netd -- Network monitor
@@ -34,14 +37,19 @@ for a service to run.
In this example the Network monitor daemon `netd` is not started until
both the `svc/sbin/setupd` *and* `svc/sbin/zebra` conditions are
satisfied. An `svc` condition is satisfied by the corresponding
service's pidfile being created.
service's PID file being created.
**NOTE:** Conditions also stop services when a condition is no longer
asserted. I.e., if the Zebra process above stops or restarts, netd
will also stop or restart.
Triggering
----------
Conditions are triggered either by plugins or by using the `cond`
command of the `initctl` control tool.
Conditions are triggered by built-in plugins, but can for debugging
purposes also be controlled using the `cond set` and `cond clear`
sub-commands to the `initctl` control tool:
* `initctl cond set your/cond/here`
@@ -53,31 +61,33 @@ command of the `initctl` control tool.
Conditions retain their current state until the next reconfiguration or
runlevel change. At that point all set conditions transition into the
`flux` state, meaning the condition's state is unknown. (See
[Internals](#internals) for the rationale behind this.) Thus, after a
reconfiguration it is up to the "owner" of the condition to convey the
new (or possibly unchanged) state of it.
`flux` state, meaning the condition's state is unknown. (For more info
on this, see [Internals](#internals).) Thus, after a reconfiguration it
is up to the "owner" of the condition to convey the new (or possibly
unchanged) state of it.
Built-in Conditions
-------------------
Finit is distributed with a `pidfile` and `netlink` plugin. If enabled,
the `pidfile` plugin watches `/var/run/` for PID files created by
the `pidfile` plugin watches `/var/run/` for PID files created by the
monitored services, and sets a corresponding condition in the `svc/`
namespace. Similarily, the `netlink` plugin provides basic conditions
for when an interface is brought up/down and when a default route
(gateway) is set.
(gateway) is set, in the `net/` namespace.
With the example listed above, finit does not start the `/sbin/netd`
daemon until `setupd` and `zebra` has started *and* created their PID
files. Which they do when they completed their main tasks of setting up
VLANs, bridge, interfaces, etc. When `netd` in turn starts up it
creates the file `/var/run/netd.pid`, and the condition `svc/sbin/netd`
is satisfied. When the file is removed, the condition is cleared.
files. Which they do when they have completed their initial set up and
are ready to receive signals.
The full path to the dependency is needed by finit to match the PID file
to a monitored process.
to a monitored process. Finit expects monitored services to touch their
PID files, i.e. update the mtime, when they reload their configuration
files after a `SIGHUP`. Some services do not support `SIGHUP` and are
instead restarted, which is a crude but effective way to have the PID
file touched (re-created).
Built-in conditions:
@@ -86,7 +96,9 @@ Built-in conditions:
- `net/<IFNAME>/exist`
- `net/<IFNAME>/up`
Note: `up` is administratively up, `IFF_UP`, not link up, `IFF_RUNNING`.
**Note:** `up` means administratively up, the interface flag `IFF_UP`,
not link up, `IFF_RUNNING`. This latter conditions is currently not
implemented by the `plugins/netlink.c` plugin.
Debugging
@@ -127,14 +139,21 @@ Then watch the console for the debug messages and then check the output
from `initctl cond show` again. (The client will likely have failed to
start, but at least the condition is now satisfied.)
There is also the `initctl cond dump` command, which dumps all known
conditions and their current status.
Internals
---------
Conditions are implemented as simple files in the file system, in the
`/var/run/finit/cond/` sub-directory. Use the `initctl cond set/clear`
commands to add/remove files in this hierarchy.
A condition is always in one of three states:
* `on` (+): The condition is asserted.
* `off` (-): The condition is deasserted.
* ` on` (+): The condition is asserted.
* ` off` (-): The condition is deasserted.
* `flux` (~): The conditions state is unknown.
All conditions that have not explicitly been set are interpreted as
@@ -154,9 +173,3 @@ Therefore, any plugin that supplies Finit with conditions must ensure
that their state is updated after each reconfiguration. This can be
done by binding to the `HOOK_SVC_RECONF` hook. For an example of how
to do this, see `plugins/pidfile.c`.
<!--
-- Local Variables:
-- mode: markdown
-- End:
-->
+153 -85
View File
@@ -1,34 +1,49 @@
Configuration
=============
Table of Contents
-----------------
* [Introduction](#introduction)
* [Syntax](#syntax)
* [Limitations](#limitations)
* [/etc/finit.conf](#etcfinitconf)
* [/etc/finit.d](#etcfinitd)
* [/etc/finit.conf](#etcfinitconf)
* [/etc/finit.d](#etcfinitd)
/etc/finit.conf
---------------
Introduction
------------
Contrary to most other script based init alternatives (SysV [init][],
[upstart][], [systemd][], [OpenRC][], etc.) Finit relies on its main
configuration file `/etc/finit.conf` and `/etc/finit.d/`.
Finit can be configured using only the original `/etc/finit.conf` file
or in combination with `/etc/finit.d/*.conf`. Finit 3 can even start a
system using only `/etc/finit.d/*.conf`, highly useful for package-based
Linux distributions -- each package can provide its own "script" file.
The command line arguments given in `/etc/finit.conf` to each service
provide a default. A plugin can be used to register a callback to a
service and then modify the behavior to suit the current runlevel and
system configuration.
- `/etc/finit.conf`: main configuration file, read only once at boot
- `/etc/finit.d/*.conf`: snippets, usually one service per file
For instance, before starting a heavily resource intensive service like
IPsec or OpenVPN, a callback can check if the outbound interface is up
and has an IP address, or just check if the service is disabled — much
like what a SysV init start script usually does.
Not all configuration directives are available in `/etc/finit.d/*.conf`
and some directives are only available at bootstrap, runlevel `S`, see
the section [Limitations](#limitations) below for details.
Syntax:
To add a new service, simply drop a `.conf` file in `/etc/finit.d` and
run `initctl reload`. (It is also possible to `SIGHUP` to PID 1, or
call `finit q`, but that has been deprecated with the `initctl` tool).
Any service read from this directory is flagged as a dynamic service, so
changes to or removal of `/etc/finit.d/*.conf` files, is detected.
* `check <DEV>`
Run fsck on a file system. Only needed if not listed in `/etc/fstab`,
Finit 3.0 and later check all file systems automatically at boot.
On `initctl reload` the following is checked for all services:
- If a service's `.conf` file has been removed, or its conditions are no
longer satisifed, the service is stopped.
- If the file is modified, or a service it depends on has been reloaded,
the service is reloaded (stopped and started).
- If a new service is added it is automatically started — respecting
runlevels and return values from any callbacks.
For more info on the different states of a service, see the separate
document [Finit Services](service.md).
Syntax
------
* `module <MODULE>`
Load a kernel module, with optional arguments
@@ -36,15 +51,15 @@ Syntax:
* `network <PATH>`
Script or program to bring up networking, with optional arguments
* `rlimit <hard|soft> RESOURCE <LIMIT|infinity>`
Modify the specified resource's hard or soft limit to be the
specifed limit. `RESOURCE` is a lower-case string matching the
constants in `setrlimit(2)` with the `RLIMIT_` prefix
removed. E.g. to select `RLIMIT_CPU`, `RESOURCE` would be
`cpu`. `LIMIT` is an integer whose unit depends on the resource
being modified, see `setrlimit(2)` for more information. The special
limit `infinity` means the there should be no limit on the resource,
i.e. `RLIM_INFINITY` is passed to `setrlimit(2)`.
* `rlimit <hard|soft> RESOURCE <LIMIT|unlimited>`
Set the hard or soft limit for a resource. `RESOURCE` is a lower-case
string matching the `RLIMIT_` constants from `setrlimit(2)`, without
the prefix. E.g. to set `RLIMIT_CPU`, use `cpu`.
The limit is an integer that depends on the resource being modified,
see the man page, or the kernel `/proc/PID/limits` file, for more
information. Finit versions before v3.1 used `infinity` for
`unlimited`, which is still a supported keyword.
```shell
# No process is allowed more than 8MB of address space
@@ -60,11 +75,20 @@ Syntax:
* `run [LVLS] <COND> /path/to/cmd ARGS -- Optional description`
One-shot command to run in sequence when entering a runlevel, with
optional arguments and description. This command is guaranteed to be
completed before running the next command.
optional arguments and description.
`run` commands are guaranteed to be completed before running the next
command. Highly useful if true serialization is needed.
* `task [LVLS] <COND> /path/to/cmd ARGS -- Optional description`
One-shot like 'run', but starts in parallel with the next command
One-shot like 'run', but starts in parallel with the next command.
Both `run` and `task` commands are run in a shell, so pipes and
redirects can be freely used:
```shell
task [s] echo "foo" | cat >/tmp/bar
```
* `service [LVLS] <COND> /path/to/daemon ARGS -- Optional description`
Service, or daemon, to be monitored and automatically restarted if it
@@ -76,6 +100,13 @@ Syntax:
service [2345] <svc/sbin/zebra> /sbin/ospfd -- OSPF daemon
```
The `[2345]` is the runlevels `ospfd` is allowed to run in, they are
optional and default to level 2-5 if left out.
The `<...>` is the condition for starting `ospfd`. In this example
Finit waits for another service, `/sbin/zebra`, to have created its
PID file in `/var/run/zebra.pid` before starting `ospfd`.
For a detailed description of conditions, and how to debug them,
see the [Finit Conditions](conditions.md) document.
@@ -121,26 +152,68 @@ Syntax:
* `include <CONF>`
Include another configuration file. Absolute path required.
* `tty [LVLS] <DEV> [BAUD] [TERM]`
Start a getty on the given TTY device DEV, in the given runlevels. If
no tty setting is given in `finit.conf` no login is possible. Use the
`service` stanza to start a stand-alone shell for really bare bones
systems.
* `tty [LVLS] <DEV> [BAUD] [noclear] [nowait] [TERM]`
`tty [LVLS] <CMD> <ARGS> [noclear] [nowait]`
The first variant of this option uses the built-in getty on the given
TTY device DEV, in the given runlevels. Default baud rate is `38400`.
Finit comes with a lightweight built-in getty, which after it has
opened a TTY and the user has input a username, calls `/bin/login`
like any other getty.
**Example:**
```conf
tty [12345] /dev/ttyAMA0 115200 noclear vt220
```
* `console <DEV>`
Use this, along with a matching `tty DEV` line, to mark this TTY as a
special "console" port with with `prctl()`. Useful in use-cases when
all logins except the console must be stopped, e.g. when performing a
flash upgrade on an embedded system.
The second `tty` syntax variant is for using an external getty, like
agetty or the BusyBox getty.
By default both variants *clear* the TTY and *wait* for the user to
press enter before starting getty.
**Example:**
```conf
tty [12345] /sbin/getty -L 115200 /dev/ttyAMA0 vt100
tty [12345] /sbin/agetty -L ttyAMA0 115200 vt100 nowait
```
The `noclear` option disables clearing the TTY after each session.
Clearing the TTY when a user logs out is usually preferable.
The `nowait` option disables the `press Enter to activate console`
message before actually starting the getty program. On small and
embedded systems running multiple unused getty wastes both memory
and CPU cycles, so `wait` is the preferred default.
Notice the ordering, the `TERM` option to the built-in getty must be
the last argument.
Embedded systems may want to enable automatic `DEV` by supplying the
special `@console` device. This works regardless weather the system
uses `ttyS0`, `ttyAMA0`, `ttyMXC0`, or anything else. Finit figures
it out by querying sysfs: `/sys/class/tty/console/active`.
**Example:**
```conf
tty [12345] @console 115200 noclear vt220
```
On really bare bones systems Finit offers a fallback shell, which
should not be enabled on production systems since. This because it
may give a user root access without having to log in. However, for
bringup and system debugging it can come in handy:
```shell
configure --enable-fallback-shell
```
One can also use the `service` stanza to start a stand-alone shell:
```conf
service [12345] /bin/sh -l
```
When running <kbd>make install</kbd> no default `/etc/finit.conf` will
be installed since system requirements differ too much. Try out the
Debian 6.0 example `/usr/share/doc/finit/finit.conf` configuration that
is capable of service monitoring SSH, sysklogd, gdm and a console getty!
is capable of service monitoring SSH, sysklogd, gdm and getty!
Every `run`, `task`, `service`, or `inetd` can also list the privileges
the `/path/to/cmd` should be executed with. Simply prefix the path with
@@ -170,50 +243,45 @@ Worth noting is that conditions is allowed for all these stanzas. For a
detailed description, see the [Conditions](conditions.md) document.
/etc/finit.d
------------
Limitations
-----------
Finit supports changes to the overall system configuration at runtime.
For this purpose the (configurable) directory `/etc/finit.d` is used.
Here you can put configuration file snippets, one per service if you
like, which are all sourced automatically by finit at boot when loading
the static configuration from `/etc/finit.conf`. This is the default
behavior, so no include directives are necessary.
To understand the limitations of `finit.conf` vs `finit.d` it is useful
to picture the different phases of the system: bootstrap, runtime, and
shutdown. The `finit.conf` file can be used for all possible settings,
but `finit.d/*.conf` can only be used for runtime settings.
To add a new service, simply drop a `.conf` file in `/etc/finit.d` and
run `initctl reload`. (It is also possible to `SIGHUP` to PID 1, or
call `finit q`, but that has been deprecated with the `initctl` tool).
Any service read from this directory is flagged as a dynamic service, so
changes to or removal of `/etc/finit.d/*.conf` files, is detected.
### /etc/finit.conf
On `initctl reload` the following is checked for all services:
This file was the only way to set up and boot a system using Finit. It
is used for pre-runtime settings like system hostname, network bringup
and shutdown:
- If a service's `.conf` file has been removed, or its conditions are no
longer satisifed, the service is stopped.
- If the file is modified, or a service it depends on has been reloaded,
the service is reloaded (stopped and started).
- If a new service is added it is automatically started — respecting
runlevels and return values from any callbacks.
- `host`
- `mkdod`
- `network`
- `runparts`
- `include`
- `shtudown`
- `runlevel`
- ... and all configuration stanzas from `/etc/finit.d` below
For more info on the different states of a service, see the separate
document [Finit Services](service.md).
### /etc/finit.d
The `/etc/finit.d` directory was previously the default Finit `runparts`
directory. Finit no longer has a default `runparts`, so make sure to
update your setup, or the finit configuration, accordingly.
Support for partial `.conf` files in `/etc/finit.d` was added to handle
changes of the system configuration at runtime. It does *not support*
the above `finit.conf` settings described above, only the following:
**Note:** Configurations read from `/etc/finit.d` are read *after*
initial bootstrap, runlevel S(1). Hence, bootstrap services *must* be
in `/etc/finit.conf`!
- `module`, but only in runlevel `S`
- `service`
- `task`
- `run`
- `inetd`
- `rlimit`
- `tty`
**NOTE:** The `/etc/finit.d` directory was previously the default Finit
`runparts` directory. Finit no longer has a default `runparts`, make
sure to update your setup, or the finit configuration, accordingly.
[init]: http://en.wikipedia.org/wiki/Init
[upstart]: http://upstart.ubuntu.com/
[systemd]: http://www.freedesktop.org/wiki/Software/systemd/
[openrc]: http://www.gentoo.org/proj/en/base/openrc/
[run-parts(8)]: http://manpages.debian.org/cgi-bin/man.cgi?query=run-parts
<!--
-- Local Variables:
-- mode: markdown
-- End:
-->
+75
View File
@@ -0,0 +1,75 @@
Distro Recommendations
======================
By default Finit uses the following directories for configuration files:
```
/etc/
|-- finit.d/ -- Regular (enabled) services
| |-- lighttpd.conf
| `- *.conf
|-- finit.conf -- Bootstrap tasks and services
:
```
To enable a service one simply drops a small configuration file in the
`/etc/finit.d/` directory. This practice works will with systems that
keep disabled services elsewhere, or generates them as needed from some
other tool.
Disitributions, however, may want a clearer separation of enabled and
available (installed but not enabled) services. They may even want to
customize the directories used, for brand labling or uniformity.
To that end Finit allows for a sub-directory `/etc/finit.d/available/`
where installed but disabled services can reside. Adding a symlink to a
configuration in this sub-directory enables the service, but it will not
be started.
To change the default configuration directory and configuration file
names the Finit `configure` script offers the following two options at
build time:
```sh
./configure --with-rcsd=/etc/init.d --with-config=/etc/init.d/init.conf
```
The resulting directory structure is depicted below. Please notice how
`/etc/finit.conf` now resides in the same sub-directory as a non-symlink
`/etc/init.d/init.conf`:
```
/etc/
|-- init.d/
| |-- available/ -- Regular (disabled) services
| | |-- httpd.conf
| | |-- ntpd.conf
| | `-- sshd.conf
| |-- sshd.conf -- Symlink to available/sshd.conf
| `- init.conf -- Bootstrap tasks and services
:
```
To facilitate the task of managing configurations, be it a service,
task, run, or other stanza, the `initctl` tool has a a few built-in
commands:
```
list List all .conf in /etc/finit.d/
enable <CONF> Enable .conf in /etc/finit.d/available/
disable <CONF> Disable .conf in /etc/finit.d/[enabled/]
reload Reload *.conf in /etc/finit.d/ (activates changes)
```
To enable a service like `sshd.conf`, above, use
initctl enable sshd
The `.conf` suffix is not needed, `initctl` adds it implicitly if it is
missing. The `disable` command works in a similar fashion.
Note, however, that `initctl` only operates on symlinks and it always
requires the `available/` sub-directory. Any non-symlink in the parent
directory, here `/etc/init.d/`, will be considered a system override by
`initctl`.
-6
View File
@@ -123,9 +123,3 @@ some NTP implementations), year 2036!
[TCP Wrappers]: https://en.wikipedia.org/wiki/TCP_Wrapper
<!--
-- Local Variables:
-- mode: markdown
-- End:
-->
+6 -7
View File
@@ -1,6 +1,12 @@
Hooks & Plugins
===============
* [Plugins](#plugins)
* [Hooks](#hooks)
* [Bootstrap Hooks](#bootstrap-hooks)
* [Runtime Hooks](#runtime-hooks)
* [Shutdown Hooks](#shutdown-hooks)
Finit can be extended to add general functionality in the form of I/O
monitors, built-in inetd services, or hook plugins.
@@ -123,10 +129,3 @@ Plugins like `initctl.so` and `tty.so` extend finit by acting on events,
they are called I/O plugins and are called from the finit main loop when
`poll()` detects an event. See the source code for `plugins/*.c` for
more help and ideas.
<!--
-- Local Variables:
-- mode: markdown
-- End:
-->
+4 -9
View File
@@ -14,8 +14,9 @@ state.
The current state depends on the two following conditions:
* `E`: Service enabled. In order for `E` to be satisfied, the service
must be allowed to run in the current runlevel and must not be
blocked. A service may be blocked for several reasons:
must be allowed to run in the current runlevel and not be stopped.
A service may be stopped, or blocked, for several reasons:
- The user has manually stopped the service using `initctl stop JOB`
- The program exits immediately. I.e. keeps crashing (make sure to use
@@ -26,13 +27,7 @@ The current state depends on the two following conditions:
- `on` (+): The condition is asserted.
- `off` (-): The condition is deasserted.
- `flux` (~): The conditions state is unknown.
- `flux` (~): The condition state is unknown.
For a detailed description of conditions, and how to debug them,
see the [Finit Conditions](conditions.md) document.
<!--
-- Local Variables:
-- mode: markdown
-- End:
-->
+6 -11
View File
@@ -6,12 +6,13 @@ Though Finit comes with its own tools for (poweroff, halt, reboot), for
compatibility with the existing BusyBox toolset the following signals
have been adopted:
* `SIGHUP`
Same effect as `finit q`, `init q`, or `initctl reload`, reloads all
*.conf files in `/etc/finit.d/`
* `SIGUSR1`
Same effect as `finit q`, reloads all *.conf files in `/etc/finit.d/`
* `SIGUSR1`
Calls shutdown hooks, including HOOK_SHUTDOWN, stops all running
processes, and unmounts all file systems. Then tells kernel to
halt. Most people these days want SIGUSR2 though.
Calls shutdown hooks, including `HOOK_SHUTDOWN`, stopping all running
processes, and unmounts all file systems. Then tells kernel to halt.
Most people these days want `SIGUSR2` though.
SysV init and systemd use this to re-open their FIFO/D-Bus.
* `SIGUSR2`
@@ -33,9 +34,3 @@ have been adopted:
UPS status. Traditionally SysV init read /etc/powerstatus and
acted on "OK", "FAIL", or "LOW" and then removed the file.
Finit currently forwards this to `SIGUSR2`.
<!--
-- Local Variables:
-- mode: markdown
-- End:
-->
Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

-516
View File
@@ -1,516 +0,0 @@
/* New client tool, complements old /dev/initctl API and telinit tool
*
* Copyright (c) 2015-2016 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
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <err.h>
#include <ctype.h>
#include <getopt.h>
#include <glob.h>
#include <paths.h>
#include <signal.h>
#include <stdio.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <lite/lite.h>
#include "config.h"
#include "finit.h"
#include "cond.h"
#include "helpers.h"
#include "service.h"
#include "util.h"
#include "utmp-api.h"
#define _PATH_COND _PATH_VARRUN "finit/cond/"
typedef struct {
char *cmd;
int (*cb)(char *arg);
} command_t;
int debug = 0;
int verbose = 0;
int silent = 1; /* For helpers.c */
int runlevel = 0;
static int do_send(struct init_request *rq, ssize_t len)
{
int sd, result = 255;
struct sockaddr_un sun = {
.sun_family = AF_UNIX,
.sun_path = INIT_SOCKET,
};
sd = socket(AF_UNIX, SOCK_STREAM, 0);
if (-1 == sd)
return -1;
if (connect(sd, (struct sockaddr*)&sun, sizeof(sun)) == -1)
goto error;
if (write(sd, rq, len) != len)
goto error;
if (read(sd, rq, len) != len)
goto error;
result = 0;
goto exit;
error:
perror("Failed communicating with finit");
exit:
close(sd);
return result;
}
static int runlevel_get(void)
{
int sd, result = 255;
struct init_request rq;
struct sockaddr_un sun = {
.sun_family = AF_UNIX,
.sun_path = INIT_SOCKET,
};
memset(&rq, 0, sizeof(rq));
rq.cmd = INIT_CMD_GET_RUNLEVEL;
rq.magic = INIT_MAGIC;
sd = socket(AF_UNIX, SOCK_STREAM, 0);
if (-1 == sd)
return -1;
if (connect(sd, (struct sockaddr*)&sun, sizeof(sun)) == -1)
goto error;
if (write(sd, &rq, sizeof(rq)) != sizeof(rq))
goto error;
if (read(sd, &rq, sizeof(rq)) != sizeof(rq))
goto error;
result = rq.runlevel;
goto exit;
error:
perror("Failed communicating with finit");
result = -1;
exit:
close(sd);
return result;
}
static int toggle_debug(char *UNUSED(arg))
{
struct init_request rq = {
.magic = INIT_MAGIC,
.cmd = INIT_CMD_DEBUG,
};
return do_send(&rq, sizeof(rq));
}
static int do_runlevel(char *arg)
{
struct init_request rq = {
.magic = INIT_MAGIC,
.cmd = INIT_CMD_RUNLVL,
.runlevel = (int)arg[0],
};
/* Not compatible with the SysV runlevel(8) command, it prints
* "PREVLEVEL RUNLEVEL", we just print the current runlevel. */
if (!rq.runlevel) {
printf("%d\n", runlevel_get());
return 0;
}
return do_send(&rq, sizeof(rq));
}
static int do_svc(int cmd, char *arg)
{
struct init_request rq = {
.magic = INIT_MAGIC,
.cmd = cmd,
};
strlcpy(rq.data, arg, sizeof(rq.data));
return do_send(&rq, sizeof(rq));
}
static int do_emit (char *arg) { return do_svc(INIT_CMD_EMIT, arg); }
static int do_reload (char *arg) { return do_svc(INIT_CMD_RELOAD, arg); }
static int do_start (char *arg) { return do_svc(INIT_CMD_START_SVC, arg); }
static int do_stop (char *arg) { return do_svc(INIT_CMD_STOP_SVC, arg); }
static int do_restart(char *arg) { return do_svc(INIT_CMD_RESTART_SVC, arg); }
static void show_cond_one(const char *_conds)
{
static char conds[MAX_ARG_LEN];
char *cond;
strlcpy(conds, _conds, sizeof(conds));
putchar('<');
for (cond = strtok(conds, ","); cond; cond = strtok(NULL, ",")) {
if (cond != conds)
putchar(',');
switch (cond_get(cond)) {
case COND_ON:
printf("+%s", cond);
break;
case COND_FLUX:
printf("\e[1m~%s\e[0m", cond);
break;
case COND_OFF:
printf("\e[1m-%s\e[0m", cond);
break;
}
}
putchar('>');
}
static int do_cond_magic(char op, char *cond)
{
cond[0] = op;
return do_emit(cond);
}
static int do_cond_set (char *cond) { return do_cond_magic('+', cond); }
static int do_cond_clear(char *cond) { return do_cond_magic('-', cond); }
static int do_cond_show(char *UNUSED(arg))
{
svc_t *svc;
enum cond_state cond;
if (verbose) {
glob_t gl;
printf("Asserted conditions (taken from %s)\n", _PATH_COND);
printf("===============================================================================\n");
if (!glob(_PATH_COND "*/*/*", 0, NULL, &gl)) {
size_t i;
for (i = 0; i < gl.gl_pathc; i++) {
char *cond, *name = gl.gl_pathv[i];
struct stat st;
if (stat(name, &st) || S_ISDIR(st.st_mode))
continue;
cond = name + strlen(_PATH_COND);
printf("\t%s\n", cond);
}
globfree(&gl);
}
puts("");
}
printf("PID Service Status Condition (+ on, ~ flux, - off)\n");
printf("===============================================================================\n");
for (svc = svc_iterator(1); svc; svc = svc_iterator(0)) {
if (!svc->cond[0])
continue;
cond = cond_get_agg(svc->cond);
printf("%-6d %-20.20s ", svc->pid, svc->cmd);
if (cond == COND_ON)
printf("%-6.6s ", condstr(cond));
else
printf("\e[1m%-6.6s\e[0m ", condstr(cond));
show_cond_one(svc->cond);
puts("");
}
return 0;
}
static int do_cond(char *cmd)
{
int c;
char *arg;
command_t command[] = {
{ "set", do_cond_set },
{ "clear", do_cond_clear },
{ "show", do_cond_show },
{ NULL, NULL }
};
arg = strpbrk(cmd, " ");
if (arg) {
*arg = 0;
for (c = 0; command[c].cmd; c++) {
if (!strcmp(command[c].cmd, cmd))
return command[c].cb(arg);
}
}
return do_cond_show(NULL);
}
static int do_signal(int signo, const char *msg)
{
if (kill(1, signo))
err(1, "Failed signalling init to %s", msg);
return 0;
}
static int do_halt (char *UNUSED(arg)) { return do_signal(SIGUSR1, "halt"); }
static int do_poweroff(char *UNUSED(arg)) { return do_signal(SIGUSR2, "power off"); }
static int do_reboot (char *UNUSED(arg)) { return do_signal(SIGTERM, "reboot"); }
static int do_utmp(char *UNUSED(cmd))
{
return utmp_show(_PATH_WTMP) ||
utmp_show(_PATH_UTMP);
}
static int show_version(char *UNUSED(arg))
{
puts("v" PACKAGE_VERSION);
return 0;
}
/* In verbose mode we skip the header and each service description.
* This in favor of having all info on one line so a machine can more
* easily parse it. */
static int show_status(char *arg)
{
svc_t *svc;
/* Fetch UTMP runlevel, needed for svc_status() call below */
runlevel = runlevel_get();
if (arg && arg[0]) {
int id = 1;
char *ptr, *next;
ptr = strchr(arg, ':');
if (ptr) {
*ptr++ = 0;
next = strchr(ptr, ' ');
if (next)
*next = 0;
id = atonum(ptr);
}
if (isdigit(arg[0]))
svc = svc_find_by_jobid(atonum(arg), id);
else
svc = svc_find_by_nameid(arg, id);
if (!svc)
return 1;
printf("%s\n", svc_status(svc));
return 0;
}
if (!verbose) {
printf("# Status PID Runlevels Service Description\n");
printf("===============================================================================\n");
}
for (svc = svc_iterator(1); svc; svc = svc_iterator(0)) {
char jobid[10], args[512] = "", *lvls;
if (svc_is_unique(svc))
snprintf(jobid, sizeof(jobid), "%d", svc->job);
else
snprintf(jobid, sizeof(jobid), "%d:%d", svc->job, svc->id);
printf("%-5s %7s ", jobid, svc_status(svc));
if (svc_is_inetd(svc))
printf("inetd ");
else
printf("%-6d ", svc->pid);
lvls = runlevel_string(svc->runlevels);
if (strchr(lvls, '\e'))
printf("%-18.18s ", lvls);
else
printf("%-10.10s ", lvls);
if (!verbose) {
char *name = strrchr(svc->cmd, '/');
if (!name)
name = svc->cmd;
else
name++;
printf("%-20.20s %-21.21s\n", name, svc->desc);
continue;
}
#ifndef INETD_DISABLED
if (svc_is_inetd(svc)) {
char *info;
struct init_request rq = {
.magic = INIT_MAGIC,
.cmd = INIT_CMD_QUERY_INETD,
};
snprintf(rq.data, sizeof(rq.data), "%s", jobid);
if (do_send(&rq, sizeof(rq))) {
snprintf(args, sizeof(args), "Unknown inetd");
info = args;
} else {
info = rq.data;
if (strcmp("internal", svc->cmd)) {
char *ptr = strchr(info, ' ');
if (ptr)
info = ptr + 1;
}
}
printf("%s %s\n", svc->cmd, info);
}
else
#endif /* !INETD_DISABLED */
{
int i;
for (i = 1; i < MAX_NUM_SVC_ARGS; i++) {
strlcat(args, svc->args[i], sizeof(args));
strlcat(args, " ", sizeof(args));
}
printf("%s %s\n", svc->cmd, args);
}
}
return 0;
}
static int usage(int rc)
{
fprintf(stderr, "Usage: %s [OPTIONS] <COMMAND>\n\n"
"Options:\n"
" -d, --debug Debug initctl (client)\n"
" -v, --verbose Verbose output\n"
" -h, --help This help text\n\n"
"Commands:\n"
" debug Toggle Finit (daemon) debug\n"
" help This help text\n"
" reload Reload *.conf in /etc/finit.d and activate changes\n"
" runlevel [0-9] Show or set runlevel: 0 halt, 6 reboot\n"
" status | show Show status of services\n"
" cond set <COND> Set (assert) condition => +COND\n"
" cond clear <COND> Clear (deassert) condition => -COND\n"
" cond show Show condition status\n"
" start <JOB|NAME>[:ID] Start service by job# or name, with optional ID\n"
" stop <JOB|NAME>[:ID] Stop/Pause a running service by job# or name\n"
" restart <JOB|NAME>[:ID] Restart (stop/start) service by job# or name\n"
" reboot Reboot system\n"
" halt Halt system\n"
" poweroff Halt and power off system\n"
" utmp show Raw dump of UTMP/WTMP db\n"
" version Show Finit version\n\n", prognm);
return rc;
}
int main(int argc, char *argv[])
{
int c;
command_t command[] = {
{ "debug", toggle_debug },
{ "reload", do_reload },
{ "runlevel", do_runlevel },
{ "status", show_status },
{ "show", show_status }, /* Convenience alias */
{ "cond", do_cond },
{ "start", do_start },
{ "stop", do_stop },
{ "restart", do_restart },
{ "reboot", do_reboot },
{ "halt", do_halt },
{ "poweroff", do_poweroff },
{ "utmp", do_utmp },
{ "version", show_version },
{ NULL, NULL }
};
struct option long_options[] = {
{"help", 0, NULL, 'h'},
{"debug", 0, NULL, 'd'},
{"verbose", 0, NULL, 'v'},
{NULL, 0, NULL, 0}
};
progname(argv[0]);
while ((c = getopt_long(argc, argv, "dh?v", long_options, NULL)) != EOF) {
switch(c) {
case 'h':
case '?':
return usage(0);
case 'd':
debug = 1;
break;
case 'v':
verbose = 1;
break;
}
}
silent = !verbose;
if (optind < argc) {
char *cmd = argv[optind++];
char arg[120] = "";
while (optind < argc) {
strlcat(arg, argv[optind++], sizeof(arg));
strlcat(arg, " ", sizeof(arg));
}
for (c = 0; command[c].cmd; c++) {
if (!strcmp(command[c].cmd, cmd))
return command[c].cb(arg);
}
}
return usage(1);
}
/**
* Local Variables:
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/
+1
View File
@@ -30,6 +30,7 @@ Optional Plugins:])
fi])
if test "x$enable_plugin" = "xyes"; then
AC_DEFINE([HAVE_]PLUGGY[_PLUGIN], 1, [Define to 1 if the $1 plugin is enabled.])
plugins="$1 $plugins"
fi
AM_CONDITIONAL([BUILD_]PLUGGY[_PLUGIN], test "x$enable_plugin" = "xyes")
enable_pluggy="$enable_plugin"])
+6 -4
View File
@@ -1,4 +1,6 @@
/*.la
/*.lo
/.deps/*
/.libs/*
*.la
*.lo
.deps/*
.libs/*
Makefile
Makefile.in
+2 -2
View File
@@ -1,6 +1,6 @@
AM_LDFLAGS = -module -avoid-version -shared
AM_CFLAGS = -W -Wall -Wextra -std=gnu99
AM_CPPFLAGS = -U_FORTIFY_SOURCE
AM_CFLAGS = -W -Wall -Wextra -Wno-unused-parameter -std=gnu99
AM_CPPFLAGS = -I$(top_srcdir)/src -U_FORTIFY_SOURCE
AM_CPPFLAGS += -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE
AM_CPPFLAGS += $(lite_CFLAGS)

Some files were not shown because too many files have changed in this diff Show More