Compare commits

..

388 Commits

Author SHA1 Message Date
William Hubbs
930e69017f version 0.44.6 2021-10-04 10:36:14 -05:00
William Hubbs
44912434cf update ChangeLog 2021-10-04 10:31:46 -05:00
William Hubbs
c7fde9a3da fix build for selinux
I would like to thank jpds@protonmail.com for the patch.

X-Gentoo-Bug: 815847
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=815847
2021-10-04 10:26:53 -05:00
William Hubbs
ffededbf95 version 0.44.5 2021-09-21 11:21:17 -05:00
William Hubbs
b0efb663f9 update ChangeLog 2021-09-21 11:12:35 -05:00
William Hubbs
aa69e48125 build: fix rootprefix
This fixes #438.
2021-09-21 11:10:36 -05:00
William Hubbs
4ba10f1d50 link runscript with audit 2021-09-18 17:06:19 -05:00
William Hubbs
38a9e2ff63 link openrc-run with audit and libpam_misc 2021-09-18 17:06:19 -05:00
William Hubbs
783af5abac version 0.44.4 2021-09-15 10:27:48 -05:00
William Hubbs
75c3b53e31 update ChangeLog 2021-09-15 10:25:47 -05:00
Natanael Copa
c300c180a2 hide error when migrating /var/run to /run
The script tries to copy non-existing files. We simply hide the error

http://bugs.alpinelinux.org/issues/3160
This fixes #451.
2021-09-15 10:23:59 -05:00
Natanael Copa
be8d2ee6e3 force root to be rw before localmount
The original service that pulled in root remount was mtab which
is not part of OpenRC.

This fixes #449.
2021-09-14 11:51:40 -05:00
Aaditya Bagga
d9ef1bb635 [runit integration] give a bit of time to start the service
Currently, we run sv start immediately after linking the service.
The runsv process may not be up at the moment, as a result of which
openrc will mark the service as stopped, even though it may be brought up
by runit at the next scan.

This is documented in the gentoo wiki:
https://wiki.gentoo.org/wiki/Runit#OpenRC.27s_runit_integration_feature

This PR adds a timeout so that correct process state can be reported.

Before:
 * Starting netdata-runit ...
fail: /run/openrc/sv/netdata: runsv not running
 * Failed to start netdata-runit

After:
 * Starting netdata-runit ...
fail: /run/openrc/sv/netdata: runsv not running
ok: run: /run/openrc/sv/netdata: (pid 9042) 0s

This fixes #253.
2021-09-12 13:28:20 -05:00
Jakub Jirutka
cfc6991219 Fix undeclared UT_LINESIZE
Fix the following error:

	broadcast.c:41:21: error: '__UT_LINESIZE' undeclared (first use in this function); did you mean 'UT_LINESIZE'?
	 #define UT_LINESIZE __UT_LINESIZE
                          ^~~~~~~~~~

Constant UT_LINESIZE is defined in <utmp.h> provided by musl.
2021-09-09 22:42:51 -05:00
Sören Tempel
97ae5af201 rc-mount: make timeout invocation compatible with busybox timeout
Busybox timeout does not support the `-k` flag. As such, invoking fuser
from do_unmount never worked without this patch. This went unnoticed as
standard error is redirected to /dev/null. This patch fixes this by
simply removing the incompatible `-k` flag.

[Ariadne: the `-k` is redundant anyway, since we are sending the KILL
 signal to begin with.]
2021-09-09 22:18:22 -05:00
William Hubbs
4c820a0e48 version 0.44.3 2021-09-09 12:56:50 -05:00
William Hubbs
9c39b381a5 update ChangeLog 2021-09-09 12:53:42 -05:00
Ariadne Conill
321bb2cd90 fix build under musl 1.2 on 32 bit systems
Since musl 1.2 time_t is a 64 bit value, even on 32 bit systems. A
hotfix for printing the value is simply using PRIu64 from inttypes.h
in the format string.

This fixes #446.
2021-09-09 12:49:03 -05:00
Ariadne Conill
8c99d817d4 fix trailing whitespace in tools/meson_runlevels.sh 2021-09-09 12:49:03 -05:00
2e1fb4d02b meson: fix symlinks with sysvinit 2021-09-08 18:18:39 -05:00
William Hubbs
a2f0afb8bc version 0.44.2 2021-09-08 15:36:20 -05:00
William Hubbs
430fa132f2 update ChangeLog 2021-09-08 15:33:46 -05:00
William Hubbs
12cd7ce9de build: install pam files 2021-09-08 15:31:42 -05:00
William Hubbs
167acac140 meson: typo fix 2021-09-08 15:31:42 -05:00
William Hubbs
f839ba27c5 version 0.44.1 2021-09-08 13:41:39 -05:00
William Hubbs
80dd6aac5f update ChangeLog 2021-09-08 13:41:20 -05:00
William Hubbs
0d00b8d8ab build: fix sysvinit script installation 2021-09-08 13:37:36 -05:00
William Hubbs
551bdff2fb build: fix symlinks 2021-09-08 13:37:36 -05:00
William Hubbs
803aa1c637 version 0.44 2021-09-07 16:16:51 -05:00
William Hubbs
fb186a3867 update ChangeLog 2021-09-07 16:14:08 -05:00
William Hubbs
c9b64b64fa update README 2021-09-07 16:13:35 -05:00
William Hubbs
9cce9f8ce8 news typo fix 2021-09-07 15:59:19 -05:00
William Hubbs
5a41f1ef20 add discussion about removing old build system to NEWS 2021-09-07 14:17:44 -05:00
William Hubbs
6e3afc29f3 update NEWS 2021-09-07 13:31:16 -05:00
William Hubbs
7c29fbd36f build: install bash and zsh completions 2021-09-07 12:45:53 -05:00
William Hubbs
593be166d1 build: fix libexecdir 2021-09-06 18:52:54 -05:00
William Hubbs
ca0270967c tools/meson_final.sh: typo fix 2021-09-06 18:37:11 -05:00
William Hubbs
3a187f88f4 build: typo fix 2021-09-06 16:04:46 -05:00
William Hubbs
f2362cc277 build: add split-usr option 2021-09-06 15:22:28 -05:00
William Hubbs
444e44eb9d build: change root_prefix to rootprefix 2021-09-06 14:30:30 -05:00
William Hubbs
c0f8313164 sync meson build version with makefiles 2021-09-05 20:04:55 -05:00
William Hubbs
d6622a1156 add meson build files
Closes #116.
Closes #171.
Closes #172.
Closes #175.
2021-09-04 16:01:29 -05:00
William Hubbs
92004a2ed6 README: add note about github discussions 2021-09-04 14:23:18 -05:00
Matt Whitlock
5f6d7ac028 supervise-daemon: implement SSD_IONICELEVEL
supervise-daemon was apparently overlooked when support for the
SSD_IONICELEVEL environment variable was added. This commit brings
supervise-daemon up to parity with start-stop-daemon with respect to
this environment variable.
2021-08-17 00:57:47 -04:00
William Hubbs
7cedc4942b update travis ci irc notifications
- move to libera network
- always notify on successful build
2021-08-14 15:05:07 -05:00
William Hubbs
091cd8015f man/supervise-daemon.8: document --pidfile option 2021-08-13 23:08:07 -05:00
Sven Wegener
63955056ec on_ac_power: support multiple power_supply devices in sysfs
Newer devices have multiple power_supply devices in sysfs:

$ grep ^ /sys/class/power_supply/*/type
/sys/class/power_supply/AC/type:Mains
/sys/class/power_supply/BAT0/type:Battery
/sys/class/power_supply/ucsi-source-psy-USBC000:001/type:USB
/sys/class/power_supply/ucsi-source-psy-USBC000:002/type:USB

There are two "USB" Type-C ports than can supply power and both are
aggregated into the "Mains" power supply by the firmware. The "Battery"
also counts as a power supply, but is missing the online attribute.

The -f check with a wildcard pattern results in an error, when multiple
devices are present:

/lib/rc/bin/on_ac_power: line 21: [: too many arguments

When the power_supply class is registered, check for a "Mains" device.

Fixes #427.
2021-08-13 13:38:07 -05:00
Alex Xu
1e975be896 conf.d/hostname: clarify hostname variable usage
https://gitlab.alpinelinux.org/alpine/aports/-/issues/9744

This fixes #433.
2021-08-13 13:13:14 -05:00
kyoreln
18e53f7fed move supervise-daemon out of experimental status
supervise-daemon is no longer experimental so remove the statements to
that affect.

This fixes #434.
2021-08-13 12:46:52 -05:00
William Hubbs
b5e4c2c2db Revert "openrc-init: ignore an empty string in argv[1]"
This reverts commit dec9ef200b.
This check is no longer needed since rc_runlevel_exists() is fixed.

    X-Gentoo-Bug: 803536
    X-Gentoo-Bug-URL: https://bugs.gentoo.org/803536
    Closes: https://github.com/OpenRC/openrc/pull/431
2021-08-13 10:46:57 -05:00
William Hubbs
0a97bad6c9 librc: fix rc_runlevel_exists return for empty string
This function should return false if the runlevel is an empty string.

    X-Gentoo-Bug: 803536
    X-Gentoo-Bug-URL: https://bugs.gentoo.org/803536
    Closes: https://github.com/OpenRC/openrc/pull/431
2021-08-13 10:28:44 -05:00
Mike Gilbert
dec9ef200b openrc-init: ignore an empty string in argv[1]
X-Gentoo-Bug: 803536
X-Gentoo-Bug-URL: https://bugs.gentoo.org/803536
Closes: https://github.com/OpenRC/openrc/pull/431
2021-08-12 15:04:38 -05:00
William Hubbs
7f47539fb1 sh/rc-cgroup.sh: fix case in starting message
X-Gentoo-Bug: 804193
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=804193
2021-08-12 14:23:34 -05:00
William Hubbs
9c7bedca9e sh/rc-cgroup.sh: fix cgroup_cleanup
X-Gentoo-Bug: 804193
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=804193
2021-08-12 14:21:58 -05:00
William Hubbs
1d282ddc80 move the irc channel to the libera network 2021-05-23 16:45:32 -05:00
Lars Wendler
0d86c4903b init.d/modules.in: Avoid loading modules twice in Linux with dash shell
Since commit 6b475ab269, openrc tries to load
modules twice which have been defined in /etc/conf.d/modules via modules=
variable when /bin/sh points to dash shell.
The reason is that when the "modules-load" service was merged into "modules"
service, the "modules" variable name got used in both, load_modules()
function and in Linux_modules() function which both get called when modules
service is started. Although "modules" variable is marked as local in
load_modules(), dash simply ignores this.

Avoid the issue by renaming "modules" variable to "_modules" in
load_modules() function.

This fixes #419.
2021-05-12 18:20:43 -05:00
William Hubbs
791322d7fa checkpath: fix code to walk the directory path
X-Gentoo-Bug: 782808
X-Gentoo-Bug-URL: https://bugs.gentoo.org/782808
2021-04-15 17:40:00 -05:00
William Hubbs
63db2d99e7 checkpath: remove extra slashes from paths
This fixes #418.
2021-04-13 17:13:25 -05:00
William Hubbs
8400e7d302 style fix 2021-04-13 16:29:21 -05:00
William Hubbs
533a8c70b3 cgroup2_set_limits: fix harmless error message
In legacy cgroups mode, we were running `mountinfo -q ""` which was
generating an error message. If we return immediately when
cgroup2_find_path returns an empty value, we avoid this message.
2021-04-04 17:31:49 -05:00
William Hubbs
852a3c86f6 NEWNET.md: fix the title 2021-04-03 15:18:30 -05:00
William Hubbs
b3e8072403 rename README.newnet to a markdown file
All of our documentation is in markdown, so rename this file to be
consistent.
2021-04-03 15:14:35 -05:00
William Hubbs
b7c03dea27 README: convert references to markdown links 2021-04-03 15:13:09 -05:00
William Hubbs
ee05403c50 version 0.43 2021-04-02 12:47:39 -05:00
William Hubbs
c1558abb0f update ChangeLog 2021-04-02 12:43:37 -05:00
William Hubbs
901b752463 README: force references to be on separate lines for github 2021-04-02 12:35:29 -05:00
William Hubbs
c88368b792 update news
This adds a note about SHLIBDIR being dropped from the makefiles.
2021-04-02 11:37:35 -05:00
William Hubbs
bfffe2c585 drop reference to gentoo bugzilla
OpenRC has a bug tracker on github, so ask people to file issues there.
2021-03-29 12:55:04 -05:00
William Hubbs
5f890ee8ab init.sh: rework the /run setup for linux xystems
- fix mount options for /run.
- run restorecon after everything is set up.

X-Gentoo-Bug: 740576
X-Gentoo-Bug-URL: https://bugs.gentoo.org/740576
2021-03-22 15:47:21 -05:00
William Hubbs
ef76a663bc stop namespaced services with specified pids
The previous fix excludes PIDs of processes running in a different namespace
regardless of whether the PID has been explicitly stored in a PID file mentioned
in the --pidfile parameter.  The correct behavior is to only exclude the pid if
it is not stored in a pidfile.

X-Gentoo-Bug: 776010
X-Gentoo-Bug-URL: https://bugs.gentoo.org/776010
2021-03-22 11:34:41 -05:00
William Hubbs
fccd37c34c add PKGCONFIGDIR to the makefiles
This allows pkgconfig files to be stored in /usr even if PREFIX is /.
2021-03-21 17:41:58 -05:00
William Hubbs
5058b6668c drop shlibdir
I know of no other build systems that have separate paths for static vs
shared libraries, so this changes ours to use libdir for all libraries.
2021-03-21 17:20:25 -05:00
Thomas Deutschmann
1878a74a12 numlock: Don't disable numlock on shutdown
When dealing with remote consoles, a shutdown could disable
host's numlock which is not desired.

This fixes #413.
2021-03-19 10:36:31 -05:00
btdmaster
897c2c00ef README: Wrap 'make install' in backticks
This fixes #412
2021-03-18 16:50:43 -05:00
William Hubbs
08d518b7fe rc_cgroup.sh: do not add newline when writing group2 values
Fixes: #407
2021-03-15 16:59:43 -05:00
William Hubbs
de77674663 rc-cgroup.sh: avoid process substitution for cgroup_get_pids
This should make cgroup_cleanup work successfully since cgroup_get_pids
no longer uses a subshell.

This fixes #396.
This fixes #397.
2021-03-01 14:21:24 -06:00
William Hubbs
4fb4674374 fix unified cgroups v2 setup
The cgroups v2 setup required the rc_cgroups_controllers variable
to be set to the list of controllers to enable regardless of whether the
mode was hybrid or unified.

This makes sense for hybrid mode since the controllers can't be in both
the cgroups v1 and v2 hierarchies, but for unified mode we should enable
all controllers that are configured in the kernel.
2021-02-23 23:08:56 -06:00
Disconnect3d
0ddab761be start-stop-daemon: Fix off by ones when checking for RC_* envvars
The same as https://github.com/OpenRC/openrc/pull/361

This fixes #362.
2021-02-22 16:09:32 -06:00
Disconnect3d
f5dd2f5baf supervise-daemon: Fix off by ones when checking for RC_* envvars
Fixes strncmp size argument off by one as the current implementation didn't
match the `=` character.

This fixes #361.
2021-02-22 15:34:45 -06:00
Rin Cat
b12c52d40f Support docker and lxc stop
This fixes #398.
2021-02-22 11:56:21 -06:00
sqozz
bac71fce5b start-stop-daemon: fix typo in manpage 2021-02-02 10:04:57 -05:00
William Hubbs
12ee72a9b3 allow devfs to run on lxc
X-Gentoo-Bug: 761918
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=761918
Closes #272.
2021-01-28 12:32:09 -06:00
William Hubbs
170ce2624a typo fix 2021-01-05 17:11:01 -06:00
William Hubbs
9a6698876a improve the diagnostic when the ulimit builtin fails
X-Gentoo-Bug:739274
X-Gentoo-Bug-URL:https://bugs.gentoo.org/739274
2021-01-05 17:02:30 -06:00
Gaël PORTAY
bf9af1fb23 net-online: fix process of symlinks in sysfs
The test `[ -h "${ifname}" ] && continue` skips the symlinks while it is
the opposite that is the expected: ignoring files that are not symlinks.

Fixes commit f42ec82f21.
This fixes #391.
2020-12-22 12:49:48 -06:00
Patrick Noll
5c9c2a1939 remove statement about not providing an init
This fixes #359.
2020-12-22 12:10:15 -06:00
Manuel Rüger
4b2a61f1b8 rc-status: Remove noise from ini-formatted output
Otherwise this would create the following output:

rc-status -f ini
 * Caching service dependencies ...        [ ok ]
[default]
dbus =  started
NetworkManager =  started
syslog-ng =  started
...

This fixes #364.
2020-12-20 16:01:02 -06:00
William Hubbs
62bc463c63 update freebsd 11.x image on cirrus ci 2020-12-20 15:37:52 -06:00
Clayton Craft
7019bfad3b user-guide: clarify note for Runlevels/rc-update usage
I found the original note a little confusing, since using rc-update will
add it to a runlevel so it *is* auto-started when the system reaches
that runlevel again, but I don't think that was the intended meaning of
'auto-start', so hopefully this makes it a little more clear.
2020-12-20 13:54:33 +01:00
lishuxiang
8346c985d5 Update user-guide.md
fix a typo

This fixes #389.
2020-12-05 12:42:00 -06:00
William Hubbs
da30767353 supervise-daemon: do not spawn a process if we are exiting
This fixes #375 and allows us to not add another level of indentation in
the supervisor loop.
2020-11-29 21:22:43 -06:00
Dermot Bradley
57d9528a0b Remove warning when osclock init.d script runs
Currently when osclock is enabled as a init.d service the following
messages appear during boot when osclock starts:

  * The command variable is undefined.
  * There is nothing for osclock to start.
  * If this is what you intend, please write a start function.
  * This will become a failure in a future release.

osclock is activated whenever a machine's system clock is automatically
configured from a RTC by the kernel and the osclock's only purpose is to
satisfy the "clock" dependency defined by other init.d services.

Adding a stub start() function prevents OpenRC from showing warnings but
continues to ensure that the osclock service still does not actually do
anything.

This fixes #377.
2020-11-27 18:06:38 -06:00
Calvin Montgomery
6ce48f124a man/openrc.8: populate OPTIONS from --help output
This fixes #378.
2020-11-27 17:46:27 -06:00
Michael Orlitzky
00ea216608 src/rc/checkpath.c: replace mkdir() with mkdirat().
The do_check() function recently gained some defenses against symlink
replacement attacks that involve the use of *at functions in place of
their vanilla counterparts; openat() instead of open(), for example.
One opportunity to replace mkdir() with mkdirat() was missed, however,
and this commit replaces it.

This fixes #386.
2020-11-27 17:29:26 -06:00
Michael Orlitzky
ac7ca6d901 src/rc/checkpath.c: fix typo "synbolic" -> "symbolic". 2020-11-27 17:25:30 -06:00
Johannes Heimansberg
47819f004c start-stop-daemon, supervise-daemon: fix parsing of usernames passed via --user that start with a number
start-stop-daemon and supervise-daemon parse usernames and group names
passed via the --user argument as numeric UID/GID if they start with a
number (e.g. user "4foo" will be treated as UID 4). This results in the
process that is being started to run under a totally unexpected user if
that UID exists.

Even though the result of the sscanf calls are tested for a result of
exactly 1, which means exactly one value was extracted, because sscanf's
format string only contains only one placeholder, it will never return
a value greater than 1, even if there are still characters left to be
parsed. This causes start-stop-daemon and supervise-daemon to assume
that usernames starting with a number are just that number. Adding a
second placeholder "%1s" to the format string, which matches a string of
length 1, makes sure that sscanf can distinguish between pure numbers
(in which case it will return 1) and strings either starting with a
number (in which case it will return 2) and any other string (in which
case it will return 0).

This fixes #379.
This fixes #380.
2020-11-27 16:40:12 -06:00
William Hubbs
0fab3e837b bootmisc: allow sysvinit compatibility during shutdown
Use "halt -w" to write the halt record if it exists.
Otherwise use openrc-shutdown.

This fixes #336.
2020-11-27 15:18:57 -06:00
William Hubbs
38aaba28ee scripts/shutdown.in: fix sysvinit compatible shutdown
X-Gentoo-Bug: https://bugs.gentoo.org/755422
2020-11-20 14:57:04 -06:00
William Hubbs
3ed4126a31 update news for 0.43 with info on checkpath fix 2020-11-20 10:00:34 -06:00
Lars Wendler
aa0fdf6d08 start-stop-daemon: Don't segfault if --exec was given a non-existing file name
Starting program: /sbin/start-stop-daemon --start --exec i-dont-exist

  Program received signal SIGSEGV, Segmentation fault.
  0x0000555555559053 in main (argc=1, argv=0x7fffffffdc20)
      at start-stop-daemon.c:631
  631                         *exec_file ? exec_file : exec);

This fixes #385.
2020-11-20 09:22:18 -06:00
William Hubbs
b6fef599bf checkpath: fix CVE-2018-21269
This walks the directory path to the file we are going to manipulate to make
sure that when we create the file and change the ownership and permissions
we are working on the same file.
Also, all non-terminal symbolic links must be owned by root. This will
keep a non-root user from making a symbolic link as described in the
bug. If root creates the symbolic link, it is assumed to be trusted.

On non-linux platforms, we no longer follow non-terminal symbolic links
by default. If you need to do that, add the -s option on the checkpath
command line, but keep in mind that this is not secure.

This fixes #201.
2020-11-20 09:15:59 -06:00
Julien Surloppe
aac1734a70 Update user-guide.md
Add missing underscore.
2020-11-01 15:45:12 -05:00
William Hubbs
2355f1a3f2 supervise-daemon: only log debug logs when verbose mode is active 2020-09-25 16:33:32 -05:00
Manuel Rüger
fbec1eed51 .cirrus.yml: Update FreeBSD releases
Signed-off-by: Manuel Rüger <manuel@rueg.eu>
2020-04-19 13:15:35 +02:00
Austin English
229692cc34 man/openrc-run.8: fix a typo 2020-02-05 12:37:46 -05:00
Sergei Trofimovich
375ef42393 src/rc/rc-logger.h: fix build failure against gcc-10
On gcc-10 (and gcc-9 -fno-common) build fails as:

```
cc  -L../librc -L../libeinfo -O2 -g -std=c99 -Wall -Wextra -Wimplicit -Wshadow \
  -Wformat=2 -Wmissing-prototypes -Wmissing-declarations -Wmissing-noreturn \
  -Wmissing-format-attribute -Wnested-externs -Winline -Wwrite-strings \
  -Wcast-align -Wcast-qual -Wpointer-arith -Wdeclaration-after-statement \
  -Wsequence-point -Werror=implicit-function-declaration    \
  -Wl,-rpath=/lib   -o openrc rc.o rc-logger.o rc-misc.o rc-plugin.o _usage.o -lutil -lrc -leinfo -Wl,-Bdynamic -ldl
ld: rc-logger.o:/home/slyfox/dev/git/openrc/src/rc/rc-logger.h:16:
  multiple definition of `rc_logger_pid'; rc.o:openrc/src/rc/rc-logger.h:16: first defined here
ld: rc-logger.o:/home/slyfox/dev/git/openrc/src/rc/rc-logger.h:17:
  multiple definition of `rc_logger_tty'; rc.o:openrc/src/rc/rc-logger.h:17: first defined here
```

gcc-10 will change the default from -fcommon to fno-common:
https://gcc.gnu.org/PR85678.

The error also happens if CFLAGS=-fno-common passed explicitly.

This fixes #348.
2020-01-19 16:52:21 -06:00
Wolf
6deda13754 supervise-daemon: Fix segfault when executable does not exist
When executable is provided just by name (and therefore searched in a
path), exec_file is reset to NULL every time. exists() handles it being
NULL just fine, but dereferencing it in eerror does not work.

Fixes #326
Fixes #327
2020-01-11 13:36:33 -06:00
eb61085951 binfmt: ensure a file is ungegistered before registering
This fixes #328
2020-01-11 13:32:38 -06:00
Andrew Scheller
039845b742 Fix typo in README
This fixes #338
2020-01-11 12:16:19 -06:00
Ethan Sommer
a7e7fd2b37 make grep usage POSIX compliant
use grep -E instead of egrep
check for space or end of line instead of GNU-specific word boundary

This fixes #345
2020-01-11 12:09:10 -06:00
Jason Bowen
12e147a107 Delete stray text.
It looks like some stray text was left at the bottom of the file:
```
package.
migrating your system to openrc-init.
```
There's a subsection on migrating a system to `openrc-ini`; perhaps this was
an embryonic section title?

This fixes #347.
2020-01-11 11:15:56 -06:00
William Hubbs
fd852865e0 openrc-shutdown.c: typo fix 2019-12-05 12:11:08 -06:00
William Hubbs
35ec935741 ci/travis.sh: run shellcheck on shell scripts 2019-10-28 18:42:10 -05:00
Austin English
19cfd82dad .travis.yml: install shellcheck 2019-10-28 16:48:40 -05:00
E5ten
87cfad3d6c cgroup2_set_limits: verify that the cgroup2 path is a mount point
prior to cgroups getting mounted, /sys/fs/cgroup will still exist,
but attempts to make directories in it will fail, change cgroup2_set_limits() to
verify that cgroups are mounted instead of just checking that /sys/fs/cgroup
exists.

This fixes #307.
This fixes #321.
2019-09-03 16:38:03 -05:00
William Hubbs
8e31614c4b fix clang build 2019-08-20 16:06:46 -05:00
William Hubbs
a177d15641 version 0.42 2019-08-20 13:13:30 -05:00
William Hubbs
2b4c486043 Update ChangeLog 2019-08-20 13:09:50 -05:00
William Hubbs
ed24d28163 update sysvinit support files 2019-08-20 13:08:44 -05:00
William Hubbs
1bc96141e6 fix single user mode 2019-08-19 14:55:54 -05:00
William Hubbs
c7000aeaab optimize loops for installing gettys 2019-08-15 18:40:51 -05:00
William Hubbs
5c5129b534 Remove "single" runlevel directory
Single user mode should be handled in the init process directly.
2019-08-15 18:40:51 -05:00
William Hubbs
0dabda6f6f fix sysvinit compatibility
This allows openrc to direct sysvinit to shut down the system by setting
the INIT_HALT environment variable appropriately. Also, we do not try to
communicate with sysvinit if its fifo does not exist.
2019-08-15 12:02:30 -05:00
William Hubbs
92de9a693b Add documentation for openrc-init and update the NEWS file 2019-08-02 16:29:03 -05:00
William Hubbs
a71aebcae1 init.d/agetty: provide the getty virtual service 2019-07-29 17:39:11 -05:00
William Hubbs
61596b16d2 Install gettys if the MKSYSVINIT switch is set to yes
The default is to put one getty in the "single" runlevel and 6 in the
"default" runlevel.
2019-07-29 17:38:47 -05:00
William Hubbs
104eb3420b Add the "single" runlevel 2019-07-29 16:27:14 -05:00
Chloe Kudryavtsev
70b8df3e9c clarify supervise-daemon-guide
1. The given default for respawn_max is wrong.
2. The example for respawn_period is nonsensical.

This fixes #311.
2019-07-26 12:52:52 -05:00
William Hubbs
cac41092e4 add ability for openrc-shutdown to communicate with sysvinit
This fixes #315.
2019-07-25 14:47:18 -05:00
Martin Wilke
7ddc281ab6 Fix build with Clang
This fixes #313.
2019-07-24 12:32:23 -05:00
William Hubbs
c092ff6da1 Add Sony Interactive Entertainment as an author 2019-07-22 10:46:32 -05:00
William Hubbs
54780a4582 supervise-daemon: allow --respawn-max to be zero 2019-03-29 14:09:08 -05:00
William Hubbs
44f5a72d1a remove hidden-visibility.h
I am removing this on the advice of a member of the Gentoo toolchain
team. It was explained to me that this doesn't offer any significant
benefits to OpenRC.

If anyone ffeels differently, please open a pull request reverting
this and adding an explanation of what it does and how to know which
functions to mark hidden in the future.

This fixes #301.
2019-02-26 17:47:55 -06:00
William Hubbs
0d378974bf openrc-init: fix waitpid checks
The do_openrc() function was not waiting properly for the child process
which started the runlevel to return. We need to repeatedly call
waitpid() until its return value matches the pid of the child process or
the child process does not exist.

This fixes #216.
This fixes #300.
2019-02-25 18:55:13 -06:00
William Hubbs
028da5c2e3 librc: fix potential buffer overflow in pid_is_argv
This fixes #299.
2019-02-23 17:44:07 -06:00
William Hubbs
d8dbb890aa Revert "src/librc/librc-daemon.c: fix buffer overrun in pid_is_argv"
This reverts commit 084877eb52.
The mentioned commit caused some systems to have some services reported
as crashed.

This fixes #297.
This fixes #298.
2019-02-23 16:24:55 -06:00
William Hubbs
56c006ebd6 Update ChangeLog 2019-02-22 19:03:41 -06:00
William Hubbs
067088bbff move ci scripts to their own directory
This fixes #296.
2019-02-22 18:50:13 -06:00
William Hubbs
52d4e56674 combine test directories
This fixes #295.
2019-02-22 18:08:19 -06:00
William Hubbs
6e6902c28b remove unused test ignore patterns 2019-02-22 16:27:52 -06:00
William Hubbs
084823182a remove unused test data files 2019-02-22 13:25:51 -06:00
Georgy Yakovlev
7478c104fc librc/librc-depend.c: fix NULL pointer dereference
In some cases deptree or depinfo can be NULL, check
before dereferencing.

Fixes https://github.com/OpenRC/openrc/issues/293
Fixes https://github.com/OpenRC/openrc/pulls/294
X-Gentoo-Bug: 659906
X-Gentoo-Bug-URL: https://bugs.gentoo.org/659906
2019-02-21 17:49:54 -06:00
Georgy Yakovlev
065b7ecc0d use cirrus-ci for FreeBSD builds
This fixes #265.
2019-02-19 13:59:01 -06:00
Sergei Trofimovich
b054aca50b src/test/runtests.sh: drop 'readelf'-based tests
The 'readelf'-based tests cover a few situations:
1. undefined symbols in shared libraries
2. unexpected exports in shared libraries

Bug #575958 shows that [2.] implementation is too simplistic
in assuming that presence of relocation equals to export presence.

It is incorrect for PLT stubs and local symbols.
Let's just drop these tests.

If one needs to cover [1.] it is better to use LDFLAGS=-Wl,--no-undefined.

This closes #292.

X-Reported-by: Benda Xu
X-Gentoo-Bug: https://bugs.gentoo.org/575958
X-Gentoo-Bug-URL: https://bugs.gentoo.org/575958
2019-02-19 11:50:11 -06:00
William Hubbs
f9e7a00ba9 rc-status: style fixes 2019-02-15 20:36:46 -06:00
William Hubbs
f1f48011ac update ChangeLog 2019-02-15 14:37:57 -06:00
William Hubbs
427a1ce299 rc-status: add -f option to allow formatting output
The -f option can be used when showing the status of services in
runlevels to allow making the output more easily parsable.
Currently, the .ini format is the only one supported.
2019-02-15 14:21:43 -06:00
William Hubbs
f43cec34ca rc-status.c: small style changes 2019-02-14 13:14:31 -06:00
William Hubbs
d64c9d2050 add experimental support for an alternate shell for service scripts
This is for #288.
2019-02-13 18:22:25 -06:00
Edan Bedrik
b2b2c57a38 librc: fix realpath() return value check
This fixes #226.
2019-02-12 17:56:17 -06:00
William Hubbs
155b845194 improve shutdown documentation
This fixes #290.
2019-02-12 16:54:12 -06:00
Austin English
9b578808fb travis: try enabling musl-gcc
This fixes #261.
2019-02-11 13:56:55 -06:00
Austin English
03164dd38d fix build with muslc
This fixes #261.
2019-02-11 13:56:33 -06:00
Austin English
2b82766452 test/skel.runtests.sh: remove unused file
git grep shows no usage, and `make test` passes

This fixes #256.
2019-02-11 11:54:10 -06:00
Felix Neumärker
3eef6e9127 zsh-completion: _rc-service support extra actions
- use rc-service <service> describe to get action list

This is for #285.
2019-01-21 17:41:59 -06:00
Felix Neumärker
77f09900a2 zsh-completion: _rc-service fix flag/command combinations
- handle `rc-service -<flag> <service> <action>` correctly

This is for #285.
2019-01-21 17:41:38 -06:00
Kim Jahn
50d77a4e5d man/openrc.8: add openrc-run.8 to see also
This fixes #283.
2019-01-18 13:40:06 -06:00
Mike Frysinger
2d31b0a3f8 man: supervise-daemon: fix various style issues
The .Dt header is supposed to be all caps.  This was mixing case.

The options block was being incorrectly indented due to a missing .El.

Some of the new options were missing the .It block, so add that.

Finally, the -D option was missing capitalization.
2019-01-01 18:36:40 -05:00
William Hubbs
b84d0bac4d travis-ci: add IRC notifications 2018-12-29 11:37:06 -06:00
William Hubbs
1ff3a37c60 start-stop-daemon: fix compiler warning 2018-12-28 09:31:38 -06:00
William Hubbs
7e95d924c9 bash-completions/rc-service: allow tab to be used again
X-Gentoo-Bug: 670290
X-Gentoo-Bug-URL: https://bugs.gentoo.org/670290
2018-12-27 16:31:15 -06:00
a15b532a02 scripts: fix halt, poweroff and reboot wrappers
These are designed to emulate the sysvinit equivalents, so pass "now" as
the time argument if no arguments are given.

This fixes #268.
2018-12-27 13:52:16 -06:00
philhofer
3e00fbc9b0 fix leading whitespace
Clean up code indented with mixed tabs and spaces.
No actual code changes.

This fixes #280.
2018-12-27 13:13:09 -06:00
philhofer
846e460075 fix potential out-of-bounds reads
readlink(3) does not nul-terminate the result it sticks
into the supplied buffer. Consequently, the code

  rc = readlink(path, buf, sizeof(buf));

does not necessarily produce a C string.

The code in rc_find_pid() produces some C strings this way
and passes them to strlen() and strcmp(), which can lead
to an out-of-bounds read.

In this case, since the code already takes care to
zero-initialize the buffers before passing them
to readlink(3), only allow sizeof(buf)-1 bytes to
be returned.

(While fixing this issue, I fixed two other locations that
used the same problematic pattern.)

This fixes #270.
2018-12-27 11:28:27 -06:00
William Hubbs
a32b14bbb4 Do not use UT_LINESIZE or __UT_LINESIZE
These are not standard.
For more information see issue #279.
This fixes #279.
2018-12-25 12:13:23 -06:00
philhofer
084877eb52 src/librc/librc-daemon.c: fix buffer overrun in pid_is_argv
The contents of /proc/<pid>/cmdline are read into
a stack buffer using

  bytes = read(fd, buffer, sizeof(buffer));

followed by appending a null terminator to the buffer with

  buffer[bytes] = '\0';

If bytes == sizeof(buffer), then this write is out-of-bounds.

Refactor the code to use rc_getfile instead, since PATH_MAX
is not the maximum size of /proc/<pid>/cmdline. (I hit this
issue in practice while compiling Linux; it tripped the
stack-smashing protector.)

This is roughly the same buffer overflow condition
that was fixed by commit 0ddee9b7d2
This fixes #269.
2018-12-24 11:55:48 -06:00
philhofer
97e74f9734 src/rc/supervise-daemon.c: formatting fixes
Fix misleading indentation and other erroneous whitespace.
This fixes #273.
2018-12-24 10:36:12 -06:00
William Hubbs
d328de198d remove /run migration script again
This time it was done correctly.
I missed a '\' the last time.
2018-12-23 21:04:00 -06:00
philhofer
a9fc26ac13 src/rc/supervise-daemon.c: do not pass NULL to strcmp
The following will cause a segfault due to NULL being
passed to strcmp(3)

$ RC_SVCNAME=foo supervise-daemon

Fix the bounds check on argc in main. If argc<=1, then
it is not safe to dereference argv[1].
2018-12-23 21:01:39 -05:00
philhofer
40f7046696 src/rc/openrc-run.c: remove duplicate statement
The statement

  ll = strlen(applet);

appears twice in the same block without any
intervening assignment to the variables
'll' or 'applet'

Remove the second (duplicate) statement.
2018-12-23 20:27:06 -05:00
William Hubbs
894995176e Revert "remove /run migration script"
For some reason removing this broke the build.

This reverts commit 5246ea7b6f.
2018-12-23 18:13:06 -06:00
William Hubbs
5246ea7b6f remove /run migration script
We have used /run for some time now and we have had this migration
script for 6 years. Linux users should have upgraded by now to a version
of OpenRC which stores its information in /run.
2018-12-23 17:49:34 -06:00
William Hubbs
ed8b768c4a fix compiler warnings 2018-12-21 12:06:15 -06:00
William Hubbs
825caa14de supervise-daemon: do not use the exec_service() function
In order to run healthcheck() and the unhealthy() function, add an
exec_command call to the supervisor.
Another difference is This function also logs errors instead of
attempting to display them.

This is for #271.
2018-12-20 17:39:31 -06:00
William Hubbs
d5c396cbfc Add debug logging to start-stop-daemon and rc-supervisor
This will make it easier to track down why the supervisor intermittently
hangs after it runs for a long time.
2018-12-18 11:29:26 -06:00
William Hubbs
5427783fdf standardize the default shell
I do not know of a need to have the default shell be a build-time
configurable setting. All *nix systems I am aware of have /bin/sh as a
default posix compatible shell.
If some systems running OpenRC do not make that assumption about
/bin/sh, I will consider bringing this back, so feel free to open an
issue.
2018-12-08 12:06:26 -06:00
William Hubbs
d95425b08a rc-cgroup.sh: remove shebang line
This is not a stand-alone script, so it does not need the shebang line.
This also means it is not necessary to run this through sed.
2018-12-07 15:31:13 -06:00
William Hubbs
76420d9849 init.d/agetty: set default respawn period to 60 seconds
Without a respawn period setting, the supervisor will give up on
respawning agetty after it is respawned respawn_max times. For most
daemons giving up like this is reasonable, but not for agettys. Agettys
should always be respawned unless they are respawning too fafst,.

If an agetty is respawning faster than 10 times in 60 seconds, this
seems to be too fast.
2018-12-06 16:37:40 -06:00
William Hubbs
bebc604438 supervise-daemon: fix busy loop
This fixes #264.
2018-12-06 16:22:15 -06:00
Alexander Zubkov
9dae4f2e38 supervise-daemon: redirect std{in,out,err} to /dev/null after demonizing
This fixes #239.
2018-12-04 16:53:39 -06:00
William Hubbs
d126542dc6 version 0.41 2018-12-03 18:14:34 -06:00
William Hubbs
ab6c8d56f1 Update ChangeLog 2018-12-03 15:56:19 -06:00
Austin English
fb4dd351c7 misc: make checks always fatal
This fixes #263.
2018-12-03 15:26:42 -06:00
Austin English
10dc65cc46 src/rc/supervise-daemon.c: fix style issue
This is for #263.
2018-12-03 15:26:20 -06:00
William Hubbs
9a2115f762 rc-status: show status for supervised services instead of a list 2018-12-03 15:16:17 -06:00
William Hubbs
eeba6df476 Update supervise-daemon man page 2018-12-03 13:08:25 -06:00
William Hubbs
ac42e81a64 supervise-daemon.sh: drop the unused stopsig variable 2018-12-03 12:43:12 -06:00
William Hubbs
af70862a7a supervise-daemon: use a default pid file if one is not specified
Since the pid file is internal to us, start moving toward deprecating it
by not requiring the user to specify it.
In the next release, I plan on working on code to start phasing out the
use of a pid file if this is possible.
2018-12-03 12:41:29 -06:00
William Hubbs
fa6611b5af rc-status: add --supervised option to show supervised services 2018-12-02 18:33:25 -06:00
William Hubbs
db01442580 rc-status: show failed services as failed 2018-12-02 18:33:25 -06:00
William Hubbs
ebf79db79e supervise-daemon: mark a service failed if it respawns too many times 2018-12-02 18:33:25 -06:00
William Hubbs
1b5a3b4ef4 supervise-daemon: make respawn-max and respawn-period independent settings 2018-12-02 18:33:25 -06:00
William Hubbs
77262c359c supervise-daemon: add support for a fifo
This will allow us to signal the daemon we are supervising as well as
send other commands to the supervisor in the future.

This fixes #227.
2018-12-02 18:33:25 -06:00
William Hubbs
7f23e0461d supervise-daemon: rework signal handling and main loop
This is needed in preparation for adding support for a fifo to allow us
to communicate with the supervisor to ask it to signal the child it is
supervising.
2018-12-02 18:33:25 -06:00
William Hubbs
ff4af908a5 Revert "checkpath: use O_PATH when available"
This reverts commit 2af0cedd59.

After speaking with Luis Ressel on the Gentoo selinux team, I am reverting
this commit for the following reasons:

- Luis told me that he feels this is not the solution we need to address
  the concern with checkpath; I will be working with him on another
  solution.

- There are concerns about the way the path variable was handled
  and the assert() call.
  The path variable should be dynamically allocated using xasprintf
  instead of defining a length at compile time. This would eliminate the
  need for the assert() call.

- It introduces the definition of _GNU_SOURCE which makes it
  easier to introduce portability concerns in the future (see #262).
2018-12-02 16:08:42 -06:00
Mike Gilbert
2af0cedd59 checkpath: use O_PATH when available
This avoids opening directories/files with read permission, which is
sometimes rejected by selinux policy.

Bug: https://bugs.gentoo.org/667122
2018-12-01 21:43:18 -08:00
William Hubbs
ee41e444ad rc.conf: typo fix
X-Gentoo-Bug: 670874
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=670874
2018-11-29 08:19:56 -06:00
William Hubbs
b7828651ba supervise-daemon: fix type of exiting flag 2018-11-28 16:06:07 -06:00
Austin English
e96f7d5658 src/tests/runtests.sh: add a FATAL_CHECKS variable to make whitespace/etc. fatal 2018-11-27 21:22:29 -05:00
Austin English
28b73fc524 src/rc/openrc-shutdown.c: fix style 2018-11-27 21:22:29 -05:00
Austin English
7a00c63420 fix misc whitespace issues 2018-11-27 21:22:29 -05:00
Austin English
f4597c546a give TravisCI a try 2018-11-27 21:22:29 -05:00
Austin English
e10afc8e75 sh/functions.sh.in: return a different value for invalid input in yesno() 2018-11-18 13:22:59 -05:00
William Hubbs
0f704402a2 supervise-daemon: make the pidfile an implementation detail
The pidfile of the supervisor doesn't need to be adjustable by the
service script. It is only used so the supervisor can stop itself when
the --stop option is used.
2018-11-15 14:15:15 -06:00
William Hubbs
2504a2c25b Do not complain if interrupted by a signal
In start-stop-daemon and rc-schedules, we were printing out a warning if
the nanosleep call was interrupted by a signal, but we did not treat
this as an error situation other than displaying the message, so there
is no need for the message.
2018-11-15 14:03:06 -06:00
William Hubbs
7eb3975543 Create save-keymaps and save-ktermencoding services
These services represent the parts of the keymaps and termencoding
services which saved the settings back to the root file system so they
can be loaded very early in the boot process.
These are needed to allow keymaps and termencoding to run earlier in the
boot sequence.

X-Gentoo-Bug: 446018
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=446018
2018-11-07 08:55:44 -06:00
William Hubbs
60e60dc9bb supervise-daemon.sh: drop invalid --signal switch
This fixes #230.
2018-11-06 10:54:02 -06:00
William Hubbs
008c9d0036 supervise-daemon: reap zombies
We need to make sure to reap zombies so that we can shut down
successfully.

Fixes #252.
Possibly related to #250.
2018-11-05 21:35:00 -06:00
William Hubbs
025c9693cc rc-service: fix help output 2018-11-05 11:39:39 -06:00
William Hubbs
ee3c4afdb7 openrc-init: add SELinux support
This is for #173.
2018-11-02 18:22:11 -05:00
William Hubbs
e2416d0893 openrc-shutdown: do not require a time for -w switch
X-Gentoo-Bug: 669500
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=669500
2018-10-24 15:24:40 -05:00
William Hubbs
a2bcfeb428 version 0.40 2018-10-24 15:18:10 -05:00
William Hubbs
53f7afd3b3 Update ChangeLog 2018-10-23 17:14:01 -05:00
William Hubbs
75e9b66f6f news.md: add information about the modules service changes 2018-10-23 16:59:20 -05:00
William Hubbs
d70b1c55b6 modules: Add --first-time switch to modprobe commands
On Linux, kernel modules should be loaded once during boot, either in an
initramfs or by this service.

This does not change anything other than printing out messages if a
module is loaded more than once.

X-Gentoo-Bug: 659530
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=659530
2018-10-23 16:47:37 -05:00
William Hubbs
c1e582586d supervise-daemon: add health checks
Health checks are a way to monitor a service and make sure it stays
healthy.

If a service is not healthy, it will be automatically restarted after
running the unhealthy() function to clean up.
2018-10-23 13:38:14 -05:00
William Hubbs
7a75bfb00c news.md: add note about scheduled shutdown 2018-10-23 13:34:08 -05:00
William Hubbs
aacf841de4 supervise-daemon-guide.md: re-format and add more variables 2018-10-22 17:49:25 -05:00
William Hubbs
3f918161aa openrc-shutdown: Add scheduled shutdown and the ability to cancel a shutdown
You can now schedule a shutdown for a certain time or a cpecific number
of minutes into the future.

When a shutdown is running, you can now cancel it with ^c from the
keyboard or by running "openrc-shutdown -c" from another shell.
2018-10-18 17:56:36 -05:00
Zac Medico
710c874e6e supervise-daemon: fix respawn_max off by one
Fix the comparison between respawn_count and respawn_max so that
respawn_max = 1 will allow for one respawn. Since respawn_count is
incremented before the comparison, use a 'greater than' comparison
so that respawn will be triggered when respawn_count is equal to
respawn_max.

Fixes: https://github.com/OpenRC/openrc/issues/247
Fixes: https://github.com/OpenRC/openrc/issues/248
2018-10-15 11:50:42 -05:00
Austin English
07908be090 misc: style fixups 2018-10-13 12:53:54 -04:00
Austin English
02af093043 misc: whitespace fixes 2018-10-13 12:53:54 -04:00
William Hubbs
67e2d6033d Complete implementation of forever timeout value in stop schedules 2018-10-09 11:34:52 -05:00
William Hubbs
eca4357892 supervise-daemon: use nanosleep() instead of sleep()
We will be using sigalrm in this process for health checking, and
sigalrm cannot be used with sleep() safely.
2018-10-06 12:51:04 -05:00
William Hubbs
7ee3e5b2d6 openrc-init: convert sleep() call to nanosleep()
Nanosleep is the safer call to use in case we need to use alarms
eventually.
2018-10-06 12:49:44 -05:00
William Hubbs
7cb8d94323 Stop mounting efivarfs read-only
We do not need to do this any longer since all supported linux kernels
make efivarfs immutable and the tools that manipulate it are aware of
this feature.

This fixes https://github.com/openrc/openrc/issues/238.
2018-08-14 10:21:27 -05:00
Zac Medico
84ed570eae librc: fix EACCES errno false-positive crash
Use errno != EACCES to fix false-positive for non-root users
with grsecurity kernels.

Fixes: 37e2944272 ("librc: Add check for crashed state")
This fixes #237
2018-08-06 17:39:52 -05:00
William Hubbs
2eea73bfd5 rc-functions.sh: Remove addon support
This is an old relic from Gentoo baselayout-1.x which should not be used
any longer.
2018-07-09 19:44:40 -05:00
William Hubbs
a571a42421 modules: remove the ability to rename modules on the fly
Kmod doesn't support the -o switch, so if you have been using this your
module loads have been failing.
2018-06-29 15:29:46 -05:00
Holger Hoffstätte
79648ac1c6 rc-status: initialize uptime pointer to prevent memory corruption
This fixes #231.
2018-06-29 08:49:13 -05:00
William Hubbs
02af762e83 version 0.39 2018-06-28 13:32:19 -05:00
William Hubbs
01c34c28e6 Update ChangeLog 2018-06-28 13:02:42 -05:00
William Hubbs
56ddda54b5 supervise-daemon.c: clean up memory leaks 2018-06-27 17:37:11 -05:00
William Hubbs
3a803b3135 librc-daemon.c: fix memory leaks 2018-06-27 12:06:19 -05:00
William Hubbs
72df51e17b librc-daemon: convert most snprintf calls to xasprintf 2018-06-22 15:41:25 -05:00
William Hubbs
b2f5531194 librc-misc: convert snprintf calls to xasprintf 2018-06-20 17:45:01 -05:00
William Hubbs
19bf49a710 libeinfo: convert remaining snprintf calls to xasprintf 2018-06-20 12:36:51 -05:00
William Hubbs
64354831da openrc: convert snprintf calls to xasprintf 2018-06-20 09:37:20 -05:00
William Hubbs
e14edd765f supervise-daemon: convert snprintf calls to xasprintf 2018-06-19 17:57:10 -05:00
William Hubbs
f9d41243d8 start-stop-daemon: convert snprintf calls to xasprintf 2018-06-19 17:46:12 -05:00
William Hubbs
be7ad06d4a rc-status: convert snprintf calls to xasprintf 2018-06-19 17:06:33 -05:00
William Hubbs
a616516895 rc-status: fix gcc 7 warnings 2018-06-19 16:18:48 -05:00
William Hubbs
04721ece03 start-stop-daemon: fix gcc 7 warnings 2018-06-19 15:32:10 -05:00
William Hubbs
c7e8f1133a checkpath: fix gcc 7 warnings 2018-06-19 14:01:54 -05:00
William Hubbs
47e4bfae57 fix gcc 7 warnings in pipe routines 2018-06-19 13:59:16 -05:00
William Hubbs
8a945194af libeinfo: clean up gcc 7 compiler warnings 2018-06-19 13:52:40 -05:00
William Hubbs
aa4a004c29 version 0.38 2018-06-17 12:45:51 -05:00
William Hubbs
9ec5d36bdd Update ChangeLog 2018-06-15 18:04:43 -05:00
William Hubbs
a097933eda sh/start-stop-daemon.sh: fix processing of the logger arguments 2018-06-15 17:44:39 -05:00
William Hubbs
a6f5b1bb63 Update ChangeLog 2018-06-15 12:59:13 -05:00
William Hubbs
e6d01471fe start-stop-daemon: add ability to log stdout or stderr to processes 2018-06-15 12:23:50 -05:00
William Hubbs
d4501a9f06 fix a typo 2018-06-14 14:55:42 -05:00
Mike Gilbert
ec8abea460 Add helper to spawn process with stdin connected to a pipe 2018-06-13 13:49:42 -05:00
William Hubbs
e4ddfa38e0 user-guide.md: small cleanups 2018-06-05 17:34:09 -05:00
William Hubbs
21d30bc6d9 service-script-guide.md: small cleanups 2018-06-05 17:26:57 -05:00
William Hubbs
2a1ff6e49c version 0.37 2018-06-05 16:11:28 -05:00
William Hubbs
6762cb875c Update ChangeLog 2018-05-31 16:53:25 -05:00
Austin English
6edf516a1f sh/supervise-daemon.sh: use start_stop_daemon_args if supervise_daemon_args is undefined 2018-05-30 12:11:10 -04:00
William Hubbs
7e56a49e23 Logger: only log printable characters and newlines
X-Gentoo-Bug: 651412
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=651412
2018-05-22 17:11:43 -05:00
William Hubbs
fa5aea80c5 openrc-run.sh: move crashed test outside started test
This is handled inside librc, so we don't need the nesting in this
script.
2018-05-22 12:20:38 -05:00
William Hubbs
0f4fa41574 Add mark_service_crashed binary 2018-05-22 12:20:38 -05:00
William Hubbs
5d6dd97bba rc-misc: add the crashed state 2018-05-22 12:20:38 -05:00
William Hubbs
37e2944272 librc: Add check for crashed state
In rc_service_state,, call rc_service_daemons_crashed to check for
a crashed daemon if the service is started.
2018-05-22 12:19:41 -05:00
William Hubbs
4e0eace837 librc: Add crashed state 2018-05-22 12:19:22 -05:00
William Hubbs
faa8318b3b Remove the _rc_can_find_pids function
This test to find if we could see pid 1 was being used inconsistently in
rc-status and mark_service_crashed to decide whether we could test to
see if the daemon for the service was crashed, and it was not part of
the librc library.

I am removing it from the executables because of inconsistent usage. I
will add it to the library if it is needed there.
2018-05-18 16:48:21 -05:00
William Hubbs
08da36149c rc-service: add --ifstarted and --ifstopped options 2018-05-16 13:25:22 -05:00
William Hubbs
56870d0db1 Man: rc-service man page cleanups 2018-05-15 17:09:56 -05:00
William Hubbs
4d47ce440c rc-service: add -d/--debug and -D/--nodeps options 2018-05-15 16:59:21 -05:00
William Hubbs
958f57d895 openrc-run: respect the RC_NODEPS environment variable 2018-05-15 16:27:42 -05:00
William Hubbs
04886efd85 Add RC_DEBUG and RC_NODEPS to environment whitelist
These are needed so rc-service can pass debug and nodeps options to
openrc-run.
2018-05-15 16:18:19 -05:00
William Hubbs
d980798d64 openrc-run: respect the IN_DRYRUN environment variable
This allows rc-service to pass the tryrun option to openrc-run.

This is for #225.
2018-05-14 19:08:19 -05:00
William Hubbs
414a9aae6c rc-misc.c: Add IN_DRYRUN to environment whitelist
This allows rc-service to pass the dryrun option to openrc-run.

This is for #225.
2018-05-14 19:04:42 -05:00
William Hubbs
a7f475ca04 rc-service: add a --dry-run option
This is for #225.
2018-05-14 19:00:04 -05:00
William Hubbs
3c53680018 build: standardize installation modes
Gentoo was changing some of our installation modes from 0444 to 0644.
There isn't a reason to install things 0444, so we are switching these
to 0644 so the Gentoo ebuild doesn't need this extra step.
2018-05-11 15:38:27 -05:00
William Hubbs
f0ad647303 Revert "savecache: stop saving the dependency tree"
It is safe to save the deptree, but we also need to regenerate it at
boot time.
2018-05-11 11:54:48 -05:00
William Hubbs
b35e03b6b1 Revert "Logger: only log printable characters and newlines"
This reverts commit 2b1392af2f.
This seems to create issues shutting down, so I need to look into it
further.
2018-05-10 19:35:24 -05:00
William Hubbs
2b1392af2f Logger: only log printable characters and newlines
X-Gentoo-Bug: 651412
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=651412
2018-05-09 17:30:08 -05:00
William Hubbs
a3d0e293ee Remove localmount from dependencies for linux-only services
This removes localmount from the dependencies of the consolefont,
keymaps, numlock and procfs services.

These services are Linux only and the default modern linux system has /
and /usr on the same file system.

This also fixes the following issue.

X-Gentoo-Bug: 651998
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=651998
2018-05-07 18:12:55 -05:00
Andrey Utkin
0200002b8c start-stop-daemon: don't fail stopping if pidfile is gone
If pidfile does not exist when we are stopping the daemon, assume it is
already stopped, and report success.

hostapd is an example of a daemon which removes its pidfile when it is
exiting. If this daemon terminates prematurely, that is, without s-s-d
involvement, then openrc fails to restart it, because s-s-d "stop"
command fails when pidfile is missing.

X-Gentoo-Bug: 646274
X-Gentoo-Bug-URL: https://bugs.gentoo.org/646274
2018-05-02 13:42:59 -05:00
William Hubbs
f4e2142089 Add _POSIX_C_SOURCE definition to Linux build
We need this to allow builds on uclibc-ng based systems.

X-Gentoo-Bug: 650908
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=650908
2018-05-01 13:29:13 -05:00
William Hubbs
49a90f27a8 typo fix 2018-04-24 10:40:57 -05:00
Scall
2ae60ca041 rc-update: fix typo 2018-03-21 08:33:33 -04:00
William Hubbs
6b475ab269 init.d/modules: add code from modules-load service
There is no reason for these to be separate services. I did add a
provide so that we don't break backward compatibility.
2018-03-16 14:33:01 -05:00
William Hubbs
b302b0c094 net-online: always start after net
X-Gentoo-Bug: 650600
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=650600
2018-03-16 13:53:02 -05:00
William Hubbs
40aa69cf3a agetty.in: allow status to be displayed 2018-03-14 20:37:02 -05:00
William Hubbs
5346fbf2c9 supervise-daemon: fix off-by-one error 2018-03-14 20:05:45 -05:00
William Hubbs
92e6bdee12 Use _BSD_SOURCE on FreeBSD 2018-03-14 13:07:46 -05:00
William Hubbs
71f275b2aa typo fix 2018-03-14 10:45:40 -05:00
William Hubbs
6dc0d0af33 Remove _XOPEN_SOURCE macros from builds 2018-03-13 18:14:55 -05:00
William Hubbs
59a9e53378 Add _POSIX_C_SOURCE macro to FreeBSD build 2018-03-13 18:04:54 -05:00
William Hubbs
122768d339 man: document default retry specification for supervise-daemon 2018-03-12 18:22:40 -05:00
William Hubbs
fa3c60c0d8 man: document default retry sppecification for start-stop-daemon 2018-03-12 18:15:06 -05:00
William Hubbs
61905bfcf5 Clean up cgroups v2 code
Remove the IFS manipulation and simplify the loop that processes the
settings.
2018-03-11 21:41:01 -05:00
Scall
3e68013631 init.d: swap should always be started after root
Otherwise if a swap file is being used, and swap is started before
root, swapon may fail because of a read-only filesystem.
2018-03-05 20:16:26 -05:00
Chris Cromer
b46123f2e1 openrc-run: fix memory size (#213)
Fixes #212
2018-03-01 19:31:33 -05:00
William Hubbs
109869641f fix build on FreeBSD 2018-03-01 11:47:29 -06:00
William Hubbs
e8a2305de0 version 0.36 2018-03-01 11:46:02 -06:00
William Hubbs
f62975a1f8 Update ChangeLog 2018-02-28 16:21:52 -06:00
Jason Zaman
5bb6f9aa31 init.sh: apply SELinux label for /run early in boot
Some initramfs mount /run which then ends up with the wrong labels.
Force relabel all of /run right after its mounted to fix.
2018-02-28 12:42:58 -06:00
Jason Zaman
1ab8541a6c init-early.sh.Linux.in: apply the selinux label to /dev/console early
/dev/console is relabelled later in the devfs init script, but by then we
have already missed some of the messages, so fix that label early.
2018-02-28 11:24:55 -06:00
William Hubbs
038c03bef3 supervise-daemon: make an error message more verbose 2018-02-27 16:02:20 -06:00
William Hubbs
e51dc29e2f cgroups: fix indentation 2018-02-27 15:56:54 -06:00
William Hubbs
c6047f887a cgroups: add rc_cgroup_memory_use_hierarchy setting for cgroups v1 2018-02-26 14:33:15 -06:00
William Hubbs
0506d68427 fstabinfo: fix an error message 2018-02-26 13:46:47 -06:00
William Hubbs
c3d666acaf openrc: remove unused #define's. 2018-02-26 13:14:31 -06:00
William Hubbs
e93b1d76d1 openrc: convert another execl() call to execlp() 2018-02-26 13:13:44 -06:00
William Hubbs
acf1e43f81 openrc-init: convert execl calls to execlp 2018-02-26 12:21:14 -06:00
William Hubbs
f383fd87b1 kill_all: change execl call to execlp 2018-02-24 17:02:02 -06:00
William Hubbs
cfded513cd openrc-init: set a default path
The default path provided by the system if one isn't set only includes
"/bin:/usr/bin". This adds the default path setting from sysvinit.
2018-02-24 16:24:08 -06:00
Christian Brauner
16ff3cd8df check whether /sys/fs/cgroup is a mountpoint
The current check only tries to detect whether /sys/fs/cgroup exists and
whether it is writable or not. But when the init system doesn't mount
cgroups then /sys/fs/cgroup will just be an empty directory. When paired
with unprivileged containers that mount sysfs this will cause misleading
errors to be printed since /sys/fs/cgroup will be owned by user
nobody:nogroup in this case. Independent of this specific problem this
check will also be misleading when the /sys/fs/cgroup exists and is in
fact writable by the init system but isn't actually a mountpoint.

Note from William. "grep -qs" doesn't need to redirect output to
/dev/null since it is completely silent.

This fixes #209.
2018-02-23 15:51:12 -06:00
William Hubbs
38032626a6 improve cgroup configuration checks
make the base/controller functions return successfully if cgroups v1/v2
are not configured in the kernel
2018-02-23 15:07:04 -06:00
William Hubbs
aa7d3a7911 openrc: force deptree update for sysinit runlevel 2018-02-22 16:16:07 -06:00
William Hubbs
98262647a9 supervise-daemon: zero out the cmdline buffer when it is allocated 2018-02-22 12:54:21 -06:00
William Hubbs
5868abe97b start-stop-daemon: compiler warning cleanup 2018-02-21 18:16:56 -06:00
William Hubbs
71aad16256 openrc-run: clean up a compiler warning 2018-02-21 18:15:35 -06:00
William Hubbs
e275da84de supervise-daemon: remove references to PATH_MAX 2018-02-21 18:14:56 -06:00
William Hubbs
a6cc7f06cf rc.c: remove PATH_MAX references 2018-02-21 13:49:41 -06:00
William Hubbs
c1178c8eeb rc-selinux.c: remove references to path_max 2018-02-20 16:35:50 -06:00
William Hubbs
3c031ca978 rc-plubin.c: remove references to PATH_MAX 2018-02-20 16:01:15 -06:00
William Hubbs
8e02406d8f rc-misc.c: remove references to PATH_MAX 2018-02-20 14:22:29 -06:00
William Hubbs
8dbdabcc5e start-stop-daemon: clean up string handling 2018-02-16 14:04:40 -06:00
William Hubbs
488d8989c5 openrc-run: clean up string handling
- remove references to PATH_MAX
- use xasprintf to create strings
2018-02-15 15:26:40 -06:00
William Hubbs
9e14b35da8 rc-update: remove reference to PATH_MAX 2018-02-15 12:23:39 -06:00
William Hubbs
7b4879cb72 mountinfo: create strings with xasprintf 2018-02-14 16:56:19 -06:00
William Hubbs
74cfb455c5 kill_all: create strings with xasprintf 2018-02-14 16:50:24 -06:00
William Hubbs
0110487722 helpers.h: silence compiler warnings about xasprintf 2018-02-10 16:48:22 -06:00
William Hubbs
68b9b0bc2a xasprintf: exit if return value of vsnprintf is invalid 2018-02-10 14:49:40 -06:00
William Hubbs
4616f8f809 helpers.h: add xasprintf function
This is our own version of asprintf(). This original code was written by
Mike Frysinger, and I was able to modify it to use our memory helper
functions.

We need a version of this code because it is not available on glibc at
least without defining _GNU_SOURCE, and I would rather not do that.

This is the first step in improving string handling in OpenRC for #207.
2018-02-09 16:27:12 -06:00
William Hubbs
287d71bd25 helpers.h: style fix 2018-02-09 15:35:12 -06:00
Michael Orlitzky
c1ffe4d9f2 man/openrc-run.8: fix mountinfo args.
The "Ar" tag for the mountinfo command contained a typo (leading
space) that resulted in the tag being output verbatim; that is,

  mountinfo ... .Ar mount1 mount2

rather than e.g.

  mountinfo ... <mount1> <mount2>

This commit deletes the leading space to fix the output.

This fixes #204.
2018-02-06 13:53:11 -06:00
Michael Orlitzky
4c517bdb2b man/openrc-run.8: add missing "Xo" tags for fstabinfo and mountinfo.
The BUILTINS are all surrounded by Xo...Xc tags, but the opening "Xo"
was missing from the two commands fstabinfo and mountinfo. This commit
adds them, and thereby fixes the spacing when viewed by man.

This is for #204.
2018-02-06 13:52:36 -06:00
William Hubbs
110582491f service-script-guide.md cleanups
Refer to /var/run in the documentation instead of /run, and make it
clear at the top of the pidfile section that we use /run under Linux.

This is for #202.
2018-01-24 17:43:08 -06:00
William Hubbs
5dd1d39d20 typo fix 2018-01-24 10:56:33 -06:00
William Hubbs
1771bc2a83 checkpath: use fchown and fchmod to handle ownership and mode changes
This is related to #195.

This is an attempt to shorten the window for the first two issues
discussed by using a file descriptor which does not follow symbolic
links and using the fchmod and fchown calls instead of chown and chmod.
with.
2018-01-23 16:56:06 -06:00
William Hubbs
87c98ebb01 checkpath: fix lchown error message
X-Gentoo-Bug: 643084
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=643084
2018-01-16 13:34:37 -06:00
William Hubbs
4af5a80b0c _rc_deptree_load - return NULL if the stat() call is not successful
X-Gentoo-Bug: 643084
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=643084
2018-01-16 13:11:22 -06:00
William Hubbs
fee2ffe559 Reformat and fix titles in documentation 2018-01-12 14:10:42 -06:00
William Hubbs
8878f8916b Rename guide.md to user-guide.md to better describe its purpose 2018-01-11 10:57:05 -06:00
William Hubbs
14e3359a9e move developer documentation from guide.md to service-script-guide.md 2018-01-10 13:25:13 -06:00
William Hubbs
918d955fd2 checkpath: use lchown instead of chown
Checkpath should never follow symbolic links when changing ownership of a file.

This is for https://github.com/openrc/openrc/issues/195.
2018-01-09 17:25:28 -06:00
William Hubbs
92cfa0e543 service-script-guide.md: formatting changes
Add a title, adjust the headings and update the example that referred to
"net.lo" to refer to "loopback".
2018-01-08 15:33:03 -06:00
Michael Orlitzky
c2bd33e483 service-script-guide.md: new guide for service script authors.
This fixes #162.
2018-01-08 13:59:12 -06:00
3PO
f42ec82f21 net-online: only process symbolic links in /sys/class/net
The /sys/class/net directory contains files which are not symlinks if
the system has bonded devices [1].  We should ignore these files.

This fixes #196.

[1] https://elkano.org/blog/manage-interface-bondings-sysfs-interface/
2018-01-05 14:56:33 -06:00
William Hubbs
7affff568a init.d.examples: pid files always go in /var
This removes the @VARBASE@ substitution since it is always translated to
/var.
2017-12-20 11:01:29 -06:00
William Hubbs
4f750933fd procfs: remove the @sysconfdir@ reference 2017-12-14 17:31:57 -06:00
William Hubbs
50b69d564a hostname: replace @SYSCONFDIR@ references with /etc
I do not know of any situation where /etc/hostname is at any other
location. Also, this does not run on prefix.
2017-12-14 17:07:31 -06:00
William Hubbs
eb18f4f348 hwclock: use shell variables for configuration file path
This removes a reference to @SYSCONFDIR@.
2017-12-14 16:38:09 -06:00
William Hubbs
d5f3fe52c8 sysctl: hard code paths for sysctl files on *bsd
For *BSD,the sysctl*.conf files are always in /etc.
2017-12-14 14:18:39 -06:00
William Hubbs
bb1bc6eeb7 local: misc cleanups
Remove references to @SYSCONFDIR@ since these can be calculated at
runtime.
Also style fixes.
2017-12-14 12:52:03 -06:00
William Hubbs
53844fd0dc devfs: cleanup
clean up local definitions. Also remove @SYSCONFDIR@ substitutions since
they can be calculated at runtime.
2017-12-14 12:08:38 -06:00
bell07
14938c29ce net-online: wait for ping_test_host
The script should wait till the ping host is available or timeout reached
Closes : #179
Closes : #191
2017-12-12 16:29:34 -06:00
William Hubbs
8bf501aaf2 network: use 'command -v ip' to test for the ip executable
This is an improved test because it doesn't require the ip executable to be
in a specific path.
2017-12-12 14:23:04 -06:00
William Hubbs
9d05f68b51 Do not use file tests in net-online
https://unix.stackexchange.com/questions/252002/help-testing-special-file-in-sys-class-net

This is for #189
2017-12-12 12:45:52 -06:00
William Hubbs
ee2524cd1d net-online: clean up quoting and test for existence
This is for #178.
2017-12-11 17:41:04 -06:00
Marcel Greter
5c81661d47 Gracefully handle unreadable /sys/class/net/dev/ nodes
Fixes https://bugs.gentoo.org/629228
Fixes #189
Fixes #185
Fixes #178
2017-12-11 14:46:16 -06:00
William Hubbs
fb96c9c127 Make bash-completion and zsh-completion optional 2017-12-07 12:53:04 -06:00
William Hubbs
6c456f9383 Add zsh-completion support 2017-12-07 11:30:32 -06:00
William Hubbs
d220fc2723 add bash completion support
This fixes #188.
2017-12-06 13:25:26 -06:00
William Hubbs
a2447dfb42 rc-service: add --ifcrashed option
This works like the other --if options. If the service is crashed, run
the command.

This fixes #154.
2017-12-04 17:17:17 -06:00
William Hubbs
cee3919908 Clean up the calls to group_add_service
This function should only be called once and it does not take any
arguments.

X-Gentoo-Bug: 639166
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=639166
2017-12-01 15:43:09 -06:00
William Hubbs
0feadd2922 man/openrc-run.8: update documentation for command_user 2017-11-30 16:00:42 -06:00
Will Miles
a7c99506d9 Fix repeated dependency cache rebuild if clock skewed
rc_deptree_update_needed would return early as soon as it found
any file newer than the existing dependency cache.  Unfortunately,
the first file found may not be the newest one there; so the
clock skew workaround in rc-misc:_rc_deptree_load would be given
a timestamp that was still too old.

This fix forces a full scan of all relevant files, so as to
ensure that we return a timestamp that will allow the clock skew
fix to operate.   The runtime cost is no worse than the case where
the cache is up to date (ie. we must check every possible file).

This fixes #161.
2017-11-30 13:56:54 -06:00
Julien Reichardt
f012930775 man/openrc-run.8: remove white space
This is for #184.
2017-11-29 15:06:06 -06:00
Julien Reichardt
ddbdb69658 add more variables for start-stop-daemon and supervise-daemon options
Add the following variables to expose more arguments that can be passed
to start-stop-daemon or supervise-daemon:

- directory will be passed to --chdir
- error_log will be passed to --stderr
- output_log will be passed to --stdout
- umask will be passed to umask

This is for #184.
2017-11-29 15:06:06 -06:00
Doug Freed
c84ebb94d1 start-stop-daemon: properly handle missing pidfile
X-Gentoo-Bug: 639218
X-Gentoo-Bug-URL: https://bugs.gentoo.org/639218
2017-11-29 15:10:39 -05:00
William Hubbs
3de6395ae3 split cgroups mounting out of sysfs
This is neceessary to allow cgroups to be mounted in an lxc/lxd
container.

Fixes https://github.com/openrc/openrc/issues/187
2017-11-28 17:14:33 -06:00
William Hubbs
6bb7ebec48 fix FreeBSD build
This is for #186.
2017-11-27 11:10:00 -06:00
Doug Freed
a192caf88f rc-schedules: if given nothing to look for, stop
This avoids trying to kill everything.

X-Gentoo-Bug: 631958
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=631958
2017-11-19 11:05:30 -05:00
William Hubbs
e805c74d31 s6 supervisor fixes
Add the ability to force-kill a service if it does not go down
successfully. Also, adjust the default wait time for an s6 service to go
down to 60 seconds.
2017-11-16 15:35:35 -06:00
William Hubbs
318e873481 strongly encourage Linux users to not make /etc/mtab a flat file
The OpenRC team does not currently know of any modern linux tools that
require /etc/mtab to be a flat file, so this puts users on notice that
the mtab service will be removed in the future.
2017-11-14 15:41:03 -06:00
William Hubbs
0d15898f58 adjust mtab and localmount dependencies
localmount had mtab in its "use" dependencies; however, it makes more
sense to add "before localmount" to the mtab service and remove
"use mtab" from the localmount service.
2017-11-14 13:20:49 -06:00
William Hubbs
971e82784c rc_find_pids: namespace fix
Ignore namespaces if there are errors reading either the pid namespace
for the current process or the process we aare testing.

This fixes https://github.com/openrc/openrc/issues/180.
2017-11-13 16:54:57 -06:00
William Hubbs
90d9ea656f start-stop-daemon: do not use do_stop to verify whether a daemon is running
X-Gentoo-Bug: 636574
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=636574
2017-11-07 15:30:34 -06:00
William Hubbs
a3d1c8a0e7 fix issue with --reexec call 2017-10-30 18:21:39 -05:00
William Hubbs
913b2ca537 supervise-daemon: use RC_SVCNAME as the first argument to the daemon
This makes ps show which service the supervisor is monitoring.
2017-10-27 19:22:09 -05:00
William Hubbs
3fe99c8b82 supervise-daemon: fix logging for reexec and the child command line 2017-10-27 17:34:29 -05:00
William Hubbs
27b8183de2 log as supervise-daemon not the service 2017-10-27 15:33:47 -05:00
William Hubbs
f32d8e1bfe supervise-daemon: clarify a log message 2017-10-26 17:01:17 -05:00
William Hubbs
d019f34a83 supervise-daemon: log the command line we run to spawn the child process 2017-10-26 13:57:04 -05:00
William Hubbs
bb9c481f02 supervise-daemon: log with the service name instead of "supervise-daemon" 2017-10-26 13:36:41 -05:00
William Hubbs
82da844b42 implement "unsupervised" status
The unsupervised status is to be used when a supervisor of a supervised
service dies but leaves the service daemon itself running.
2017-10-26 13:11:12 -05:00
William Hubbs
667a09983c supervise-daemon: remove child_pid from saved options during shutdown
This allows us to detect when the supervisor dies unexpectedly because
in that case child_pid will still exist.
2017-10-26 12:58:59 -05:00
William Hubbs
cf429ee359 rc_service_value_set: remove the option if NULL is the value
This allows the equivalent of "unsetting" a value for a service.
2017-10-26 12:54:37 -05:00
William Hubbs
6f3e2e2d7d supervise-daemon.sh: fix status function with no namespaces 2017-10-25 21:20:15 -05:00
Patrick McLean
35b88fb42b cgroups_cleanup: clean up shutdown signaling
- do not sleep for the full 90 seconds if processes are dead
- re-arrange the order of signals we attempt to send to the processes
2017-10-25 21:19:15 -05:00
William Hubbs
a428c325a9 add "unsupervised" status and return code 64 to supervise-daemon status function
This is to be used if the service is being supervised and the
supervisor is somehow killed.

Currently, this is very linux specific, but I will expand to other
platforms, patches are welcome.
2017-10-25 15:09:42 -05:00
William Hubbs
3219ecd608 supervise-daemon: fix build issue for >=glibc-2.26
X-Gentoo-Bug: 635334
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=635334
2017-10-24 16:47:53 -05:00
William Hubbs
0d8dc4f798 version 0.35 2017-10-24 16:46:52 -05:00
208 changed files with 6327 additions and 3284 deletions

15
.cirrus.yml Normal file
View File

@@ -0,0 +1,15 @@
# Cirrus CI integration
# https://cirrus-ci.org
test_task:
freebsd_instance:
matrix:
image: freebsd-12-1-release-amd64
image: freebsd-11-4-release-amd64
env:
OS: FreeBSD
procfs_script: >
[ -f /proc/curproc ] || mount -t procfs proc /proc
pkg_install_script: pkg install -y bash gawk gmake gsed
gsed_hack_script: rm /usr/bin/sed && ln -s /usr/local/bin/gsed /usr/bin/sed
test_script: bash ci/cirrus.sh

32
.travis.yml Normal file
View File

@@ -0,0 +1,32 @@
# Travis build integration.
# https://docs.travis-ci.com/
language: c
os:
- linux
compiler:
- gcc
- clang
- musl-gcc
addons:
apt:
packages:
- musl-tools
notifications:
irc:
channels:
- "irc.libera.chat#openrc"
on_success: always # options: [always|never|change] default: always
on_failure: always # options: [always|never|change] default: always
on_start: false # default: false
before_install:
- sudo apt-get update
- sudo apt-get install -y shellcheck
script:
- ./ci/travis.sh

View File

@@ -82,6 +82,7 @@ Semen Maryasin <marsoft@ya.ru>
Sergei Trofimovich <slyfox@gentoo.org>
Seth Robertson <in-gentoo@baka.org>
S. Gilles <sgilles@umd.edu>
Sony Interactive Entertainment, llc.
Stefan Knoblich <s.knoblich@axsentis.de>
Stef Simoens <stef.simoens@scarlet.be>
Steve L <slong@rathaus.eclipse.co.uk>

View File

@@ -1,4 +1,5 @@
# Using Busybox as your Default Shell with OpenRC
Using Busybox as your Default Shell with OpenRC
===============================================
If you have/bin/sh linked to busybox, you need to be aware of several
incompatibilities between busybox's applets and the standalone

2286
ChangeLog

File diff suppressed because it is too large Load Diff

View File

@@ -1,11 +1,12 @@
# Features Scheduled for Removal
Features Scheduled for Removal
==============================
The following is a list of files and features that are going to be removed in
the source tree. Every entry should contain what exactly is going away, why it
is happening, and who is going to be doing the work. When the feature is
removed, it should also be removed from this file.
## Service pause action
# Service pause action
When: 1.0
@@ -13,7 +14,7 @@ Why: The same affect can be obtained with the --nodeps option to stop.
Who:
## start-stop-daemon options --startas, --chuid , --oknodo
# start-stop-daemon options --startas, --chuid , --oknodo
When: 1.0
@@ -25,7 +26,7 @@ Why: Obsolete or replaced by other options.
Who:
## runscript and rc symbolic links
# runscript and rc symbolic links
When: 1.0
@@ -34,7 +35,7 @@ Why: Deprecated in favor of openrc-run and openrc due to naming
Who:
## support for the opts variable in service scripts
# support for the opts variable in service scripts
When: 1.0
@@ -43,7 +44,7 @@ Why: Deprecated in favor of extra_commands, extra_started_commands
Who:
## support for local_start and local_stop
# support for local_start and local_stop
When: 1.0
@@ -51,7 +52,7 @@ Why: Deprecated in favor of executable scripts in @SYSCONFDIR@/local.d
Who:
## the mtab service script
# the mtab service script
When: force /etc/mtab to link to /proc/self/mounts in 1.0, remove
service in 2.0
@@ -61,13 +62,13 @@ Why: /etc/mtab should be a symbolic link to /proc/self/mounts on modern
Who:
## C API Functions in rc.h
# C API Functions in rc.h
If you have a c program that links to librc and uses functions from
there, this section will list API functions which are deprecated and
will be removed along with the reason they are being removed.
### rc_getline()
## rc_getline()
When: 1.0

View File

@@ -1,4 +1,5 @@
# OpenRC History
OpenRC History
==============
This history of OpenRC was written by Daniel Robbins, Roy Marples, William
Hubbs and others.

View File

@@ -15,14 +15,27 @@ include ${TOP}/Makefile.inc
SUBDIR= conf.d etc init.d local.d man scripts sh src support sysctl.d
# Build bash completion or not
MKBASHCOMP?= no
ifeq (${MKBASHCOMP},yes)
SUBDIR+= bash-completion
endif
# Build pkgconfig or not
MKPKGCONFIG?= yes
ifeq (${MKPKGCONFIG},yes)
SUBDIR+= pkgconfig
endif
# We need to ensure that runlevels is done last
# Build zsh completion or not
MKZSHCOMP?= no
ifeq (${MKZSHCOMP},yes)
SUBDIR+= zsh-completion
endif
# We need to ensure that runlevels is done last other than test
SUBDIR+= runlevels
SUBDIR+= test
INSTALLAFTER= _installafter

View File

@@ -1,3 +1,3 @@
NAME= openrc
VERSION= 0.34.7
VERSION= 0.44.6
PKG= ${NAME}-${VERSION}

View File

@@ -1,5 +1,5 @@
OpenRC Network Ideals
---------------------
=====================
The new style networking for OpenRC is very simplistic - provide a basic means
of configuring static interface address and routes whilst allowing the

142
NEWS.md
View File

@@ -1,8 +1,148 @@
# OpenRC NEWS
OpenRC NEWS
===========
This file will contain a list of notable changes for each release. Note
the information in this file is in reverse order.
## OpenRC 0.44
This version is the first to use a meson-based build system.
The gnu make build system should now be considered deprecated; it will
be removed sometime after 0.44.x.
I have opened a [discussion](https://github.com/OpenRC/openrc/discussions/441)
where you can voice concerns about removing it.
## OpenRC 0.43
This version changes the behavior of the checkpath helper to address
CVE-2018-21269. on Linux systems, We require non-terminal symbolic links
to be owned by root. Since we can't do this on non-linux systems, we do
not dereference non-terminal symbolic links by default. If you need them
dereferenced, you should add the "-s" switch to the appropriate
checkpath calls.
For more information, see http://github.com/openrc/openrc/issues/201.
The SHLIBDIR variable has been removed from the makefiles to make them
more consistent with most common makefiles. All libraries are now in
LIBDIR, so if you need to put them in /, override the LIBDIR variable
when you run make.
## OpenRC 0.42
openrc-shutdown now has the ability to shut down sysvinit-based systems.
A guide has been added for migrating systems using another init system
to openrc-init.
## OpenRC 0.41.
This version adds the ability to format the output of rc-status when
showing the status of services in a runlevel so that it may be parsed.
Currently, the -f switch only accepts ini as an argument which
causes the output to be in the .ini format.
This version adds an experimental build time switch to allow setting the
default shell to use for service scripts.
By default, this is set to /bin/sh if it is changed, the new shell must
be able to understand posix-compatible syntax.
## OpenRC 0.40
In this version, the keymaps and termencoding services on Linux needed
to be modified so they do not write to the root file system. This was
done so they can run earlier in the boot sequence. AS a result, you will
need to add save-termencoding and save-keymaps to your boot runlevel.
This can be done as follows:
```
# rc-update add save-keymaps boot
# rc-update add save-termencoding boot
```
## OpenRC 0.39
This version removes the support for addons.
The only place I know that this was used was Gentoo Baselayout 1.x, so
it shouldn't affect anyone since baselayout-1 has been dead for a few
years.
Since all supported Linux kernel versions now make efivarfs immutable
and all of the tools that access efivarfs are aware of this, we no
longer mount efivarfs read-only. See the following github issue for more
information:
https://github.com/openrc/openrc/issues/238
This version adds timed shutdown and cancelation of shutdown to
openrc-shutdown. Shutdowns can now be delayed for a certain amount of
time or scheduled for an exact time.
supervise-daemon supports health checks, which are a periodic way to make sure a
service is healthy. For more information on setting this up, please see
supervise-daemon-guide.md.
The --first-time switch has been added to all modprobe commands in the
modules service. This means that, on Linux, you will see failures if a
module was loaded by an initramfs or device manager before this service
runs. These messages are harmless, but to clean them up, you should adjust your
modules autoload configuration.
## OpenRC 0.37
start-stop-daemon now supports logging stdout and stderr of daemons to
processes instead of files. These processes are defined by the
output_logger and error_logger variables in standard service scripts, or
by the -3/--output-logger or -4/--error-logger switches if you use
start-stop-daemon directly. For more information on this, see the
start-stop-daemon man page.
## OpenRC 0.36
In this release, the modules-load service has been combined into the
modules service since there is no reason I know of to keep them
separate. However, modules also provides modules-load in case you were
using modules-load in your dependencies.
The consolefont, keymaps, numlock and procfs service scripts no longer
have a dependency on localmount.
If you are a linux user and are still separaating / from /usr,
you will need to add the following line to the appropriate conf.d files:
rc_need="localmount"
## OpenRC 0.35
In this version, the cgroups mounting logic has been moved from the
sysfs service to the cgroups service. This was done so cgroups can be
mounted inside an lxc/lxd container without using the other parts of the
sysfs service.
?As a result of this change, if you are upgrading, you need to add
cgroups to your sysinit runlevel by running the following command as
root:
```
# rc-update add cgroups sysinit
```
For more information, see the following issue:
https://github.com/openrc/openrc/issues/187
Consider this your second notification with regard to /etc/mtab being a
file instead of a symbolic link.
In this version, the mtab service will complain loudly if you have
mtab_is_file set to yes and recommend that you change this to no and
restart the mtab service to migrate /etc/mtab to a symbolic link.
If there is a valid technical reason to keep /etc/mtab as a flat file
instead of a symbolic link to /proc/self/mounts, we are interested and
we will keep the support in that case. Please open an issue and let us
know however. Otherwise, consider this your final notice that the mtab
service will be removed in the future.
## OpenRC 0.33
This version removes the "service" binary which was just a copy of

View File

@@ -1,19 +1,28 @@
# OpenRC README
OpenRC README
=============
OpenRC is a dependency-based init system that works with the
system-provided init program, normally `/sbin/init`. Currently, it does
not have an init program of its own.
system-provided init program, normally `/sbin/init`.
## Installation
## building and installing
OpenRC uses the [meson](http://mesonbuild.com) build system, so use the
usual methods for this build system to build and install.
The old build system is still available for the 0.44.x branch, but it is
considered deprecated and will be removed. The previous documentation is
below.
## Installation (historical)
OpenRC requires GNU make.
Once you have GNU Make installed, the default OpenRC installation can be
executed using this command:
make install
`make install`
## Configuration
## Configuration (historical)
You may wish to configure the installation by passing one or more of the
below arguments to the make command
@@ -22,6 +31,7 @@ below arguments to the make command
PROGLDFLAGS=-static
LIBNAME=lib64
DESTDIR=/tmp/openrc-image
MKBASHCOMP=no
MKNET=no
MKPAM=pam
MKPREFIX=yes
@@ -31,23 +41,27 @@ MKSTATICLIBS=no
MKSYSVINIT=yes
MKTERMCAP=ncurses
MKTERMCAP=termcap
MKZSHCOMP=no
PKG_PREFIX=/usr/pkg
LOCAL_PREFIX=/usr/local
PREFIX=/usr/local
BRANDING=\"Gentoo/$(uname -s)\"
SH=/bin/sh
```
## Notes
We don't support building a static OpenRC with PAM.
You may need to use `PROGLDFLAGS=-Wl,-Bstatic` on glibc instead of just `-static`.
You may need to use `PROGLDFLAGS=-Wl,-Bstatic` on glibc instead of just `-static`
(This is now handled by the meson build system).
If you are building OpenRC for a Gentoo Prefix installation, add `MKPREFIX=yes`.
If you are building OpenRC for a Gentoo Prefix installation, add `MKPREFIX=yes`
(this is not supported in the meson build currently, but patches are welcome).
`PKG_PREFIX` should be set to where packages install to by default.
`LOCAL_PREFIX` should be set when to where user maintained packages are.
`LOCAL_PREFIX` should be set to where user maintained packages are.
Only set `LOCAL_PREFIX` if different from `PKG_PREFIX`.
`PREFIX` should be set when OpenRC is not installed to /.
@@ -73,20 +87,21 @@ Obviously, if you're installing this onto a system that does not use
OpenRC by default then you may wish to backup the above listed files,
remove them and then install so that the OS hooks into OpenRC.
## Discussions
We are testing [discussions](https://github.com/OpenRC/openrc/discussions), so
feel free to open topics there.
## Reporting Bugs
If you are using Gentoo Linux, bugs can be filed on their bugzilla under
the `gentoo hosted projects` product and the `openrc` component [1].
Otherwise, you can report issues on our github [2].
Please report bugs on our [bug tracker](http://github.com/OpenRC/openrc/issues).
Better yet, if you can contribute code, please feel free to submit pull
requests [3].
If you can contribute code , please feel free to do so by opening
[pull requests](https://github.com/OpenRC/openrc/pulls).
## IRC Channel
We have an official irc channel, #openrc on freenode, feel free to join
us there.
We have an official irc channel, #openrc on the libera network.
Please connect your irc client to irc.libera.chat and join #openrc on
that network.
[1] https://bugs.gentoo.org/
[2] https://github.com/openrc/openrc/issues
[3] https://github.com/openrc/openrc/pulls

View File

@@ -1,4 +1,5 @@
# OpenRC Style Guide
OpenRC Coding Style Guide
=========================
This is the openrc style manual. It governs the coding style of all code
in this repository. Follow it. Contact openrc@gentoo.org for any questions

View File

@@ -1,4 +1,5 @@
# Setting up the agetty service in OpenRC
Setting up the agetty service in OpenRC
=================================xxxxxx
The agetty service is an OpenRC specific way to monitor and respawn a
getty, using agetty, on Linux. To use this method, make sure you aren't

11
bash-completion/Makefile Normal file
View File

@@ -0,0 +1,11 @@
DIR= ${BASHCOMPDIR}
CONF= openrc \
openrc-service-script \
rc-service \
rc-status \
rc-update \
MK= ../mk
include ${MK}/os.mk
include ${MK}/scripts.mk

View File

@@ -0,0 +1,10 @@
bash_completions = [
'openrc',
'openrc-service-script',
'rc-service',
'rc-status',
'rc-update',
]
install_data(bash_completions,
install_dir : get_option('datadir') / 'bash-completion/completions')

24
bash-completion/openrc Normal file
View File

@@ -0,0 +1,24 @@
# Copyright (c) 2017 The OpenRC Authors.
# See the Authors file at the top-level directory of this distribution and
# https://github.com/OpenRC/openrc/blob/master/AUTHORS
#
# This file is part of OpenRC. It is subject to the license terms in
# the LICENSE file found in the top-level directory of this
# distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE
# This file may not be copied, modified, propagated, or distributed
# except according to the terms contained in the LICENSE file.
#
# openrc completion command
#
_openrc()
{
local cur
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
if [[ ${#COMP_WORDS[*]} -le 2 ]]; then
COMPREPLY=($(compgen -W "$(rc-status --list)" -- $cur))
fi
return 0
} &&
complete -F _openrc openrc

View File

@@ -0,0 +1,29 @@
# Copyright (c) 2017 The OpenRC Authors.
# See the Authors file at the top-level directory of this distribution and
# https://github.com/OpenRC/openrc/blob/master/AUTHORS
#
# This file is part of OpenRC. It is subject to the license terms in
# the LICENSE file found in the top-level directory of this
# distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE
# This file may not be copied, modified, propagated, or distributed
# except according to the terms contained in the LICENSE file.
_openrc_service_script()
{
local script="${COMP_WORDS[0]}"
local cur="${COMP_WORDS[$COMP_CWORD]}"
if [[ ( -f "${script}" || -h "${script}" ) && -r "${script}" ]] \
&& [[ "$(head -n 1 "${script}")" =~ \#\!.*/openrc-run ]]
then
[[ $COMP_CWORD -gt 1 ]] && return 1
COMPREPLY=($(opts="start stop status restart pause zap ineed needsme iuse usesme broken"; \
eval "$(grep '^opts=' "${script}")"; echo "${opts}"))
[[ -n "$COMPREPLY" ]] || COMPREPLY=(start stop restart zap)
COMPREPLY=($(compgen -W "${COMPREPLY[*]}" -- "${cur}"))
else
COMPREPLY=($(compgen -o default -- "${cur}"))
fi
return 0
}
complete -F _openrc_service_script */etc/init.d/*

116
bash-completion/rc-service Normal file
View File

@@ -0,0 +1,116 @@
# Copyright (c) 2017 The OpenRC Authors.
# See the Authors file at the top-level directory of this distribution and
# https://github.com/OpenRC/openrc/blob/master/AUTHORS
#
# This file is part of OpenRC. It is subject to the license terms in
# the LICENSE file found in the top-level directory of this
# distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE
# This file may not be copied, modified, propagated, or distributed
# except according to the terms contained in the LICENSE file.
#
# rc-service completion command
#
_rc_service()
{
local cur prev numwords opts
local words i x filename
local action actionpos
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
numwords=${#COMP_WORDS[*]}
if [[ ${prev} == '>' || ${prev} == '<' ]] ; then
COMPREPLY=($(compgen -f -- ${cur}))
return 0
fi
# find action
for x in ${COMP_LINE} ; do
if [[ ${x} =~ --(list|exists|resolve) ]] || [[ ${x} =~ -(l|e|r) ]]
then
action=${x}
break
fi
done
if [[ -n ${action} ]]; then
for ((i = 0; i < ${numwords}; i++ )); do
if [[ ${COMP_WORDS[${i}]} == "${action}" ]]; then
actionpos=${i}
break
fi
done
for ((i = 1; i < ${numwords}; i++ )); do
if [[ ! ${COMP_WORDS[$i]} == -* ]]; then
break
fi
done
fi
if [[ ${COMP_CWORD} -eq 3 ]]; then
return 1
fi
# check if an option was typed
if [[ ${cur} == -* ]]; then
if [[ ${cur} == --* ]]; then
opts="--list --exists --resolve"
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
elif [[ ${cur} == -* ]]; then
opts="-l -e -r"
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
fi
# NOTE: This slows things down!
# (Adapted from bash_completion by Ian Macdonald <ian@caliban.org>)
# This removes any options from the list of completions that have
# already been specified on the command line.
COMPREPLY=($(echo "${COMP_WORDS[@]}" | \
(while read -d ' ' i; do
[[ -z ${i} ]] && continue
# flatten array with spaces on either side,
# otherwise we cannot grep on word boundaries of
# first and last word
COMPREPLY=" ${COMPREPLY[@]} "
# remove word from list of completions
COMPREPLY=(${COMPREPLY/ ${i%% *} / })
done
echo ${COMPREPLY[@]})))
return 0
else
# no option was typed
if [[ ${COMP_CWORD} -eq 1 ]]; then # if first word typed
words="$(rc-service --list | grep ^${cur})" # complete for init scripts
COMPREPLY=($(for i in ${words} ; do \
[[ ${i} == ${cur}* ]] && echo ${i} ; \
done))
return 0
elif [[ ${COMP_CWORD} -eq 2 ]] && [[ ${prev} != -* ]]; then # if second word typed and we didn't type in a function
rc-service --exists "$prev" || return
shopt -s extglob
while read -r _ line; do
if [[ $line == +([[:alnum:]_]):* ]]; then
opts+="${line%%:*} "
fi
done < <(rc-service "$prev" describe 2>&1)
shopt -u extglob
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
fi
fi
if [[ ${action} == '--exists' ]] || [[ ${action} == '-e' ]] || \
[[ ${action} == '--resolve' ]] || [[ ${action} == '-r' ]]; then
words="$(rc-service --list | grep ^${cur})"
COMPREPLY=($(for i in ${words} ; do \
[[ ${i} == ${cur}* ]] && echo ${i} ; \
done))
return 0
fi
return 0
} &&
complete -F _rc_service rc-service

31
bash-completion/rc-status Normal file
View File

@@ -0,0 +1,31 @@
# Copyright (c) 2017 The OpenRC Authors.
# See the Authors file at the top-level directory of this distribution and
# https://github.com/OpenRC/openrc/blob/master/AUTHORS
#
# This file is part of OpenRC. It is subject to the license terms in
# the LICENSE file found in the top-level directory of this
# distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE
# This file may not be copied, modified, propagated, or distributed
# except according to the terms contained in the LICENSE file.
#
# rc-status completion command
#
_rcstatus()
{
local cur
cur="${COMP_WORDS[COMP_CWORD]}"
if [[ $COMP_CWORD -eq 1 ]]; then
if [[ "${cur}" == --* ]]; then
COMPREPLY=($(compgen -W '--all --list --unused' -- ${cur}))
elif [[ "${cur}" == -* ]]; then
COMPREPLY=($(compgen -W '-a -l -u' -- ${cur}))
else
COMPREPLY=($(compgen -W "$(rc-status --list)" -- ${cur}))
fi
else
unset COMPREPLY
fi
return 0
} &&
complete -F _rcstatus rc-status

42
bash-completion/rc-update Normal file
View File

@@ -0,0 +1,42 @@
# Copyright (c) 2017 The OpenRC Authors.
# See the Authors file at the top-level directory of this distribution and
# https://github.com/OpenRC/openrc/blob/master/AUTHORS
#
# This file is part of OpenRC. It is subject to the license terms in
# the LICENSE file found in the top-level directory of this
# distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE
# This file may not be copied, modified, propagated, or distributed
# except according to the terms contained in the LICENSE file.
#
# rc-update completion command
#
_rc_update()
{
local cur show
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
if [[ $COMP_CWORD -eq 1 ]]; then
if [[ "${cur}" == -* ]]; then
COMPREPLY=($(compgen -W '-a -d -s' -- ${cur}))
else
COMPREPLY=($(compgen -W 'add del show' ${cur}))
fi
else
if [[ "${COMP_WORDS[1]}" == "show" ]] || [[ "${COMP_WORDS[1]}" == "-s" ]]; then
show="TRUE"
fi
if ([[ $COMP_CWORD -eq 3 ]] && [[ -z "$show" ]]) || \
([[ $COMP_CWORD -eq 2 ]] && [[ -n "$show" ]]); then
COMPREPLY=($(compgen -W "$(rc-status --list)" -- $cur))
elif [[ $COMP_CWORD -eq 2 ]]; then
COMPREPLY=($(compgen -W "$(rc-service --list)" $cur))
elif [[ ${#COMP_WORDS[*]} -gt 2 ]] ; then
COMPREPLY=($(compgen -W "$(rc-status --list)" -- $cur))
else
unset COMPREPLY
fi
fi
return 0
} &&
complete -F _rc_update rc-update

21
ci/cirrus.sh Executable file
View File

@@ -0,0 +1,21 @@
#!/bin/bash
# Copyright (c) 2007-2018 The OpenRC Authors.
# See the Authors file at the top-level directory of this distribution and
# https://github.com/OpenRC/openrc/blob/master/AUTHORS
#
# This file is part of OpenRC. It is subject to the license terms in
# the LICENSE file found in the top-level directory of this
# distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE
# This file may not be copied, modified, propagated, or distributed
# except according to the terms contained in the LICENSE file.
set -e
set -u
set -x
# These are steps to run on Cirrus CI under a jailed FreeBSD system.
# See $TOP/.cirrus.yml for more info about the Cirrus CI setup.
cpus=$(getconf NPROCESSORS_CONF || echo 1)
gmake -j"${cpus}" -O
gmake test

40
ci/travis.sh Executable file
View File

@@ -0,0 +1,40 @@
#!/bin/bash
# Copyright (c) 2007-2018 The OpenRC Authors.
# See the Authors file at the top-level directory of this distribution and
# https://github.com/OpenRC/openrc/blob/master/AUTHORS
#
# This file is part of OpenRC. It is subject to the license terms in
# the LICENSE file found in the top-level directory of this
# distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE
# This file may not be copied, modified, propagated, or distributed
# except according to the terms contained in the LICENSE file.
set -e
set -u
set -x
# These are steps to run on TravisCI under a containerized Ubuntu system.
# See $TOP/.travis.yml for more info about the TravisCI setup.
# Run shellcheck, but don't fail (yet):
shellcheck --version
for shellscript in $(git ls-files); do
case $shellscript in
init.d/*.in) ;;
sh/*.in) ;;
sh/*.sh) ;;
support/init.d.examples/*.in) ;;
support/openvpn/*.sh) ;;
support/sysvinit/halt.sh) ;;
test/*.sh) ;;
*) continue ;;
esac
echo "Checking ${shellscript} with shellcheck:"
shellcheck -s sh "${shellscript}" || true
done
cpus=$(getconf _NPROCESSORS_CONF || echo 1)
# make on TravisCI doesn't support -O yet
make -j"${cpus}"
make test

View File

@@ -1,2 +1,2 @@
# Set to the hostname of this machine
# Hostname fallback if /etc/hostname does not exist
hostname="localhost"

59
conf.d/meson.build Normal file
View File

@@ -0,0 +1,59 @@
conf_d_dir = get_option('sysconfdir') / 'conf.d'
conf_common = [
'bootmisc',
'fsck',
'hostname',
'localmount',
'netmount',
'swap',
'urandom',
]
conf_net = [
'network',
'staticroute',
]
conf_FreeBSD = [
'ipfw',
'modules',
'moused',
'powerd',
'rarpd',
'savecore',
'syscons',
]
conf_Linux = [
'agetty',
'consolefont',
'devfs',
'dmesg',
'hwclock',
'keymaps',
'killprocs',
'modules',
'mtab',
'net-online',
]
conf_NetBSD = [
'moused',
'rarpd',
'savecore',
]
conf_data = conf_common
if get_option('newnet')
conf_data = conf_data + conf_net
endif
if os == 'FreeBSD'
conf_data = conf_data + conf_FreeBSD
elif os == 'Linux'
conf_data = conf_data + conf_Linux
elif os == 'NetBSD'
conf_data = conf_data + conf_NetBSD
endif
install_data(conf_data, install_dir : conf_d_dir)

View File

@@ -8,11 +8,6 @@
#modules_2="ipv6"
#modules="ohci1394"
# Linux users can give modules a different name when they load - the new name
# will also be used to pick arguments below.
# This is not supported on FreeBSD.
#modules="dummy:dummy1"
# Linux users can give the modules some arguments if needed, per version
# if necessary.
# Again, the most specific versioned variable will take precedence.

View File

@@ -1,5 +1,13 @@
# As far as we are aware, there are no modern linux tools or use cases
# which require /etc/mtab to be a separate file from /proc/self/mounts,
# so this setting should be commented out.
# If it is set to yes, please comment it out and run this command:
# # rc-service mtab restart
# In the future, the mtab service will be removed since we are not aware
# of any need to manipulate /etc/mtab as a separate file from
# /proc/self/mounts.
# If you have a technical reason we should keep this support, please
# open an issue at https://github.com/openrc/openrc/issues and let us
# know about your situation.
# This setting controls whether /etc/mtab is a file or symbolic link.
# Most of the time, you shouldn't touch this. However, if the default
# breaks your system in some way, please see the NEWS.md file that comes
# with OpenRC for the actions to take.
# mtab_is_file=no

44
etc/meson.build Normal file
View File

@@ -0,0 +1,44 @@
etc_conf_data = configuration_data()
if os == 'FreeBSD'
etc_conf_data.set('TERM', 'cons25')
elif os == 'Linux'
etc_conf_data.set('TERM', 'wsvt25')
endif
etc_conf_common = [
'rc.conf',
]
etc_bin_FreeBSD = [
'rc.devd',
]
etc_conf_FreeBSD = [
'devd.conf',
]
etc_bin_NetBSD = [
'rc.in',
'rc.shutdown.in',
]
install_data(etc_conf_common,
install_dir : get_option('sysconfdir'))
if os == 'FreeBSD'
install_data(etc_bin_FreeBSD,
install_dir : get_option('sysconfdir'),
install_mode: 'rwxr-xr-x')
install_data(etc_conf_FreeBSD,
install_dir : get_option('sysconfdir'))
endif
if os == 'FreeBSD' or os == 'NetBSD'
foreach file : etc_bin_NetBSD
configure_file(input : file,
output : '@BASENAME@',
configuration : etc_conf_data,
install_dir: get_option('sysconfdir'),
install_mode: 'rwxr-xr-x')
endforeach
endif

View File

@@ -198,10 +198,9 @@ rc_tty_number=12
# "unified" mounts cgroups version 2 on /sys/fs/cgroup
#rc_cgroup_mode="hybrid"
# This is a list of controllers which should be enabled for cgroups version 2.
# If hybrid mode is being used, controllers listed here will not be
# available for cgroups version 1.
# This is a global setting.
# This is a list of controllers which should be enabled for cgroups version 2
# when hybrid mode is being used.
# Controllers listed here will not be available for cgroups version 1.
#rc_cgroup_controllers=""
# This variable contains the cgroups version 2 settings for your services.
@@ -227,6 +226,11 @@ rc_tty_number=12
# /sys/fs/cgroup in hybrid or legacy mode.
#rc_controller_cgroups="YES"
# The following setting turns on the memory.use_hierarchy setting in the
# root memory cgroup for cgroups v1.
# It must be set to yes in this file if you want this functionality.
#rc_cgroup_memory_use_hierarchy="NO"
# The following settings allow you to set up values for the cgroups version 1
# controllers for your services.
# They can be set in this file;, however, if you do this, the settings

View File

@@ -1,4 +1,4 @@
#!@SHELL@
#!/bin/sh
# Copyright (c) 2007-2015 The OpenRC Authors.
# See the Authors file at the top-level directory of this distribution and
# https://github.com/OpenRC/openrc/blob/master/AUTHORS

View File

@@ -1,4 +1,4 @@
#!@SHELL@
#!/bin/sh
# Copyright (c) 2007-2015 The OpenRC Authors.
# See the Authors file at the top-level directory of this distribution and
# https://github.com/OpenRC/openrc/blob/master/AUTHORS

47
init-guide.md Normal file
View File

@@ -0,0 +1,47 @@
# OpenRC init process guide
OpenRC now includes an init process which can be used on Linux systems
in place of sysvinit.
## migrating a live system to openrc-init
Configuring a live system to use this init process is very
straight-forward, but the steps must be completed in this order.
* have your boot loader add "init=/sbin/openrc-init" to the kernel command line
The details of how to do this will vary from distro to distro, so they are
out of scope for this document.
* Install gettys into the runlevels where you need them.
If you are using the provided /etc/init.d/agetty script,, you should
first create symlinks in /etc/init.d to it for the ports where you
want gettys to run, e.g. the following will work if you want gettys on
tty1-tty6.
```
# cd /etc/init.d
# for x in tty1 tty2 tty3 tty4 tty5 tty6; do
ln -snf agetty agetty.$x
done
```
Once this is done, use ```rc-update``` as normal to install the agetty
services in the appropriate runlevels.
* Reboot your system.
At this point you are running under openrc-init, and you should use
openrc-shutdown to handle shutting down, powering off, rebooting etc.
## optional sysvinit compatibility
If you build and install OpenRC with MKSYSVINIT=yes, you will build and install
wrappers that make openrc-init compatible with sysvinit -- you will have
commands like "halt" "shutdown" "reboot" and "poweroff".
If you want this functionality on a live system, you should first
migrate the system to openrc-init, remove sysvinit, then rebuild and
install this package with MKSYSVINIT=yes.

3
init.d/.gitignore vendored
View File

@@ -1,5 +1,6 @@
agetty
binfmt
cgroups
modules-load
bootmisc
fsck
@@ -40,6 +41,8 @@ rc-enabled
rpcbind
runsvdir
savecore
save-keymaps
save-termencoding
swap-blk
swclock
syslogd

View File

@@ -19,11 +19,12 @@ SRCS-FreeBSD= hostid.in modules.in moused.in newsyslog.in pf.in rarpd.in \
rc-enabled.in rpcbind.in savecore.in syslogd.in
# These are FreeBSD specific
SRCS-FreeBSD+= adjkerntz.in devd.in dumpon.in encswap.in ipfw.in \
modules-load.in mixer.in nscd.in powerd.in syscons.in
mixer.in nscd.in powerd.in syscons.in
SRCS-Linux= agetty.in binfmt.in devfs.in dmesg.in hwclock.in consolefont.in \
keymaps.in killprocs.in modules.in modules-load.in mount-ro.in mtab.in \
numlock.in procfs.in net-online.in sysfs.in termencoding.in
SRCS-Linux= agetty.in binfmt.in devfs.in cgroups.in dmesg.in hwclock.in \
consolefont.in keymaps.in killprocs.in modules.in \
mount-ro.in mtab.in numlock.in procfs.in net-online.in save-keymaps.in \
save-termencoding.in sysfs.in termencoding.in
# Generic BSD scripts
SRCS-NetBSD= hostid.in moused.in newsyslog.in pf.in rarpd.in rc-enabled.in \

View File

@@ -12,15 +12,16 @@
description="start agetty on a terminal line"
supervisor=supervise-daemon
port="${RC_SVCNAME#*.}"
respawn_period="${respawn_period:-60}"
term_type="${term_type:-linux}"
command=/sbin/agetty
command_args_foreground="${agetty_options} ${port} ${baud} ${term_type}"
pidfile="/run/${RC_SVCNAME}.pid"
export EINFO_QUIET="${quiet:-yes}"
depend() {
after local
keyword -prefix
provide getty
}
start_pre() {
@@ -29,5 +30,12 @@ start_pre() {
eerror "symbolic links to it for the ports you want to start"
eerror "agetty on and add those to the appropriate runlevels."
return 1
else
export EINFO_QUIET="${quiet:-yes}"
fi
}
stop_pre()
{
export EINFO_QUIET="${quiet:-yes}"
}

View File

@@ -113,8 +113,10 @@ migrate_to_run()
rm $src
elif [ ! -L $src -a -d $src ]; then
ebegin "Migrating $src to $dst"
cp -a $src/* $dst/
rm -rf $src
if ! rmdir $src 2>/dev/null; then
cp -a $src/* $dst/
rm -rf $src
fi
eend $?
fi
# If $src doesn't exist at all, just run this
@@ -241,7 +243,13 @@ stop()
{
# Write a halt record if we're shutting down
if [ "$RC_RUNLEVEL" = shutdown ]; then
[ "$RC_UNAME" = Linux ] && openrc-shutdown -w
if [ "$RC_UNAME" = Linux ]; then
if [ -x /sbin/halt ]; then
halt -w
else
openrc-shutdown -w
fi
fi
if [ "$RC_SYS" = OPENVZ ]; then
yesno $RC_REBOOT && printf "" >/reboot
fi

157
init.d/cgroups.in Normal file
View File

@@ -0,0 +1,157 @@
#!@SBINDIR@/openrc-run
# Copyright (c) 2017 The OpenRC Authors.
# See the Authors file at the top-level directory of this distribution and
# https://github.com/OpenRC/openrc/blob/master/AUTHORS
#
# This file is part of OpenRC. It is subject to the license terms in
# the LICENSE file found in the top-level directory of this
# distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE
# This file may not be copied, modified, propagated, or distributed
# except according to the terms contained in the LICENSE file.
description="Mount the control groups."
cgroup_opts=nodev,noexec,nosuid
depend()
{
keyword -docker -prefix -systemd-nspawn -vserver
after sysfs
}
cgroup1_base()
{
grep -qw cgroup /proc/filesystems || return 0
if ! mountinfo -q /sys/fs/cgroup; then
ebegin "Mounting cgroup filesystem"
local opts="${cgroup_opts},mode=755,size=${rc_cgroupsize:-10m}"
mount -n -t tmpfs -o "${opts}" cgroup_root /sys/fs/cgroup
eend $?
fi
if ! mountinfo -q /sys/fs/cgroup/openrc; then
local agent="${RC_LIBEXECDIR}/sh/cgroup-release-agent.sh"
mkdir /sys/fs/cgroup/openrc
mount -n -t cgroup \
-o none,${cgroup_opts},name=openrc,release_agent="$agent" \
openrc /sys/fs/cgroup/openrc
printf 1 > /sys/fs/cgroup/openrc/notify_on_release
fi
return 0
}
cgroup1_controllers()
{
yesno "${rc_controller_cgroups:-YES}" && [ -e /proc/cgroups ] &&
grep -qw cgroup /proc/filesystems || return 0
while read -r name _ _ enabled _; do
case "${enabled}" in
1) mountinfo -q "/sys/fs/cgroup/${name}" && continue
local x
for x in $rc_cgroup_controllers; do
[ "${name}" = "blkio" ] && [ "${x}" = "io" ] &&
continue 2
[ "${name}" = "${x}" ] &&
continue 2
done
mkdir "/sys/fs/cgroup/${name}"
mount -n -t cgroup -o "${cgroup_opts},${name}" \
"${name}" "/sys/fs/cgroup/${name}"
yesno "${rc_cgroup_memory_use_hierarchy:-no}" &&
[ "${name}" = memory ] &&
echo 1 > /sys/fs/cgroup/memory/memory.use_hierarchy
;;
esac
done < /proc/cgroups
return 0
}
cgroup2_base()
{
grep -qw cgroup2 /proc/filesystems || return 0
local base
base="$(cgroup2_find_path)"
mkdir -p "${base}"
mount -t cgroup2 none -o "${cgroup_opts},nsdelegate" "${base}" 2> /dev/null ||
mount -t cgroup2 none -o "${cgroup_opts}" "${base}"
return 0
}
cgroup2_controllers()
{
grep -qw cgroup2 /proc/filesystems || return 0
local active cgroup_path x y
cgroup_path="$(cgroup2_find_path)"
[ -z "${cgroup_path}" ] && return 0
[ ! -e "${cgroup_path}/cgroup.controllers" ] && return 0
[ ! -e "${cgroup_path}/cgroup.subtree_control" ]&& return 0
read -r active < "${cgroup_path}/cgroup.controllers"
for x in ${active}; do
case "$rc_cgroup_mode" in
unified)
echo "+${x}" > "${cgroup_path}/cgroup.subtree_control"
;;
hybrid)
for y in ${rc_cgroup_controllers}; do
if [ "$x" = "$y" ]; then
echo "+${x}" > "${cgroup_path}/cgroup.subtree_control"
fi
done
;;
esac
done
return 0
}
cgroups_hybrid()
{
cgroup1_base
cgroup2_base
cgroup2_controllers
cgroup1_controllers
return 0
}
cgroups_legacy()
{
cgroup1_base
cgroup1_controllers
return 0
}
cgroups_unified()
{
cgroup2_base
cgroup2_controllers
return 0
}
mount_cgroups()
{
case "${rc_cgroup_mode:-hybrid}" in
hybrid) cgroups_hybrid ;;
legacy) cgroups_legacy ;;
unified) cgroups_unified ;;
esac
return 0
}
restorecon_cgroups()
{
if [ -x /sbin/restorecon ]; then
ebegin "Restoring SELinux contexts in /sys/fs/cgroup"
restorecon -rF /sys/fs/cgroup >/dev/null 2>&1
eend $?
fi
return 0
}
start()
{
# set up kernel support for cgroups
if [ -d /sys/fs/cgroup ]; then
mount_cgroups
restorecon_cgroups
fi
return 0
}

View File

@@ -13,7 +13,7 @@ description="Sets a font for the consoles."
depend()
{
need localmount termencoding
need termencoding
after hotplug bootmisc modules
keyword -docker -lxc -openvz -prefix -systemd-nspawn -uml -vserver -xenu
}

View File

@@ -15,14 +15,17 @@ depend()
{
provide dev-mount
before dev
keyword -docker -lxc -prefix -systemd-nspawn -vserver
keyword -docker -prefix -systemd-nspawn -vserver
}
mount_dev()
{
local action=--mount devfstype msg=Mounting
local action conf_d_dir devfstype msg mountopts
action=--mount
conf_d_dir="${RC_SERVICE%/*/*}/conf.d"
msg=Mounting
# Some devices require exec, Bug #92921
local mountopts="exec,nosuid,mode=0755"
mountopts="exec,nosuid,mode=0755"
if yesno ${skip_mount_dev:-no} ; then
einfo "/dev will not be mounted due to user request"
return 0
@@ -33,7 +36,7 @@ mount_dev()
msg=Remounting
fi
if fstabinfo -q /dev; then
ebegin "$msg /dev according to @SYSCONFDIR@/fstab"
ebegin "$msg /dev according to fstab"
fstabinfo -q $action /dev
eend $?
return 0
@@ -54,7 +57,7 @@ mount_dev()
ewarn "is no entry for /dev in fstab."
ewarn "This means /dev will not be mounted."
ewarn "To avoid this message, set CONFIG_DEVTMPFS or CONFIG_TMPFS to y"
ewarn "in your kernel configuration or see @SYSCONFDIR@/conf.d/devfs"
ewarn "in your kernel configuration or see ${conf_d_dir}/${RC_SVCNAME}"
fi
return 0
}
@@ -63,18 +66,20 @@ seed_dev()
{
# Seed /dev with some things that we know we need
# creating /dev/console, /dev/tty and /dev/tty1 to be able to write
# to $CONSOLE with/without bootsplash before udevd creates it
[ -c /dev/console ] || mknod -m 600 /dev/console c 5 1
[ -c /dev/tty1 ] || mknod -m 620 /dev/tty1 c 4 1
[ -c /dev/tty ] || mknod -m 666 /dev/tty c 5 0
if [ "${RC_SYS}" != LXC ]; then
# creating /dev/console, /dev/tty and /dev/tty1 to be able to write
# to $CONSOLE with/without bootsplash before udevd creates it
[ -c /dev/console ] || mknod -m 600 /dev/console c 5 1
[ -c /dev/tty1 ] || mknod -m 620 /dev/tty1 c 4 1
[ -c /dev/tty ] || mknod -m 666 /dev/tty c 5 0
# udevd will dup its stdin/stdout/stderr to /dev/null
# and we do not want a file which gets buffered in ram
[ -c /dev/null ] || mknod -m 666 /dev/null c 1 3
# udevd will dup its stdin/stdout/stderr to /dev/null
# and we do not want a file which gets buffered in ram
[ -c /dev/null ] || mknod -m 666 /dev/null c 1 3
# so udev can add its start-message to dmesg
[ -c /dev/kmsg ] || mknod -m 660 /dev/kmsg c 1 11
# so udev can add its start-message to dmesg
[ -c /dev/kmsg ] || mknod -m 660 /dev/kmsg c 1 11
fi
# extra symbolic links not provided by default
[ -e /dev/fd ] || ln -snf /proc/self/fd /dev/fd

View File

@@ -20,9 +20,9 @@ depend()
start()
{
local h source x
if [ -s @SYSCONFDIR@/hostname ] && [ -r @SYSCONFDIR@/hostname ]; then
read h x <@SYSCONFDIR@/hostname
source="from @SYSCONFDIR@/hostname"
if [ -s /etc/hostname ] && [ -r /etc/hostname ]; then
read h x </etc/hostname
source="from /etc/hostname"
else
# HOSTNAME variable used to be defined in caps in conf.d/hostname.
# It is also a magic variable in bash.

View File

@@ -105,7 +105,7 @@ start()
done
[ -n "$modname" ] &&
ewarn "The $modname module needs to be configured in" \
"@SYSCONFDIR@/conf.d/modules or built in."
"${RC_SERVICE%/*/*}/conf.d/modules or built in."
fi
fi

View File

@@ -13,8 +13,8 @@ description="Applies a keymap for the consoles."
depend()
{
need localmount termencoding
after bootmisc clock
need termencoding
after devfs
keyword -docker -lxc -openvz -prefix -systemd-nspawn -uml -vserver -xenu
}
@@ -68,10 +68,5 @@ start()
echo "altgr keycode 18 = U+20AC" | loadkeys -q -
eend $?
fi
# Save the keymapping for use immediately at boot
if checkpath -W "$RC_LIBEXECDIR"; then
mkdir -p "$RC_LIBEXECDIR"/console
dumpkeys >"$RC_LIBEXECDIR"/console/keymap
fi
return 0
}

View File

@@ -9,7 +9,10 @@
# This file may not be copied, modified, propagated, or distributed
# except according to the terms contained in the LICENSE file.
description="Executes user programs in @SYSCONFDIR@/local.d"
conf_d_dir="${RC_SERVICE%/*/*}/conf.d"
local_d_dir="${RC_SERVICE%/*/*}/local.d"
description="Executes user programs in ${local_d_dir}"
depend()
{
@@ -19,12 +22,12 @@ depend()
start()
{
ebegin "Starting local"
local file has_errors=0 redirect retval
local file has_errors redirect retval
has_errors=0
yesno $rc_verbose || redirect='> /dev/null 2>&1'
ebegin "Starting local"
eindent
for file in @SYSCONFDIR@/local.d/*.start; do
for file in "${local_d_dir}"/*.start; do
if [ -x "${file}" ]; then
vebegin "Executing \"${file}\""
eval "${file}" $redirect
@@ -38,32 +41,32 @@ start()
eoutdent
if command -v local_start >/dev/null 2>&1; then
ewarn "\"@SYSCONFDIR@/conf.d/local\" should be removed."
ewarn "\"${conf_d_dir}/local\" should be removed."
ewarn "Please move the code from the local_start function"
ewarn "to executable scripts with an .start extension"
ewarn "in \"@SYSCONFDIR@/local.d\""
ewarn "in \"${local_d_dir}\""
local_start
fi
eend ${has_errors}
# We have to end with a zero exit code, because a failed execution
# of an executable @SYSCONFDIR@/local.d/*.start file shouldn't result in
# of an executable ${local_d_dir}/*.start file shouldn't result in
# marking the local service as failed. Otherwise we are unable to
# execute any executable @SYSCONFDIR@/local.d/*.stop file, because a failed
# execute any executable ${local_d_dir}/*.stop file, because a failed
# marked service cannot be stopped (and the stop function would
# actually call the executable @SYSCONFDIR@/local.d/*.stop file(s)).
# actually call the executable ${local_d_dir}/*.stop file(s)).
return 0
}
stop()
{
ebegin "Stopping local"
local file has_errors=0 redirect retval
local file has_errors redirect retval
has_errors=0
yesno $rc_verbose || redirect='> /dev/null 2>&1'
ebegin "Stopping local"
eindent
for file in @SYSCONFDIR@/local.d/*.stop; do
for file in "${local_d_dir}"/*.stop; do
if [ -x "${file}" ]; then
vebegin "Executing \"${file}\""
eval "${file}" $redirect
@@ -77,16 +80,16 @@ stop()
eoutdent
if command -v local_stop >/dev/null 2>&1; then
ewarn "\"@SYSCONFDIR@/conf.d/local\" should be removed."
ewarn "\"${conf_d_dir}/local\" should be removed."
ewarn "Please move the code from the local_stop function"
ewarn "to executable scripts with an .stop extension"
ewarn "in \"@SYSCONFDIR@/local.d\""
ewarn "in \"${local_d_dir}\""
local_stop
fi
eend ${has_errors}
# An executable @SYSCONFDIR@/local.d/*.stop file which failed with a
# An executable ${local_d_dir}/*.stop file which failed with a
# non-zero exit status is not a reason to mark this service
# as failed, therefore we have to end with a zero exit code.
return 0

View File

@@ -13,9 +13,9 @@ description="Mounts disks and swap according to /etc/fstab."
depend()
{
need fsck
use lvm modules mtab root
after clock lvm modules root
need fsck root
use lvm modules
after clock lvm modules
keyword -docker -jail -lxc -prefix -systemd-nspawn -vserver
}

100
init.d/meson.build Normal file
View File

@@ -0,0 +1,100 @@
init_d_dir = get_option('sysconfdir') / 'init.d'
init_common = [
'bootmisc.in',
'fsck.in',
'hostname.in',
'local.in',
'localmount.in',
'loopback.in',
'netmount.in',
'osclock.in',
'root.in',
'savecache.in',
'swap.in',
'swclock.in',
'sysctl.in',
'runsvdir.in',
'urandom.in',
's6-svscan.in',
]
if get_option('newnet')
init_common = init_common + [
'network.in',
'staticroute.in',
]
endif
init_Linux = [
'agetty.in',
'binfmt.in',
'cgroups.in',
'consolefont.in',
'devfs.in',
'dmesg.in',
'hwclock.in',
'keymaps.in',
'killprocs.in',
'modules.in',
'mount-ro.in',
'mtab.in',
'numlock.in',
'procfs.in',
'net-online.in',
'save-keymaps.in',
'save-termencoding.in',
'sysfs.in',
'termencoding.in',
]
init_BSD = [
'hostid.in',
'moused.in',
'newsyslog.in',
'pf.in',
'rarpd.in',
'rc-enabled.in',
'rpcbind.in',
'savecore.in',
'syslogd.in',
]
init_FreeBSD = [
'adjkerntz.in',
'devd .in',
'dumpon.in',
'encswap.in',
'ipfw.in',
'modules.in',
'mixer.in',
'nscd.in',
'powerd.in',
'syscons.in',
]
init_NetBSD = [
'devdb.in',
'swap-blk.in',
'ttys.in',
'wscons.in',
]
init_data = init_common
if os == 'Dragonfly'
init_data = init_data + init_BSD
elif os == 'FreeBSD' or os == 'Gnu-kFreeBSD'
init_data = init_data + init_BSD + init_FreeBSD
elif os == 'Linux'
init_data = init_data + init_Linux
elif os == 'NetBSD'
init_data = init_data + init_BSD + init_NetBSD
endif
foreach init_d_file : init_data
configure_file(input : init_d_file,
output : '@BASENAME@',
configuration : init_d_conf_data,
install_dir: init_d_dir,
install_mode: 'rwxr-xr-x')
endforeach

View File

@@ -1,72 +0,0 @@
#!@SBINDIR@/openrc-run
# Copyright (c) 2016 The OpenRC Authors.
# See the Authors file at the top-level directory of this distribution and
# https://github.com/OpenRC/openrc/blob/master/AUTHORS
#
# This file is part of OpenRC. It is subject to the license terms in
# the LICENSE file found in the top-level directory of this
# distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE
# This file may not be copied, modified, propagated, or distributed
# except according to the terms contained in the LICENSE file.
description="Loads a list of modules from systemd-compatible locations."
depend()
{
keyword -docker -lxc -openvz -prefix -systemd-nspawn -vserver
}
find_modfiles()
{
local dirs="/usr/lib/modules-load.d /run/modules-load.d /etc/modules-load.d"
local basenames files fn x y
for x in $dirs; do
[ ! -d $x ] && continue
for y in $x/*.conf; do
[ -f $y ] && basenames="${basenames}\n${y##*/}"
done
done
basenames=$(printf "$basenames" | sort -u)
for x in $basenames; do
for y in $dirs; do
[ -r $y/$x ] &&
fn=$y/$x
done
files="$files $fn"
done
echo $files
}
load_modules()
{
local file m modules rc x
file=$1
[ -z "$file" ] && return 0
while read m x; do
case $m in
\;*) continue ;;
\#*) continue ;;
*) modules="$modules $m"
;;
esac
done < $file
for x in $modules; do
ebegin "Loading module $x"
case "$RC_UNAME" in
FreeBSD) kldload "$x"; rc=$? ;;
Linux) modprobe --use-blacklist -q "$x"; rc=$? ;;
*) ;;
esac
eend $rc "Failed to load $x"
done
}
start()
{
local x
files=$(find_modfiles)
for x in $files; do
load_modules $x
done
return 0
}

View File

@@ -14,10 +14,66 @@ description="Loads a user defined list of kernel modules."
depend()
{
use isapnp
want modules-load
provide modules-load
keyword -docker -lxc -openvz -prefix -systemd-nspawn -vserver
}
find_modfiles()
{
local dirs="/usr/lib/modules-load.d /run/modules-load.d /etc/modules-load.d"
local basenames files fn x y
for x in $dirs; do
[ ! -d $x ] && continue
for y in $x/*.conf; do
[ -f $y ] && basenames="${basenames}\n${y##*/}"
done
done
basenames=$(printf "$basenames" | sort -u)
for x in $basenames; do
for y in $dirs; do
[ -r $y/$x ] &&
fn=$y/$x
done
files="$files $fn"
done
echo $files
}
load_modules()
{
local file m _modules rc x
file=$1
[ -z "$file" ] && return 0
while read m x; do
case $m in
\;*) continue ;;
\#*) continue ;;
*) _modules="$_modules $m"
;;
esac
done < $file
for x in $_modules; do
ebegin "Loading module $x"
case "$RC_UNAME" in
FreeBSD) kldload "$x"; rc=$? ;;
Linux) modprobe --first-time -q --use-blacklist "$x"; rc=$? ;;
*) ;;
esac
eend $rc "Failed to load $x"
done
return 0
}
modules_load_d()
{
local x
files=$(find_modfiles)
for x in $files; do
load_modules $x
done
return 0
}
FreeBSD_modules()
{
local cnt=0 x
@@ -48,7 +104,7 @@ Linux_modules()
x=${x%.*}
done
local list= x= xx= y= args= mpargs= a=
local list= x= xx= y= args=
for x in $kv_variant_list ; do
eval list=\$modules_$(shell_var "$x")
[ -n "$list" ] && break
@@ -57,24 +113,13 @@ Linux_modules()
[ -n "$list" ] && ebegin "Loading kernel modules"
for x in $list; do
a=${x#*:}
if [ "$a" = "$x" ]; then
unset mpargs
else
x=${x%%:*}
mpargs="-o $a"
fi
aa=$(shell_var "$a")
xx=$(shell_var "$x")
for y in $kv_variant_list ; do
eval args=\$module_${aa}_args_$(shell_var "$y")
[ -n "${args}" ] && break
eval args=\$module_${xx}_args_$(shell_var "$y")
[ -n "${args}" ] && break
done
[ -z "$args" ] && eval args=\$module_${aa}_args
[ -z "$args" ] && eval args=\$module_${xx}_args
eval modprobe --use-blacklist --verbose "$mpargs" "$x" "$args"
eval modprobe --first-time --use-blacklist --verbose "$x" "$args"
done
[ -n "$list" ] && eend
}
@@ -82,7 +127,10 @@ Linux_modules()
start()
{
case "$RC_UNAME" in
FreeBSD|Linux) ${RC_UNAME}_modules ;;
FreeBSD|Linux)
modules_load_d
${RC_UNAME}_modules
;;
*) ;;
esac
return 0

View File

@@ -14,6 +14,7 @@ description="Update /etc/mtab to match what the kernel knows about"
depend()
{
after clock
before localmount
need root
keyword -prefix -systemd-nspawn
}
@@ -30,6 +31,10 @@ start()
einfo "Creating mtab symbolic link"
ln -snf /proc/self/mounts /etc/mtab
else
ewarn "The ${RC_SVCNAME} service will be removed in the future."
ewarn "Please change the mtab_is_file setting to no and run"
ewarn "# rc-service mtab restart"
ewarn "to create the mtab symbolic link."
[ -L /etc/mtab ] && ewarn "Removing /etc/mtab symbolic link"
rm -f /etc/mtab
einfo "Creating mtab file"

View File

@@ -13,7 +13,7 @@ description="Delays until the network is online or a specific timeout"
depend()
{
after modules
after modules net
need sysfs
provide network-online
keyword -docker -jail -lxc -openvz -prefix -systemd-nspawn -uml -vserver
@@ -23,6 +23,7 @@ get_interfaces()
{
local ifname iftype
for ifname in /sys/class/net/*; do
[ -h "${ifname}" ] || continue
read iftype < ${ifname}/type
[ "$iftype" = "1" ] && printf "%s " ${ifname##*/}
done
@@ -31,7 +32,7 @@ get_interfaces()
start ()
{
local carriers configured dev gateway ifcount infinite
local rc state x
local carrier operstate rc
ebegin "Checking to see if the network is online"
rc=0
@@ -44,10 +45,12 @@ start ()
ifcount=0
for dev in ${interfaces}; do
: $((ifcount += 1))
read x < /sys/class/net/$dev/carrier
[ $x -eq 1 ] && : $((carriers += 1))
read x < /sys/class/net/$dev/operstate
[ "$x" = up ] && : $((configured += 1))
read carrier < /sys/class/net/$dev/carrier 2> /dev/null ||
carrier=
[ "$carrier" = 1 ] && : $((carriers += 1))
read operstate < /sys/class/net/$dev/operstate 2> /dev/null ||
operstate=
[ "$operstate" = up ] && : $((configured += 1))
done
[ $configured -eq $ifcount ] && [ $carriers -ge 1 ] && break
sleep 1
@@ -61,8 +64,12 @@ start ()
if [ $rc -eq 0 ] && yesno ${include_ping_test:-no}; then
ping_test_host="${ping_test_host:-google.com}"
if [ -n "$ping_test_host" ]; then
ping -c 1 $ping_test_host > /dev/null 2>&1
rc=$?
while $infinite || [ $timeout -gt 0 ]; do
ping -c 1 $ping_test_host > /dev/null 2>&1
rc=$?
[ $rc -eq 0 ] && break
: $((timeout -= 1))
done
fi
fi
eend $rc "The network is offline"

View File

@@ -76,7 +76,7 @@ tentative()
case "$RC_UNAME" in
Linux)
[ -x /sbin/ip ] || [ -x /bin/ip ] || return 1
[ -n "$(command -v ip)" ] || return 1
[ -n "$(ip -f inet6 addr show tentative)" ]
;;
*)
@@ -174,7 +174,7 @@ runip()
routeflush()
{
if [ "$RC_UNAME" = Linux ]; then
if [ -x /sbin/ip ] || [ -x /bin/ip ]; then
if [ -n "$(command -v ip)" ]; then
ip route flush scope global
ip route delete default 2>/dev/null
else
@@ -346,7 +346,7 @@ stop()
then
veinfo "$int"
runargs /etc/ifdown."$int" "$downcmd"
if [ -x /sbin/ip ] || [ -x /bin/ip ]; then
if [ -n "$(command -v ip)" ]; then
# We need to do this, otherwise we may
# fail to add things correctly on restart
ip address flush dev "$int" 2>/dev/null

View File

@@ -15,7 +15,6 @@ ttyn=${rc_tty_number:-${RC_TTY_NUMBER:-12}}
depend()
{
need localmount
keyword -docker -lxc -openvz -prefix -systemd-nspawn -vserver
}
@@ -43,6 +42,8 @@ start()
stop()
{
yesno $RC_GOINGDOWN && return 0
ebegin "Disabling numlock on ttys"
_setleds -
eend $? "Failed to disable numlock"

View File

@@ -17,3 +17,15 @@ depend()
{
provide clock
}
start()
{
# This stub function is required to avoid OpenRC warning at boot:
#
# * The command variable is undefined.
# * There is nothing for osclock to start.
# * If this is what you intend, please write a start function.
# * This will become a failure in a future release.
#
return 0
}

View File

@@ -16,7 +16,6 @@ depend()
after clock
use devfs
want modules
need localmount
keyword -docker -lxc -openvz -prefix -systemd-nspawn -vserver
}
@@ -27,8 +26,8 @@ start()
[ ! -e /proc/sys/fs/binfmt_misc/register ]; then
if ! grep -qs binfmt_misc /proc/filesystems &&
modprobe -q binfmt-misc; then
ewarn "The binfmt-misc module needs to be configured in" \
"@SYSCONFDIR@/conf.d/modules or built in."
ewarn "The binfmt-misc module needs to be loaded by" \
"the modules service or built in."
fi
if grep -qs binfmt_misc /proc/filesystems; then
ebegin "Mounting misc binary format filesystem"

28
init.d/save-keymaps.in Normal file
View File

@@ -0,0 +1,28 @@
#!@SBINDIR@/openrc-run
# Copyright (c) 2018 Sony Interactive Entertainment, Inc.
#
# This file is part of OpenRC. It is subject to the license terms in
# the LICENSE file found in the top-level directory of this
# distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE
# This file may not be copied, modified, propagated, or distributed
# except according to the terms contained in the LICENSE file.
description="Save the keymap for use as early as possible"
depend()
{
need termencoding
after bootmisc clock keymaps
keyword -docker -lxc -openvz -prefix -systemd-nspawn -uml -vserver -xenu
}
start()
{
# Save the keymapping for use immediately at boot
ebegin "Saving key mapping"
if checkpath -W "$RC_LIBEXECDIR"; then
mkdir -p "$RC_LIBEXECDIR"/console
dumpkeys >"$RC_LIBEXECDIR"/console/keymap
fi
eend $? "Unable to save keymapping"
}

View File

@@ -0,0 +1,35 @@
#!@SBINDIR@/openrc-run
# Copyright (c) 2018 Sony Interactive Entertainment, Inc.
#
# This file is part of OpenRC. It is subject to the license terms in
# the LICENSE file found in the top-level directory of this
# distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE
# This file may not be copied, modified, propagated, or distributed
# except according to the terms contained in the LICENSE file.
description="Configures terminal encoding."
ttyn=${rc_tty_number:-${RC_TTY_NUMBER:-12}}
: ${unicode:=${UNICODE}}
depend()
{
keyword -docker -lxc -openvz -prefix -systemd-nspawn -uml -vserver -xenu
use root
after bootmisc clock termencoding
}
start()
{
ebegin "Saving terminal encoding"
# Save the encoding for use immediately at boot
if checkpath -W "$RC_LIBEXECDIR"; then
mkdir -p "$RC_LIBEXECDIR"/console
if yesno ${unicode:-${UNICODE}}; then
echo "" > "$RC_LIBEXECDIR"/console/unicode
else
rm -f "$RC_LIBEXECDIR"/console/unicode
fi
fi
eend 0
}

View File

@@ -49,7 +49,7 @@ start()
fi
ebegin "Saving dependency cache"
local rc=0 save=
for x in shutdowntime softlevel rc.log; do
for x in depconfig deptree rc.log shutdowntime softlevel; do
[ -e "$RC_SVCDIR/$x" ] && save="$save $RC_SVCDIR/$x"
done
if [ -n "$save" ]; then

View File

@@ -11,7 +11,7 @@
depend()
{
after clock
after clock root
before localmount
keyword -docker -jail -lxc -openvz -prefix -systemd-nspawn -vserver
}

View File

@@ -21,7 +21,7 @@ BSD_sysctl()
[ -e /etc/sysctl.conf ] || return 0
local retval=0 var= comments= conf=
eindent
for conf in @SYSCONFDIR@/sysctl.conf @SYSCONFDIR@/sysctl.d/*.conf; do
for conf in /etc/sysctl.conf /etc/sysctl.d/*.conf; do
if [ -r "$conf" ]; then
vebegin "applying $conf"
while read var comments; do

View File

@@ -101,128 +101,17 @@ mount_misc()
if [ -d /sys/firmware/efi/efivars ] &&
! mountinfo -q /sys/firmware/efi/efivars; then
ebegin "Mounting efivarfs filesystem"
mount -n -t efivarfs -o ro \
mount -n -t efivarfs -o ${sysfs_opts} \
efivarfs /sys/firmware/efi/efivars 2> /dev/null
eend 0
fi
}
cgroup1_base()
{
grep -qw cgroup /proc/filesystems || return 0
if ! mountinfo -q /sys/fs/cgroup; then
ebegin "Mounting cgroup filesystem"
local opts="${sysfs_opts},mode=755,size=${rc_cgroupsize:-10m}"
mount -n -t tmpfs -o "${opts}" cgroup_root /sys/fs/cgroup
eend $?
fi
if ! mountinfo -q /sys/fs/cgroup/openrc; then
local agent="${RC_LIBEXECDIR}/sh/cgroup-release-agent.sh"
mkdir /sys/fs/cgroup/openrc
mount -n -t cgroup \
-o none,${sysfs_opts},name=openrc,release_agent="$agent" \
openrc /sys/fs/cgroup/openrc
printf 1 > /sys/fs/cgroup/openrc/notify_on_release
fi
return 0
}
cgroup1_controllers()
{
yesno "${rc_controller_cgroups:-YES}" && [ -e /proc/cgroups ] || return 0
while read -r name _ _ enabled rest; do
case "${enabled}" in
1) mountinfo -q "/sys/fs/cgroup/${name}" && continue
local x
for x in $rc_cgroup_controllers; do
[ "${name}" = "blkio" ] && [ "${x}" = "io" ] &&
continue 2
[ "${name}" = "${x}" ] &&
continue 2
done
mkdir "/sys/fs/cgroup/${name}"
mount -n -t cgroup -o "${sysfs_opts},${name}" \
"${name}" "/sys/fs/cgroup/${name}"
;;
esac
done < /proc/cgroups
return 0
}
cgroup2_base()
{
local base
base="$(cgroup2_find_path)"
mkdir -p "${base}"
mount -t cgroup2 none -o "${sysfs_opts},nsdelegate" "${base}" 2> /dev/null ||
mount -t cgroup2 none -o "${sysfs_opts}" "${base}"
return 0
}
cgroup2_controllers()
{
local active cgroup_path x y
cgroup_path="$(cgroup2_find_path)"
[ -z "${cgroup_path}" ] && return 0
[ -e "${cgroup_path}/cgroup.controllers" ] &&
read -r active < "${cgroup_path}/cgroup.controllers"
for x in ${rc_cgroup_controllers}; do
for y in ${active}; do
[ "$x" = "$y" ] &&
[ -e "${cgroup_path}/cgroup.subtree_control" ]&&
echo "+${x}" > "${cgroup_path}/cgroup.subtree_control"
done
done
return 0
}
cgroups_hybrid()
{
grep -qw cgroup /proc/filesystems || return 0
cgroup1_base
if grep -qw cgroup2 /proc/filesystems; then
cgroup2_base
cgroup2_controllers
fi
cgroup1_controllers
return 0
}
cgroups_legacy()
{
grep -qw cgroup /proc/filesystems || return 0
cgroup1_base
cgroup1_controllers
return 0
}
cgroups_unified()
{
cgroup2_base
cgroup2_controllers
return 0
}
mount_cgroups()
{
# set up kernel support for cgroups
if [ -d /sys/fs/cgroup ]; then
case "${rc_cgroup_mode:-hybrid}" in
hybrid) cgroups_hybrid ;;
legacy) cgroups_legacy ;;
unified) cgroups_unified ;;
esac
fi
return 0
}
restorecon_sys()
{
if [ -x /sbin/restorecon ]; then
ebegin "Restoring SELinux contexts in /sys"
restorecon -F /sys/devices/system/cpu/online >/dev/null 2>&1
restorecon -rF /sys/fs/cgroup >/dev/null 2>&1
eend $?
fi
}
@@ -231,7 +120,6 @@ start()
{
mount_sys
mount_misc
mount_cgroups
restorecon_sys
return 0
}

View File

@@ -17,8 +17,7 @@ ttyn=${rc_tty_number:-${RC_TTY_NUMBER:-12}}
depend()
{
keyword -docker -lxc -openvz -prefix -systemd-nspawn -uml -vserver -xenu
use root
after bootmisc clock
after devfs
}
start()

7
local.d/meson.build Normal file
View File

@@ -0,0 +1,7 @@
local_d_dir = get_option('sysconfdir') / 'local.d'
local_data = [
'README'
]
install_data(local_data, install_dir : local_d_dir)

34
man/meson.build Normal file
View File

@@ -0,0 +1,34 @@
man3 = [
'einfo.3',
'rc_config.3',
'rc_deptree.3',
'rc_find_pids.3',
'rc_plugin_hook.3',
'rc_runlevel.3',
'rc_service.3',
'rc_stringlist.3',
]
man8 = [
'openrc.8',
'openrc-run.8',
'rc-service.8',
'rc-status.8',
'rc-update.8',
'start-stop-daemon.8',
'supervise-daemon.8',
]
if os == 'Linux'
man8 = man8 + [
'rc-sstat.8',
'openrc-init.8',
'openrc-shutdown.8',
]
endif
install_data(man3,
install_dir : get_option('mandir') / 'man3')
install_data(man8,
install_dir : get_option('mandir') / 'man8')
meson.add_install_script('meson_man_links.sh', get_option('mandir'), man3 + man8)

20
man/meson_man_links.sh Executable file
View File

@@ -0,0 +1,20 @@
#!/bin/sh
get_links() {
sed -e 's/ ,//g' \
-e '/^\.Sh NAME$/,/\.Sh/ s/\.Nm //p' \
-n ${MESON_SOURCE_ROOT}/man/${1}
}
MANDIR="$1"
shift
for man in $@; do
prefix=${man%%.*}
suffix=${man#*.}
links=$(get_links ${man})
for link in ${links}; do
if [ "${link}" != "${prefix}" ]; then
ln -sf ${man} ${MESON_INSTALL_DESTDIR_PREFIX}/${MANDIR}/man${suffix}/${link}.${suffix}
fi
done
done

View File

@@ -8,7 +8,7 @@
.\" This file may not be copied, modified, propagated, or distributed
.\" except according to the terms contained in the LICENSE file.
.\"
.Dd December 31, 2011
.Dd November 30, 2017
.Dt openrc-run 8 SMM
.Os OpenRC
.Sh NAME
@@ -104,18 +104,22 @@ supervisor=s6.
or set
supervisor=supervise-daemon
to use supervise-daemon.
Note that supervise-daemon is still in early development, so it is
considered experimental.
.It Ar s6_service_path
The path to the s6 service directory if you are monitoring this service
with S6. The default is /var/svc.d/${RC_SVCNAME}.
.It Ar s6_svwait_options_start
The options to pass to s6-svwait when starting the service via s6.
.It Ar s6_force_kill
Should we force-kill this service if s6_service_timeout_stop expires
but the service doesn't go down during shutdown? The default is yes.
.It Ar s6_service_timeout_stop
The amount of time, in milliseconds, s6-svc should wait for the service
to go down when stopping the service. The default is 10000.
to go down when stopping the service. The default is 60000.
.It Ar start_stop_daemon_args
List of arguments passed to start-stop-daemon when starting the daemon.
.It Ar supervise_daemon_args
List of arguments passed to supervise-daemon when starting the daemon.
If undefined, start_stop_daemon_args is used as a fallback.
.It Ar command
Daemon to start or stop via
.Nm start-stop-daemon
@@ -139,21 +143,56 @@ List of arguments to pass to the daemon when starting via
.Nm supervise-daemon .
to force the daemon to stay in the foreground
.It Ar command_background
Set this to "true", "yes" or "1" (case-insensitive) if you want
Set this to "true", "yes" or "1" (case-insensitive) if you want
.Xr start-stop-daemon 8
to force the daemon into the background. This forces the
"--make-pidfile" and "--pidfile" options, so the pidfile variable must be set.
.It Ar command_progress
Set this to "true", "yes" or "1" (case-insensitive) if you want
Set this to "true", "yes" or "1" (case-insensitive) if you want
.Xr start-stop-daemon 8
to display a progress meter when waiting for a daemon to stop.
.It Ar command_user
If the daemon does not support changing to a different user id, you can
use this to change the user id before
use this to change the user id, and optionally group id, before
.Xr start-stop-daemon 8
or
.Xr supervise-daemon 8
launches the daemon
launches the daemon.
.It Ar output_log
This is the path to a file or named pipe where the standard output from
the service will be redirected. If you are starting this service with
.Xr start-stop-daemon 8 ,
, you must set
.Pa command_background
to true. Keep in mind that this path will be inside the chroot if the
.Pa chroot
variable is set.
.It Ar error_log
The same thing as
.Pa output_log
but for the standard error output.
.It Ar output_logger
This is a process which will be used to log the standard output from the
service. If you are starting this service with
.Xr start-stop-daemon 8 ,
, you must set
.Pa command_background
to true. Keep in mind that this command must be executable as a shell
command inside the chroot if the
.Pa chroot
variable is set. Keep in mind also that this command works by accepting
the stdout of the service on stdin.
An example of a command that can be run this way is logger if you want
your service output to go to syslog.
.It Ar error_logger
The same thing as
.Pa output_logger
but for the standard error output.
.It Ar directory
.Xr start-stop-daemon 8
and
.Xr supervise-daemon 8
will chdir to this directory before starting the daemon.
.It Ar chroot
.Xr start-stop-daemon 8
and
@@ -198,6 +237,8 @@ used along with in_background_fake to support re-entrant services.
.It Ar in_background_fake
Space separated list of commands which should always succeed when
in_background is yes.
.It Ar umask
Set the umask of the daemon.
.Pp
Keep in mind that eval is used to process chroot, command, command_args_*,
command_user, pidfile and procname. This may affect how they are
@@ -289,7 +330,7 @@ section below.
.Sh _pre AND _post FUNCTIONS
Any command defined in extra_commands, extra_started_commands or
extra_stopped_commands can have _pre and _post functions in the service
script. If the command function is called foo, the_pre and _post
script. If the command function is called foo, the _pre and _post
functions for it should be called foo_pre and foo_post.
.Pp
These functions should be used to perform preparation before the
@@ -418,6 +459,7 @@ Mark the service as inactive.
.Op Fl p , -pipe
.Op Fl m , -mode Ar mode
.Op Fl o , -owner Ar owner
.Op Fl s , -symlinks
.Op Fl W , -writable
.Op Fl q , -quiet
.Ar path ...
@@ -438,6 +480,11 @@ or with names, and are separated by a colon.
The truncate options (-D and -F) cause the directory or file to be
cleared of all contents.
.Pp
If -s is not specified on a non-linux platform, checkpath will refuse to
allow non-terminal symbolic links to exist in the path. This is for
security reasons so that a non-root user can't create a symbolic link to
a root-owned file and take ownership of that file.
.Pp
If -W is specified, checkpath checks to see if the first path given on
the command line is writable. This is different from how the test
command in the shell works, because it also checks to make sure the file
@@ -447,6 +494,7 @@ Also, the -d, -f or -p options should not be specified along with this option.
.Pp
The -q option suppresses all informational output. If it is specified
twice, all error messages are suppressed as well.
.It Xo
.Ic fstabinfo
.Op Fl M , -mount
.Op Fl R , -remount
@@ -463,6 +511,7 @@ remounted.
.Pp
The -q option suppresses all informational output. If it is specified
twice, all error messages are suppressed as well.
.It Xo
.Ic mountinfo
.Op Fl f, -fstype-regex Ar regex
.Op Fl F, -skip-fstype-regex Ar regex
@@ -477,7 +526,7 @@ twice, all error messages are suppressed as well.
.Op Fl i, -options
.Op Fl s, -fstype
.Op Fl t, -node
.Ar mount1 mount2 ...
.Ar mount1 mount2 ...
.Xc
The f, F, n, N, o, O, p, P, e and E options specify what you want to
search for or skip in the mounted file systems. The i, s and t options
@@ -569,7 +618,7 @@ rc_net_tap1_provide="!net"
# It's also possible to negate keywords. This is mainly useful for prefix
# users testing OpenRC.
rc_keyword="!-prefix"
# This can also be used to block a script from runining in all
# This can also be used to block a script from running in all
# containers except one or two
rc_keyword="!-containers !-docker"
.Ed
@@ -708,6 +757,8 @@ Users are encouraged to use the is_newer_than function which returns correctly.
.Xr rc_plugin_hook 3 ,
.Xr sh 1p ,
.Xr start-stop-daemon 8 ,
.Xr supervise-daemon 8 ,
.Xr uname 1
.Sh AUTHORS
.An Roy Marples <roy@marples.name>
.An William Hubbs <w.d.hubbs@gmail.com>

View File

@@ -16,15 +16,36 @@
.Nd bring the system down
.Sh SYNOPSIS
.Nm
.Op Fl c , -cancel
.Nm
.Op Fl R , -reexec
.Nm
.Op Fl w , -write-only
.Nm
.Op Fl d , -no-write
.Op Fl D , -dry-run
.Op Fl H , -halt
time
.Nm
.Op Fl d , -no-write
.Op Fl D , -dry-run
.Op Fl k , -kexec
time
.Nm
.Op Fl d , -no-write
.Op Fl D , -dry-run
.Op Fl p , -poweroff
.Op Fl R , -reexec
time
.Nm
.Op Fl d , -no-write
.Op Fl D , -dry-run
.Op Fl r , -reboot
time
.Nm
.Op Fl d , -no-write
.Op Fl D , -dry-run
.Op Fl s , -single
.Op Fl w , -write-only
time
.Sh DESCRIPTION
.Nm
is the utility that communicates with
@@ -32,6 +53,8 @@ is the utility that communicates with
to bring down the system or instruct openrc-init to re-execute itself.
It supports the following options:
.Bl -tag -width "poweroff"
.It Fl c , -cancel
Cancel a pending shutdown.
.It Fl d , -no-write
Do not write the wtmp boot record.
.It Fl D , -dry-run
@@ -53,7 +76,7 @@ Stop all services, kill all processes and reboot the system.
.It Fl s , -single
Stop all services, kill all processes and move to single user mode.
.It Fl w , -write-only
Stop all services, kill all processes and move to single user mode.
Wrrite a wtmp shutdown record and do nothing else.
.El
.Sh SEE ALSO
.Xr openrc-init 8 ,

View File

@@ -65,7 +65,31 @@ Instead you should use
and
.Xr shutdown 8
and let them call these special runlevels.
.Sh OPTIONS
.Pp
.Bl -tag -width "-o , --override"
.It Fl n , -no-stop
Do not stop any services.
.It Fl o , -override
Override the next runlevel to change into when leaving single user or boot
runlevels
.It Fl s , -service
Run the service specified with the rest of the arguments.
.It Fl S , -sys
Output the RC system type, if any.
.It Fl h , -help
Display usage information and exit.
.It Fl C , -nocolor
Disable color output.
.It Fl V , -version
Display software version.
.It Fl v , -verbose
Run verbosely.
.It Fl q , -quiet
Run quietly (repeat to suppress errors).
.El
.Sh SEE ALSO
.Xr openrc-run 8 ,
.Xr rc-status 8 ,
.Xr rc-update 8 ,
.Xr init 8 ,

View File

@@ -16,6 +16,18 @@
.Nd locate and run an OpenRC service with the given arguments
.Sh SYNOPSIS
.Nm
.Op Fl c , -ifcrashed
.Ar service cmd
.Op Ar ...
.Nm
.Fl d , -debug
.Ar service cmd
.Op Ar ...
.Nm
.Fl D , -nodeps
.Ar service cmd
.Op Ar ...
.Nm
.Op Fl i , -ifexists
.Ar service cmd
.Op Ar ...
@@ -28,9 +40,21 @@
.Ar service cmd
.Op Ar ...
.Nm
.Op Fl s , -ifstarted
.Ar service cmd
.Op Ar ...
.Nm
.Op Fl S , -ifstopped
.Ar service cmd
.Op Ar ...
.Nm
.Fl e , -exists
.Ar service
.Nm
.Fl Z , -dry-run
.Ar service cmd
.Op Ar ...
.Nm
.Fl l , -list
.Nm
.Fl r , -resolve
@@ -64,6 +88,15 @@ return 0 if it can find
otherwise -1.
.Fl r , -resolve
does the same and also prints the full path of the service to stdout.
.Pp
.Fl d , -debug
sets -x when running the service script(s).
.Pp
.Fl D , -nodeps
ignores dependencies when running the service.
.Pp
.Fl Z , -dry-run
displays commands rather than executing them.
.Sh SEE ALSO
.Xr openrc 8 ,
.Xr stdout 3

View File

@@ -17,6 +17,7 @@
.Sh SYNOPSIS
.Nm
.Op Fl aclsuC
.Op Fl f Ar ini
.Op Ar runlevel
.Sh DESCRIPTION
.Nm
@@ -37,12 +38,17 @@ The options are as follows:
Show all runlevels and their services.
.It Fl c , -crashed
List all services that have crashed.
.It Fl f , -format
Select a format for the output. Currently, the only one that can be
specified is ini, which outputs in *.ini format.
.It Fl l , -list
List all defined runlevels.
.It Fl m , -manual
Show all manually started services.
.It Fl r , -runlevel
Print the current runlevel name.
.It Fl S , -supervised
Show all supervised services.
.It Fl s , -servicelist
Show all services.
.It Fl u , -unused

View File

@@ -120,7 +120,7 @@ Saves the pid of the daemon in the file specified by the
.Fl p , -pidfile
option. Only useful when used with daemons that run in the foreground and
forced into the background with the
.Fl -b , -background
.Fl b , -background
option.
.It Fl I , -ionice Ar class Ns Op : Ns Ar data
Modifies the IO scheduling priority of the daemon.
@@ -131,9 +131,34 @@ Modifies the scheduling priority of the daemon.
.It Fl 1 , -stdout Ar logfile
Redirect the standard output of the process to logfile when started with
.Fl background .
Must be an absolute pathname, but relative to the path optionally given with
The logfile Must be an absolute pathname, but relative to the path
optionally given with
.Fl r , -chroot .
The logfile can also be a named pipe.
.It Fl 2 , -stderr Ar logfile
Redirect the standard error of the process to logfile when started with
.Fl background .
The logfile must be an absolute pathname, but relative to the path
optionally given with
.Fl r , -chroot .
The logfile can also be a named pipe.
.It Fl 3 , -stdout-logger Ar cmd
Run cmd as a child process redirecting the standard output to the
standard input of cmd when started with
.Fl background .
Cmd must be an absolute pathname, but relative to the path optionally given with
.Fl r , -chroot .
This process must be prepared to accept input on stdin and be able to
log it or send it to another location.
.It Fl 4 , -stderr-logger Ar cmd
Run cmd as a child process and
Redirect the standard error of the process to the standard input of cmd
when started with
.Fl background .
Cmd must be an absolute pathname, but relative to the path optionally given with
.Fl r , -chroot .
This process must be prepared to accept input on stdin and be able to
log it or send it to another location.
.It Fl w , -wait Ar milliseconds
Wait
.Ar milliseconds
@@ -151,6 +176,7 @@ These options are only used for stopping daemons:
.It Fl R , -retry Ar timeout | Ar signal Ns / Ns Ar timeout
The retry specification can be either a timeout in seconds or multiple
signal/timeout pairs (like SIGTERM/5).
If this option is not given, the default is SIGTERM/5.
.El
.Sh ENVIRONMENT
.Va SSD_IONICELEVEL

View File

@@ -9,13 +9,18 @@
.\" except according to the terms contained in the LICENSE file.
.\"
.Dd April 27, 2016
.Dt supervise-DAEMON 8 SMM
.Dt SUPERVISE-DAEMON 8 SMM
.Os OpenRC
.Sh NAME
.Nm supervise-daemon
.Nd starts a daemon and restarts it if it crashes
.Sh SYNOPSIS
.Nm
servicename
.Fl a , -healthcheck-timer
.Ar seconds
.Fl A , -healthcheck-delay
.Ar seconds
.Fl D , -respawn-delay
.Ar seconds
.Fl d , -chdir
@@ -33,7 +38,7 @@
.Fl N , -nicelevel
.Ar level
.Fl p , -pidfile
.Ar pidfile
.Ar supervisorpidfile
.Fl P , -respawn-period
.Ar seconds
.Fl R , -retry
@@ -51,10 +56,15 @@
.Op Fl -
.Op Ar arguments
.Nm
servicename
.Fl K , -stop
.Ar daemon
.Fl p , -pidfile
.Ar pidfile
.Fl r , -chroot
.Ar chrootpath
.Nm
servicename
.Fl s , -signal
.Ar signal
.Fl r , -chroot
.Ar chrootpath
.Sh DESCRIPTION
@@ -62,22 +72,15 @@
provides a consistent method of starting, stopping and restarting
daemons. If
.Fl K , -stop
or
.Fl s , -signal
is not provided, then we assume we are starting the daemon.
.Nm
only works with daemons which do not fork. Also, it uses its own pid
file, so the daemon should not write a pid file, or the pid file passed
to
.Nm
should not be the one the daemon writes.
only works with daemons which do not fork. If your daemon has options to
tell it not to fork, it should be configured to not fork.
.Pp
Here are the options to specify the daemon and how it should start or stop:
.Bl -tag -width indent
.It Fl p , -pidfile Ar pidfile
When starting, we write a
.Ar pidfile
so we know which supervisor to stop. When stopping we only stop the pid(s)
listed in the
.Ar pidfile .
.It Fl u , -user Ar user Ns Op : Ns Ar group
Start the daemon as the
.Ar user
@@ -87,11 +90,17 @@ owned by the user. You can optionally append a
name here also.
.It Fl v , -verbose
Print the action(s) that are taken just before doing them.
.El
.Pp
The options are as follows:
.Bl -tag -width indent
.It Fl a , -healthcheck-timer Ar seconds
Run the healthcheck() command, possibly followed by the unhealthy()
command every time this number of seconds passes.
.It Fl A , -healthcheck-delay Ar seconds
Wait this long before the first health check.
.It Fl D , -respawn-delay Ar seconds
wait this number of seconds before restarting a daemon after it crashes.
Wait this number of seconds before restarting a daemon after it crashes.
The default is 0.
.It Fl d , -chdir Ar path
chdir to this directory before starting the daemon.
@@ -106,23 +115,34 @@ Data can be from 0 to 7 inclusive.
.It Fl k , -umask Ar mode
Set the umask of the daemon.
.It Fl m , -respawn-max Ar count
Sets the maximum number of times a daemon will be respawned during a
respawn period. If a daemon dies more than this number of times during a
respawn period,
Sets the maximum number of times a daemon will be respawned. If a daemon
crashes more than this number of times,
.Nm
will give up trying to respawn it and exit. The default is 10, and 0
means unlimited.
will give up and exit. The default is 10 and 0 means unlimited.
.Pp
If respawn-period is also set, more than respawn-max crashes must occur
during respawn-period seconds to cause
.Nm
to give up and exit.
.It Fl p , -pidfile Ar supervisorpidfile
Sets a path for the supervisor's pid file. Note that this is not the pid
file of the process that is being supervised.
.It Fl N , -nicelevel Ar level
Modifies the scheduling priority of the daemon.
.It Fl P , -respawn-period Ar seconds
Sets the length of a respawn period. The default is 10 seconds. See the
Sets the length of a respawn period. See the
description of --respawn-max for more information.
.It Fl R , -retry Ar timeout | Ar signal Ns / Ns Ar timeout
The retry specification can be either a timeout in seconds or multiple
signal/timeout pairs (like SIGTERM/5).
If this option is not given, the default is SIGTERM/5.
.It Fl r , -chroot Ar path
chroot to this directory before starting the daemon. All other paths, such
as the path to the daemon, chdir and pidfile, should be relative to the chroot.
as the path to the daemon and chdir should be relative to the chroot.
.It Fl , -signal Ar signal
Instruct a supervisor to signal the process it is supervising. The
process to communicate with is determined by the name of the service
taken from the RC_SVCNAME environment variable.
.It Fl u , -user Ar user
Start the daemon as the specified user.
.It Fl 1 , -stdout Ar logfile
@@ -135,8 +155,11 @@ The same thing as
.Fl 1 , -stdout
but with the standard error output.
.El
.El
.Sh ENVIRONMENT
.Va SSD_IONICELEVEL
can also set the IO scheduling priority of the daemon, but the command line
option takes precedence.
.Pp
.Va SSD_NICELEVEL
can also set the scheduling priority of the daemon, but the command line
option takes precedence.
@@ -157,15 +180,16 @@ make sure the settings mmake sense. For example, a respawn period of 5
seconds with a respawn max of 10 and a respawn delay of 1 second leads
to infinite respawning since there can never be 10 respawns within 5
seconds.
.Sh NOTE
Invoking supervise-daemon requires both the RC_SVCNAME environment
variable to be set and the name of the service as the first argument on
the command line, so it is best to invoke it inside a service script
rather than manually.
.Sh SEE ALSO
.Xr chdir 2 ,
.Xr chroot 2 ,
.Xr getopt 3 ,
.Xr nice 2 ,
.Xr rc_find_pids 3
.Sh BUGS
.Nm
cannot stop an interpreted daemon that no longer exists without a pidfile.
.Sh HISTORY
.Nm
first appeared in Debian.

190
meson.build Normal file
View File

@@ -0,0 +1,190 @@
project('OpenRC', 'c',
version : '0.44.6',
license: 'BSD-2',
default_options : [
'c_std=c99',
'prefix=/usr',
'warning_level=3',
],
meson_version : '>=0.49.0')
cc = meson.get_compiler('c')
audit_dep = dependency('audit', required : get_option('audit'))
if audit_dep.found()
cc_audit_flags = '-DHAVE_AUDIT'
else
cc_audit_flags = []
endif
if get_option('branding') != ''
cc_branding_flags = '-DBRANDING=' + get_option('branding')
else
cc_branding_flags = []
endif
libname = get_option('libdir').split('/')[-1]
option_local_prefix = get_option('local_prefix')
if option_local_prefix == ''
local_prefix = get_option('prefix') / 'usr' / 'local'
else
local_prefix = option_local_prefix
endif
option_os = get_option('os')
if option_os == ''
uname = find_program('uname')
r = run_command(uname, '-s')
os = r.stdout().strip()
os = '-'.join(os.split('/'))
else
os = option_os
endif
pam = get_option('pam')
if pam
libpam = cc.find_library('pam')
libpam_misc = cc.find_library('pam_misc')
cc_pam_flags = '-DHAVE_PAM'
else
libpam = []
libpam_misc = []
cc_pam_flags = []
endif
option_pkg_prefix = get_option('pkg_prefix')
if option_pkg_prefix == ''
if os == 'Dragonfly' or os == 'FreeBSD'
pkg_prefix = '/usr/local'
elif os == 'GNU' or os == 'GNU-kFreeBSD' or os == 'Linux'
pkg_prefix = '/usr'
elif os == 'NetBSD'
pkg_prefix = '/usr/pkg'
endif
else
pkg_prefix = option_pkg_prefix
endif
if get_option('split-usr') == 'auto'
split_usr = run_command('test', '-L', '/bin').returncode() != 0
else
split_usr = get_option('split-usr') == 'true'
endif
rootprefix = get_option('rootprefix')
rootprefix_default = '/'
if rootprefix == ''
rootprefix = rootprefix_default
endif
bindir = rootprefix / get_option('bindir')
libdir = rootprefix / get_option('libdir')
libexecdir = get_option('libexecdir')
if os == 'Linux' and libexecdir == 'libexec'
libexecdir = 'lib'
endif
libexecdir = rootprefix / libexecdir
rc_libexecdir = libexecdir / 'rc'
sbindir = rootprefix / get_option('sbindir')
selinux_dep = dependency('libselinux', required : get_option('selinux'))
if selinux_dep.found()
cc_selinux_flags = '-DHAVE_SELINUX'
else
cc_selinux_flags = []
endif
termcap = get_option('termcap')
if termcap != ''
termcap_dep = dependency(termcap)
termcap_flags = '-DHAVE_TERMCAP'
else
termcap_dep = []
termcap_flags = []
endif
if get_option('buildtype').startswith('debug')
cc_debug_flags = ['-DRC_DEBUG']
else
cc_debug_flags = []
endif
if os == 'Linux' or os == 'GNU-kFreeBSD'
cc_os_flags = ['-D_DEFAULT_SOURCE']
elif os == 'FreeBSD'
cc_os_flags = ['-D_BSD_SOURCE']
elif os == 'GNU'
cc_os_flags = ['-D_DEFAULT_SOURCE', '-DMAXPATHLEN=4096', '-DPATH_MAX=4096']
endif
# Try and use some good cc flags if we're building from git. We don't use
# -pedantic as it will warn about our perfectly valid use of %m in our logger.
# We should be using -Wredundant-decls, but our library hidden proto stuff gives
# loads of warnings. I don't fully understand it (the hidden proto, not the
# warning) so we just silence the warning.
cc_warning_flags_test = [
'-Wcast-align',
'-Wcast-qual',
'-Wdeclaration-after-statement',
'-Wformat=2',
'-Winline',
'-Wmissing-declarations',
'-Wmissing-format-attribute',
'-Wmissing-noreturn',
'-Wmissing-prototypes',
'-Wnested-externs',
'-Wpointer-arith',
'-Wsequence-point',
'-Wshadow',
'-Wwrite-strings',
'-Werror=implicit-function-declaration',
]
cc_warning_flags = cc.get_supported_arguments(cc_warning_flags_test)
cc_flags = [cc_debug_flags, cc_os_flags, cc_warning_flags]
add_project_arguments(cc_flags, language : 'c')
incdir = include_directories('src/includes')
einfo_incdir = include_directories('src/libeinfo')
rc_incdir = include_directories('src/librc')
init_d_conf_data = configuration_data()
init_d_conf_data.set('SBINDIR', sbindir)
init_d_conf_data.set('PKG_PREFIX', pkg_prefix)
init_d_conf_data.set('SYSCONFDIR', get_option('sysconfdir'))
dl_dep = cc.find_library('dl', required: false)
util_dep = cc.find_library('util', required: false)
if get_option('bash-completions')
subdir('bash-completion')
endif
subdir('conf.d')
subdir('etc')
subdir('init.d')
subdir('local.d')
subdir('man')
if get_option('pam')
subdir('pam')
endif
if get_option('pkgconfig')
subdir('pkgconfig')
endif
subdir('scripts')
subdir('sh')
subdir('src')
subdir('support')
subdir('sysctl.d')
if get_option('zsh-completions')
subdir('zsh-completion')
endif
meson.add_install_script('tools/meson_runlevels.sh',
os,
get_option('newnet') ? 'yes' : 'no',
rc_libexecdir,
get_option('sysconfdir'),
get_option('sysvinit') ? 'yes' : 'no')
meson.add_install_script('tools/meson_final.sh',
rc_libexecdir,
os)

37
meson_options.txt Normal file
View File

@@ -0,0 +1,37 @@
option('audit', type : 'feature', value : 'auto',
description : 'enable libaudit support')
option('bash-completions', type : 'boolean',
description : 'install bash completions')
option('branding', type : 'string',
description : 'Add branding to OpenRC')
option('local_prefix', type : 'string', value : '/usr/local',
description : 'default location of user maintained packages')
option('newnet', type : 'boolean',
description : 'build and install our networking scripts')
option('os', type : 'combo',
choices :
[ '', 'DragonFly', 'FreeBSD', 'GNU', 'GNU-kFreeBSD', 'Linux', 'NetBSD' ],
description : 'Operating System (autodetected if not specified)')
option('pam', type : 'boolean',
description : 'enable PAM support')
option('pkg_prefix', type : 'string',
description : 'default location where packages are installed')
option('pkgconfig', type : 'boolean',
description : 'build PKGConfig files')
option('rootprefix', type : 'string',
description : 'override the root prefix')
option('selinux', type : 'feature', value : 'auto',
description : 'enable SELinux support')
option('shell', type : 'string', value : '/bin/sh',
description : 'Default posix compatible shell')
option('split-usr', type : 'combo',
choices : ['auto', 'true', 'false'],
description : '''/bin, /sbin aren't symlinks into /usr''')
option('sysvinit', type : 'boolean', value : false,
description : 'enable SysVinit compatibility (linux only)')
option('termcap', type : 'combo',
choices :
[ '', 'ncurses', 'termcap' ],
description : 'the termcap library to use')
option('zsh-completions', type : 'boolean',
description : 'install zsh completions')

View File

@@ -52,13 +52,12 @@ ${SHLIB_NAME}: ${SOBJS}
${SOBJS} ${LDADD}
install: all
ifeq (${MKSTATICLIBS},yes)
${INSTALL} -d ${DESTDIR}${LIBDIR}
ifeq (${MKSTATICLIBS},yes)
${INSTALL} -m ${LIBMODE} lib${LIB}.a ${DESTDIR}${LIBDIR}
endif
${INSTALL} -d ${DESTDIR}${SHLIBDIR}
${INSTALL} -m ${LIBMODE} ${SHLIB_NAME} ${DESTDIR}${SHLIBDIR}
ln -fs ${SHLIB_NAME} ${DESTDIR}${SHLIBDIR}/${SHLIB_LINK}
${INSTALL} -m ${LIBMODE} ${SHLIB_NAME} ${DESTDIR}${LIBDIR}
ln -fs ${SHLIB_NAME} ${DESTDIR}${LIBDIR}/${SHLIB_LINK}
${INSTALL} -d ${DESTDIR}${INCDIR}
for x in ${INCS}; do ${INSTALL} -m ${INCMODE} $$x ${DESTDIR}${INCDIR}; done

View File

@@ -11,3 +11,5 @@
# Generic definitions
include ${MK}/os-BSD.mk
CPPFLAGS+= -D_BSD_SOURCE

View File

@@ -13,6 +13,6 @@
SFX= .GNU-kFreeBSD.in
PKG_PREFIX?= /usr
CPPFLAGS+= -D_BSD_SOURCE -D_XOPEN_SOURCE=700
CPPFLAGS+= -D_BSD_SOURCE
LIBDL= -Wl,-Bdynamic -ldl
LIBKVM?=

View File

@@ -11,5 +11,5 @@
SFX= .GNU.in
PKG_PREFIX?= /usr
CPPFLAGS+= -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=700 -DMAXPATHLEN=4096 -DPATH_MAX=4096
CPPFLAGS+= -D_DEFAULT_SOURCE -DMAXPATHLEN=4096 -DPATH_MAX=4096
LIBDL= -Wl,-Bdynamic -ldl

View File

@@ -11,7 +11,7 @@
SFX= .Linux.in
PKG_PREFIX?= /usr
CPPFLAGS+= -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=700
CPPFLAGS+= -D_DEFAULT_SOURCE -D_POSIX_C_SOURCE=200809L -D_BSD_SOURCE -D_XOPEN_SOURCE
LIBDL= -Wl,-Bdynamic -ldl
ifeq (${MKSELINUX},yes)

View File

@@ -19,7 +19,7 @@ _PKG_SED:= $(shell ${_PKG_SED_SH})
_LCL_SED_SH= if test "${PREFIX}" = "${LOCAL_PREFIX}"; then echo "-e 's:@LOCAL_PREFIX@::g'"; else echo "-e 's:@LOCAL_PREFIX@:${LOCAL_PREFIX}:g'"; fi
_LCL_SED:= $(shell ${_LCL_SED_SH})
SED_REPLACE= -e 's:@SHELL@:${SH}:g' -e 's:@LIB@:${LIBNAME}:g' -e 's:@SYSCONFDIR@:${SYSCONFDIR}:g' -e 's:@LIBEXECDIR@:${LIBEXECDIR}:g' -e 's:@PREFIX@:${PREFIX}:g' -e 's:@BINDIR@:${BINDIR}:g' -e 's:@SBINDIR@:${SBINDIR}:g' ${_PKG_SED} ${_LCL_SED}
SED_REPLACE= -e 's:@SHELL@:${SH}:' -e 's:@LIB@:${LIBNAME}:g' -e 's:@SYSCONFDIR@:${SYSCONFDIR}:g' -e 's:@LIBEXECDIR@:${LIBEXECDIR}:g' -e 's:@PREFIX@:${PREFIX}:g' -e 's:@BINDIR@:${BINDIR}:g' -e 's:@SBINDIR@:${SBINDIR}:g' ${_PKG_SED} ${_LCL_SED}
# Tweak our shell scripts
%.sh: %.sh.in
@@ -53,7 +53,6 @@ realinstall: ${BIN} ${CONF} ${INC}
install: all realinstall ${INSTALLAFTER}
check test::
@if test -e runtests.sh ; then ./runtests.sh || exit $$? ; fi
# A lot of scripts don't have anything to clean
# Also, some rm implentation require a file argument regardless of error

View File

@@ -34,6 +34,7 @@ PICFLAG?= -fPIC
SYSCONFDIR?= ${PREFIX}/etc
INITDIR?= ${SYSCONFDIR}/init.d
CONFDIR?= ${SYSCONFDIR}/conf.d
CONFMODE?= 0644
LOCALDIR?= ${SYSCONFDIR}/local.d
SYSCTLDIR?= ${SYSCONFDIR}/sysctl.d
@@ -44,20 +45,22 @@ SBINDIR?= ${PREFIX}/sbin
SBINMODE?= 0755
INCDIR?= ${UPREFIX}/include
INCMODE?= 0444
INCMODE?= 0644
_LIBNAME_SH= case `readlink /lib` in /lib64|lib64) echo "lib64";; *) echo "lib";; esac
_LIBNAME:= $(shell ${_LIBNAME_SH})
LIBNAME?= ${_LIBNAME}
LIBDIR?= ${UPREFIX}/${LIBNAME}
LIBMODE?= 0444
SHLIBDIR?= ${PREFIX}/${LIBNAME}
LIBMODE?= 0644
LIBEXECDIR?= ${PREFIX}/libexec/rc
PKGCONFIGDIR?= ${UPREFIX}/${LIBNAME}/pkgconfig
MANPREFIX?= ${UPREFIX}/share
MANDIR?= ${MANPREFIX}/man
MANMODE?= 0444
MANMODE?= 0644
BASHCOMPDIR?= ${UPREFIX}/share/bash-completion/completions
DATADIR?= ${UPREFIX}/share/openrc
DATAMODE?= 0644
@@ -65,4 +68,4 @@ DATAMODE?= 0644
DOCDIR?= ${UPREFIX}/share/doc
DOCMODE?= 0644
CONFMODE?= 0644
ZSHCOMPDIR?= ${UPREFIX}/share/zsh/site-functions

9
pam/meson.build Normal file
View File

@@ -0,0 +1,9 @@
pam_dir = get_option('sysconfdir') / 'pam.d'
pam_files = [
'start-stop-daemon',
'supervise-daemon',
]
install_data(pam_files,
install_dir : pam_dir)

6
pam/start-stop-daemon Normal file
View File

@@ -0,0 +1,6 @@
#%PAM-1.0
auth required pam_permit.so
account required pam_permit.so
password required pam_deny.so
session optional pam_limits.so

6
pam/supervise-daemon Normal file
View File

@@ -0,0 +1,6 @@
#%PAM-1.0
auth required pam_permit.so
account required pam_permit.so
password required pam_deny.so
session optional pam_limits.so

View File

@@ -1,4 +1,4 @@
DIR= ${LIBDIR}/pkgconfig
DIR= ${PKGCONFIGDIR}
SRCS= einfo.pc.in openrc.pc.in
INC= einfo.pc openrc.pc

22
pkgconfig/meson.build Normal file
View File

@@ -0,0 +1,22 @@
pkgconfig_dir = get_option('libdir') / 'pkgconfig'
pkgconfig_conf_data = configuration_data()
if rootprefix != '/'
pkgconfig_conf_data.set('PREFIX', rootprefix)
else
pkgconfig_conf_data.set('PREFIX', '')
endif
pkgconfig_conf_data.set('LIB', get_option('libdir'))
pkgconfig_conf_data.set('VERSION', meson.project_version())
pkgconfig_files = [
'einfo.pc.in',
'openrc.pc.in',
]
foreach file : pkgconfig_files
configure_file(input : file,
output : '@BASENAME@',
configuration : pkgconfig_conf_data,
install_dir : pkgconfig_dir)
endforeach

View File

@@ -1,4 +1,5 @@
# Using runit with OpenRC
Using runit with OpenRC
=======================
Beginning with OpenRC-0.21, we support using runit [1] in place of
start-stop-daemon for monitoring and restarting daemons.

View File

@@ -36,9 +36,10 @@ BOOT-FreeBSD+= hostid modules newsyslog savecore syslogd
# FreeBSD specific stuff
BOOT-FreeBSD+= adjkerntz dumpon syscons
BOOT-Linux+= binfmt hwclock keymaps modules mtab procfs termencoding
BOOT-Linux+= binfmt hwclock keymaps modules mtab procfs save-keymaps \
save-termencoding termencoding
SHUTDOWN-Linux= killprocs mount-ro
SYSINIT-Linux= devfs dmesg sysfs
SYSINIT-Linux= devfs cgroups dmesg sysfs
# Generic BSD stuff
BOOT-NetBSD+= hostid newsyslog savecore syslogd
@@ -89,6 +90,12 @@ install:
fi; \
ln -snf ${INITDIR}/"$$x" ${SHUTDOWNDIR}/"$$x" || exit $$?; done \
fi
if test "${MKSYSVINIT}" = yes && test "${OS}" = Linux; then \
for x in tty1 tty2 tty3 tty4 tty5 tty6; do \
ln -snf ${INITDIR}/agetty ${DESTDIR}/${INITDIR}/"agetty.$$x" || exit $$?; \
ln -snf ${INITDIR}/agetty.$$x ${DEFAULTDIR}/"agetty.$$x" || exit $$?; \
done; \
fi
check test::

View File

@@ -1,4 +1,5 @@
# Using S6 with OpenRC
Using S6 with OpenRC
====================
Beginning with OpenRC-0.16, we support using the s6 supervision suite
from Skarnet Software in place of start-stop-daemon for monitoring
@@ -39,6 +40,10 @@ s6_service_path - the path to the s6 service directory. The default is
s6_svwait_options_start - the options to pass to s6-svwait when starting
the service. If this is not set, s6-svwait will not be called.
s6_force_kill - Should we try to force kill this service if the
s6_service_timeout_stop timeout expires when shutting down this service?
The default is yes.
s6_service_timeout_stop - the amount of time, in milliseconds, s6-svc
should wait for a service to go down when stopping.

View File

@@ -1,4 +1,4 @@
#!@SHELL@
#!/bin/sh
option_arg=
poweroff_arg=
@@ -21,4 +21,9 @@ if [ -z "${poweroff_arg}" ]; then
poweroff_arg=--poweroff
fi
exec @SBINDIR@/openrc-shutdown ${option_arg} ${poweroff_arg} "$@"
script_args="$@"
if [ -z "${script_args}" ]; then
script_args=now
fi
exec @SBINDIR@/openrc-shutdown ${option_arg} ${poweroff_arg} "${script_args}"

45
scripts/meson.build Normal file
View File

@@ -0,0 +1,45 @@
script_conf_data = configuration_data()
script_conf_data.set('SBINDIR', sbindir)
script_dir = rc_libexecdir / 'bin'
scripts_internal = [
'on_ac_power',
]
scripts_Linux = [
'rc-sstat.in',
]
scripts_sysvinit = [
'halt.in',
'poweroff.in',
'shutdown.in',
'reboot.in',
]
install_data(scripts_internal,
install_dir : script_dir,
install_mode: 'rwxr-xr-x')
if os == 'Linux'
foreach file : scripts_Linux
configure_file(input : file,
output : '@BASENAME@',
configuration : script_conf_data,
install_dir: script_dir,
install_mode: 'rwxr-xr-x')
endforeach
if get_option('sysvinit')
foreach file : scripts_sysvinit
configure_file(input : file,
output : '@BASENAME@',
configuration : script_conf_data,
install_dir: script_dir,
install_mode: 'rwxr-xr-x')
endforeach
endif
endif
meson.add_install_script('meson_script_links.sh', rc_libexecdir,
sbindir)

19
scripts/meson_script_links.sh Executable file
View File

@@ -0,0 +1,19 @@
#!/bin/sh
set -e
set -u
rc_libexecdir="$1"
sbindir="$2"
binaries=" halt poweroff rc-sstat reboot shutdown"
for f in $binaries; do
if [ -x "${DESTDIR}${rc_libexecdir}/bin/${f}" ]; then
ln -snf "${rc_libexecdir}/bin/${f}" \
"${DESTDIR}${sbindir}/${f}"
fi
done
# sysvinit is active when halt exits
if [ -x "${DESTDIR}${rc_libexecdir}/bin/halt" ]; then
ln -snf "${sbindir}/openrc-init" \
"${DESTDIR}${sbindir}/init"
fi

View File

@@ -18,9 +18,10 @@ if [ -f /proc/acpi/ac_adapter/*/state ]; then
"state:"*"off-line") exit 128;;
esac
done
elif [ -f /sys/class/power_supply/*/online ]; then
cat /sys/class/power_supply/*/online | while read line; do
[ "${line}" = 0 ] && exit 128
elif [ -d /sys/class/power_supply ]; then
for dir in /sys/class/power_supply/*/; do
[ "$(cat "${dir}/type")" != "Mains" ] && continue
[ "$(cat "${dir}/online")" = 0 ] && exit 128
done
elif [ -f /proc/pmu/info ]; then
cat /proc/pmu/info | while read line; do

View File

@@ -1,4 +1,4 @@
#!@SHELL@
#!/bin/sh
option_arg=
poweroff_arg=
@@ -20,4 +20,9 @@ if [ -z "${poweroff_arg}" ]; then
poweroff_arg=--poweroff
fi
exec @SBINDIR@/openrc-shutdown ${option_arg} ${poweroff_arg} "$@"
script_args="$@"
if [ -z "${script_args}" ]; then
script_args=now
fi
exec @SBINDIR@/openrc-shutdown ${option_arg} ${poweroff_arg} "${script_args}"

View File

@@ -1,4 +1,4 @@
#!@SHELL@
#!/bin/sh
# Copyright (c) 2015 The OpenRC Authors.
# See the Authors file at the top-level directory of this distribution and
# https://github.com/OpenRC/openrc/blob/master/AUTHORS

View File

@@ -1,4 +1,4 @@
#!@SHELL@
#!/bin/sh
option_arg=
poweroff_arg=
@@ -22,4 +22,9 @@ if [ -z "${poweroff_arg}" ]; then
poweroff_arg=--reboot
fi
exec @SBINDIR@/openrc-shutdown ${option_arg} ${poweroff_arg} "$@"
script_args="$@"
if [ -z "${script_args}" ]; then
script_args=now
fi
exec @SBINDIR@/openrc-shutdown ${option_arg} ${poweroff_arg} "${script_args}"

View File

@@ -1,14 +1,31 @@
#!@SHELL@
#!/bin/sh
shutdown_arg=
do_halt=false
while getopts :akrhPHfFnct: opt; do
case "$opt" in
a) ;;
k) ;;
r) shutdown_arg=--reboot ;;
h) shutdown_arg=--halt ;;
P) shutdown_arg=--poweroff ;;
H) shutdown_arg=--halt ;;
r)
shutdown_arg=--reboot
;;
h)
do_halt=true
shutdown_arg=--poweroff
;;
P)
if ! ${do_halt}; then
printf "%s\n" "The -P flag requires the -h flag" >&2
exit 1
fi
shutdown_arg=--poweroff
;;
H)
if ! ${do_halt}; then
printf "%s\n" "The -H flag requires the -h flag" >&2
exit 1
fi
shutdown_arg=--halt
;;
f) ;;
F) ;;
n) ;;
@@ -25,5 +42,5 @@ if [ -z "${shutdown_arg}" ]; then
shutdown_arg=--single
fi
echo @SBINDIR@/openrc-shutdown ${shutdown_arg} "$@"
printf "%s %s\n" "@SBINDIR@/openrc-shutdown ${shutdown_arg}" "$@"
exec @SBINDIR@/openrc-shutdown ${shutdown_arg} "$@"

495
service-script-guide.md Normal file
View File

@@ -0,0 +1,495 @@
OpenRC Service Script Writing Guide
===================================
This document is aimed at developers or packagers who
write OpenRC service scripts, either for their own projects, or for
the packages they maintain. It contains advice, suggestions, tips,
tricks, hints, and counsel; cautions, warnings, heads-ups,
admonitions, proscriptions, enjoinders, and reprimands.
It is intended to prevent common mistakes that are found "in the wild"
by pointing out those mistakes and suggesting alternatives. Each
good/bad thing that you should/not do has a section devoted to it. We
don't consider anything exotic, and assume that you will use
start-stop-daemon to manage a fairly typical long-running UNIX
process.
# Syntax of Service Scripts
Service scripts are shell scripts. OpenRC aims at using only the standardized
POSIX sh subset for portability reasons. The default interpreter (build-time
toggle) is `/bin/sh`, so using for example mksh is not a problem.
OpenRC has been tested with busybox sh, ash, dash, bash, mksh, zsh and possibly
others. Using busybox sh has been difficult as it replaces commands with
builtins that don't offer the expected features.
The interpreter for service scripts is `#!/sbin/openrc-run`.
Not using this interpreter will break the use of dependencies and is not
supported. (iow: if you insist on using `#!/bin/sh` you're on your own)
A `depend` function declares the dependencies of this service script.
All scripts must have start/stop/status functions, but defaults are
provided and should be used unless you have a very strong reason not to
use them.
Extra functions can be added easily:
```
extra_commands="checkconfig"
checkconfig() {
doSomething
}
```
This exports the checkconfig function so that `/etc/init.d/someservice
checkconfig` will be available, and it "just" runs this function.
While commands defined in `extra_commands` are always available, commands
defined in `extra_started_commands` will only work when the service is started
and those defined in `extra_stopped_commands` will only work when the service is
stopped. This can be used for implementing graceful reload and similar
behaviour.
Adding a restart function will not work, this is a design decision within
OpenRC. Since there may be dependencies involved (e.g. network -> apache) a
restart function is in general not going to work.
restart is internally mapped to `stop()` + `start()` (plus handling dependencies).
If a service needs to behave differently when it is being restarted vs
started or stopped, it should test the `$RC_CMD` variable, for example:
```
[ "$RC_CMD" = restart ] && do_something
```
# The Depend Function
This function declares the dependencies for a service script. This
determines the order the service scripts start.
```
depend() {
need net
use dns logger netmount
want coolservice
}
```
`need` declares a hard dependency - net always needs to be started before this
service does
`use` is a soft dependency - if dns, logger or netmount is in this runlevel
start it before, but we don't care if it's not in this runlevel.
`want` is between need and use - try to start coolservice if it is
installed on the system, regardless of whether it is in the
runlevel, but we don't care if it starts.
`before` declares that we need to be started before another service
`after` declares that we need to be started after another service, without
creating a dependency (so on calling stop the two are independent)
`provide` allows multiple implementations to provide one service type, e.g.:
`provide cron` is set in all cron-daemons, so any one of them started
satisfies a cron dependency
`keyword` allows platform-specific overrides, e.g. `keyword -lxc` makes this
service script a noop in lxc containers. Useful for things like keymaps,
module loading etc. that are either platform-specific or not available
in containers/virtualization/...
FIXME: Anything missing in this list?
# The Default Functions
All service scripts are assumed to have the following functions:
```
start()
stop()
status()
```
There are default implementations in `lib/rc/sh/openrc-run.sh` - this allows very
compact service scripts. These functions can be overridden per service script as
needed.
The default functions assume the following variables to be set in the service
script:
```
command=
command_args=
pidfile=
```
Thus the 'smallest' service scripts can be half a dozen lines long
## Don't write your own start/stop functions
OpenRC is capable of stopping and starting most daemons based on the
information that you give it. For a well-behaved daemon that
backgrounds itself and writes its own PID file by default, the
following OpenRC variables are likely all that you'll need:
* command
* command_args
* pidfile
Given those three pieces of information, OpenRC will be able to start
and stop the daemon on its own. The following is taken from an
[OpenNTPD](http://www.openntpd.org/) service script:
```sh
command="/usr/sbin/ntpd"
# The special RC_SVCNAME variable contains the name of this service.
pidfile="/run/${RC_SVCNAME}.pid"
command_args="-p ${pidfile}"
```
If the daemon runs in the foreground by default but has options to
background itself and to create a pidfile, then you'll also need
* command_args_background
That variable should contain the flags needed to background your
daemon, and to make it write a PID file. Take for example the
following snippet of an
[NRPE](https://github.com/NagiosEnterprises/nrpe) service script:
```sh
command="/usr/bin/nrpe"
command_args="--config=/etc/nagios/nrpe.cfg"
command_args_background="--daemon"
pidfile="/run/${RC_SVCNAME}.pid"
```
Since NRPE runs as *root* by default, it needs no special permissions
to write to `/run/nrpe.pid`. OpenRC takes care of starting and
stopping the daemon with the appropriate arguments, even passing the
`--daemon` flag during startup to force NRPE into the background (NRPE
knows how to write its own PID file).
But what if the daemon isn't so well behaved? What if it doesn't know
how to background itself or create a pidfile? If it can do neither,
then use,
* command_background=true
which will additionally pass `--make-pidfile` to start-stop-daemon,
causing it to create the `$pidfile` for you (rather than the daemon
itself being responsible for creating the PID file).
If your daemon doesn't know how to change its own user or group, then
you can tell start-stop-daemon to launch it as an unprivileged user
with
* command_user="user:group"
Finally, if your daemon always forks into the background but fails to
create a PID file, then your only option is to use
* procname
With `procname`, OpenRC will try to find the running daemon by
matching the name of its process. That's not so reliable, but daemons
shouldn't background themselves without creating a PID file in the
first place. The next example is part of the [CA NetConsole
Daemon](https://oss.oracle.com/projects/cancd/) service script:
```sh
command="/usr/sbin/cancd"
command_args="-p ${CANCD_PORT}
-l ${CANCD_LOG_DIR}
-o ${CANCD_LOG_FORMAT}"
command_user="cancd"
# cancd daemonizes itself, but doesn't write a PID file and doesn't
# have an option to run in the foreground. So, the best we can do
# is try to match the process name when stopping it.
procname="cancd"
```
To recap, in order of preference:
1. If the daemon backgrounds itself and creates its own PID file, use
`pidfile`.
2. If the daemon does not background itself (or has an option to run
in the foreground) and does not create a PID file, then use
`command_background=true` and `pidfile`.
3. If the daemon backgrounds itself and does not create a PID file,
use `procname` instead of `pidfile`. But, if your daemon has the
option to run in the foreground, then you should do that instead
(that would be the case in the previous item).
4. The last case, where the daemon does not background itself but
does create a PID file, doesn't make much sense. If there's a way
to disable the daemon's PID file (or, to write it straight into the
garbage), then do that, and use `command_background=true`.
## Reloading your daemon's configuration
Many daemons will reload their configuration files in response to a
signal. Suppose your daemon will reload its configuration in response
to a `SIGHUP`. It's possible to add a new "reload" command to your
service script that performs this action. First, tell the service
script about the new command.
```sh
extra_started_commands="reload"
```
We use `extra_started_commands` as opposed to `extra_commands` because
the "reload" action is only valid while the daemon is running (that
is, started). Now, start-stop-daemon can be used to send the signal to
the appropriate process (assuming you've defined the `pidfile`
variable elsewhere):
```sh
reload() {
ebegin "Reloading ${RC_SVCNAME}"
start-stop-daemon --signal HUP --pidfile "${pidfile}"
eend $?
}
```
## Don't restart/reload with a broken config
Often, users will start a daemon, make some configuration change, and
then attempt to restart the daemon. If the recent configuration change
contains a mistake, the result will be that the daemon is stopped but
then cannot be started again (due to the configuration error). It's
possible to prevent that situation with a function that checks for
configuration errors, and a combination of the `start_pre` and
`stop_pre` hooks.
```sh
checkconfig() {
# However you want to check this...
}
start_pre() {
# If this isn't a restart, make sure that the user's config isn't
# busted before we try to start the daemon (this will produce
# better error messages than if we just try to start it blindly).
#
# If, on the other hand, this *is* a restart, then the stop_pre
# action will have ensured that the config is usable and we don't
# need to do that again.
if [ "${RC_CMD}" != "restart" ] ; then
checkconfig || return $?
fi
}
stop_pre() {
# If this is a restart, check to make sure the user's config
# isn't busted before we stop the running daemon.
if [ "${RC_CMD}" = "restart" ] ; then
checkconfig || return $?
fi
}
```
To prevent a *reload* with a broken config, keep it simple:
```sh
reload() {
checkconfig || return $?
ebegin "Reloading ${RC_SVCNAME}"
start-stop-daemon --signal HUP --pidfile "${pidfile}"
eend $?
}
```
## PID files should be writable only by root
PID files must be writable only by *root*, which means additionally
that they must live in a *root*-owned directory. This directory is
normally /run under Linux and /var/run under other operating systems.
Some daemons run as an unprivileged user account, and create their PID
files (as the unprivileged user) in a path like
`/var/run/foo/foo.pid`. That can usually be exploited by the unprivileged
user to kill *root* processes, since when a service is stopped, *root*
usually sends a SIGTERM to the contents of the PID file (which are
controlled by the unprivileged user). The main warning sign for that
problem is using `checkpath` to set ownership on the directory
containing the PID file. For example,
```sh
# BAD BAD BAD BAD BAD BAD BAD BAD
start_pre() {
# Ensure that the pidfile directory is writable by the foo user/group.
checkpath --directory --mode 0700 --owner foo:foo "/var/run/foo"
}
# BAD BAD BAD BAD BAD BAD BAD BAD
```
If the *foo* user owns `/var/run/foo`, then he can put whatever he wants
in the `/var/run/foo/foo.pid` file. Even if *root* owns the PID file, the
*foo* user can delete it and replace it with his own. To avoid
security concerns, the PID file must be created as *root* and live in
a *root*-owned directory. If your daemon is responsible for forking
and writing its own PID file but the PID file is still owned by the
unprivileged runtime user, then you may have an upstream issue.
Once the PID file is being created as *root* (before dropping
privileges), it can be written directly to a *root*-owned
directory. For example, the *foo* daemon might write
`/var/run/foo.pid`. No calls to checkpath are needed. Note: there is
nothing technically wrong with using a directory structure like
`/var/run/foo/foo.pid`, so long as *root* owns the PID file and the
directory containing it.
Ideally (see "Upstream your service scripts"), your service script
will be integrated upstream and the build system will determine the
appropriate directory for the pid file. For example,
```sh
pidfile="@piddir@/${RC_SVCNAME}.pid"
```
A decent example of this is the [Nagios core service
script](https://github.com/NagiosEnterprises/nagioscore/blob/master/openrc-init.in),
where the full path to the PID file is specified at build-time.
## Don't let the user control the PID file location
It's usually a mistake to let the end user control the PID file
location through a conf.d variable, for a few reasons:
1. When the PID file path is controlled by the user, you need to
ensure that its parent directory exists and is writable. This
adds unnecessary code to the service script.
2. If the PID file path changes while the service is running, then
you'll find yourself unable to stop the service.
3. The directory that should contain the PID file is best determined
by the upstream build system (see "Upstream your service scripts").
On Linux, the preferred location these days is `/run`. Other systems
still use `/var/run`, though, and a `./configure` script is the
best place to decide which one you want.
4. Nobody cares where the PID file is located, anyway.
Since OpenRC service names must be unique, a value of
```sh
pidfile="/var/run/${RC_SVCNAME}.pid"
```
guarantees that your PID file has a unique name.
## Upstream your service scripts (for packagers)
The ideal place for an OpenRC service script is **upstream**. Much like
systemd services, a well-crafted OpenRC service script should be
distribution-agnostic, and the best place for it is upstream. Why? For
two reasons. First, having it upstream means that there's a single
authoritative source for improvements. Second, a few paths in every
service script are dependent upon flags passed to the build system. For
example,
```sh
command=/usr/bin/foo
```
in an autotools-based build system should really be
```sh
command=@bindir@/foo
```
so that the user's value of `--bindir` is respected. If you keep the
service script in your own distribution's repository, then you have to
keep the command path and package synchronized yourself, and that's no
fun.
## Be wary of "need net" dependencies
There are two things you need to know about "need net" dependencies:
1. They are not satisfied by the loopback interface, so "need net"
requires some *other* interface to be up.
2. Depending on the value of `rc_depend_strict` in `rc.conf`, the
"need net" will be satisfied when either *any* non-loopback
interface is up, or when *all* non-loopback interfaces are up.
The first item means that "need net" is wrong for daemons that are
happy with `0.0.0.0`, and the second point means that "need net" is
wrong for daemons that need a particular (for example, the WAN)
interface. We'll consider the two most common users of "need net";
network clients who access some network resource, and network servers
who provide them.
### Network clients
Network clients typically want the WAN interface to be up. That may
tempt you to depend on the WAN interface; but first, you should ask
yourself a question: does anything bad happen if the WAN interface is
not available? In other words, if the administrator wants to disable
the WAN, should the service be stopped? Usually the answer to that
question is "no," and in that case, you should forego the "net"
dependency entirely.
Suppose, for example, that your service retrieves virus signature
updates from the internet. In order to do its job correctly, it needs
a (working) internet connection. However, the service itself does not
require the WAN interface to be up: if it is, great; otherwise, the
worst that will happen is that a "server unavailable" warning will be
logged. The signature update service will not crash, and—perhaps more
importantly—you don't want it to terminate if the administrator turns
off the WAN interface for a second.
### Network servers
Network servers are generally easier to handle than their client
counterparts. Most server daemons listen on `0.0.0.0` (all addresses)
by default, and are therefore satisfied to have the loopback interface
present and operational. OpenRC ships with the loopback service in the
*boot* runlevel, and therefore most server daemons require no further
network dependencies.
The exceptions to this rule are those daemons who produce negative
side-effects when the WAN is unavailable. For example, the Nagios
server daemon will generate "the sky is falling" alerts for as long as
your monitored hosts are unreachable. So in that case, you should
require some other interface (often the WAN) to be up. A "need"
dependency would be appropriate, because you want Nagios to be
stopped before the network is taken down.
If your daemon can optionally be configured to listen on a particular
interface, then please see the "Depending on a particular interface"
section.
### Depending on a particular interface
If you need to depend on one particular interface, usually it's not
easy to determine programmatically what that interface is. For
example, if your *sshd* daemon listens on `192.168.1.100` (rather than
`0.0.0.0`), then you have two problems:
1. Parsing `sshd_config` to figure that out; and
2. Determining which network service name corresponds to the
interface for `192.168.1.100`.
It's generally a bad idea to parse config files in your service
scripts, but the second problem is the harder one. Instead, the most
robust (i.e. the laziest) approach is to make the user specify the
dependency when he makes a change to sshd_config. Include something
like the following in the service configuration file,
```sh
# Specify the network service that corresponds to the "bind" setting
# in your configuration file. For example, if you bind to 127.0.0.1,
# this should be set to "loopback" which provides the loopback interface.
rc_need="loopback"
```
This is a sensible default for daemons that are happy with `0.0.0.0`,
but lets the user specify something else, like `rc_need="net.wan"` if
he needs it. The burden is on the user to determine the appropriate
service whenever he changes the daemon's configuration file.

3
sh/.gitignore vendored
View File

@@ -1,10 +1,7 @@
functions.sh
gendepends.sh
rc-functions.sh
openrc-run.sh
cgroup-release-agent.sh
init.sh
init-early.sh
rc-cgroup.sh
migrate-to-run.sh
binfmt.sh

View File

@@ -1,8 +1,8 @@
DIR= ${LIBEXECDIR}/sh
SRCS= init.sh.in functions.sh.in gendepends.sh.in \
openrc-run.sh.in rc-functions.sh.in ${SRCS-${OS}}
openrc-run.sh.in ${SRCS-${OS}}
INC= rc-mount.sh functions.sh rc-functions.sh runit.sh s6.sh \
start-stop-daemon.sh supervise-daemon.sh
start-stop-daemon.sh supervise-daemon.sh ${INC-${OS}}
BIN= gendepends.sh init.sh openrc-run.sh ${BIN-${OS}}
INSTALLAFTER= _installafter
@@ -13,10 +13,9 @@ include ${MK}/os.mk
SRCS-FreeBSD=
BIN-FreeBSD=
SRCS-Linux= binfmt.sh.in cgroup-release-agent.sh.in init-early.sh.in \
migrate-to-run.sh.in rc-cgroup.sh.in
BIN-Linux= binfmt.sh cgroup-release-agent.sh init-early.sh migrate-to-run.sh \
rc-cgroup.sh
SRCS-Linux= binfmt.sh.in cgroup-release-agent.sh.in init-early.sh.in
BIN-Linux= binfmt.sh cgroup-release-agent.sh init-early.sh
INC-Linux= rc-cgroup.sh
SRCS-NetBSD=
BIN-NetBSD=
@@ -32,4 +31,3 @@ _installafter:
ln -snf ${LIBEXECDIR}/sh/functions.sh ${DESTDIR}/${INITDIR} || exit $$?
check test::
./runtests.sh

View File

@@ -1,4 +1,4 @@
#!@SHELL@
#!/bin/sh
# This is a reimplementation of the systemd binfmt.d code to register
# misc binary formats with the kernel.
#
@@ -29,6 +29,9 @@ apply_file() {
\;*) continue ;;
esac
local reg=${line#*:}
[ -e /proc/sys/fs/binfmt_misc/${reg%%:*} ] && echo -1 > /proc/sys/fs/binfmt_misc/${reg%%:*}
echo "${line}" > /proc/sys/fs/binfmt_misc/register
rc=$?
if [ $rc -ne 0 ]; then

View File

@@ -1,4 +1,4 @@
#!@SHELL@
#!/bin/sh
# This is run by the kernel after the last task is removed from a
# control group in the openrc hierarchy.

Some files were not shown because too many files have changed in this diff Show More