Commit Graph
701 Commits
Author SHA1 Message Date
Joachim Wiberg d5bea7eeeb Re-concatenate string arguments to commands, ugly patch
This is quite possibly the ugliest pieces of code in this project.

It is a quick fix to the problem with strtok() to split up the cmd into
cmd + args[].  Without it wordexp() will later get very cranky about
trying to expand `"Partial` strings from commands like this:

    /sbin/udhcpc-wrapper.sh -f -S -V "myOS v9.99" -t 8 -T 5 -A 10 -R -p \
        /var/run/udhcpc-vlan1.pid -i vlan1 -x hostname:myos-12-34-50 -o \
	-O 1 -O 3 -O 6 -O 7 -O 12 -O 15 -O 42 -O 121 -a

Yes really.

It's an obviously far from perfect solution.  One might even start to
question why we have an args[64[64] per svc_t and not just a cmd + arg?

Well, there's a lot of improvement potential here, let's talk!

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-02 22:33:41 +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 63033d7dcf Drop developer debug message
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-02 20:23:43 +01:00
Joachim Wiberg 8355c37285 initctl: fix edit command fallback handling
If mg doesn't exist, command doesn't evaluate the second argument (vi),
so we need to use `... || command -v vi` instead.  Found during demo,
because why not.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-01 17:36:06 +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 c5083c4bbc Move sync files to temporary storage
We don't want these files to exist while starting up, it wrecks all
sorts of havoc to a system.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 22:31:07 +01:00
Joachim Wiberg 1020695ebd Skip termios setup of TTY in rescue mode
This patch fixes an issue with rescue mode on Alpine Linux where the
rescue shell was never properly started.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 21:27:16 +01:00
Joachim Wiberg 3d50a28fe3 Make sure to _exit() TTY child also on error
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 21:25:54 +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 89be90cade initctl: fix compilation warning
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 12:13:32 +01:00
Joachim Wiberg 93f9856da8 initctl: ignore missing files to delete command, simplify yorn() str
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 12:12:03 +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 c5db989bed initctl: skip errors from disable while deleting services
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 11:51:37 +01:00
Joachim Wiberg 928110b19e Minor whitespace in sample.conf
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 11:43:16 +01:00
Joachim Wiberg c204724353 Follow-up, fix variable expansion if unset
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 11:42:48 +01:00
Joachim Wiberg 2ac39e1917 initctl: restore Andreas' clever $(command ...) eval, it works
Turns out that on some systems, that has none of the first two, and
neither of the two environment variables set in ${VISUAL:-${EDITOR}},
they evaluate to 'sh /etc/finit.d/file.conf', which is true, so we
wouldn't even try mg or vi ...

This patch reverts to the spirit of Andreas Egebergs initial commit,
which turns out to be a better solution anyway :)

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 11:35:22 +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 2bfede2cfe Add /lib/finit/sample.conf for initctl create
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 10:26:39 +01:00
Joachim Wiberg 6862d7cd5f Refactor --with-sysconfig, default to /etc/default and /etc/conf.d
Both Debian and Builroot based systems use /etc/default and
Alpine Linux use /etc/conf.d, so let's just put both in by
default.  If the directories exist we monitor them.

The --with-syconfig configure option is now disabled by default.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 09:53:48 +01:00
Joachim Wiberg 7e3b18a38d Refactor install/uninstall of rescue.conf
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 09:34:36 +01:00
Joachim Wiberg f8c07e81ff Reclassify module as BOOTSTRAP only, including minor refactor
The module setting is deprecated, other mechanisms exist.  This change
is to ensure we don't try to (re)load any modules at runtime, only at
bootstrap.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 09:24:04 +01:00
Joachim Wiberg 270512bc97 Refactor, collapse parse_conf() and parse_conf_dynamic()
This patch collapses the two similar functions parse_conf() and
parse_conf_dynamic() into a single function.  It also lifts old
restrictions on what config stanzas are allowed in /etc/finit.d

The only remaining restriction is the global rlimits, they remain
as the last setting only possible to define /etc/finit.conf which
then applies to all other services.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 08:38:41 +01:00
Joachim Wiberg c001349dd3 Wrapper for init q and init -t sec 0, used by sysvnit shutdown
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 07:54:16 +01:00
Joachim Wiberg 510bd1ac0b initctl: if edit cannot find the file, list available ones
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-27 20:13:57 +01:00
Joachim Wiberg 0d52583624 initctl: return correct path if -c is given
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-27 20:13:32 +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 c7d189f199 initctl: refactor list command slightly
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-27 19:27:22 +01:00
Joachim Wiberg 83cdb884d9 initctl: extend semantics for enable/disable cmd
A system may, or may not, have the available/ and enabled/
subdirectories in /etc/finit.d.  This is up to distros but
we support the following, example uses /etc/finit.d as the
FINIT_RCSD base directory:

 1. No subdirectories
    - enable: nop
    - disable: nop
 2. Only available/
    - enable: checks if there's a service in available/
      then symlinks to /etc/finit.d/
    - disable: checks if service in /etc/finit.d is a
      symlink, then removes it
 3. Both available/ and enabled/
    - enable: relative symlink in enabled/ is created if
      service is available in available/
    - disable: symlink in enabled/ is removed if exists

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-27 19:22:50 +01:00
Joachim Wiberg e9ed90cb34 initctl: let touch command handle both rcsd and available dirs
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-27 19:22:16 +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 2fd4418371 initctl: add support for reading config to 'create' from stdin
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-27 17:02:37 +01:00
Joachim Wiberg 6d4bc670e6 Relocate paste() from helpers.h to util.h, for sharing with initctl
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 16:21:53 +01:00
Joachim Wiberg 5e37f94775 Improve error messages for failing wordexp()
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 15:06:02 +01:00
Joachim Wiberg 41319a8cf8 Work around forbidden chars in wordexp(): | < > & ;
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 14:54:34 +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 6cf8c7ade4 initctl: minor refactor, simplify edit command
- Gamble a bit by redirecting stderr to /dev/null instead of command -v
- Drop vi from VISUAL/EDITOR expansion alternatives, tested later anyway

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 11:45:04 +01:00
Joachim Wiberg 7439fa0c2a initctl: fix logic in edit command fallback handling
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 11:08:03 +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 bf2272c6b3 Beautify code 2021-02-26 10:51:30 +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 6b7255fdeb Fix regression introduced in 7ef25ab, global rlimits not initialized
Services that are instantiated by plugins, and thus don't have a .conf
file, tried to use uninitialized rlimits.  This caused the kernel to
immediately kill those services for violating their own rlimits.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 09:11:56 +01:00
Joachim Wiberg 80e4f025d3 flog: new helper function for debugging to file
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 09:09:34 +01:00
Joachim Wiberg 064d124e19 Refactor, add new helper fn paste() to concat directory compoents
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-25 17:41:39 +01:00
Joachim Wiberg f8a989439b Minor, insert '/' only if pasting components require it
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-25 17:18:44 +01:00
Joachim Wiberg 74d3194775 Follow-up to f4a0b99: track modifications of service env: files
Add support for monitoring environment files for services declared with
the `env:[-]/path/to/file` option.  The default path to such files has
been chosen to follow Debian and Buildroot /etc/default/*

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-25 17:14:26 +01:00
Joachim Wiberg 7ef25abecf Refactor, use new iwatch module for inotify of Finit *.conf files
- Use iwatch, modeled after pidfile plugin
- Use one .conf watcher for all *.conf paths/files
- Use full path of conf file for changes, from realpath().
  This fixes a long-standing limitation on unique filenames
  for services, that absolutely nobody knew about

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-25 14:28:03 +01:00
Joachim Wiberg 8790fcabf3 iwatch: minor, check if file/dir exists before trying to add
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-25 14:27:01 +01:00
Joachim Wiberg 3d9ee49759 Follow-up to 6cdcacf, fix minor regression, premature clear of pid
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-25 14:23:45 +01:00
Joachim Wiberg 939c6f2f67 Fix regression in displaying progress at runtime
We don't want to show progress (starting/stopping/restaring) at
runtime, since Finit v3.  Many systems hooked up to a console
get confused by sudden output, or even ansi escape sequences.

This patch drops code added recently which caused a regression
in this policy.  The resulting code is even more readable.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-25 00:22:01 +01:00