OpenBSD CVS

CVS log for src/etc/rc.d/rc.subr


[BACK] Up to [local] / src / etc / rc.d

Request diff between arbitrary revisions


Default branch: MAIN


Revision 1.162 / (download) - annotate - [select for diffs], Wed Jan 17 08:26:06 2024 UTC (4 months, 2 weeks ago) by ajacoutot
Branch: MAIN
CVS Tags: OPENBSD_7_5_BASE, OPENBSD_7_5, HEAD
Changes since 1.161: +2 -2 lines
Diff to previous 1.161 (colored)

Zap trailing space.

from Kirill Miazine, thanks.

Revision 1.161 / (download) - annotate - [select for diffs], Fri Dec 15 16:59:48 2023 UTC (5 months, 2 weeks ago) by jca
Branch: MAIN
Changes since 1.160: +10 -2 lines
Diff to previous 1.160 (colored)

Run non-daemons services in a different process group to avoid SIGHUP at boot

12 factors apps and similar don't daemonize and are thus vulnerable to
receiving a SIGHUP signal at the end of /etc/rc.  Shield them by running
them in a different process group.  Do this only for services that need
rc_bg=Yes, as suggested by ajacoutot@

There have been several reports about this issue in the past years, the
last one being from edd@ who successfully tested this fix.  Input from
several folks, ok sthen@ ajacoutot@

Revision 1.160 / (download) - annotate - [select for diffs], Wed Oct 19 21:04:45 2022 UTC (19 months, 1 week ago) by ajacoutot
Branch: MAIN
CVS Tags: OPENBSD_7_4_BASE, OPENBSD_7_4, OPENBSD_7_3_BASE, OPENBSD_7_3
Changes since 1.159: +1 -3 lines
Diff to previous 1.159 (colored)

Drop support for $rcexec; people should now use the rc_exec function.

prodded by jsg@

Revision 1.159 / (download) - annotate - [select for diffs], Thu Sep 8 13:17:30 2022 UTC (20 months, 3 weeks ago) by ajacoutot
Branch: MAIN
CVS Tags: OPENBSD_7_2_BASE, OPENBSD_7_2
Changes since 1.158: +1 -5 lines
Diff to previous 1.158 (colored)

_rc_quirks is only called by _rc_parse_conf, so just merge the two.

ok robert@ sthen@ kn@

Revision 1.158 / (download) - annotate - [select for diffs], Fri Sep 2 22:11:57 2022 UTC (20 months, 4 weeks ago) by ajacoutot
Branch: MAIN
Changes since 1.157: +16 -11 lines
Diff to previous 1.157 (colored)

Make rc_configtest behave like rc_pre and rc_post; i.e. don't define a default
function (each rc.d script is supposed to define its own if wanted).
This way, we can filter out the "configtest" action depending on whether the
function exists or not.
Adapt documentation.

tweak/ok kn@

Revision 1.157 / (download) - annotate - [select for diffs], Thu Sep 1 07:25:32 2022 UTC (21 months ago) by ajacoutot
Branch: MAIN
Changes since 1.156: +9 -5 lines
Diff to previous 1.156 (colored)

Add a new action: "configtest", to check configuration syntax of the daemon.
A few adjustments will be done in the next days (like disabling this action if
there's no specific rc_configtest function defined).

e.g.
/etc/rc.d/sshd configtest
rcctl configtest sshd

idea from naddy@

Revision 1.156 / (download) - annotate - [select for diffs], Mon Aug 29 19:37:32 2022 UTC (21 months ago) by ajacoutot
Branch: MAIN
Changes since 1.155: +2 -2 lines
Diff to previous 1.155 (colored)

When using logger(1), also log the message to standard error so we don't
have to check syslog when running in debug mode (`-d').

Revision 1.155 / (download) - annotate - [select for diffs], Mon Aug 29 19:14:02 2022 UTC (21 months ago) by ajacoutot
Branch: MAIN
Changes since 1.154: +11 -1 lines
Diff to previous 1.154 (colored)

Introduce the rc_configtest() function.
By default it just returns "0" but can be overriden by rc.d scripts to check
that the daemon configuration is valid when running "start", "reload" and
"restart".

Revision 1.154 / (download) - annotate - [select for diffs], Thu May 26 11:27:03 2022 UTC (2 years ago) by ajacoutot
Branch: MAIN
Changes since 1.153: +14 -6 lines
Diff to previous 1.153 (colored)

Introduce a new daemon_execdir variable for changing to a specified directory
before running rc_rcexec.

Based on an proposal from openbsd.tech at aisha.cc
ok robert@ abieber@

Revision 1.153 / (download) - annotate - [select for diffs], Sat May 21 10:50:09 2022 UTC (2 years ago) by ajacoutot
Branch: MAIN
Changes since 1.152: +13 -6 lines
Diff to previous 1.152 (colored)

Replace the $rcexec variable by an rc_exec function.
It is much cleaner to the eyes and makes more sense from a functionnal point of
view.
This will allow to extend rc_exec with other functionnalities (like upcoming
rc_startdir).
Bonus point: daemon_logger will now work with manually crafted rc_start
functions.

This will require a mechanical change from ${rcexec} to rc_exec in rc.d scripts.
ports will be fixed right after this commit but we will keep compatibility to
give a chance to people to fix their custom scripts.

positive tests from a few
ok robert@

Revision 1.152 / (download) - annotate - [select for diffs], Thu Feb 10 16:57:33 2022 UTC (2 years, 3 months ago) by robert
Branch: MAIN
CVS Tags: OPENBSD_7_1_BASE, OPENBSD_7_1
Changes since 1.151: +3 -3 lines
Diff to previous 1.151 (colored)

look for the login class in both login.conf and login.conf.d/${class}

ok aja@

Revision 1.151 / (download) - annotate - [select for diffs], Mon Nov 15 12:56:11 2021 UTC (2 years, 6 months ago) by ajacoutot
Branch: MAIN
Changes since 1.150: +3 -4 lines
Diff to previous 1.150 (colored)

Tidy up; no change.

Revision 1.150 / (download) - annotate - [select for diffs], Sun Nov 14 09:31:44 2021 UTC (2 years, 6 months ago) by ajacoutot
Branch: MAIN
Changes since 1.149: +49 -49 lines
Diff to previous 1.149 (colored)

Improve and simplify timer handling in "stop" and "reload".
Rename _rc_wait to _rc_wait_for_start since only "start" uses this now (to
handle rc_bg daemons).
In any situation, none of these actions should be able to hang boot or shutdown.

We should now be able to manage most corner cases out there ("most" because it's
unreasonable to assume we can cope with all the non-default
rc_{start,stop,reload} crazyness).

Several tests have been made and no obvious regression has been found.
But that doesn't mean there isn't; if some behavior changed for the worst, talk
to me.

ok robert@ sthen@

Revision 1.149 / (download) - annotate - [select for diffs], Fri Nov 12 08:47:02 2021 UTC (2 years, 6 months ago) by ajacoutot
Branch: MAIN
Changes since 1.148: +3 -3 lines
Diff to previous 1.148 (colored)

Consistency in test; no behavior change.

Revision 1.148 / (download) - annotate - [select for diffs], Fri Nov 12 08:44:05 2021 UTC (2 years, 6 months ago) by ajacoutot
Branch: MAIN
Changes since 1.147: +3 -1 lines
Diff to previous 1.147 (colored)

Set SECONDS to 0 in _rc_wait.
While this is not strictly required, it's a failsafe and more fair to
daemon_timeout as we will effectively wait for the start/stop/reload sequence
instead of the duration of the rc.d script itself.

Revision 1.147 / (download) - annotate - [select for diffs], Fri Nov 12 08:38:02 2021 UTC (2 years, 6 months ago) by ajacoutot
Branch: MAIN
Changes since 1.146: +2 -9 lines
Diff to previous 1.146 (colored)

Simplify _rc_exit.

Revision 1.146 / (download) - annotate - [select for diffs], Thu Nov 11 12:08:36 2021 UTC (2 years, 6 months ago) by ajacoutot
Branch: MAIN
Changes since 1.145: +5 -4 lines
Diff to previous 1.145 (colored)

Run "_rc_wait stop" _before_ stopping the daemon and not after...
This doesn't change the default behavior but fixes rc.d scripts with a home made
rc_stop() function that can block and potentially hangs halt/reboot forever.

ok robert@

Revision 1.145 / (download) - annotate - [select for diffs], Thu Nov 11 10:37:36 2021 UTC (2 years, 6 months ago) by ajacoutot
Branch: MAIN
Changes since 1.144: +9 -2 lines
Diff to previous 1.144 (colored)

Return 0 in case we reach KILL; this allows "restart" to work as expected
in this situation.

reported by and ok robert@

Revision 1.144 / (download) - annotate - [select for diffs], Tue Nov 9 11:29:33 2021 UTC (2 years, 6 months ago) by sthen
Branch: MAIN
Changes since 1.143: +2 -1 lines
Diff to previous 1.143 (colored)

check that the rc script including rc.subr is using ksh; rc.subr uses ksh
features and scripts will not work correctly with sh. tweak jca/ok kn/
ok with direction aja

Revision 1.143 / (download) - annotate - [select for diffs], Mon Nov 8 10:10:50 2021 UTC (2 years, 6 months ago) by ajacoutot
Branch: MAIN
Changes since 1.142: +2 -3 lines
Diff to previous 1.142 (colored)

rc_reload_signal & rc_stop_signal are not rc.conf(8) variables; they're
only for rc.d scripts.

Revision 1.142 / (download) - annotate - [select for diffs], Sun Nov 7 08:31:24 2021 UTC (2 years, 6 months ago) by ajacoutot
Branch: MAIN
Changes since 1.141: +5 -4 lines
Diff to previous 1.141 (colored)

Speed up _rc_wait: only sleep 1/2 second between rc_check tries and make sure
we have at least 1s for SIGTERM to do its job.

Revision 1.141 / (download) - annotate - [select for diffs], Sun Nov 7 08:26:12 2021 UTC (2 years, 6 months ago) by ajacoutot
Branch: MAIN
Changes since 1.140: +4 -7 lines
Diff to previous 1.140 (colored)

Use built-in SECONDS instead of hand roller timer.

with a tweak from kn@
ok sthen@

Revision 1.140 / (download) - annotate - [select for diffs], Sat Nov 6 13:33:10 2021 UTC (2 years, 6 months ago) by ajacoutot
Branch: MAIN
Changes since 1.139: +7 -7 lines
Diff to previous 1.139 (colored)

Always run _rc_rm_runfile when process is sent a SIGKILL or rc_post fails (at
this point the process has been terminated).

Revision 1.139 / (download) - annotate - [select for diffs], Sat Nov 6 11:02:53 2021 UTC (2 years, 6 months ago) by ajacoutot
Branch: MAIN
Changes since 1.138: +5 -5 lines
Diff to previous 1.138 (colored)

Drop uneeded sleep.

Revision 1.138 / (download) - annotate - [select for diffs], Sat Nov 6 10:38:04 2021 UTC (2 years, 6 months ago) by ajacoutot
Branch: MAIN
Changes since 1.137: +25 -5 lines
Diff to previous 1.137 (colored)

Allow passing a different signal than SIGTERM in the default rc_stop()
function. This will allow to simplify some rc.d script that cook there own
function to gracefully stop a process (e.g. web servers). There are other use
cases as well.
And do the same for rc_reload because it's cheap and can also simplify a
handful of rc.d scripts.

Behave like shutdown and if the process is still not down after daemon_timeout
(configurable; default to 30s), then send a SIGKILL.

While here, factorise pkill invocations into a _rc_sendsig() function that can
potentially be used by rc.d scripts instead of cooking pkill lines; this will
benefit from the configured routing table etc.

tested & ok robert@

Revision 1.137 / (download) - annotate - [select for diffs], Sun Oct 31 17:46:23 2021 UTC (2 years, 7 months ago) by ajacoutot
Branch: MAIN
Changes since 1.136: +67 -67 lines
Diff to previous 1.136 (colored)

Shuffle things around to have FUNCS_ONLY higher in the script so consummers
source only what they really needs.
Only expose the following which are used by /etc/rc, netstart and rcctl:
_rc_parse_conf
_rc_check_name
_rc_err
_rc_do
_rc_quirk

ok sthen@

Revision 1.136 / (download) - annotate - [select for diffs], Sat Feb 27 09:28:04 2021 UTC (3 years, 3 months ago) by ajacoutot
Branch: MAIN
CVS Tags: OPENBSD_7_0_BASE, OPENBSD_7_0, OPENBSD_6_9_BASE, OPENBSD_6_9
Changes since 1.135: +9 -5 lines
Diff to previous 1.135 (colored)

Add logger(1) support for daemons that are logging to stdout/stderr (mostly from
the go ecosystem).
Properly handle failing daemon startup now that we have pipefail.

To take advantage of this new feature, just add foo_logger=facility to the
daemon rc.d(8) script or in rc.conf.local(8) or use rcctl:
rcctl set foo logger daemon.info

tweak for checking flags in rcctl(8) from martijn@
"this looks pretty good" deraadt@
ok sthen@

Revision 1.135 / (download) - annotate - [select for diffs], Sun Jul 12 14:35:38 2020 UTC (3 years, 10 months ago) by jca
Branch: MAIN
CVS Tags: OPENBSD_6_8_BASE, OPENBSD_6_8
Changes since 1.134: +2 -2 lines
Diff to previous 1.134 (colored)

Use su -fl to avoid sourcing /etc/profile / the target user's .profile

This way rc.d and rcctl don't suffer from side effects in people's rc
files.  If you somehow used those files to set environment variables,
you should have used login.conf as described in rc.d(8) instead.

ok ajacoutot@

Revision 1.134 / (download) - annotate - [select for diffs], Wed Apr 29 15:38:31 2020 UTC (4 years, 1 month ago) by ajacoutot
Branch: MAIN
CVS Tags: OPENBSD_6_7_BASE, OPENBSD_6_7
Changes since 1.133: +7 -7 lines
Diff to previous 1.133 (colored)

Sort variables and fix a comment.
No functional change.

Revision 1.133 / (download) - annotate - [select for diffs], Sat Feb 22 18:58:13 2020 UTC (4 years, 3 months ago) by ajacoutot
Branch: MAIN
Changes since 1.132: +2 -2 lines
Diff to previous 1.132 (colored)

Do not run _rc_parse_conf of /var/run/rc.d/foobar on "start".
This is needed in case a foobar fails to start but still returns 0. Changing its
flags (in rc.conf.local) would then get ignored because of this cache (which is
around to handle stop/check/reload on flags changes).

claudio@ reported this issue when struggling with prometheus several weeks ago

Revision 1.132 / (download) - annotate - [select for diffs], Sat Sep 7 10:02:19 2019 UTC (4 years, 8 months ago) by ajacoutot
Branch: MAIN
CVS Tags: OPENBSD_6_6_BASE, OPENBSD_6_6
Changes since 1.131: +2 -2 lines
Diff to previous 1.131 (colored)

Remove dependency on basename(1).

prodded by deraadt@
ok kn@ deraadt@ tb@

Revision 1.131 / (download) - annotate - [select for diffs], Thu Mar 21 15:10:27 2019 UTC (5 years, 2 months ago) by ajacoutot
Branch: MAIN
CVS Tags: OPENBSD_6_5_BASE, OPENBSD_6_5
Changes since 1.130: +2 -2 lines
Diff to previous 1.130 (colored)

Start in the daemon configured routing table and not in the one we're currently
in. This fixes the case where one would be in a non default rdomain shell then
run an rdomain 0 rc.d daemon.

reported by YASUOKA Masahiko and Pierre Emeriaud
ok sthen@ claudio@ benno@

Revision 1.130 / (download) - annotate - [select for diffs], Sun Jan 20 04:52:07 2019 UTC (5 years, 4 months ago) by ajacoutot
Branch: MAIN
Changes since 1.129: +4 -2 lines
Diff to previous 1.129 (colored)

The shell will strip the quotes from daemon_flags when starting a daemon so make
sure pexp matches the process (i.e. doesn't include the quotes).
It's a bit hackish but it allows things like these in rc.conf.local:
relayd_flags=-D IPS="1.2.3.4 2.3.4.5"

And we properly end up with...
$ grep ^pexp /var/run/rc.d/relayd
pexp=/usr/sbin/relayd -D IPS=1.2.3.4 1.2.3.5
... which matches what is in the process list:
root     14217  <snip>    0:00.01 /usr/sbin/relayd -D IPS=1.2.3.4 1.2.3.5

There's always the possibility that we have introduced a regressions with hand
crafted functions in rc.d scripts (mostly from packags), so watch out.

reported by and debugged with claudio@

Revision 1.129 / (download) - annotate - [select for diffs], Mon Oct 29 07:55:40 2018 UTC (5 years, 7 months ago) by ajacoutot
Branch: MAIN
Changes since 1.128: +1 -1 lines
Diff to previous 1.128 (colored)

Revert previous (for now).
semarie found a few regressions with daemon that will fail if cwd is not
accessible.

Revision 1.128 / (download) - annotate - [select for diffs], Tue Oct 16 07:07:05 2018 UTC (5 years, 7 months ago) by ajacoutot
Branch: MAIN
Changes since 1.127: +2 -2 lines
Diff to previous 1.127 (colored)

Change the way we call su(1) in rcexec:
- drop `-'l' to prevent simulating a full login and running /root/.profile
(prodded by a mail from J Greely)
- use `-m' to preserve the environment because we now set HOME to "/" like
/etc/rc does; note that we now also clear the environment using `env -i' before
running su(1) which leaves us with only HOME, PATH and SHELL

Committing early to catch regressions fast, if any.
ok halex@

Revision 1.127 / (download) - annotate - [select for diffs], Mon Jun 5 18:31:23 2017 UTC (6 years, 11 months ago) by ajacoutot
Branch: MAIN
CVS Tags: OPENBSD_6_4_BASE, OPENBSD_6_4, OPENBSD_6_3_BASE, OPENBSD_6_3, OPENBSD_6_2_BASE, OPENBSD_6_2
Changes since 1.126: +6 -2 lines
Diff to previous 1.126 (colored)

Temporarily disable the second call to rc_check until I figure out what
is going on. Should fix another case of false negative reported by sthen
(redis).

Revision 1.126 / (download) - annotate - [select for diffs], Mon Jun 5 15:24:57 2017 UTC (6 years, 11 months ago) by ajacoutot
Branch: MAIN
Changes since 1.125: +4 -3 lines
Diff to previous 1.125 (colored)

Fix logic in _rc_wait to properly cope with setproctitle(3) daemons. It was a
regression from my recent rc.subr changes.

reported by deraadt@ and naddy@ : pflogd was marked as failed during boot while
it was properly running

Revision 1.125 / (download) - annotate - [select for diffs], Tue May 30 12:04:26 2017 UTC (7 years ago) by tb
Branch: MAIN
Changes since 1.124: +3 -3 lines
Diff to previous 1.124 (colored)

Introduce a scary rc.conf(8) knob library_aslr=(YES|NO) to turn off the
reordering of libraries by rc(8). This way machines with very slow disk I/O
have a chance of booting within reasonable time now that libcrypto is also
randomized.

Discussed with various;
input & ok from deraadt ajacoutot

Revision 1.124 / (download) - annotate - [select for diffs], Sun May 28 18:51:27 2017 UTC (7 years ago) by ajacoutot
Branch: MAIN
Changes since 1.123: +2 -2 lines
Diff to previous 1.123 (colored)

Move check later to mitigate a possible race.

Revision 1.123 / (download) - annotate - [select for diffs], Sun May 28 10:12:42 2017 UTC (7 years ago) by ajacoutot
Branch: MAIN
Changes since 1.122: +8 -6 lines
Diff to previous 1.122 (colored)

Indent and rename var; no functional change.

Revision 1.122 / (download) - annotate - [select for diffs], Sun May 28 09:31:45 2017 UTC (7 years ago) by ajacoutot
Branch: MAIN
Changes since 1.121: +5 -3 lines
Diff to previous 1.121 (colored)

When a daemon reaches its timeout when starting, display "timeout" instead
of "ok" so the user is warned and has a chance to fix it (most of the time
due to bogus flags). Daemons reaching the timeout without being able to
start are still marked as "failed" (which should also give a clue to the
user that some investigation is needed).

prodded by beck@ a while ago
discussed with and ok sthen@

Revision 1.121 / (download) - annotate - [select for diffs], Sun May 28 08:38:10 2017 UTC (7 years ago) by ajacoutot
Branch: MAIN
Changes since 1.120: +12 -13 lines
Diff to previous 1.120 (colored)

Drop useless lines continuation; no functional change.

Revision 1.120 / (download) - annotate - [select for diffs], Sat May 27 19:55:48 2017 UTC (7 years ago) by ajacoutot
Branch: MAIN
Changes since 1.119: +3 -2 lines
Diff to previous 1.119 (colored)

Ok turns out we still want to keep the rc_bg variable around but we need
to know which daemon cannot background themselves (actually we want to
know the opposite, but there are much more). However, it's only needed in
_rc_wait and rc.subr still does its magic without the need to add `&'.

Revision 1.119 / (download) - annotate - [select for diffs], Sat May 27 13:51:52 2017 UTC (7 years ago) by ajacoutot
Branch: MAIN
Changes since 1.118: +28 -8 lines
Diff to previous 1.118 (colored)

Add an ALRM timer to cope with 2 annoying issues in rc.d(8):
- prevent a daemon from hanging the boot
(typo in your flagsm e.g. httpd_flags=-d)
- make sure we can get the status of a backgrounded daemon instead of always
returning success

Side effect of this is that we can kill a knob! rip rc_bg :-)
Ports will need love, and a second commit is coming for that.

The diff is small yet not trivial so I am committing early in the release
process in one shot so it can easily be reverted if needed. I started working on
this during g2k16 in Cambridge then finished it in Brisbane for a2k17 where
robert@, beck@ and sthen@ agreed it was the correct way to go and I should move
ahead with it post 6.1.

If you see any regression, please talk to me!

Revision 1.118 / (download) - annotate - [select for diffs], Fri Feb 17 16:42:41 2017 UTC (7 years, 3 months ago) by ajacoutot
Branch: MAIN
CVS Tags: OPENBSD_6_1_BASE, OPENBSD_6_1
Changes since 1.117: +1 -6 lines
Diff to previous 1.117 (colored)

Stop supporting the historical way of starting ypbind(8); that is setting
'ypbind_flags=""' when domainname is set and /var/yp/binding exists.
This can lead to inconsistent behavior at startup since /var may not be
mounted yet and /etc/rc's start_daemon() will not start ypbind.

A.K.A. make ypbind startup consistent with all other OpenBSD daemons.

ok deraadt@

Revision 1.117 / (download) - annotate - [select for diffs], Tue Jan 24 01:11:11 2017 UTC (7 years, 4 months ago) by ajacoutot
Branch: MAIN
Changes since 1.116: +3 -3 lines
Diff to previous 1.116 (colored)

Whitespace.

Revision 1.116 / (download) - annotate - [select for diffs], Wed Sep 7 13:12:42 2016 UTC (7 years, 8 months ago) by ajacoutot
Branch: MAIN
Changes since 1.115: +8 -2 lines
Diff to previous 1.115 (colored)

Introduce an _rc_check_name() function to check the input script name so that
we don't end up with cryptic error messages.
Regex help from rpe@
Issue reported by Anthony Coulter in rcctl(8), but better fix the root cause.

Also clarify the mage page that rc.d script name must follow ksh(1) variable
naming.

ok robert@ sthen@

Revision 1.115 / (download) - annotate - [select for diffs], Wed Aug 31 08:47:11 2016 UTC (7 years, 9 months ago) by ajacoutot
Branch: MAIN
Changes since 1.114: +2 -2 lines
Diff to previous 1.114 (colored)

use tab.

Revision 1.114 / (download) - annotate - [select for diffs], Tue May 3 08:59:29 2016 UTC (8 years, 1 month ago) by otto
Branch: MAIN
CVS Tags: OPENBSD_6_0_BASE, OPENBSD_6_0
Changes since 1.113: +2 -2 lines
Diff to previous 1.113 (colored)

signal name should be first, fixes reload; ok deraadt@

Revision 1.113 / (download) - annotate - [select for diffs], Thu Apr 28 09:15:16 2016 UTC (8 years, 1 month ago) by ajacoutot
Branch: MAIN
Changes since 1.112: +4 -4 lines
Diff to previous 1.112 (colored)

Experiment on matching on the daemon_user is over. It needs more work.
portmap isn't happy with it as reported by naddy@

Revision 1.112 / (download) - annotate - [select for diffs], Wed Apr 27 17:29:50 2016 UTC (8 years, 1 month ago) by ajacoutot
Branch: MAIN
Changes since 1.111: +3 -3 lines
Diff to previous 1.111 (colored)

Revert the revert and match on the daemon_user again.
We'll see if something else breaks but it's the right thing to do.

discussed with robert@

Revision 1.111 / (download) - annotate - [select for diffs], Wed Apr 27 12:58:12 2016 UTC (8 years, 1 month ago) by ajacoutot
Branch: MAIN
Changes since 1.110: +4 -4 lines
Diff to previous 1.110 (colored)

Revert matching on the daemon user for now; it breaks sndiod handling which
does start as root but does not have a root master process and instead
changed its uid.

reported by deraadt@

Revision 1.110 / (download) - annotate - [select for diffs], Tue Apr 26 17:00:20 2016 UTC (8 years, 1 month ago) by ajacoutot
Branch: MAIN
Changes since 1.109: +2 -2 lines
Diff to previous 1.109 (colored)

Bump copyright.

Revision 1.109 / (download) - annotate - [select for diffs], Tue Apr 26 16:59:15 2016 UTC (8 years, 1 month ago) by ajacoutot
Branch: MAIN
Changes since 1.108: +12 -6 lines
Diff to previous 1.108 (colored)

Introduce rtable(4) support to rc.subr(8).
It works by adding daemon_rtable=$id in /etc/rc.conf.local.
rcctl(8) support coming in a few and so are the man pages bits.

If you want multiple instances of the same daemon running in different
routing tables, just symlink the original rc.d script.
e.g.
# cd /etc/rc.d && ln -s dhcpd dhcpd42

Then enable your daemons as such in rc.conf.local:
dhcpd_flags=
dhcpd42_flags=
dhcpd42_rtable=42

most work done by Jiri B <jirib@devio.us>; with a few tweaks and simplifications
by yours truly
ok robert@

... should make henning happy ;-)

Revision 1.108 / (download) - annotate - [select for diffs], Tue Apr 26 16:39:59 2016 UTC (8 years, 1 month ago) by ajacoutot
Branch: MAIN
Changes since 1.107: +14 -15 lines
Diff to previous 1.107 (colored)

Extend _RC_RUNFILE (/var/run/rc.d/scriptname) content with:
daemon_class, daemon_flags, daemon_timeout, daemon_user, pexp

Add "pexp" as a valid variable to _rc_parse_conf() and sort the list while here.

Besides having an easy way to see how a daemon was started exactly, it opens the
door to rdomain/rtable support in rc.d(8). We need to have as much information
on a daemon as possible if we want to target a specific rtable (using -T) and it
also makes it easier to start multiple instances of the same daemon with similar
flags as a different user...
Of course that only works with rc.d scripts *not* overwritting the default rc_*
functions.

Man page tweaks coming later.

discussed with and ok robert@

Revision 1.107 / (download) - annotate - [select for diffs], Sat Mar 26 13:59:36 2016 UTC (8 years, 2 months ago) by ajacoutot
Branch: MAIN
Changes since 1.106: +4 -2 lines
Diff to previous 1.106 (colored)

Make it possible to get usage as a non-root user.

ok robert@

Revision 1.106 / (download) - annotate - [select for diffs], Sat Mar 26 09:21:24 2016 UTC (8 years, 2 months ago) by ajacoutot
Branch: MAIN
Changes since 1.105: +6 -9 lines
Diff to previous 1.105 (colored)

Handle the rc_stop=NO => rc_restart=NO case within _rc_not_supported().

Revision 1.105 / (download) - annotate - [select for diffs], Mon Dec 21 10:18:05 2015 UTC (8 years, 5 months ago) by ajacoutot
Branch: MAIN
CVS Tags: OPENBSD_5_9_BASE, OPENBSD_5_9
Changes since 1.104: +2 -2 lines
Diff to previous 1.104 (colored)

Revert, rc.d scripts have been fixed.

Revision 1.104 / (download) - annotate - [select for diffs], Mon Dec 21 09:29:12 2015 UTC (8 years, 5 months ago) by ajacoutot
Branch: MAIN
Changes since 1.103: +2 -2 lines
Diff to previous 1.103 (colored)

Comment the wait for start until I fix the x11 managers rc.d script.

Revision 1.103 / (download) - annotate - [select for diffs], Sat Dec 19 14:10:41 2015 UTC (8 years, 5 months ago) by ajacoutot
Branch: MAIN
Changes since 1.102: +2 -7 lines
Diff to previous 1.102 (colored)

After starting, unconditionally wait up to $daemon_timeout seconds to check that
the daemon is actually running (instead of only when using rc_bg).

This *may* trigger the following side effect: if a daemon starts then stops
right away (because of a config parsing issue for e.g.), then it will slow down
the boot process because rc will wait a bit before considering the start action
failed. But at least it will allow us to detect those daemons and fix them or
their rc.d(8) script.

At least as far as I can tell, all base daemons should cope with it just fine.

ok sthen@ robert@ on an earlier diff

Revision 1.102 / (download) - annotate - [select for diffs], Sat Dec 19 11:19:17 2015 UTC (8 years, 5 months ago) by ajacoutot
Branch: MAIN
Changes since 1.101: +8 -11 lines
Diff to previous 1.101 (colored)

Tidy up _rc_wait().

ok sthen@ robert@

Revision 1.101 / (download) - annotate - [select for diffs], Sat Dec 5 18:43:12 2015 UTC (8 years, 5 months ago) by mpi
Branch: MAIN
Changes since 1.100: +2 -2 lines
Diff to previous 1.100 (colored)

It does not make sense to insert a specific route for 224/4 when the
default one is good enough.

So merge rc.conf(8)'s 'multicast_router' and 'multicast_host' into a
single 'multicast'.  If set to YES the reject route for 224/4 is not
inserted by netstart(8).

Manual bits from jmc@

ok henning@, ajacoutot@

Revision 1.100 / (download) - annotate - [select for diffs], Fri Oct 16 20:12:00 2015 UTC (8 years, 7 months ago) by ajacoutot
Branch: MAIN
Changes since 1.99: +2 -2 lines
Diff to previous 1.99 (colored)

Missing local.

ok schwarze@

Revision 1.99 / (download) - annotate - [select for diffs], Wed Jul 15 13:48:16 2015 UTC (8 years, 10 months ago) by ajacoutot
Branch: MAIN
CVS Tags: OPENBSD_5_8_BASE, OPENBSD_5_8
Changes since 1.98: +4 -4 lines
Diff to previous 1.98 (colored)

By default, require an exact match of the process name and argument list.
This allows running several instances of the same rc.d(8) script by just
linking it to different name.
e.g.
ln -s ftpproxy ftpproxy6
echo 'ftpproxy6_flags=-6' >>/etc/rc.conf.local

This is likely to break some rc.d scripts in ports. I will try and fix them all
in the next few days but I'd appreciate reports if I missed some.

ok halex@

Revision 1.98 / (download) - annotate - [select for diffs], Wed Jul 15 12:26:25 2015 UTC (8 years, 10 months ago) by ajacoutot
Branch: MAIN
Changes since 1.97: +5 -2 lines
Diff to previous 1.97 (colored)

Always use the default flags when running !start.
This is necessary so that rc.d scripts launched with `-f' can be properly
stopped, checked and reloaded.

ok schwarze@

Revision 1.97 / (download) - annotate - [select for diffs], Wed Jul 15 03:21:38 2015 UTC (8 years, 10 months ago) by ajacoutot
Branch: MAIN
Changes since 1.96: +2 -3 lines
Diff to previous 1.96 (colored)

Merge comments.

Revision 1.96 / (download) - annotate - [select for diffs], Wed Jun 17 07:50:38 2015 UTC (8 years, 11 months ago) by ajacoutot
Branch: MAIN
Changes since 1.95: +4 -5 lines
Diff to previous 1.95 (colored)

Really make daemon_class read-only; it's set to "daemon" of a matching
login class.

Revision 1.95 / (download) - annotate - [select for diffs], Sat May 2 09:36:27 2015 UTC (9 years, 1 month ago) by ajacoutot
Branch: MAIN
Changes since 1.94: +2 -3 lines
Diff to previous 1.94 (colored)

No more pf_rules ipsec_rules.

Revision 1.94 / (download) - annotate - [select for diffs], Wed Apr 29 11:05:16 2015 UTC (9 years, 1 month ago) by ajacoutot
Branch: MAIN
Changes since 1.93: +17 -9 lines
Diff to previous 1.93 (colored)

Check arguments before eval so we don't end up with a cryptic error message.
reported by jasper@

While here: _rc_is_supported() -> _rc_not_supported()
- saves a fork
- reduces triple negation to double negation in _rc_not_supported()
- simplifie condition for rc_restart=NO
from schwarze@

ok jasper@ schwarze@

Revision 1.93 / (download) - annotate - [select for diffs], Sat Mar 28 07:34:16 2015 UTC (9 years, 2 months ago) by ajacoutot
Branch: MAIN
Changes since 1.92: +2 -3 lines
Diff to previous 1.92 (colored)

_rc_err(): only display error message if there's an actual one.
Remove an exit() statement that could never be reached.

Revision 1.92 / (download) - annotate - [select for diffs], Fri Jan 2 14:44:05 2015 UTC (9 years, 5 months ago) by ajacoutot
Branch: MAIN
CVS Tags: OPENBSD_5_7_BASE, OPENBSD_5_7
Changes since 1.91: +4 -2 lines
Diff to previous 1.91 (colored)

Fix return code of _rc_quirks().
ok robert@

Revision 1.91 / (download) - annotate - [select for diffs], Fri Jan 2 08:03:28 2015 UTC (9 years, 5 months ago) by ajacoutot
Branch: MAIN
Changes since 1.90: +3 -4 lines
Diff to previous 1.90 (colored)

Add a comment about the default values being duplicated in rcctl(8).
discussed with schwarze@

Revision 1.90 / (download) - annotate - [select for diffs], Mon Nov 17 13:52:44 2014 UTC (9 years, 6 months ago) by ajacoutot
Branch: MAIN
Changes since 1.89: +2 -3 lines
Diff to previous 1.89 (colored)

"reload" should fail if the service is not running in the first place.

ok robert@ sthen@

Revision 1.89 / (download) - annotate - [select for diffs], Sat Aug 30 20:33:27 2014 UTC (9 years, 9 months ago) by ajacoutot
Branch: MAIN
Changes since 1.88: +2 -2 lines
Diff to previous 1.88 (colored)

Make it possible to pass a specific error code to _rc_err().

ok robert@ schwarze@

Revision 1.88 / (download) - annotate - [select for diffs], Mon Aug 25 07:34:12 2014 UTC (9 years, 9 months ago) by ajacoutot
Branch: MAIN
Changes since 1.87: +2 -2 lines
Diff to previous 1.87 (colored)

Put _rc_err argument under quotes to respect the syntax we are passing.

Revision 1.87 / (download) - annotate - [select for diffs], Sun Aug 24 17:15:24 2014 UTC (9 years, 9 months ago) by ajacoutot
Branch: MAIN
Changes since 1.86: +2 -2 lines
Diff to previous 1.86 (colored)

Fix reversed logic.

ok schwarze@

Revision 1.86 / (download) - annotate - [select for diffs], Sun Aug 24 13:32:53 2014 UTC (9 years, 9 months ago) by ajacoutot
Branch: MAIN
Changes since 1.85: +2 -2 lines
Diff to previous 1.85 (colored)

Drop uneeded parenthesis in usage().

ok schwarze@

Revision 1.85 / (download) - annotate - [select for diffs], Sun Aug 24 13:30:27 2014 UTC (9 years, 9 months ago) by ajacoutot
Branch: MAIN
Changes since 1.84: +2 -3 lines
Diff to previous 1.84 (colored)

Drop unused variables.

Revision 1.84 / (download) - annotate - [select for diffs], Sun Aug 24 13:29:16 2014 UTC (9 years, 9 months ago) by ajacoutot
Branch: MAIN
Changes since 1.83: +7 -5 lines
Diff to previous 1.83 (colored)

In debug mode, make it clear when we are using the default flags when
none are set.

initial patch from me but reworked by schwarze@
ok schwarze@

Revision 1.83 / (download) - annotate - [select for diffs], Sun Aug 24 07:55:20 2014 UTC (9 years, 9 months ago) by ajacoutot
Branch: MAIN
Changes since 1.82: +1 -3 lines
Diff to previous 1.82 (colored)

In debug mode (`-d'), only print the flags relevant to the rc.d(8) we are
calling instead of all flags which makes it very difficult to see the
information we actually need.

ok schwarze@ robert@

Revision 1.82 / (download) - annotate - [select for diffs], Thu Aug 21 10:06:14 2014 UTC (9 years, 9 months ago) by ajacoutot
Branch: MAIN
Changes since 1.81: +2 -6 lines
Diff to previous 1.81 (colored)

Drop sanitation, _rc_parse_conf does this for us already.

ok schwarze@

Revision 1.81 / (download) - annotate - [select for diffs], Sun Aug 17 14:41:03 2014 UTC (9 years, 9 months ago) by ajacoutot
Branch: MAIN
Changes since 1.80: +4 -2 lines
Diff to previous 1.80 (colored)

When running interactively, display the output of the "check" action
(ok or failed) like we do with all other actions.

ok jung@ rpe@

Revision 1.80 / (download) - annotate - [select for diffs], Mon Aug 11 20:24:57 2014 UTC (9 years, 9 months ago) by ajacoutot
Branch: MAIN
Changes since 1.79: +2 -2 lines
Diff to previous 1.79 (colored)

Typo.

ok kili@

Revision 1.79 / (download) - annotate - [select for diffs], Mon Aug 11 20:16:04 2014 UTC (9 years, 9 months ago) by kili
Branch: MAIN
Changes since 1.78: +4 -3 lines
Diff to previous 1.78 (colored)

Let _rc_parse_conf stick to parsing /etc/rc.conf and /etc/rc.conf.local
if it's invoked without parameters. It's simpler than adding adding
/etc/rc.conf and /etc/rc.conf.local parameters whereever _rc_parse_conf
is used (e.g. /etc/rc and /etc/netstart).

While here, replace a

        for foo in "$@"; do something; done

by

        for foo; do something; done

ok aja@

Revision 1.78 / (download) - annotate - [select for diffs], Mon Aug 11 13:25:23 2014 UTC (9 years, 9 months ago) by ajacoutot
Branch: MAIN
Changes since 1.77: +3 -5 lines
Diff to previous 1.77 (colored)

Make it possible to pass arguments to _rc_parse_conf().

ok robert@

Revision 1.77 / (download) - annotate - [select for diffs], Fri Aug 1 04:57:01 2014 UTC (9 years, 10 months ago) by rpe
Branch: MAIN
CVS Tags: OPENBSD_5_6_BASE, OPENBSD_5_6
Changes since 1.76: +2 -2 lines
Diff to previous 1.76 (colored)

Don't return, just skip over non existing rc.conf or rc.conf.local file.

OK ajacoutot@ halex@

Revision 1.76 / (download) - annotate - [select for diffs], Thu Jul 31 14:57:41 2014 UTC (9 years, 10 months ago) by ajacoutot
Branch: MAIN
Changes since 1.75: +9 -3 lines
Diff to previous 1.75 (colored)

In debug mode, properly sort and drop duplicates so that we don't end
up with a confusing output like:
multicast_host      >NO<
<...>
multicast_host      >YES<

Also properly evaluate values _after_ running _rc_quirks() because these
can modify flags.

ok robert@ halex@

Revision 1.75 / (download) - annotate - [select for diffs], Wed Jul 30 13:18:59 2014 UTC (9 years, 10 months ago) by ajacoutot
Branch: MAIN
Changes since 1.74: +2 -2 lines
Diff to previous 1.74 (colored)

Fix evil typo (multicast_hosts -> multicast_host).

Revision 1.74 / (download) - annotate - [select for diffs], Sat Jul 12 15:32:43 2014 UTC (9 years, 10 months ago) by robert
Branch: MAIN
Changes since 1.73: +10 -6 lines
Diff to previous 1.73 (colored)

replace the heavy shell magic in quirks to handle backward compat with simpler
methods

Revision 1.73 / (download) - annotate - [select for diffs], Sat Jul 12 10:14:03 2014 UTC (9 years, 10 months ago) by robert
Branch: MAIN
Changes since 1.72: +118 -62 lines
Diff to previous 1.72 (colored)

Make rc.conf a parsed configuration file and stop sourcing it as a shell
script.
From now on rc.conf has a fixed syntax (key=val) and it is not allowed
to add anything to it besides the supported syntax, it all going to be
ignored.

discussed with and help from deraadt@ and halex@

Revision 1.72 / (download) - annotate - [select for diffs], Wed Jul 9 14:19:22 2014 UTC (9 years, 10 months ago) by ajacoutot
Branch: MAIN
Changes since 1.71: +7 -4 lines
Diff to previous 1.71 (colored)

Add a daemon_timeout variable for rc_wait().
It represents the maximum time in seconds to wait for the start, stop
and reload actions to return. Defaults to "30".
No default behavior is changed.

ok beck@ sthen@ jasper@ giovanni@

Revision 1.71 / (download) - annotate - [select for diffs], Wed Jul 9 10:59:35 2014 UTC (9 years, 10 months ago) by ajacoutot
Branch: MAIN
Changes since 1.70: +3 -3 lines
Diff to previous 1.70 (colored)

White spaces.

Revision 1.70 / (download) - annotate - [select for diffs], Thu Jul 11 09:34:33 2013 UTC (10 years, 10 months ago) by otto
Branch: MAIN
CVS Tags: OPENBSD_5_5_BASE, OPENBSD_5_5, OPENBSD_5_4_BASE, OPENBSD_5_4
Changes since 1.69: +2 -2 lines
Diff to previous 1.69 (colored)

no double negatives in error message; ok aja@

Revision 1.69 / (download) - annotate - [select for diffs], Thu Apr 4 06:50:44 2013 UTC (11 years, 2 months ago) by zhuk
Branch: MAIN
Changes since 1.68: +18 -5 lines
Diff to previous 1.68 (colored)

Show only available actions in RC script usage messages.
Also, prettify representation of actions list a bit.

a lot of input and ok halex@ aja@
also ok schwarze@
small nit spotted by marc@
"makes a lot of sense to me" todd@

Revision 1.68 / (download) - annotate - [select for diffs], Mon Nov 19 07:10:59 2012 UTC (11 years, 6 months ago) by ajacoutot
Branch: MAIN
CVS Tags: OPENBSD_5_3_BASE, OPENBSD_5_3
Changes since 1.67: +2 -2 lines
Diff to previous 1.67 (colored)

Remove useless test: rc_rm_runfile() uses rm -f which always returns 0
so we don't care if the file is present or not; also this function
should never return a failure.

ok halex@

Revision 1.67 / (download) - annotate - [select for diffs], Sun Nov 18 18:54:52 2012 UTC (11 years, 6 months ago) by ajacoutot
Branch: MAIN
Changes since 1.66: +5 -2 lines
Diff to previous 1.66 (colored)

Don't output "$action is not supported" when running an rc.d(8) script
from /etc/rc(8). This prevents the warning to be displayed at shutdown
time when the script has rc_stop=NO.

req. and input from fgsch@

"go ahead" schwarze@
input from an ok halex@, ok robert@

Revision 1.66 / (download) - annotate - [select for diffs], Mon Nov 12 08:07:53 2012 UTC (11 years, 6 months ago) by ajacoutot
Branch: MAIN
Changes since 1.65: +2 -2 lines
Diff to previous 1.65 (colored)

Don't check if ${local_rcconf} is defined before sourcing rc.conf but do
it unconditionally.
The only place local_rcconf could have been defined is from /etc/rc
sourcing rc.conf but then the variable is not exported so it will never
be seen by rc.subr.

ok robert@

Revision 1.65 / (download) - annotate - [select for diffs], Thu Sep 13 05:55:21 2012 UTC (11 years, 8 months ago) by ajacoutot
Branch: MAIN
Changes since 1.64: +3 -3 lines
Diff to previous 1.64 (colored)

Simplify the way we call the rc.d(8) script in "restart".

ok sthen@

Revision 1.64 / (download) - annotate - [select for diffs], Sat Sep 1 07:08:37 2012 UTC (11 years, 9 months ago) by ajacoutot
Branch: MAIN
Changes since 1.63: +5 -10 lines
Diff to previous 1.63 (colored)

Make '-f' only affects the "start" action.
There is no reason we couldn't reload|stop a daemon even when _flags is
set to NO.
As a bonus side effect, we can now see usage() on disabled scripts.

discussed with sthen@ and espie@
ok sthen@

Revision 1.63 / (download) - annotate - [select for diffs], Tue Aug 21 06:38:52 2012 UTC (11 years, 9 months ago) by ajacoutot
Branch: MAIN
Changes since 1.62: +2 -2 lines
Diff to previous 1.62 (colored)

Use the new "-q" option of pgrep(1) instead of redirecting stdout
to /dev/null.

Revision 1.62 / (download) - annotate - [select for diffs], Mon Aug 13 10:10:07 2012 UTC (11 years, 9 months ago) by ajacoutot
Branch: MAIN
Changes since 1.61: +5 -2 lines
Diff to previous 1.61 (colored)

unset _rcflags and _rcuser so that they don't get inherited by rc.d(8)
scripts; from robert at peichaer dot org
ok halex@

While here, put the "sanitation" commands in their own block.

Revision 1.61 / (download) - annotate - [select for diffs], Mon Aug 13 08:08:00 2012 UTC (11 years, 9 months ago) by ajacoutot
Branch: MAIN
Changes since 1.60: +2 -1 lines
Diff to previous 1.60 (colored)

Set the daemon_class as readonly as it should be (and is documented as
such).

from robert at peichaer dot org
modified after a discussion with halex@
ok halex@ robert@

Revision 1.60 / (download) - annotate - [select for diffs], Sat Aug 11 17:55:58 2012 UTC (11 years, 9 months ago) by ajacoutot
Branch: MAIN
Changes since 1.59: +3 -2 lines
Diff to previous 1.59 (colored)

Make a couple of variables local.

from robert at peichaer dot org
ok halex@

Revision 1.59 / (download) - annotate - [select for diffs], Sat Aug 4 15:30:25 2012 UTC (11 years, 9 months ago) by ajacoutot
Branch: MAIN
Changes since 1.58: +6 -4 lines
Diff to previous 1.58 (colored)

Add a new rc_usercheck variable (default to YES). When set to no, root
privilege is needed to run rc_check.
In effect this means /etc/rc.d/foobar check can now be run as a regular
user.
Discussed with robert@ during g2k12.

ok todd@

Revision 1.58 / (download) - annotate - [select for diffs], Sat Jul 7 10:28:07 2012 UTC (11 years, 10 months ago) by ajacoutot
Branch: MAIN
CVS Tags: OPENBSD_5_2_BASE, OPENBSD_5_2
Changes since 1.57: +4 -5 lines
Diff to previous 1.57 (colored)

Simplify rc_wait() (no functionnal change).

initially from robert at peichaer dot org with some enhancement by halex@
ok halex@

Revision 1.57 / (download) - annotate - [select for diffs], Wed May 30 08:19:14 2012 UTC (12 years ago) by espie
Branch: MAIN
Changes since 1.56: +9 -2 lines
Diff to previous 1.56 (colored)

in -d mode, display an error message before exiting, in the case the
daemon is not active (happens often to me, as I forget which box has
which daemons).

okay ajacoutot@

Revision 1.56 / (download) - annotate - [select for diffs], Wed Nov 30 08:06:02 2011 UTC (12 years, 6 months ago) by ajacoutot
Branch: MAIN
CVS Tags: OPENBSD_5_1_BASE, OPENBSD_5_1
Changes since 1.55: +2 -2 lines
Diff to previous 1.55 (colored)

Fix an issue when uid != euid (e.g. when running shutdown(8) as a
regular user, member of the operator group); rm(1) was waiting for
interactive input to remove the runfiles which made no sense, so just
use `-f'.

issue spotted by weerd@
ok weerd@ robert@

Revision 1.55 / (download) - annotate - [select for diffs], Sat Oct 15 16:05:15 2011 UTC (12 years, 7 months ago) by halex
Branch: MAIN
Changes since 1.54: +5 -3 lines
Diff to previous 1.54 (colored)

either set or unset variables that are to be examined further on, don't
just leave them untouched

ok ajacoutot@ sthen@ schwarze@

Revision 1.54 / (download) - annotate - [select for diffs], Wed Oct 12 23:04:02 2011 UTC (12 years, 7 months ago) by schwarze
Branch: MAIN
Changes since 1.53: +3 -2 lines
Diff to previous 1.53 (colored)

Localize _new_pexp unconditionally, or rc_read_runfile()
might pick it up from a polluted environment.
Requested by halex@, ok ajacoutot@ halex@

Revision 1.53 / (download) - annotate - [select for diffs], Sun Oct 9 16:46:55 2011 UTC (12 years, 7 months ago) by schwarze
Branch: MAIN
Changes since 1.52: +3 -2 lines
Diff to previous 1.52 (colored)

When the _RC_RUNFILE (by some ill chance) happened to be empty or
reading it failed, ${pexp} ended up as the empty string and the script
would send SIGTERM to init(1), which was really inconvenient.
Fix that by never allowing pexp to become empty.
My patch considerably simplified by and ok  ajacoutot@.

Revision 1.52 / (download) - annotate - [select for diffs], Sun Oct 9 08:48:53 2011 UTC (12 years, 7 months ago) by ajacoutot
Branch: MAIN
Changes since 1.51: +22 -1 lines
Diff to previous 1.51 (colored)

Finally make it possible to restart/stop a daemon after having changed
its _flags in rc.conf(8).
When the rc.d(8) system starts a daemon, it will record its pexp under
/var/run/rc.d/rcscriptname and use that to interact with it (errors in
creating /var/run/rc.d or missing pexp file are non fatal, the framework
will just fallback to what it currently does).

deraadt@ doesn't mind a long as it doesn't come in the way of people
manually managing their daemons.

discussed with and input from sthen@ halex@ robert@ schwarze@
ok sthen@ robert@

Revision 1.51 / (download) - annotate - [select for diffs], Fri Oct 7 07:26:49 2011 UTC (12 years, 7 months ago) by ajacoutot
Branch: MAIN
Changes since 1.50: +3 -4 lines
Diff to previous 1.50 (colored)

Check if we are root right from the start.

ok robert@

Revision 1.50 / (download) - annotate - [select for diffs], Fri Oct 7 07:17:25 2011 UTC (12 years, 7 months ago) by ajacoutot
Branch: MAIN
Changes since 1.49: +12 -10 lines
Diff to previous 1.49 (colored)

Prepend an underscore to internal variable names; this was reverted by
mistake in the previous commit.
No functionnal change.

ok robert@

Revision 1.49 / (download) - annotate - [select for diffs], Sun Sep 25 17:55:14 2011 UTC (12 years, 8 months ago) by halex
Branch: MAIN
Changes since 1.48: +9 -7 lines
Diff to previous 1.48 (colored)

revert previous and pass on the RC_DEBUG and RC_FORCE flags in the start+stop
dance on restart rather than exporting them and expose the script to a
potentially polluted environment

ok ajacoutot@ robert@

Revision 1.48 / (download) - annotate - [select for diffs], Sat Sep 24 17:35:15 2011 UTC (12 years, 8 months ago) by ajacoutot
Branch: MAIN
Changes since 1.47: +7 -8 lines
Diff to previous 1.47 (colored)

Repair "restart" debug and force modes (we need to export RC_DEBUG and
RC_FORCE since "restart" calls "stop" then "start").
While here, append "_" to these variable names to make it clear they are
internal.

ok robert@

Revision 1.47 / (download) - annotate - [select for diffs], Thu Sep 22 08:15:01 2011 UTC (12 years, 8 months ago) by ajacoutot
Branch: MAIN
Changes since 1.46: +9 -2 lines
Diff to previous 1.46 (colored)

Add missing "*)" case statement and make sure RC_DEBUG and RC_FORCE are
unset beforehands; prodded by halex@

Add rc_usage().

ok halex@

Revision 1.46 / (download) - annotate - [select for diffs], Mon Sep 19 20:41:50 2011 UTC (12 years, 8 months ago) by robert
Branch: MAIN
Changes since 1.45: +11 -2 lines
Diff to previous 1.45 (colored)

Use arugments for rc script instead of environment variables to indicate
debug mode.
This commit also adds a force mode for the script to allow one to force
operations even if daemon_flags is set to NO.
In this case the sane default values will be used for each script.

e.g.: "/etc/rc.d/foo -f start" will start sshd even if it's disabled

ok ajacoutot@

Revision 1.45 / (download) - annotate - [select for diffs], Sun Jul 31 20:22:34 2011 UTC (12 years, 10 months ago) by robert
Branch: MAIN
CVS Tags: OPENBSD_5_0_BASE, OPENBSD_5_0
Changes since 1.44: +3 -3 lines
Diff to previous 1.44 (colored)

when reloading do an rc_wait instead of just an rc_check
from david@, okay sthen@ and input from schwarze@

Revision 1.44 / (download) - annotate - [select for diffs], Sun Jul 31 20:18:45 2011 UTC (12 years, 10 months ago) by robert
Branch: MAIN
Changes since 1.43: +2 -2 lines
Diff to previous 1.43 (colored)

redirect rc_err() output to stderr, from david@

Revision 1.43 / (download) - annotate - [select for diffs], Sat Jul 23 22:41:44 2011 UTC (12 years, 10 months ago) by sthen
Branch: MAIN
Changes since 1.42: +6 -2 lines
Diff to previous 1.42 (colored)

Print the daemon name before starting, and ok/failed afterwards, providing
better visual cues as to what's happening. Feedback/ok aja@ schwarze@

Revision 1.42 / (download) - annotate - [select for diffs], Fri Jul 8 18:57:49 2011 UTC (12 years, 10 months ago) by robert
Branch: MAIN
Changes since 1.41: +18 -1 lines
Diff to previous 1.41 (colored)

add license, ok ajacoutot@, deraadt@

Revision 1.41 / (download) - annotate - [select for diffs], Thu Jul 7 17:37:30 2011 UTC (12 years, 10 months ago) by ajacoutot
Branch: MAIN
Changes since 1.40: +3 -2 lines
Diff to previous 1.40 (colored)

Fix reload:
* if we try to reload a non running daemon, just exit gracefully, like
we do for 'stop'
* add an rc_check call right after rc_reload to make sure the daemon is
still around; until now we only checked the pkill(1) return code but
that is not enough

ok robert@

Revision 1.40 / (download) - annotate - [select for diffs], Wed Jul 6 18:55:36 2011 UTC (12 years, 10 months ago) by robert
Branch: MAIN
Changes since 1.39: +2 -2 lines
Diff to previous 1.39 (colored)

Add rc.d(8) script for the system daemons that are restartable.
From now on rc(8) is going to call these scripts to start them up on boot
in the same order than before.
In addition the inetd and rwhod variables in rc.conf are deprecated so that
inetd_flags and rwhod_flags should be used. The old flags are still going
to be used for some time to allow users to switch.
There are more rc modifications to come later so let's put this in so
we can base more work on this.
It is important to mention that you can still keep using rc.local just
like the way you did before, and we have no intention to remove that either.

I'd also like to thank ajacoutot@, halex@, sthen@ and schwarze@ for working
on this with me.

Revision 1.39 / (download) - annotate - [select for diffs], Sun Jul 3 16:09:06 2011 UTC (12 years, 11 months ago) by schwarze
Branch: MAIN
Changes since 1.38: +3 -2 lines
Diff to previous 1.38 (colored)

let reload report (ok) or (failed) just like all other actions;
ajacoutot@ and robert@ couldn't really remember the reason to be different,
either

Revision 1.38 / (download) - annotate - [select for diffs], Mon Jun 20 21:26:27 2011 UTC (12 years, 11 months ago) by schwarze
Branch: MAIN
Changes since 1.37: +24 -35 lines
Diff to previous 1.37 (colored)

Refactoring for simplicity, no functional change:
* Instead of nesting subshells, perform a linear series of operations
and bail out as soon as one of them fails.
* Rename rc_print to rc_exit, let it calculate the exit code itself
and let it exit, considerably simplifying error handling; new name
suggested by sthen@.
OK ajacoutot@ sthen@

Revision 1.37 / (download) - annotate - [select for diffs], Fri Jun 10 08:43:26 2011 UTC (12 years, 11 months ago) by ajacoutot
Branch: MAIN
Changes since 1.36: +28 -6 lines
Diff to previous 1.36 (colored)

Finally deal with background processes: "rc_cmd start" will now return
the correct code according whether the daemon did start successfully or
not.

rc_wait()
This function has been extended, first we need to pass in which mode we
are running (start or stop) and second we can pass a number of seconds
to wait (optionnal, will default to 30s).
The function will return the correct code whether we are running during
"rc_cmd start" or "rc_cmd stop".

rc_cmd() start
If we are running in background mode, then we call rc_wait with the
"start" argument.
The sleep(1) is needed to prevent a race condition where the process
will appear in the list before failing and rc_check will see it as
running. Call rc_post() when failing to prevent being left in an
inconsistent state (because rc_pre() would have run successfully)

rc_cmd() stop
We are now calling rc_wait with the "stop" argument.

"looks good" sthen@, ok robert@

Revision 1.36 / (download) - annotate - [select for diffs], Thu May 19 09:50:50 2011 UTC (13 years ago) by ajacoutot
Branch: MAIN
Changes since 1.35: +2 -2 lines
Diff to previous 1.35 (colored)

Setting RC_DEBUG is enough, it does not need to be explicitely set to
"1".

hint from MERIGHI Marcus
ok robert@

Revision 1.35 / (download) - annotate - [select for diffs], Sat Apr 9 15:39:22 2011 UTC (13 years, 1 month ago) by schwarze
Branch: MAIN
Changes since 1.34: +3 -2 lines
Diff to previous 1.34 (colored)

Fix multiple issues and make the code simpler and more robust:
 - As noticed by ajacoutot@, re_format(7) does not treat '\t' as a tab,
   so some t's got stripped from daemon names.
 - The tr(1) failed to sanitize mixtures of blanks and tabs.
ok ajacoutot@

Revision 1.34 / (download) - annotate - [select for diffs], Wed Apr 6 17:10:38 2011 UTC (13 years, 1 month ago) by robert
Branch: MAIN
Changes since 1.33: +4 -3 lines
Diff to previous 1.33 (colored)

- in case reload fails, print the failed message (from Piotr Sikora)
- (ok) is only printed while in interactive mode, but (failed) stays
  even for rc if the command fails

ok ajacoutot@

Revision 1.33 / (download) - annotate - [select for diffs], Wed Apr 6 06:09:28 2011 UTC (13 years, 1 month ago) by ajacoutot
Branch: MAIN
Changes since 1.32: +2 -2 lines
Diff to previous 1.32 (colored)

Remove leading/trailing spaces from daemon_flags.

ok schwarze@

Revision 1.32 / (download) - annotate - [select for diffs], Tue Apr 5 13:57:57 2011 UTC (13 years, 2 months ago) by guenther
Branch: MAIN
Changes since 1.31: +2 -2 lines
Diff to previous 1.31 (colored)

Handle a daemon_flags of '-n' by using printf '%s\n' instead of echo
ok otto@, aja@

Revision 1.31 / (download) - annotate - [select for diffs], Tue Apr 5 11:47:32 2011 UTC (13 years, 2 months ago) by ajacoutot
Branch: MAIN
Changes since 1.30: +2 -2 lines
Diff to previous 1.30 (colored)

Quote $daemon_flags to prevent echo(1) picking them as input flags.

from Piotr Sikora
ok robert@

Revision 1.30 / (download) - annotate - [select for diffs], Fri Mar 25 10:03:26 2011 UTC (13 years, 2 months ago) by ajacoutot
Branch: MAIN
Changes since 1.29: +2 -2 lines
Diff to previous 1.29 (colored)

Bump timeout to 30s.

ok robert@

Revision 1.29 / (download) - annotate - [select for diffs], Thu Mar 24 07:28:31 2011 UTC (13 years, 2 months ago) by robert
Branch: MAIN
Changes since 1.28: +3 -1 lines
Diff to previous 1.28 (colored)

if daemon_flags=NO is set, just exit
ok ajacoutot@

Revision 1.28 / (download) - annotate - [select for diffs], Sat Mar 19 19:03:57 2011 UTC (13 years, 2 months ago) by ian
Branch: MAIN
Changes since 1.27: +2 -2 lines
Diff to previous 1.27 (colored)

Since we now use pkill -0 for "check", it must be run as root,
so remove that test condition. Commented by schwarze@, OK ajacoutot@

Revision 1.27 / (download) - annotate - [select for diffs], Thu Mar 17 16:43:51 2011 UTC (13 years, 2 months ago) by robert
Branch: MAIN
Changes since 1.26: +40 -16 lines
Diff to previous 1.26 (colored)

- introduce the INRC environment variable so that rc.subr(8) knows if it
  gets called from rc.local or rc.shutdown
- notify the user if a given operation was successfull or not by appending
  the (ok) or (failed) strings to the end of the daemon name
- hide stdout and stdin unless RC_DEBUG=1 is set, otherwise all the function
  names will be printed out and all output sent to stdin or stdout
- since from now on rc.subr is taking care of printing out the daemon names
  on startup, we don't need to do this from rc.{local,shutdown} anymore

brainkilling work done by me and ajacoutot@, ok ajacoutot@

Revision 1.26 / (download) - annotate - [select for diffs], Mon Mar 14 11:28:44 2011 UTC (13 years, 2 months ago) by ajacoutot
Branch: MAIN
Changes since 1.25: +23 -13 lines
Diff to previous 1.25 (colored)

Return proper codes so that we don't rc_start if rc_pre failed and we
don't rc_post if rc_stop failed.

"I agree with the direction" sthen@
ok robert@

Revision 1.25 / (download) - annotate - [select for diffs], Thu Mar 10 10:21:39 2011 UTC (13 years, 2 months ago) by ajacoutot
Branch: MAIN
Changes since 1.24: +8 -6 lines
Diff to previous 1.24 (colored)

Add a small comment at the top to explain what this file does.
Use $() constructs as it's safer than ``.
Both req. by deraadt@

Use pkill instead of pgrep in rc_check so that we don't need to fiddle
with redirections in reload.
prodded by schwarze@

ok robert@

Revision 1.24 / (download) - annotate - [select for diffs], Wed Mar 9 19:37:16 2011 UTC (13 years, 2 months ago) by ajacoutot
Branch: MAIN
Changes since 1.23: +4 -4 lines
Diff to previous 1.23 (colored)

Make reload and check consistent with start/stop.

ok robert@

Revision 1.23 / (download) - annotate - [select for diffs], Wed Mar 9 18:50:46 2011 UTC (13 years, 2 months ago) by ajacoutot
Branch: MAIN
Changes since 1.22: +4 -4 lines
Diff to previous 1.22 (colored)

Move the redirections into the rc_cmd itself instead of rc_start and
rc_stop so scripts don't need to set it.

ok sthen@ (on a much bigger diff) robert@

Revision 1.22 / (download) - annotate - [select for diffs], Wed Mar 9 09:10:44 2011 UTC (13 years, 2 months ago) by ajacoutot
Branch: MAIN
Changes since 1.21: +13 -9 lines
Diff to previous 1.21 (colored)

Move rc_pre and rc_post out of the rc_start/rc_stop functions into the
rc_cmd start/stop actions. This way when rc.d(8) scripts override these
functions, we don't loose rc_{pre,post}.

Add a max 5 secs loop after rc_stop in the rc_cmd top action. This seems
to be a good default for returning to command line only after the daemon
has really stopped. This fixes "restart" for some daemons and allows to
properly stop some others at shutdown time.
Note that this is just a best-effort default, some daemons may need a
lot more time to shutdown but this case is usually handled in the
rc.d(8) script itself and we obviously do not want to hang the shutdown
process.

Call rc_cmd start/stop in restart and _not_ rc_start/rc_stop which can
get overriden in a script.

discussed with and inputs from sthen@ and schwarze@
ok sthen@ robert@

Revision 1.21 / (download) - annotate - [select for diffs], Sun Mar 6 16:49:48 2011 UTC (13 years, 2 months ago) by ajacoutot
Branch: MAIN
Changes since 1.20: +4 -2 lines
Diff to previous 1.20 (colored)

Add an "rc_bg" variable that is undefined by default and allows to start
a daemon in the background.

man page tweaks from schwarze@
discussed with an ok schwarze@ robert@

Revision 1.20 / (download) - annotate - [select for diffs], Thu Feb 24 07:07:03 2011 UTC (13 years, 3 months ago) by ajacoutot
Branch: MAIN
CVS Tags: OPENBSD_4_9_BASE, OPENBSD_4_9
Changes since 1.19: +2 -5 lines
Diff to previous 1.19 (colored)

Remove daemon_shell and force the use of /bin/sh for the su(1) call.

ok robert@ espie@ miod@

Revision 1.19 / (download) - annotate - [select for diffs], Wed Jan 5 16:04:21 2011 UTC (13 years, 4 months ago) by ajacoutot
Branch: MAIN
Changes since 1.18: +3 -4 lines
Diff to previous 1.18 (colored)

Put the "su -c ..." command into an rcexec variable so that we can
easily use it in rc scripts instead of copying/pasting the same huge
command lines everywhere.

ok robert@ sthen@

Revision 1.18 / (download) - annotate - [select for diffs], Tue Jan 4 16:02:24 2011 UTC (13 years, 5 months ago) by ajacoutot
Branch: MAIN
Changes since 1.17: +6 -5 lines
Diff to previous 1.17 (colored)

Check for a login class that match the rc script name and if we find one
let's use it. If not, then fall back to using daemon.
While here, do some reordering.

"I like this" sthen@, ok robert@

Revision 1.17 / (download) - annotate - [select for diffs], Wed Dec 29 15:28:01 2010 UTC (13 years, 5 months ago) by ajacoutot
Branch: MAIN
Changes since 1.16: +22 -25 lines
Diff to previous 1.16 (colored)

After the recent changes, there is no need for an rc_conf function.
As schwarze@ also stated, this will prevent anyone from calling it
(which would be an error) and makes it clearer that rc.subr is not just
a functions container.

No functionnal change, unless you were calling rc_conf from an rc script
which would have been wrong anyway.

ok schwarze@ robert@

Revision 1.16 / (download) - annotate - [select for diffs], Mon Dec 27 14:49:05 2010 UTC (13 years, 5 months ago) by ajacoutot
Branch: MAIN
Changes since 1.15: +4 -3 lines
Diff to previous 1.15 (colored)

There is no point in calling rc_conf manually from each and every rc
script; instead, rc.subr can call rc_conf itself right after reading in
rc.conf.

from schwarze@ (committing on his behalf)
ok robert@

Revision 1.15 / (download) - annotate - [select for diffs], Fri Dec 24 10:37:24 2010 UTC (13 years, 5 months ago) by ajacoutot
Branch: MAIN
Changes since 1.14: +22 -13 lines
Diff to previous 1.14 (colored)

Fix a flaw in the rc.subr framework reported by stephan@ where
local_rcconf would get overwritten by flags from the rc script itself.

Based on an original idea and diff from robert@, create an rc_conf
function that we add in the rc_script after the defaults daemon*
variables.
This way we can use defaults variables names in other part of the script
(when defining a specific pexp for instance).

While here, simplify setting up the default daemon variables so that we
don't need to do any substitution in rc_start.

rc scripts must include daemon variables before calling rc_conf. All
other locally modified variables (pexp, rc_reload, local additions...)
must come after.

feedback from and works for sthen@
ok robert@

Revision 1.14 / (download) - annotate - [select for diffs], Mon Dec 13 16:06:45 2010 UTC (13 years, 5 months ago) by ajacoutot
Branch: MAIN
Changes since 1.13: +2 -2 lines
Diff to previous 1.13 (colored)

Prefer '-l' over '-' which is deprecated.

Also noticed and agreed by eric@
ok robert@

Revision 1.13 / (download) - annotate - [select for diffs], Mon Dec 13 15:27:27 2010 UTC (13 years, 5 months ago) by robert
Branch: MAIN
Changes since 1.12: +2 -2 lines
Diff to previous 1.12 (colored)

simulate a full login with su, now that the environment is fine after
the last su(1) commit

Revision 1.12 / (download) - annotate - [select for diffs], Sat Dec 11 12:57:21 2010 UTC (13 years, 5 months ago) by ajacoutot
Branch: MAIN
Changes since 1.11: +3 -1 lines
Diff to previous 1.11 (colored)

Make it possible to mark an rc action as unsupported by setting the
corresponding variable to NO.
e.g.
rc_reload=NO

This will save us the trouble of copying the same rc_reload() function
(or others) all over the tree.

ok robert@

Revision 1.11 / (download) - annotate - [select for diffs], Sat Dec 11 10:15:23 2010 UTC (13 years, 5 months ago) by ajacoutot
Branch: MAIN
Changes since 1.10: +2 -1 lines
Diff to previous 1.10 (colored)

Sanitise daemon_flags: remove multiple whitespaces from _rcflags.

requested by okan@, ok robert@

Revision 1.10 / (download) - annotate - [select for diffs], Sat Dec 11 09:55:37 2010 UTC (13 years, 5 months ago) by robert
Branch: MAIN
Changes since 1.9: +10 -5 lines
Diff to previous 1.9 (colored)

Do not overwrite the settings in the rc scripts itself, so use the same
method to handle  _class, _user and _shell as we do for _flags.

discussed with and ok ajacoutot@

Revision 1.9 / (download) - annotate - [select for diffs], Fri Dec 10 21:25:50 2010 UTC (13 years, 5 months ago) by robert
Branch: MAIN
Changes since 1.8: +6 -2 lines
Diff to previous 1.8 (colored)

Add support for setting _user _class and _shell for a specific daemon,
and use su to start the daemons.
By default if there is no class defined, daemon will be used. For a shell
it defaults to /bin/sh.

Revision 1.8 / (download) - annotate - [select for diffs], Thu Oct 28 21:36:45 2010 UTC (13 years, 7 months ago) by robert
Branch: MAIN
Changes since 1.7: +1 -4 lines
Diff to previous 1.7 (colored)

remove my debug printf

Revision 1.7 / (download) - annotate - [select for diffs], Thu Oct 28 21:03:33 2010 UTC (13 years, 7 months ago) by robert
Branch: MAIN
Changes since 1.6: +10 -2 lines
Diff to previous 1.6 (colored)

After discussing with Ingo and Antoine we decided to rename
files to not include -. This way we can easily overwrite
daemon flags from rc.conf.local.

Revision 1.6 / (download) - annotate - [select for diffs], Thu Oct 28 15:36:37 2010 UTC (13 years, 7 months ago) by robert
Branch: MAIN
Changes since 1.5: +2 -0 lines
Diff to previous 1.5 (colored)

add $

Revision 1.5 / (download) - annotate - [select for diffs], Wed Oct 27 13:34:21 2010 UTC (13 years, 7 months ago) by ajacoutot
Branch: MAIN
Changes since 1.4: +7 -7 lines
Diff to previous 1.4 (colored)

Protect variable names, to be consistent with rc(8).

ok robert@

Revision 1.4 / (download) - annotate - [select for diffs], Wed Oct 27 13:08:53 2010 UTC (13 years, 7 months ago) by robert
Branch: MAIN
Changes since 1.3: +2 -2 lines
Diff to previous 1.3 (colored)

Remove 'status', because 'check' is what is used internally and we don't
need two functions doing the same thing, and also allow check to run as
non-root.

Revision 1.3 / (download) - annotate - [select for diffs], Wed Oct 27 10:27:03 2010 UTC (13 years, 7 months ago) by robert
Branch: MAIN
Changes since 1.2: +1 -1 lines
Diff to previous 1.2 (colored)

Missing redirection to /dev/null in rc_start

Revision 1.2 / (download) - annotate - [select for diffs], Wed Oct 27 08:53:21 2010 UTC (13 years, 7 months ago) by robert
Branch: MAIN
Changes since 1.1: +2 -2 lines
Diff to previous 1.1 (colored)

quote $local_rcconf in [ ] and remove eval from rc_start()

Revision 1.1 / (download) - annotate - [select for diffs], Tue Oct 26 20:56:03 2010 UTC (13 years, 7 months ago) by robert
Branch: MAIN

Add a simple 'rc' system to base in order to start/stop/restart/reload
services installed by the ports system (for now).
It only uses pgrep/pkill to handle these processes. A manual page will
come later.

'put it in' deraadt@

This form allows you to request diff's between any two revisions of a file. You may select a symbolic revision name using the selection box or you may type in a numeric name using the type-in text box.