Commit Graph
33 Commits
Author SHA1 Message Date
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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 fff68b7b06 Relocate source files to an src/ subdirectory
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-16 01:31:02 +01:00