Commit Graph
102 Commits
Author SHA1 Message Date
Joachim Wiberg 8000d361b3 initctl: restore 'cond [set|clr] foo' for user-defined conditions
In 7447192 we dropped support for 'cond set' and 'cond clear' commands
with the motivation they were unsafe and sent the wrong message to the
user.  That was true, but mostly because it was too generic and required
the user to call `initctl reload` to apply the changes.

This patch restores the behavior, albeit in a very reduced and simple
format.  All conditions set with this command are constrained to the
'usr/...' namespace.  No subdirectories are allowed.  The argument to
the 'cond set|clear' command is disallowed if it contains '/' or '.'
but anything else is supported, for example:

    initctl cond set foo:2

creates a static/oneshot condition in /run/finit/cond/usr/foo:2

These conditions are static and are fully handled by the user.  The
initctl command is the recommended, and only supported, way of setting
and clearing usr conditions.

This patch also includes a new plugin, usr.so, which is a very simple
inotify plugin for the /run/finit/cond/usr/ directory.  When files are
created or removed here the plugin tells the Finit condition engine to
update and trigger service changes.

For instance, the following service is not started by default at boot:

    service <usr/foo> myservice -- MyService

However, as soon as `initctl cond set foo` is called, myservice starts.
Consequently, it is stopped when `initctl cond clr foo` is called.

Another major difference from the original is that this implementation
doesn't send IPC commands to create/delete the conditions.  This makes
calling these new commands non-blocking so they can be used very early
in the bootstrap, by plugins, if needed.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-11 11:44:23 +01:00
Joachim Wiberg e3c8febe3b Refactor; common nomenclature, ordering, possib. security fix
- Use _PATH_foo for all condition paths, *with* trailing /
- Read condition file first, may not exist, in which case we save time
- Change from libte makepath() to mkpath(), this changes from hard-coded
  0777 perms on all cond dirs to 0755 -- possible security fix

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-11 11:44:23 +01:00
Joachim Wiberg 32ca117949 initctl: refactor command line parser, use concept from mroutectl
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-11 11:44:23 +01:00
Joachim Wiberg b966d031c8 initctl: enable plain mode for ls and utmp commands
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-09 21:30:11 +01:00
Joachim Wiberg 7d429bdbb1 initctl: restore -p,--plain output for headings and ps listing
This is the same output style as used in the mroutectl and pimctl tools.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-07 23:30:13 +01:00
Joachim Wiberg 07a364e570 initctl: fix use of possibly unterminated string, found by Coverity
No point in using rq.data, which could have been modified, instead use
the input argument to the function in the error message.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-05 10:51:25 +01:00
Joachim Wiberg b3b7a33252 initctl: developer mode, hidden command
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-05 08:22:38 +01:00
Joachim Wiberg d1efc60c84 initctl: add show command to cat foo.conf, default finit.conf
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-05 08:06:01 +01:00
Joachim Wiberg 9a24dfd98d initctl: refactor command composition for status command
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-05 00:13:01 +01:00
Joachim Wiberg 0e3fe5e3bf initctl: fix too long args list to status command
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-05 00:06:36 +01:00
Joachim Wiberg e60eb94810 initctl: complete rewrite of cgroup dumper in 'ps' command
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-04 23:49:42 +01:00
Joachim Wiberg fe27ed17eb initctl: status command formatting updates, add origin .conf file
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-04 07:27:06 +01:00
Joachim Wiberg b3ea23ed26 initctl: drop old 'job:id' format support, canonical is 'name:id'
With the recent changes to the condition handling it has become more and
more evident that the canonical reference for a task/run/service is the
NAME:ID representation.  Up until now we've kept the older JOB:ID for
some sort of compatibility fallback.

This patch removes the support to simplify maintenance going forward.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-04 07:23:19 +01:00
Joachim Wiberg 5da0a460fe initctl: fix runlevel and start/stop/restart segfault regression
Introduced in e2f6ac0.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-02 20:31:34 +01:00
Joachim Wiberg dc49b523d1 initctl: fix cond segfault, regression introduced in e2f6ac0
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-01 11:13:02 +01:00
Joachim Wiberg 1b05220376 initctl: fix reload segfault regression introduced in e2f6ac0
Found thanks to the new unit test suite \o/

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 22:57:14 +01:00
Joachim Wiberg 460add3cae initctl: introduce -f,--force option, for delete command
Never prompt, for scripting.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 12:20:29 +01:00
Joachim Wiberg e2f6ac0ece initctl: iterate command over all args, e.g. delete foo bar baz
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 12:06:59 +01:00
Joachim Wiberg 49582c70c5 initctl: add companion delete command
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 11:15:36 +01:00
Joachim Wiberg f9532d11ba initctl: only show enable/disable commands on compat systems
The enable/disable commands require either both the available/ and
enabled/ subdirectories in /etc/finit.d, or at least available/

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-27 19:27:58 +01:00
Joachim Wiberg 689e6cd52a initctl: add -c create flag, to force creation at edit
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-27 19:21:18 +01:00
Joachim Wiberg 001e859a97 initctl: add create command, no template yet
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 12:47:47 +01:00
Joachim Wiberg 8077169ea9 Merge pull request #157 from troglobit/usr/kandeg/initctl-edit
initctl: add edit command, fix #154 

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 10:54:00 +01:00
Andreas Egeberg 60d0ca1075 Added Edit command
Command Edit <CONF>  opens file /etc/finit.d/available/<CONF>.conf in
the editor referenced by Linux environment variable $EDITOR
If $EDITOR is not set it will try to open emacs and if emacs is not
found it will try to open the file in vim.

Signed-off-by: Andreas Egeberg <andreas.egeberg@gmail.com>
2021-02-26 10:28:21 +01:00
Joachim Wiberg f4a0b99df8 Fix #155: add support for env:/a/bc to service/run/task
This patch makes it possible to create a service with optional
arguments, similar to the systemd EnvironmentFile= setting.

The major difference to systemd, is that Finit does not attempt
to start a service if it cannot find the env. file, unless it
is prefixed with '-'.

Example:

    /etc/default/syslogd:
    SYSLOGD_OPTS="-m0 -r 128k:10 -s"

    /etc/finit.d/enabled/syslogd.conf
    service env:-/etc/default/syslogd syslogd -F $SYSLOGD_OPTS

Only downside, right now, is that changing the contents of the file
/etc/default/syslogd does not mark the syslogd.conf as modified and
a subsequent `initctl reload` will *not* restart syslogd.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-22 16:18:22 +01:00
Joachim Wiberg 7e42203627 Fix #147: refactor reboot as multi-call to initctl
This patch drops the stand-alone reboot binary and folds it into the
initctl tool, which now becomes a multi-call binary.

With this change the reboot/shutdown/poweroff/halt/suspend commands also
no longer default to sending signals to PID 1, instead it now uses the
initctl <--> finit UNIX domain socket API.  Signals are only used as a
fallback in case of non-working domain socket.  The -f,--force mode of
operation still works, where `reboot(2)` is called directly.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-21 10:59:08 +01:00
Joachim Wiberg e5a53c175a initctl: fix too long cmd arglist with 'initctl -v show'
Only append args that have length, MAX number of args are many.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-17 11:06:46 +01:00
Joachim Wiberg 89a57054f5 initctl: drop utmp/wtmp functionality on systems w/o it (musl)
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-14 04:18:34 +01:00
Joachim Wiberg 87f6769c51 Revert "Workaround for _PATH_UTMP and _PATH_WTMP defines on musl libc"
This reverts commit 8a71f2d323 because
if no other application has a working utmp then there's no poit for
Finit to have one.  Instead we'll be disabling all utmp support when
running on a musl based system.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-14 03:59:52 +01:00
Joachim Wiberg 8a71f2d323 Workaround for _PATH_UTMP and _PATH_WTMP defines on musl libc
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-14 03:52:56 +01:00
Joachim Wiberg b175b4a2ae initctl: add PID and IDENT to 'cond dump' command
Instead of just walking /run/finit/cond, also show the source of each
condition.  The hook and net conditions are hard-coded to init[1] atm.
and unknown conditions are shown as unknown[0].

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-13 12:07:20 +01:00
Joachim Wiberg 3aeb150eef initctl: minor refactor and set min column width
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-13 12:07:20 +01:00
Joachim Wiberg 27bd9423bc initctl: add job number to "show foo"
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-11 22:32:37 +01:00
Joachim Wiberg 72a0ba6a55 initctl: primarily check for /var/log/syslog, fallback to messages
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-11 22:32:12 +01:00
Joachim Wiberg 56eb2c6b21 initctl: slight adjustment to whitespace between columns
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-11 22:31:35 +01:00
Joachim Wiberg 02d7c6747b initctl: minor refactor, keep related functions together
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-11 22:17:54 +01:00
Jacques de Laval cb64c068e3 Fix #136: drop old init client tool
The SysV API compatibility layer gives too little value to be worth
the effort of maintaining it. Users are encouraged to use the
`initctl` tool instead.

Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-11 17:52:08 +01:00
Joachim Wiberg e8561b7f90 initctl: add '-n, --numeric' mode to prefer JOB:ID over NAME:ID
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-11 16:16:43 +01:00
Joachim Wiberg 815454c065 initctl: fix missing '--no-heading' longopt in getopt()
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-11 16:16:07 +01:00
Joachim Wiberg d1afc705ab initctl: refactor, reduce code duplication
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-11 16:14:28 +01:00
Joachim Wiberg ab8e813c7a initctl: name:id also for conditions and adjust column widths
Slight reshuffle of columns so status and condition listings are more
similar.  Also, calculate and adjust necessary column widths.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-11 15:37:43 +01:00
Joachim Wiberg 99d22a7c21 initctl: add '-t' switch to hide table headings
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-11 14:11:47 +01:00
Joachim Wiberg a226c93539 initctl: change layout to put (name,id) tuple in focus
With the recent change in the condition handling we've decided to put
the (name,id) tuple in focus for everything Finit.

This patch changes from job:id in the status listing to name:id instead.
In verbose mode we change to show the job:id and the command + args.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-11 14:07:43 +01:00
Joachim Wiberg e88a9b14ff Fix #101: remove built-in inetd from finit
This patch removes the built-in inetd support from Finit.  We recommend
using an external inetd instead, e.g. xinetd.

If you liked the feature set our inetd provided; filtering per interface
and port redirection, then please let us know or use the code in this
patch (MIT licensed) to recreate it.  We are open to reintroducing it,
but then as a stand-alone daemon like the bundled watchdogd and getty.

So long for now, old friend.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-11 12:46:40 +01:00
Joachim Wiberg 1fb78742c7 Fix gcc warning, prevlevel may be used uninitialized
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-10 11:56:16 +01:00
Joachim Wiberg a5714a058c Update copyright years
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-09 22:07:03 +01:00
Joachim Wiberg 0c85f8adfe initctl: add 'ls' alias for 'list'
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-06 20:55:09 +01:00
Joachim Wiberg 24a78d3246 Update copyright years and author last name
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2020-09-02 23:38:11 +02:00
Joachim Nilsson 54e5fd2a78 initctl: Show :ID in process listing(s) only if non-zero
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-23 15:14:09 +02:00
Joachim Nilsson f06e17ccc6 initctl: Widen status column a bit to fit 'stopping' state
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-03-05 17:51:52 +01:00