oweals/dinit.git
7 years agoCombine start/stop queues, and add propagation queue.
Davin McCall [Wed, 9 Nov 2016 14:28:48 +0000 (14:28 +0000)]
Combine start/stop queues, and add propagation queue.

The propagation queue is used to propagate changes other than
immediate start/stop requests. It might be possible to combine the
two queues at a later stage.

This commit eliminates all recursion from service.cc.

7 years agoCheck desired state == started before allowing service to begin
Davin McCall [Tue, 8 Nov 2016 23:15:52 +0000 (23:15 +0000)]
Check desired state == started before allowing service to begin
smooth recovery.

7 years agorootfscheck service: use the passed-from-parent control socket file descriptor
Davin McCall [Wed, 21 Sep 2016 07:23:30 +0000 (08:23 +0100)]
rootfscheck service: use the passed-from-parent control socket file descriptor
to issue reboot commands (--use-passed-cfd option to reboot).

This may be necessary since the control socket may not have been created yet, due
to the root filesystem being read-only at this point.

7 years agoAdd an option to shutdown to allow for receiving the control socket file
Davin McCall [Wed, 21 Sep 2016 07:17:28 +0000 (08:17 +0100)]
Add an option to shutdown to allow for receiving the control socket file
descriptor from the parent process (identified by DINIT_CS_FD).

7 years agoRemove use of strcpy in favour of memcpy (save the relevant string lengths
Davin McCall [Thu, 30 Jun 2016 14:20:56 +0000 (15:20 +0100)]
Remove use of strcpy in favour of memcpy (save the relevant string lengths
when they are calculated beforehand, so that they can be used as the length
argument). This is slightly more efficient and will silence and OpenBSD linker
warning.

7 years agoFix a TODO comment
Davin McCall [Mon, 27 Jun 2016 12:02:18 +0000 (13:02 +0100)]
Fix a TODO comment

7 years agoAdd a "pass-cs-fd" service option, which passes a control socket file
Davin McCall [Sun, 26 Jun 2016 18:21:10 +0000 (19:21 +0100)]
Add a "pass-cs-fd" service option, which passes a control socket file
descriptor directly to service processes, allowing them issue commands
even if the regular control socket has not been created (or if they
will not have permission to access it).

This has limited use cases and has security implications when used,
but allows early launching of a service which can pass events / issue
commands to dinit. In particular this could be useful for a device
watcher daemon which starts services as certain devices come online
(eg check and mount disks as they are detected by the kernel).

7 years agoRemove activated state if a service stops naturally
Davin McCall [Fri, 24 Jun 2016 15:30:27 +0000 (16:30 +0100)]
Remove activated state if a service stops naturally
(if auto-restart is enabled, it will restart instead).

7 years agoAdd release/wake commands to dinitctl
Davin McCall [Fri, 24 Jun 2016 15:14:28 +0000 (16:14 +0100)]
Add release/wake commands to dinitctl

7 years agoUse getWatchFd() from dasynq::FdWatcher rather than storing the fd in
Davin McCall [Fri, 24 Jun 2016 12:39:13 +0000 (13:39 +0100)]
Use getWatchFd() from dasynq::FdWatcher rather than storing the fd in
a separate member variable, in various places.
Squashes some TODOs.

7 years agoClean up signal and fd handling around fork().
Davin McCall [Thu, 23 Jun 2016 22:40:28 +0000 (23:40 +0100)]
Clean up signal and fd handling around fork().
Mask signals while we are doing dup() since it is allowed to return
EINTR apparently.
Make sure we obtain fds for stdin/stdout/stderr before we exec().

7 years agoLatest Dasynq updates
Davin McCall [Thu, 23 Jun 2016 22:38:27 +0000 (23:38 +0100)]
Latest Dasynq updates

7 years agoIgnore SIGTSTP (^Z) for run-on-console processes.
Davin McCall [Thu, 23 Jun 2016 20:25:36 +0000 (21:25 +0100)]
Ignore SIGTSTP (^Z) for run-on-console processes.
We don't want to be job control shell.

7 years agoImplement "list services" command in control protocol, and use it in
Davin McCall [Thu, 23 Jun 2016 11:33:36 +0000 (12:33 +0100)]
Implement "list services" command in control protocol, and use it in
"dinitctl list" command.

7 years agoIgnore SIGPIPE to prevent sudden exit when control socket is closed
Davin McCall [Thu, 23 Jun 2016 10:33:30 +0000 (11:33 +0100)]
Ignore SIGPIPE to prevent sudden exit when control socket is closed

7 years agoFix bug in buffer pointer calculation
Davin McCall [Thu, 23 Jun 2016 10:00:32 +0000 (11:00 +0100)]
Fix bug in buffer pointer calculation

7 years agoReport (instead of silently ignoring) various errors when reading service descriptions.
Davin McCall [Wed, 22 Jun 2016 16:22:05 +0000 (17:22 +0100)]
Report (instead of silently ignoring) various errors when reading service descriptions.
Squashes a bunch of TODO's.

7 years agoUpdate Linux documentation
Davin McCall [Wed, 22 Jun 2016 08:20:41 +0000 (09:20 +0100)]
Update Linux documentation

7 years agoRemove redundant service settings.
Davin McCall [Wed, 22 Jun 2016 08:08:29 +0000 (09:08 +0100)]
Remove redundant service settings.
Change "nosigterm" option to "no-sigterm".

7 years agoMake SIGQUIT perform immediate shutdown ("shutdown --sytem"), rather than exec()int
Davin McCall [Tue, 21 Jun 2016 18:52:02 +0000 (19:52 +0100)]
Make SIGQUIT perform immediate shutdown ("shutdown --sytem"), rather than exec()int
the plain "shutdown" command, which would have tried to contact Dinit in order to
roll back services anyway.

7 years agoCorrect exit status checks (status 0 returned by wait() doesn't have to mean
Davin McCall [Tue, 21 Jun 2016 18:24:10 +0000 (19:24 +0100)]
Correct exit status checks (status 0 returned by wait() doesn't have to mean
"exited cleanly with 0 exit status", though it probably does on most real
systems).

7 years agoLog some error conditions (kill some TODOs)
Davin McCall [Tue, 21 Jun 2016 15:11:10 +0000 (16:11 +0100)]
Log some error conditions (kill some TODOs)

7 years agoUpdate Dasynq
Davin McCall [Tue, 21 Jun 2016 13:25:19 +0000 (14:25 +0100)]
Update Dasynq

7 years agoClean up some TODOs
Davin McCall [Tue, 21 Jun 2016 08:32:16 +0000 (09:32 +0100)]
Clean up some TODOs

7 years agoScratch one TODO: default case in switch can't occur, function is only
Davin McCall [Mon, 20 Jun 2016 22:12:45 +0000 (23:12 +0100)]
Scratch one TODO: default case in switch can't occur, function is only
called once command has been established, therefore there's no need
to handle other cases.

7 years agoAdd documentation: using Dinit as your system init on Linux
Davin McCall [Sun, 19 Jun 2016 22:01:28 +0000 (23:01 +0100)]
Add documentation: using Dinit as your system init on Linux

7 years agoOne less TODO
Davin McCall [Sun, 19 Jun 2016 19:14:36 +0000 (20:14 +0100)]
One less TODO

7 years agoMerge branch 'master' of https://github.com/davmac314/dinit
Davin McCall [Sun, 19 Jun 2016 19:13:09 +0000 (20:13 +0100)]
Merge branch 'master' of https://github.com/davmac314/dinit

7 years agoFix kqueue backend bug; wasn't disabling read/write channels of a
Davin McCall [Sun, 19 Jun 2016 19:11:17 +0000 (20:11 +0100)]
Fix kqueue backend bug; wasn't disabling read/write channels of a
Bidi watcher appropriately when watcher added

7 years agoFix build problems with kqueue backend
Davin McCall [Sun, 19 Jun 2016 17:50:10 +0000 (18:50 +0100)]
Fix build problems with kqueue backend

7 years agoAdd root level Makefile, make "shutdown" be optionally built by "make all"
Davin McCall [Sun, 19 Jun 2016 17:05:01 +0000 (18:05 +0100)]
Add root level Makefile, make "shutdown" be optionally built by "make all"
(BUILD_SHUTDOWN in mconfig)

7 years agoRe-vamp shutdown
Davin McCall [Sun, 19 Jun 2016 16:44:05 +0000 (17:44 +0100)]
Re-vamp shutdown

7 years agoUpdate version in README (v0.03) v0.03
Davin McCall [Sun, 19 Jun 2016 16:00:12 +0000 (17:00 +0100)]
Update version in README (v0.03)

7 years agoAdd note that dinitctl isn't working on OpenBSD ATM.
Davin McCall [Sun, 19 Jun 2016 14:30:04 +0000 (15:30 +0100)]
Add note that dinitctl isn't working on OpenBSD ATM.

7 years agonext_for_console was not being set null when a service queued for
Davin McCall [Sun, 19 Jun 2016 14:16:10 +0000 (15:16 +0100)]
next_for_console was not being set null when a service queued for
the console (and was not initialised).

7 years agoUpdate README and TODO
Davin McCall [Sun, 19 Jun 2016 13:32:57 +0000 (14:32 +0100)]
Update README and TODO

7 years agoLarge refactoring of dinitctl.
Davin McCall [Sun, 19 Jun 2016 13:24:39 +0000 (14:24 +0100)]
Large refactoring of dinitctl.

7 years agoLog correct information regarding reason for process termination:
Davin McCall [Sat, 18 Jun 2016 22:29:37 +0000 (23:29 +0100)]
Log correct information regarding reason for process termination:
did it exit, was it signalled?

7 years agoDon't display "can't bind socket: read only file sytem" error on the
Davin McCall [Sat, 18 Jun 2016 19:37:14 +0000 (20:37 +0100)]
Don't display "can't bind socket: read only file sytem" error on the
first attempt to bind the control socket (immediately after starting).
It's pretty normal for the filesystem to be mounted read-only at that
stage.

7 years agoSeparate the commencement of logging and the opening of the control socket
Davin McCall [Sat, 18 Jun 2016 19:25:17 +0000 (20:25 +0100)]
Separate the commencement of logging and the opening of the control socket
into two distinct functions.

7 years agoAdd a new service setting, "options", which can be used for various options
Davin McCall [Sat, 18 Jun 2016 19:22:18 +0000 (20:22 +0100)]
Add a new service setting, "options", which can be used for various options
and which deprecates several other settings. Includes a new option, starts-log,
specifying that the service starts the syslog service.

7 years agoAdd a method to discard the console log buffer contents.
Davin McCall [Sat, 18 Jun 2016 19:21:06 +0000 (20:21 +0100)]
Add a method to discard the console log buffer contents.

7 years agoFix calculation of buffer size for LISTEN_FDS environment variable.
Davin McCall [Sat, 18 Jun 2016 17:05:01 +0000 (18:05 +0100)]
Fix calculation of buffer size for LISTEN_FDS environment variable.
(Fortunately, it still gave the correct result in all expected cases).

7 years agoSmall documentation updates.
Davin McCall [Sat, 18 Jun 2016 16:51:10 +0000 (17:51 +0100)]
Small documentation updates.

7 years agoUpdate Dasynq, again, and update Dinit code to reflect API changes.
Davin McCall [Sat, 18 Jun 2016 14:11:19 +0000 (15:11 +0100)]
Update Dasynq, again, and update Dinit code to reflect API changes.

Hopefully the Dasynq API is now fairly stable.

7 years agoYet another Dasynq update
Davin McCall [Thu, 16 Jun 2016 22:54:54 +0000 (23:54 +0100)]
Yet another Dasynq update

7 years agoPull in latest Dasynq, which means a massive amount of renaming.
Davin McCall [Thu, 16 Jun 2016 18:31:01 +0000 (19:31 +0100)]
Pull in latest Dasynq, which means a massive amount of renaming.

7 years agoUpdate TODO
Davin McCall [Thu, 16 Jun 2016 17:33:46 +0000 (18:33 +0100)]
Update TODO

7 years agoUpdate dasynq to latest HEAD
Davin McCall [Thu, 16 Jun 2016 07:27:22 +0000 (08:27 +0100)]
Update dasynq to latest HEAD

7 years agoUse the start queue instead of starting services immediately.
Davin McCall [Thu, 16 Jun 2016 07:26:09 +0000 (08:26 +0100)]
Use the start queue instead of starting services immediately.

7 years agoWrite log messages which cross the circular buffer boundary atomically,
Davin McCall [Wed, 15 Jun 2016 15:59:48 +0000 (16:59 +0100)]
Write log messages which cross the circular buffer boundary atomically,
using writev.

7 years agoIgnore SIGPIPE.
Davin McCall [Tue, 14 Jun 2016 22:02:40 +0000 (23:02 +0100)]
Ignore SIGPIPE.

7 years agoMake control socket handling safer and fix an inverted logic bug.
Davin McCall [Tue, 14 Jun 2016 22:01:22 +0000 (23:01 +0100)]
Make control socket handling safer and fix an inverted logic bug.
queuePacket() now no longer deletes the connection, meaning its
use the service listener is now safe.

7 years agoMissed processing start/stop queue in one place
Davin McCall [Tue, 14 Jun 2016 18:05:00 +0000 (19:05 +0100)]
Missed processing start/stop queue in one place

7 years agoIntroduce a "stop queue" and "start queue" in ServiceSet, to better
Davin McCall [Tue, 14 Jun 2016 17:05:31 +0000 (18:05 +0100)]
Introduce a "stop queue" and "start queue" in ServiceSet, to better
manage service interactions and avoid recursion. Both are implemented
as a singly-linked list of services. The queues are processed one
at a time until empty.

7 years agoUse _exit instead of exit after fork
Davin McCall [Tue, 14 Jun 2016 13:14:53 +0000 (14:14 +0100)]
Use _exit instead of exit after fork

7 years agoRework control protocol handling a little.
Davin McCall [Mon, 13 Jun 2016 21:21:08 +0000 (22:21 +0100)]
Rework control protocol handling a little.

7 years agoUpdate dasynq
Davin McCall [Mon, 13 Jun 2016 21:20:28 +0000 (22:20 +0100)]
Update dasynq

7 years agoUse a BidiFdWatcher for control connections. One step closer to
Davin McCall [Sun, 12 Jun 2016 23:57:52 +0000 (00:57 +0100)]
Use a BidiFdWatcher for control connections. One step closer to
working with kqueue...

7 years agoUpdate dasynq
Davin McCall [Sun, 12 Jun 2016 23:57:20 +0000 (00:57 +0100)]
Update dasynq

7 years agoCatch a broader range of exceptions when creating a ControlConn
Davin McCall [Sun, 12 Jun 2016 23:21:09 +0000 (00:21 +0100)]
Catch a broader range of exceptions when creating a ControlConn

7 years agoFix condition for detecting read failure in process_child_status().
Davin McCall [Sun, 12 Jun 2016 23:18:57 +0000 (00:18 +0100)]
Fix condition for detecting read failure in process_child_status().

7 years agoImplement DINIT_CP_RELEASESERVICE command.
Davin McCall [Sun, 12 Jun 2016 09:06:01 +0000 (10:06 +0100)]
Implement DINIT_CP_RELEASESERVICE command.

7 years agoCode consistency and documentation update
Davin McCall [Sun, 12 Jun 2016 09:00:49 +0000 (10:00 +0100)]
Code consistency and documentation update

7 years agoMap dinit-log log levels to syslog log levels
Davin McCall [Sat, 11 Jun 2016 20:21:25 +0000 (21:21 +0100)]
Map dinit-log log levels to syslog log levels

7 years agoEnable logging to syslog. v0.02
Davin McCall [Sat, 11 Jun 2016 19:38:22 +0000 (20:38 +0100)]
Enable logging to syslog.

7 years agoIncorporate latest bugfixes from dasynq
Davin McCall [Sat, 11 Jun 2016 18:24:02 +0000 (19:24 +0100)]
Incorporate latest bugfixes from dasynq

7 years agoFix (remove) noexcept specification for init_log().
Davin McCall [Sat, 11 Jun 2016 14:59:46 +0000 (15:59 +0100)]
Fix (remove) noexcept specification for init_log().

7 years agoFull support within the logging subsystem to an external source (fd).
Davin McCall [Sat, 11 Jun 2016 14:55:46 +0000 (15:55 +0100)]
Full support within the logging subsystem to an external source (fd).

7 years agoMore refactoring in preparation for proper logging support
Davin McCall [Sat, 11 Jun 2016 10:51:14 +0000 (11:51 +0100)]
More refactoring in preparation for proper logging support

7 years agoMinor refactoring
Davin McCall [Sat, 11 Jun 2016 10:06:54 +0000 (11:06 +0100)]
Minor refactoring

7 years agoAvoid hanging if a BGPROCESS is not a child of dinit, by probing
Davin McCall [Tue, 7 Jun 2016 07:30:00 +0000 (08:30 +0100)]
Avoid hanging if a BGPROCESS is not a child of dinit, by probing
status with waitpid() and assuming the process is stopped if it
is not a child.

7 years agoTODO updates.
Davin McCall [Mon, 6 Jun 2016 23:30:20 +0000 (00:30 +0100)]
TODO updates.

7 years agoWhitespace fixes v0.01
Davin McCall [Mon, 6 Jun 2016 22:40:51 +0000 (23:40 +0100)]
Whitespace fixes

7 years agoNo need to link libev anymore.
Davin McCall [Mon, 6 Jun 2016 22:12:18 +0000 (23:12 +0100)]
No need to link libev anymore.

7 years agoRefactoring, and actually enable console log in enable_console_log()...
Davin McCall [Mon, 6 Jun 2016 22:11:49 +0000 (23:11 +0100)]
Refactoring, and actually enable console log in enable_console_log()...

7 years agoRemove obseleted TODO comment
Davin McCall [Mon, 6 Jun 2016 19:40:39 +0000 (20:40 +0100)]
Remove obseleted TODO comment

7 years agoAdd console watch for logging once, then enable and disable as necessary,
Davin McCall [Mon, 6 Jun 2016 18:12:18 +0000 (19:12 +0100)]
Add console watch for logging once, then enable and disable as necessary,
rather than constantly adding and removing it.

7 years agoUpdate dasynq
Davin McCall [Mon, 6 Jun 2016 18:11:18 +0000 (19:11 +0100)]
Update dasynq

7 years agoCode documentation - ServiceRecord and ServiceSet. Add a few lines on how
Davin McCall [Mon, 6 Jun 2016 15:31:00 +0000 (16:31 +0100)]
Code documentation - ServiceRecord and ServiceSet. Add a few lines on how
require/release operate and control service start/stop.

7 years agoSuppress "invalid offsetof" warnings.
Davin McCall [Mon, 6 Jun 2016 07:31:48 +0000 (08:31 +0100)]
Suppress "invalid offsetof" warnings.

7 years agoRelease on failure to start.
Davin McCall [Mon, 6 Jun 2016 07:30:38 +0000 (08:30 +0100)]
Release on failure to start.
(Ensures dependencies will stop if they are not otherwise required).

7 years agoFix condition in is_log_flushed
Davin McCall [Sun, 5 Jun 2016 20:25:53 +0000 (21:25 +0100)]
Fix condition in is_log_flushed

7 years agoMake all log messages go via the log buffer.
Davin McCall [Sun, 5 Jun 2016 20:05:40 +0000 (21:05 +0100)]
Make all log messages go via the log buffer.
Flush the log buffer before exit.

7 years agoRefactorings.
Davin McCall [Sun, 5 Jun 2016 18:31:15 +0000 (19:31 +0100)]
Refactorings.

7 years agoFix style inconsistency in CPBuffer: fillTo -> fill_to
Davin McCall [Sun, 5 Jun 2016 17:28:36 +0000 (18:28 +0100)]
Fix style inconsistency in CPBuffer: fillTo -> fill_to

There is generally inconsistent style throughout the codebase, but
at least this one class can be self-consistent...

7 years agoOpenBSD: use __thrsigdivert as a replacement for sigtimedwait.
Davin McCall [Sun, 5 Jun 2016 14:32:48 +0000 (15:32 +0100)]
OpenBSD: use __thrsigdivert as a replacement for sigtimedwait.

7 years agoMake selection of epoll/kqueue backend automatic
Davin McCall [Sun, 5 Jun 2016 09:31:00 +0000 (10:31 +0100)]
Make selection of epoll/kqueue backend automatic

8 years agoBeginnings of kqueue support (far from complete)
Davin McCall [Sun, 5 Jun 2016 02:29:12 +0000 (03:29 +0100)]
Beginnings of kqueue support (far from complete)

8 years agoRip out libev, replace with dasynq (new library written for the purpose).
Davin McCall [Sun, 5 Jun 2016 00:49:23 +0000 (01:49 +0100)]
Rip out libev, replace with dasynq (new library written for the purpose).

8 years agoRefactoring. Move buffered output management (variables) into a
Davin McCall [Tue, 19 Jan 2016 19:13:18 +0000 (19:13 +0000)]
Refactoring. Move buffered output management (variables) into a
class.

8 years agoUse non-blocking I/O and event notification for console logging.
Davin McCall [Tue, 19 Jan 2016 11:13:55 +0000 (11:13 +0000)]
Use non-blocking I/O and event notification for console logging.
(needs some cleanup).

8 years agoOnly enable console logging via the service layer (when no services
Davin McCall [Sat, 16 Jan 2016 14:45:52 +0000 (14:45 +0000)]
Only enable console logging via the service layer (when no services
are using the console).

8 years agoIntroduce method to enable/disable console logging, instead of
Davin McCall [Sat, 16 Jan 2016 14:17:20 +0000 (14:17 +0000)]
Introduce method to enable/disable console logging, instead of
using a global variable. (introduce "enable_console_log(bool)",
remove "log_to_console").

8 years agoAdd/correct some comments
Davin McCall [Sat, 16 Jan 2016 13:47:08 +0000 (13:47 +0000)]
Add/correct some comments

8 years agoMake CPBuffer a template, parameterized by buffer size
Davin McCall [Sat, 16 Jan 2016 12:54:05 +0000 (12:54 +0000)]
Make CPBuffer a template, parameterized by buffer size

8 years agoMakefile improvements (fix clean target), and build with -fno-rtti
Davin McCall [Fri, 15 Jan 2016 19:26:16 +0000 (19:26 +0000)]
Makefile improvements (fix clean target), and build with -fno-rtti
for reduced binary size.

8 years agoUse $HOME/dinit.d for default service directory if not system init.
Davin McCall [Fri, 15 Jan 2016 11:49:46 +0000 (11:49 +0000)]
Use $HOME/dinit.d for default service directory if not system init.
Add command line options to specify service directory and control
socket path. Add command line option to run as system init (default
when pid == 1).

8 years agoRemove some explicit memory deallocation in favor of using unique_ptr.
Davin McCall [Thu, 14 Jan 2016 18:19:41 +0000 (18:19 +0000)]
Remove some explicit memory deallocation in favor of using unique_ptr.

8 years agoUse delete[] to delete buffers allocated via new[]
Davin McCall [Thu, 14 Jan 2016 10:02:40 +0000 (10:02 +0000)]
Use delete[] to delete buffers allocated via new[]
(thank you LLVM static analyzer...)