Commit Graph
1896 Commits
Author SHA1 Message Date
Jonas Holmberg a19a3c774e Fix issue where svc_find() finds the wrong service
This issue may arise in situations where the name of the service being
compared is a sub-string of the service we want to see if it exist.

Example:
  - Two different services: teamd, teamdagentd
  - They have the same id, 1 being the default if none is specified
  - The service with the shortest name is created first

While checking if the "teamdagentd" service exists we eventually compare
it to the "teamd" service.  Prior to this fix we only compare the names
names with the length of the existing service.  Hence, teamdagentd will
seem to be the same as teamd since the first part of the string is equal
to the existing.

Signed-off-by: Jonas Holmberg <jonas.holmberg@westermo.se>
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-07 13:23:53 +01:00
Joachim Nilsson a4f1330eae Simplify, no need to check svc->id, is always a valid string
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-07 13:21:46 +01:00
Joachim Nilsson 38d768ac9e Travis-CI: Enable all -Wfoo CFLAGS globally and build logit in all
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-07 13:07:27 +01:00
Joachim Nilsson 36b14f9ff7 Travis-CI: Move environment variable PKG_CONFIG_PATH to env:->global:
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-07 13:06:55 +01:00
Joachim Nilsson bdbd2afc40 Travis-CI: Re-enable clang builds after Coverity Scan run
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-07 13:05:26 +01:00
Joachim Nilsson 33bb6ed5ac Add --enable-logit to configure, disabled by default
Since sysklogd now ships an excellent enhanced logger tool there is no
need for Finit to provide its own tool for the same purpose by default.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-07 13:02:06 +01:00
Joachim Nilsson 212083b922 Introduce strterm(), hard-add terminating '\0' at end of buffer
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-07 03:02:39 +01:00
Joachim Nilsson 55c49a0bf0 Sanitize job[:id] tuple read from UNIX socket using a regex
This is a really tight check for a single "job[:id]" tuple, not much
escapes it, Coverity should be a lot more happy about our addressing
CWE-20 with this one.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-07 02:51:15 +01:00
Joachim Nilsson b369e1cfa2 Refactor svc_parse_jobstr(), use tokstr() instead of strtok_r()
This is a safer version of strtok() that makes sure we do not step
outside of string bounds.  Coverity complained about this, but was
likely more concerned with the lacking sanitize() and trusting data
read from a UNIX domain socket ...

Note: not only is tokstr() not re-entrant, it is also hard-coded
      to only check for whitespace as token separator.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-07 02:51:15 +01:00
Joachim Nilsson cfefe23275 Fix another GCC 9 string truncation warning
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-07 02:51:15 +01:00
Joachim Nilsson 338c358a75 Defensive programming, check bounds of loop variable first
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-07 02:51:15 +01:00
Joachim Nilsson fe017642de Refactor do_query() to same calling convention used elsewhere
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-07 02:51:15 +01:00
Joachim Nilsson 8d271ac5b8 Fix GCC 9 string trunction warning
- Increase size of resulting path buffer, unlikely a real problem
- Check return value from snprintf() to detect errors and truncation
- Add logit() function wrapper to initctl, maps to _e()/_d()/_pe()

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-07 01:03:57 +01:00
Joachim Nilsson 744719219e initctl: Remove experimental cond set/clear commands
The commands are both unsafe (insecure) and send the wrong message,
that initctl can be used to script conditions.  Only plugins are
officially supported to manage conditions.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-07 00:35:13 +01:00
Joachim Nilsson 7bf2fcb6e3 Fix Coverity CID 265222, guard init_request::data member
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-06 23:56:59 +01:00
Joachim Nilsson ae9ed20d94 Revert "Attempt to fix Coverity CID 265222"
This reverts commit 238f63c0d3.
2020-01-06 23:54:32 +01:00
Joachim Nilsson a5c9d0a3f4 initctl: Fix file descriptor leak, found by Coverity
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-06 22:04:59 +01:00
Joachim Nilsson a8c071c5ef Fix memory leak, call strdup() as late as possible, found by Coverity
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-06 22:03:01 +01:00
Joachim Nilsson 238f63c0d3 Attempt to fix Coverity CID 265222
When reading data from (presumably) initctl over the UNIX domain socket
we might actually be receiving corrupt data from a malicious attacker.

This patch is an attempt at, the very least, guarding against C string
functions reading out of bounds due to non-NULL terminated strings.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-06 21:58:03 +01:00
Joachim Nilsson 41647a814c Handle improbable case were dev may be NULL, found by Coverity
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-06 21:46:44 +01:00
Joachim Nilsson 765ef63274 Handle mkdir() error in cgroups, don't fail if already exists
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-06 21:41:43 +01:00
Joachim Nilsson 6a5f4398a2 initctl: Check mkdir() for error and give helpful message on fail
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-06 21:37:07 +01:00
Joachim Nilsson 7fc515678f Check if svc ID is non-empty before strcmp(), found by Coverity
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-06 21:31:04 +01:00
Joachim Nilsson e410a24d13 Fix %s i _d() message
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-06 21:26:51 +01:00
Joachim Nilsson 397f67d03a Clear current line before starting built-in getty
When logging out from the shell, e.g. with Ctrl-D, artifacts from that
session may remain on the current line.  This patch makes sure to clear
up that line before issuing a newline and starting the built-in getty.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-06 19:37:00 +01:00
Joachim Nilsson b4b9111b33 Enable line wrap in TTY, in case was disabled previously
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-06 19:26:56 +01:00
Joachim Nilsson c19489d6c3 Add support for @console to external getty in tty_register()
- Refactor code to figure out device so it works for both the built-in
  and external getty code paths
- Fix memory leak when user edits an existing tty device
- Replace @console in argument list to external getty

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-06 19:05:20 +01:00
Joachim Nilsson 00a2840853 Allow Ctrl-U, Ctrl-D again in built-in getty
Many users found it very frustrating that it was impossible to use
standard commands like Ctrl-U and Ctrl-D at the login: prompt.  It
was never the intention to hamper users for no reason like that.

Also, compensate for cursor-up in "Please press Enter" wait-handler.
Curiously, this makes everything very neat looking also when having
'nowait' enabled for the tty.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-06 19:01:53 +01:00
Joachim Nilsson d1718d338e Set proper RAW mode for "Please press Enter to activate ..."
Also, while leading with a \n for the activation text and clearing the
line before getty is called, some getty implementations, e.g. BusyBox,
write an extra \n before printing /etc/issue.  For perfectionists that
want a single newline separating started services and the first line
of /etc/issue we now not only clear the line, we also move the cursor
one line up before handing over to getty.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-06 18:58:08 +01:00
Joachim Nilsson 58ade5d74e Allow built-in getty to show in ps as 'tty DEV'
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-06 18:52:40 +01:00
Joachim Nilsson c391e04983 Hide command line arguments from ps, for forked children like getty
The built-in gety in Finit forks but does not execv().  To prevent
confusion on the part of the user, this patch hides all command line
arguments to PID 1 so it won't show up in ps listings of children.

Finit currently reads its arguments from the kernel /proc/cmdline,
it has hard-coded paths to /etc/finit.conf etc.  A future version
of Finit may take command line params, in which case this patch
should be moved after any getopt() handling.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-06 18:49:14 +01:00
Joachim Nilsson 85fe613b30 Account for 3-4 byte wide unicode characters in heading
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-05 16:10:41 +01:00
Joachim Nilsson 880ad98dbe Workaround markdown parser
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-04 11:49:50 +01:00
Joachim Nilsson b1a88df9fc Pad heading in modern style using ═══════════════════
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-04 11:40:09 +01:00
Joachim Nilsson aaf7888411 Move badges to top row
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-03 14:27:45 +01:00
Joachim Nilsson 6edb01a72b Update ingress, time passes oh so quickly ...
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-03 14:27:41 +01:00
Joachim Nilsson 636f6678ed Introducing Finit progress 𝓜𝓸𝓭𝓮𝓻𝓷
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-02 14:59:32 +01:00
Joachim Nilsson 3b62f46599 TODO: Remember to collect siginfo_t on SIGCHLD
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-12-12 17:57:09 +01:00
Joachim Nilsson 49f0d94b95 Drop reference to non-existing site, refers to *good* example now
Also, drop the Emacs hint, not needed anymore.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-04 06:09:59 +01:00
Joachim Nilsson abccb26a83 Check for pkg-config in configure before looking for deps
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-07-04 22:26:08 +02:00
Joachim Nilsson 0848b9b07a Minor, replace cgroup hard-coded path with path from configure
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-05-14 10:15:10 +02:00
Joachim Nilsson c64188bfc5 plugins: rtc: Simplify failed restore from RTC warning
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-04-29 18:20:38 +02:00
Joachim Nilsson 5e789401d4 Rename hwclock.so plugin to rtc.so since it's now stand-alone
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-04-05 21:35:13 +02:00
Joachim Nilsson 744fdd654f plugins: hwclock: Native ioctl support for RTC, skip hwclock tool
The BusyBox hwclock is really bad at handling, or rather displaying,
errors properly.  When the kernel signals EINVAL, or ENOENT, it just
shows that message on stderr.

This patch implements proper RTC load/store at boot/halt with quite
some improved error handling suitable for embedded systems.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-04-05 21:27:39 +02:00
Joachim Nilsson f51fde4d46 Initial support for cgroups
Similar to how systemd creates cgroups for all services, for purposes of
tracking, Finit now does the same.  We also mount all available cgroups
in the /sys/fs/cgroup namespace.

This patch adds support for grouping processes in logical cgroups, like
systemd, and an `initctl ps` command to list the hieararchy.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-02-05 18:35:36 +01:00
Joachim Nilsson 85261c9acd initctl: Create 'enabled' services directory if it doesn't exist
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-02-05 12:42:13 +01:00
Joachim Nilsson 6a1082a947 New helper function: echo(), like shell echo but for C
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-02-05 10:33:00 +01:00
Joachim Nilsson 2094d2a53a Warn if Finit fail to mount /proc and /sys
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-02-05 10:31:36 +01:00
Joachim Nilsson d7da177742 Relocate images to img/
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-01-27 10:56:39 +01:00
Joachim Nilsson 170e5aa3fd docs: TODO: Drop simple conf item, contrib/finit.conf exists
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-01-27 10:54:47 +01:00