oweals/dinit.git
6 years agoImplement mock functionality for some system calls in bp_sys.
Davin McCall [Mon, 15 Jan 2018 09:10:10 +0000 (09:10 +0000)]
Implement mock functionality for some system calls in bp_sys.

6 years agoStub out system functions for testing (WIP).
Davin McCall [Sun, 14 Jan 2018 23:34:21 +0000 (23:34 +0000)]
Stub out system functions for testing (WIP).

This is a more thorough and should be an overall better approach than
stubbing/mocking the base_proc_service class itself.

This commit introduces a baseproc-sys.h header which holds aliases for
the system functions that are used (kill, fcntl, etc). When running
tests the functions will be mocked (currently they are rigged to abort
when called).

6 years agoMove 'run_child_proc' function into a separate source file.
Davin McCall [Sun, 14 Jan 2018 12:17:19 +0000 (12:17 +0000)]
Move 'run_child_proc' function into a separate source file.

6 years agoMove base_process_service timer expiry handling out of friend class.
Davin McCall [Sat, 13 Jan 2018 18:52:22 +0000 (18:52 +0000)]
Move base_process_service timer expiry handling out of friend class.

One less friend class is a good thing. The timer now just calls a single
public 'timer_expiry' function. The latter function can also be used in
tests.

6 years agoAdd some process-service tests.
Davin McCall [Sat, 13 Jan 2018 16:58:12 +0000 (16:58 +0000)]
Add some process-service tests.

6 years agoUse general dinit.h header in baseproc-service.cc.
Davin McCall [Sat, 13 Jan 2018 16:47:57 +0000 (16:47 +0000)]
Use general dinit.h header in baseproc-service.cc.

6 years agoMakefile: build dependency lists (*.d) during regular build.
Davin McCall [Sat, 13 Jan 2018 13:18:44 +0000 (13:18 +0000)]
Makefile: build dependency lists (*.d) during regular build.

No need to build the dependency files as a separate step.

Also, make "make check" no longer build main objects.

6 years agoStub out Dasynq functionality for tests.
Davin McCall [Sat, 13 Jan 2018 12:32:33 +0000 (12:32 +0000)]
Stub out Dasynq functionality for tests.

Later some of this may be turned into proper mock functionality.

6 years agoAdd more missing includes for tests.
Davin McCall [Sat, 13 Jan 2018 12:02:03 +0000 (12:02 +0000)]
Add more missing includes for tests.

6 years agoFix makefile typo preventing build of 'shutdown'.
Davin McCall [Fri, 12 Jan 2018 21:10:30 +0000 (21:10 +0000)]
Fix makefile typo preventing build of 'shutdown'.

6 years agotests: infrastructure for implementing mock headers.
Davin McCall [Fri, 12 Jan 2018 20:21:07 +0000 (20:21 +0000)]
tests: infrastructure for implementing mock headers.

We need to duplicate the header directory entirely in order to be able
to replace header 'xyz.h' (so that 'include "xyz.h"' in other, real,
headers resolves to the mock).

6 years agoFix some includes (for testing/general resilience).
Davin McCall [Fri, 12 Jan 2018 20:15:41 +0000 (20:15 +0000)]
Fix some includes (for testing/general resilience).

6 years agoMove includes into a separate directory.
Davin McCall [Fri, 12 Jan 2018 16:45:51 +0000 (16:45 +0000)]
Move includes into a separate directory.

6 years agoMinor cleanup: remove unnecessary aliases.
Davin McCall [Fri, 12 Jan 2018 16:24:41 +0000 (16:24 +0000)]
Minor cleanup: remove unnecessary aliases.

6 years agoPull some commonly occurring declarations into a new header file.
Davin McCall [Fri, 12 Jan 2018 16:17:25 +0000 (16:17 +0000)]
Pull some commonly occurring declarations into a new header file.

Adds a new header file, dinit.h, which includes declarations for some
types and functions exported from dinit.cc.

6 years agoTests: use stubs for various functions.
Davin McCall [Thu, 11 Jan 2018 22:17:54 +0000 (22:17 +0000)]
Tests: use stubs for various functions.

6 years agoproc-service.cc: add intro comment.
Davin McCall [Thu, 11 Jan 2018 19:34:37 +0000 (19:34 +0000)]
proc-service.cc: add intro comment.

6 years agoRefactoring: split out exec_succeeded function.
Davin McCall [Thu, 11 Jan 2018 19:09:25 +0000 (19:09 +0000)]
Refactoring: split out exec_succeeded function.

The status pipe watcher (exec_status_pipe_watcher) had some
service-record-type specific code. Split it out as a virtual function.

6 years agoMove separate_args function from header to source file.
Davin McCall [Thu, 11 Jan 2018 18:09:32 +0000 (18:09 +0000)]
Move separate_args function from header to source file.

This avoids potential ODR violations. The function isn't worth making
inline, it's large enough and not on a critical path so just compile it
once.

6 years agoFix build of tests.
Davin McCall [Thu, 11 Jan 2018 17:44:01 +0000 (17:44 +0000)]
Fix build of tests.

6 years agoSplit service.cc into multiple files.
Davin McCall [Thu, 11 Jan 2018 09:04:54 +0000 (09:04 +0000)]
Split service.cc into multiple files.

service.cc becomes service.cc + proc-service.cc + baseproc-service.cc.
The header service.h becomes service.h + proc-service.h.

This refactoring should make testing easier.

6 years agoFix issue with start timeouts not correctly stopping dependents.
Davin McCall [Wed, 10 Jan 2018 18:22:37 +0000 (18:22 +0000)]
Fix issue with start timeouts not correctly stopping dependents.

6 years agoBig rename/namespace cleanup.
Davin McCall [Tue, 9 Jan 2018 17:37:34 +0000 (17:37 +0000)]
Big rename/namespace cleanup.

6 years agoMinor refactoring/code documentation.
Davin McCall [Tue, 9 Jan 2018 09:56:04 +0000 (09:56 +0000)]
Minor refactoring/code documentation.

6 years agoProperly handle scripted service start interrupt.
Davin McCall [Mon, 8 Jan 2018 22:00:43 +0000 (22:00 +0000)]
Properly handle scripted service start interrupt.

If we issue an interrupt (SIGINT) to a starting script, but the script
completes normally, we should run the stop script before marking the
service as stopped.

6 years agoClean up warning in process_restart_timer.
Davin McCall [Mon, 8 Jan 2018 19:56:43 +0000 (19:56 +0000)]
Clean up warning in process_restart_timer.

Initialise the service pointer via the constructor to avoid warning.

6 years agoRename service_type (type) to service_type_t.
Davin McCall [Mon, 8 Jan 2018 19:42:34 +0000 (19:42 +0000)]
Rename service_type (type) to service_type_t.

This is consistent with a number of other service-related types, and as
a bonus makes building with GCC 4.8 possible (it was previously confused
by a "service_type service_type = ..." declaration).

6 years agoLinux examples: use reasonable start-timeout for filesystem services.
Davin McCall [Mon, 8 Jan 2018 19:26:43 +0000 (19:26 +0000)]
Linux examples: use reasonable start-timeout for filesystem services.

6 years agoAllow specifying service start timeout in service description.
Davin McCall [Mon, 8 Jan 2018 11:05:00 +0000 (11:05 +0000)]
Allow specifying service start timeout in service description.

Default is 60 seconds.

6 years agoCorrectly handle start timeout of 0 (i.e. no timeout).
Davin McCall [Mon, 8 Jan 2018 09:11:33 +0000 (09:11 +0000)]
Correctly handle start timeout of 0 (i.e. no timeout).

6 years agoImplement start timeout for services, default of 60 seconds.
Davin McCall [Sun, 7 Jan 2018 23:39:55 +0000 (23:39 +0000)]
Implement start timeout for services, default of 60 seconds.

If a service doesn't start within the timeout it is sent SIGINT, and
then SIGKILL after the stop timeout (if there is one).

6 years agoSample service defs: enable smooth recovery for ttys. v0.07
Davin McCall [Sat, 6 Jan 2018 23:47:13 +0000 (23:47 +0000)]
Sample service defs: enable smooth recovery for ttys.

Also change dependency on ttys from depends-on to depends-ms.

6 years agoUpdate version to 0.07.
Davin McCall [Sat, 6 Jan 2018 23:46:07 +0000 (23:46 +0000)]
Update version to 0.07.

6 years agoInstall: allow specifying sbin and man directories.
Davin McCall [Sat, 6 Jan 2018 23:07:31 +0000 (23:07 +0000)]
Install: allow specifying sbin and man directories.

6 years agoPut man pages in the correct directory (man8 not man1).
Davin McCall [Sat, 6 Jan 2018 22:56:39 +0000 (22:56 +0000)]
Put man pages in the correct directory (man8 not man1).

6 years agoAdd "start-interruptible" service option.
Davin McCall [Sat, 6 Jan 2018 22:52:08 +0000 (22:52 +0000)]
Add "start-interruptible" service option.

This option allows a service startup to be interrupted if the service
becomes inactive while starting, by sending it the SIGINT signal. This
is useful for file system checks, which can otherwise delay
reboot/shutdown.

6 years agoAllow decimal comma separator for times expressed as decimals.
Davin McCall [Sat, 6 Jan 2018 22:23:35 +0000 (22:23 +0000)]
Allow decimal comma separator for times expressed as decimals.

Some locales use a comma to separate a decimal whole from its fractional
part, so allow either a decimal stop or a decimal comma.

6 years agoFix minor style inconsistencies.
Davin McCall [Sat, 6 Jan 2018 22:10:10 +0000 (22:10 +0000)]
Fix minor style inconsistencies.

6 years agoAdd "tests" generated binary to .gitignore
Davin McCall [Sat, 6 Jan 2018 21:43:40 +0000 (21:43 +0000)]
Add "tests" generated binary to .gitignore

6 years agoUse _Pragma to turn off invalid-offsetof warnings at appropriate places.
Davin McCall [Sat, 6 Jan 2018 19:03:58 +0000 (19:03 +0000)]
Use _Pragma to turn off invalid-offsetof warnings at appropriate places.

This means that we no longer need to build with -Wno-invalid-offsetof.

6 years agoAdd some missing includes, necessary on some platforms.
Davin McCall [Sat, 6 Jan 2018 15:20:03 +0000 (15:20 +0000)]
Add some missing includes, necessary on some platforms.

6 years agoAllow for interrupting process startup (by sending SIGINT).
Davin McCall [Fri, 5 Jan 2018 20:09:28 +0000 (20:09 +0000)]
Allow for interrupting process startup (by sending SIGINT).

6 years agoRefactoring: Move fields from service_record to base_process_service.
Davin McCall [Fri, 5 Jan 2018 19:33:47 +0000 (19:33 +0000)]
Refactoring: Move fields from service_record to base_process_service.

6 years agoservice_record: encapsulation: make some members private, add accessors.
Davin McCall [Thu, 4 Jan 2018 11:07:37 +0000 (11:07 +0000)]
service_record: encapsulation: make some members private, add accessors.

6 years agoBuild and run tests with sanitizers enabled.
Davin McCall [Tue, 19 Dec 2017 10:01:07 +0000 (10:01 +0000)]
Build and run tests with sanitizers enabled.

6 years agoMerge pull request #1 from mskarbek/tests_fix
Davin McCall [Fri, 5 Jan 2018 07:17:58 +0000 (07:17 +0000)]
Merge pull request #1 from mskarbek/tests_fix

Fixed tests after start_ps_process and all_deps_stopped rename.

6 years agoFixed tests 1/head
Marcin Skarbek [Fri, 5 Jan 2018 01:16:32 +0000 (02:16 +0100)]
Fixed tests

Fixed tests after start_ps_process and all_deps_stopped rename

6 years agoRenamed 'start_ps_process' function to 'bring_up'.
Davin McCall [Sun, 31 Dec 2017 20:19:21 +0000 (20:19 +0000)]
Renamed 'start_ps_process' function to 'bring_up'.

Also some minor reorganising, improve comments etc.

6 years agoRename 'all_deps_stopped' function to 'bring_down'.
Davin McCall [Sun, 31 Dec 2017 20:10:22 +0000 (20:10 +0000)]
Rename 'all_deps_stopped' function to 'bring_down'.

The former name doesn't imply the action to be taken.

6 years agoMake do_start/do_stop protected instead of public.
Davin McCall [Sun, 31 Dec 2017 20:02:41 +0000 (20:02 +0000)]
Make do_start/do_stop protected instead of public.

6 years agoHandle fork+exec failure in a separate virtual method.
Davin McCall [Sun, 31 Dec 2017 16:29:31 +0000 (16:29 +0000)]
Handle fork+exec failure in a separate virtual method.

This cleans up the code and removes a lot of conditional handling for
the different service types.

6 years agoTypo fix.
Davin McCall [Sun, 31 Dec 2017 15:24:56 +0000 (15:24 +0000)]
Typo fix.

6 years agoFix potential issue stopping process services.
Davin McCall [Thu, 28 Dec 2017 00:07:32 +0000 (00:07 +0000)]
Fix potential issue stopping process services.

Process services undergoing smooth recovery count as "STARTED" but have
a pid of -1, or a valid pid but with a process launch underway (waiting
for exec status). If all dependencies stopped at the wrong time, the
behaviour was to treat the service as stopped, but the smooth recovery
was still kicking on and could cause an issue if it "succeeded" after
the service was supposedly terminated.

To resolve this, don't send a kill signal to a process during smooth
recovery (i.e. if waiting_for_execstat is true) and send it once
recovery has completed instead.

6 years agoVarious minor cleanups.
Davin McCall [Wed, 27 Dec 2017 00:58:35 +0000 (00:58 +0000)]
Various minor cleanups.

6 years agoBuild: use EXTRA_LIBS when building "shutdown". v0.06
Davin McCall [Tue, 26 Dec 2017 14:18:52 +0000 (14:18 +0000)]
Build: use EXTRA_LIBS when building "shutdown".

6 years agobgproc_service: remove redundant initialisation from subclass.
Davin McCall [Tue, 26 Dec 2017 14:18:26 +0000 (14:18 +0000)]
bgproc_service: remove redundant initialisation from subclass.

6 years agoUpdate comparison on similar systems.
Davin McCall [Sun, 24 Dec 2017 14:03:42 +0000 (14:03 +0000)]
Update comparison on similar systems.

6 years agoUpdate Dasynq to 1.0.3.
Davin McCall [Sun, 24 Dec 2017 11:36:26 +0000 (11:36 +0000)]
Update Dasynq to 1.0.3.

6 years agoUpdate Dasynq to 1.0.2.
Davin McCall [Fri, 22 Dec 2017 20:10:41 +0000 (20:10 +0000)]
Update Dasynq to 1.0.2.

6 years agoUpgrade bundled Dasynq to 1.0.1.
Davin McCall [Mon, 18 Dec 2017 09:28:56 +0000 (09:28 +0000)]
Upgrade bundled Dasynq to 1.0.1.

6 years agoIncorporate upstream changes from Dasynq.
Davin McCall [Mon, 11 Dec 2017 18:45:12 +0000 (05:45 +1100)]
Incorporate upstream changes from Dasynq.

This updates bundled Dasynq to 1.0 (plus minor changes since).

7 years agoAdd some tests for milestone dependencies.
Davin McCall [Tue, 3 Oct 2017 21:33:42 +0000 (22:33 +0100)]
Add some tests for milestone dependencies.

7 years agoDefine and use a macro to run a named test.
Davin McCall [Mon, 2 Oct 2017 19:38:39 +0000 (20:38 +0100)]
Define and use a macro to run a named test.

7 years agoAdd "depends-ms" dependency option for milestone dependencies.
Davin McCall [Mon, 2 Oct 2017 19:20:51 +0000 (20:20 +0100)]
Add "depends-ms" dependency option for milestone dependencies.

7 years agoCorrect use of SOFT vs WAITS_FOR dependency type in various places.
Davin McCall [Sun, 1 Oct 2017 23:49:35 +0000 (00:49 +0100)]
Correct use of SOFT vs WAITS_FOR dependency type in various places.

Also fix implementation of WAITS_FOR. SOFT presently behaves the same as
WAITS_FOR (but cannot presently be specified as a dependency type in a
service description).

7 years agoSimplify dependency checking logic.
Davin McCall [Fri, 29 Sep 2017 20:10:31 +0000 (21:10 +0100)]
Simplify dependency checking logic.

7 years agoAdd service set destructor.
Davin McCall [Fri, 29 Sep 2017 19:26:05 +0000 (20:26 +0100)]
Add service set destructor.

Destructor deletes all services in the service set. This fixes a memory
leak currently present in the tests.

7 years agoRe-work dependency specification for service_record constructors.
Davin McCall [Wed, 27 Sep 2017 15:44:10 +0000 (16:44 +0100)]
Re-work dependency specification for service_record constructors.

Dependencies of different types are now given together in a single list,
wth each dependency tagged by its type, rather than as two lists (one
for regular and one for soft dependencies). This opens up the
possibility of supporting additional dependency types.

7 years agoImprove a test (and make it pass).
Davin McCall [Thu, 7 Sep 2017 19:05:39 +0000 (20:05 +0100)]
Improve a test (and make it pass).

When a service is unpinned from pinned start, it needs to check
force_stop and stop if set.

7 years agoFix test 6, add a new test (test 7).
Davin McCall [Tue, 5 Sep 2017 21:51:29 +0000 (22:51 +0100)]
Fix test 6, add a new test (test 7).

7 years agoKeep all dependencies (soft and regular) in a single list.
Davin McCall [Tue, 5 Sep 2017 08:14:39 +0000 (09:14 +0100)]
Keep all dependencies (soft and regular) in a single list.

We had separate lists for regular dependencies, dependents, and soft
dependencies and dependents. Combining the two dependency types
simplifies code in several places and allows for adding new dependency
types much more easily.

7 years agoss_read: silence signed vs unsigned comparison warning.
Davin McCall [Fri, 7 Jul 2017 18:53:13 +0000 (19:53 +0100)]
ss_read: silence signed vs unsigned comparison warning.

7 years agotests: add another.
Davin McCall [Fri, 7 Jul 2017 18:52:39 +0000 (19:52 +0100)]
tests: add another.

7 years agoservice: fix recently introduced double-start bug.
Davin McCall [Fri, 7 Jul 2017 17:13:40 +0000 (18:13 +0100)]
service: fix recently introduced double-start bug.

7 years agoTests: add another test.
Davin McCall [Thu, 6 Jul 2017 16:22:58 +0000 (17:22 +0100)]
Tests: add another test.

7 years agoFix "make check" on OS X / BSD.
Davin McCall [Thu, 6 Jul 2017 16:11:21 +0000 (17:11 +0100)]
Fix "make check" on OS X / BSD.

7 years agotests: correct get_state call (after rename from getState).
Davin McCall [Thu, 6 Jul 2017 16:09:02 +0000 (17:09 +0100)]
tests: correct get_state call (after rename from getState).

7 years agoDasynq: merge changes from upstream.
Davin McCall [Wed, 5 Jul 2017 20:04:36 +0000 (21:04 +0100)]
Dasynq: merge changes from upstream.

7 years agoTODO list: a couple of items done.
Davin McCall [Tue, 4 Jul 2017 18:36:13 +0000 (19:36 +0100)]
TODO list: a couple of items done.

7 years agoMore camelCase to under_score renaming.
Davin McCall [Tue, 4 Jul 2017 18:34:42 +0000 (19:34 +0100)]
More camelCase to under_score renaming.

7 years agoConsolidate linux-specific code.
Davin McCall [Tue, 4 Jul 2017 18:07:37 +0000 (19:07 +0100)]
Consolidate linux-specific code.

7 years agoVarious renaming of camelCase to underscored_name for consistency.
Davin McCall [Tue, 4 Jul 2017 08:37:21 +0000 (09:37 +0100)]
Various renaming of camelCase to underscored_name for consistency.

7 years ago(Linux) set dinit as child subreaper.
Davin McCall [Mon, 3 Jul 2017 00:12:33 +0000 (01:12 +0100)]
(Linux) set dinit as child subreaper.

This allows catching/watching double-forking processes even if we
are not PID 1. Double-fork orphans will be reparented to the
subreaper (i.e. Dinit) rather than PID 1 (init).

7 years agoUse getpgid to determine process group of service process.
Davin McCall [Mon, 3 Jul 2017 00:10:28 +0000 (01:10 +0100)]
Use getpgid to determine process group of service process.

Using pid (i.e. 'kill(-pid, signo)') doesn't work if the process has
double-forked but not set a new process group for the child, and
anyway it's not clear if POSIX actually guarantees that process group
IDs will match process IDs.

7 years agosmooth recovery: wait for dependencies to start before relaunch.
Davin McCall [Thu, 29 Jun 2017 17:55:41 +0000 (18:55 +0100)]
smooth recovery: wait for dependencies to start before relaunch.

If pinned started, dependencies may be stopped; the smooth recovery
process should wait for dependencies to start before trying to re-launch
the service process.

7 years agobgprocess: eliminate doing_recovery field.
Davin McCall [Thu, 29 Jun 2017 10:12:56 +0000 (11:12 +0100)]
bgprocess: eliminate doing_recovery field.

We can use the existing 'restarting' instead after some minor changes.

7 years agoTODO: update
Davin McCall [Tue, 27 Jun 2017 23:10:44 +0000 (00:10 +0100)]
TODO: update

7 years agoFix spacing / remove hard tabs.
Davin McCall [Tue, 27 Jun 2017 18:30:45 +0000 (19:30 +0100)]
Fix spacing / remove hard tabs.

7 years agoservice descriptions: Implement the stop-timeout setting.
Davin McCall [Tue, 27 Jun 2017 16:29:11 +0000 (17:29 +0100)]
service descriptions: Implement the stop-timeout setting.

7 years agoservice: implement stop timeout / hard kill.
Davin McCall [Tue, 27 Jun 2017 16:05:30 +0000 (17:05 +0100)]
service: implement stop timeout / hard kill.

If a service fails to stop in its alloted time, it will be killed with
SIGKILL. The timeout is currently hardcoded to 10 seconds.

7 years agoservice: check error from kill when checking ability to track child.
Davin McCall [Tue, 27 Jun 2017 08:54:31 +0000 (09:54 +0100)]
service: check error from kill when checking ability to track child.

We check whether the process exists using kill. We were treating any
error return as meaning the process ID was invalid, but in fact we may
simply not have permission to signal the process (if we are not being
run as root and the service process is suid).

7 years agoservice: add safety check before unlinking old socket path.
Davin McCall [Tue, 27 Jun 2017 08:36:01 +0000 (09:36 +0100)]
service: add safety check before unlinking old socket path.

7 years agoservice: improve robustness of read_pid_file().
Davin McCall [Mon, 26 Jun 2017 18:26:46 +0000 (19:26 +0100)]
service: improve robustness of read_pid_file().

Cleans up some TODOs.

7 years agoservice: use recorded state to check whether we can track child process
Davin McCall [Mon, 26 Jun 2017 17:58:03 +0000 (18:58 +0100)]
service: use recorded state to check whether we can track child process

We have a flag which records whether we are tracking the child process.
A BGPROCESS service can't always track the child, so it stops once the
dependencies have stopped without waiting for the process. Previously we
did a manual check rather than using the existing flag to see whether
the process could be tracked before immediately stopping.

7 years agoMakefile: fix warnings on initial build due to missing *.d files.
Davin McCall [Mon, 26 Jun 2017 09:21:49 +0000 (10:21 +0100)]
Makefile: fix warnings on initial build due to missing *.d files.

These are the auto-generated dependency information files, which do not
exist on initial build (or after clean).

7 years agoprocess service: more fixes to child watch reservation.
Davin McCall [Mon, 26 Jun 2017 09:15:25 +0000 (10:15 +0100)]
process service: more fixes to child watch reservation.

7 years agoVarious renaming (from CamelCase to underscore_separated).
Davin McCall [Mon, 26 Jun 2017 08:42:32 +0000 (09:42 +0100)]
Various renaming (from CamelCase to underscore_separated).

For consistency with most of the rest of the code base.

7 years agoImprove code documentation.
Davin McCall [Mon, 26 Jun 2017 08:32:40 +0000 (09:32 +0100)]
Improve code documentation.

7 years agoFix child watch reservation.
Davin McCall [Sun, 25 Jun 2017 16:51:42 +0000 (17:51 +0100)]
Fix child watch reservation.

7 years agoFix minor typos
Davin McCall [Fri, 23 Jun 2017 09:29:17 +0000 (10:29 +0100)]
Fix minor typos