Commit Graph

111 Commits

Author SHA1 Message Date
andvar f42f89fd6f fix various small typos, mainly in comments. 2022-05-22 11:27:33 +00:00
alnsn 082b9a1ec4 Small changes in mount_critical_filesystems_zfs
avoid unnecessary eval, switch to $() and -ne.

from kre@, thanks!
2022-02-06 16:23:12 +00:00
alnsn a8b6a164d2 Compare $_mount_es with 0 2022-02-03 21:02:47 +00:00
alnsn ae342f4716 Add mount_critical_filesystems_zfs
The new function is similar to mount_critical_filesystems
but it walks through ZFS datasets and mounts matching entries.
2022-02-03 20:52:44 +00:00
christos 0a50b87edf Set the path unconditionally to what rc sets it to, so that when running
individual scripts like 'env - /etc/rc.d/syslogd restart' programs like
rcorder are found.
2021-11-06 23:11:43 +00:00
uwe c34ee3711d run_rc_command - don't prefix the rcvar variable name with the dollar sign.
The output without the dollar sign is less confusing as it's actual
valid shell syntax:

  $ /etc/rc.d/foo rcvar
  # food
  food=YES

Brought up on tech-userlevel@ by Rocky Hotas with some LGTMs from
other people and no objections.

We still refer to '$food' in warnings/errors though.
2020-12-20 21:30:28 +00:00
otis 5af20f9893 Fix waiting for PIDs on stop.
Fix expansion of positional parameters. Also move the local
variable declaration to more apropriate place.
2020-09-17 20:29:03 +00:00
christos 3dd07195ab Prevent waiting for processes to exit forever by introducing _rc_kill_ntries,
which if set, will SIGKILL the processes that did not die yet.
2020-04-05 21:03:08 +00:00
kre e063fa5f54 rc.subr can be used in install images (from sysinst) so must use only
POSIX specified test uses (no -a or -o).   Also, use printf always,
rather than echo (replace echo as a function using echo with one which
uses printf).
2018-09-23 23:02:39 +00:00
christos 7e6759edb0 Hide ps error about processes not found (we could be more specific...)
It is superfluous, since we print:
    foo not running? (check /var/run/foo/foo.pid).
2018-04-11 18:51:22 +00:00
kre 7d5ae540ad PR misc/53145 (Bruce Lilly)
Use ps -A instead of ps -ax (-A means -ax, but -A is posix, -x is not)
Use ps -o args instead of ps -o command (same reason).

This makes no difference when the ps used is /bin/ps on NetBSD, but
can make a difference when some other ps command gets invoked instead.

XXX pullup -8
2018-04-01 18:26:51 +00:00
christos bb9e7fd375 remove env. 2017-04-13 02:15:36 +00:00
christos bda2cfe499 Clear rc variables that contain state that is gone after the boot process
is complete, so that scripts invoked from powerd don't think that they
are still invoked by the rc system and fail.
Reported by rudolf @ tech-userlevel
2017-03-21 22:52:10 +00:00
christos 709030f1f5 Introduce kat() a built-in version of cat(1) that strips shell-like comments. 2016-03-06 18:49:42 +00:00
phx 8e58c9596b PR misc/50046
Remove the expensive tests in _have_rc_postprocessor(), as proposed by apb@.
It more than halves the multiuser boot time on slow machines and brings
it back near to the previous level.
2015-10-31 12:31:37 +00:00
roy ccc4fd50bb sleep for 0.05 seconds instead of 2 seconds when checking if the pids
are still alive for a much faster exit.
2014-10-07 19:09:45 +00:00
roy 56e4b525ee Add checkyesnox function so we can test a configurable without
being warned of its non-existance.
2014-09-21 09:47:24 +00:00
apb 7bc384757f In rc.subr, add _have_rc_postprocessor function and use it instead of
inline tests like [ -n "${_rc_postprocessor_fd}" ]. The new function
performs a few new tests, including verifying that /etc/rc is still
running (using a new _rc_pid variable set by /etc/rc).

This is intended to deal with the case that a script run from /etc/rc
spawns a background process, then /etc/rc exits, but the background
process still has environment variables inherited from /etc/rc.

Fixes PR 46546.
2014-07-27 07:46:46 +00:00
wiz 7f6fa64667 'file system' for consistency with documentation (instead of 'filesystem'). 2014-07-22 17:11:09 +00:00
apb 532fa0d9ae Add shell implementations of basename and dirname to rc.subr. They
are supposed to mimic basename(1) and dirname(1), except that they
are usable before /usr/bin is mounted.
2012-12-17 18:17:27 +00:00
christos 850b856e4a back out change that makes onestart work, to be committed at some other time. 2012-04-07 17:28:44 +00:00
christos 05e9a23818 give wedges to everyone 2012-04-07 17:22:10 +00:00
apb f932526a86 The error message when /var is not a file system chhanged from
mount: unknown special file or file system `/var'
to
mount: Unknown special file or file system `/var'
so match them both.
2012-04-07 16:39:32 +00:00
apb 7535058544 Allow "echo -n" to work as expected in rc.d scripts that are executed
by /etc/rc.  Similarly for printf with a format that does not end with
"\n".  Previously, the partial line would not be visible on the console
until a newline was printed, possibly after an annoying delay.

This is done by adding echo() and printf() shell functions to rc.subr,
so that naive use of the echo and printf commands in rc.d scripts will
call these functions instead of the underlying commands.  These shell
functions send a new "nop" metadata message after the partial line, and
the rc_postprocess function in /etc/rc disentangles the partial line of
plain output from the metadata "nop".

Also add a "-n" option to the print_rc_normal function in rc.subr,
and make some cosmetic changes.
2011-08-11 22:52:46 +00:00
christos 3a128b33dc PR/42642: Ed Ravin: Handle daemons that start with #!/usr/bin/env interp 2011-06-09 14:52:01 +00:00
apb f265a7c0e8 Add a collapse_backslash_newline function to rc.subr. 2010-09-26 18:37:14 +00:00
christos 2ae8ee3aef use modulo instead of logical and. from pooka 2010-06-08 18:04:17 +00:00
christos a3299c9005 explain why this code is there. 2010-06-08 13:48:58 +00:00
christos d6169708b4 fix conditional, from dholland. 2010-06-06 12:37:57 +00:00
christos 520fd1e568 print human readable exit code. 2010-06-04 18:42:54 +00:00
jmmv bff64ddc47 Allow the run_rc_command function in rc.subr to pass extra parameters to
the command being executed.  This is to allow rc.d scripts to do:

    run_rc_command "${@}"

instead of:

    run_rc_command "${1}"

and let the command handler (start, stop, etc.) receive the arguments after
the command name.

None of the default commands allow extra arguments, and they will error out
if any are given.  This is mostly useful for script-specific commands that
are only supposed to be used through the command line and, therefore, need
to provide a friendly interface.

Proposed in tech-userlevel@.  No major objections except for some minor
concerns regarding whether this should be allowed or not at all.  Note that
I'm not touching any of the rc.d scripts in the base system, so this is
effectively a no-op from the user point of view.
2010-03-15 18:59:47 +00:00
apb 1e2ed7f3ca Fix some errors in the way scripts with "KEYWORD: interactive"
are handled.  There was an inverted test, and "set $_args"
had the wrong scope (in several nearly-identical blocks of code).
2009-09-14 22:30:30 +00:00
apb 70472a4826 Add the ability for file systems mounted via mount_critical_filesystems()
in rc.subr to be marked as optional.  This means that it's not an
error if the file system is not mentioned in /etc/fstab.  It is
still an error if something else goes wrong.

Change the defaults for these two variables in /etc/defaults/rc.conf:
critical_filesystems_local="OPTIONAL:/var"
critical_filesystems_remote="OPTIONAL:/usr"
2009-09-14 12:05:12 +00:00
apb 89fd535731 Add a postprocessor to /etc/rc, which logs messages to /var/run/rc.log,
and which can suppress output in silent mode.  Silent mode is enabled
via the new rc_silent variable, which defaults to a value that depends
on the kern.boothowto sysctl.

Part of the /etc/rc silent changes requested in PR 41946
and proposed in tech-userlevel.
2009-09-11 18:17:04 +00:00
apb cd291484dc Change multiple spaces to tabs on one line 2009-09-05 16:45:33 +00:00
christos 87fc4e29f5 1. centralize the fsck error handling
2. don't check if root is on nfs
3. reboot -n if root was modified as the manual page suggests
2009-07-10 20:02:21 +00:00
reed 9a8032873e Get rid of extra space in Usage statement. 2009-04-28 03:03:52 +00:00
salo 74bbb8ef72 A very old patch sitting in my tree..
When rc scripts are started from interactive shell, be nice and when user
tries to start an unconfigured service, point him to rc.conf(5) and tell
him about the one* keyword.  Also be more user friendly when an unknown
argument is entered.

Example:

 # /etc/rc.d/cron start
 $cron is not enabled - see rc.conf(5).
 Use the following if you wish to perform the operation:
   /etc/rc.d/cron onestart

 # /etc/rc.d/cron nonsense
 /etc/rc.d/cron: unknown directive 'nonsense'.
 Usage: /etc/rc.d/cron [fast|force|one](start stop restart rcvar  status poll)


Inspired by discussion on tech-userlevel:

 http://mail-index.netbsd.org/tech-userlevel/2007/02/13/0010.html
 http://mail-index.netbsd.org/tech-userlevel/2007/02/13/0011.html
 http://mail-index.netbsd.org/tech-userlevel/2007/02/13/0012.html

Reminded about it and reviewed by <lukem>
2008-12-06 23:21:32 +00:00
dholland dbdaee06a4 fix typo 2008-06-23 03:26:18 +00:00
he 4ff90c621b Add support for optionally setting some environment variables before
starting ${command}, via ${name}_env.

Discussed with lukem.
2008-05-22 14:03:26 +00:00
martin 11a6dbe728 Convert TNF licenses to new 2 clause variant 2008-04-30 13:10:46 +00:00
ad 2ecdf58c2c Remove systrace. Ok core@. 2007-12-31 15:31:24 +00:00
apb 31edfc6f0f * Add a stop_boot() function in rc.subr, to terminate a multi-user boot
by killing the parent process.  The parent's PID is saved in $RC_PID.
* In all rc.d/* scripts that previously tried to stop the boot,
  replace in-line code with "stop_boot".
* Document this.

This should fix PR 29822.
2007-04-06 14:20:08 +00:00
hubertf 78b99d6807 _find_processes(): in addition to the existing "interpreter: /path/to/daemon"
also recognize "interpreter: daemon" in ps(1) output.

That case statement should be rewritten with expr(1) if more flexibility is
needed.

Fixes PR 35366 by Dominik Joe Pantucek, debugged with much assistance
by him on IRC.
2007-01-27 14:30:26 +00:00
elad fa3f94a430 PR/32004: Ed Ravin: command interpreter test in rc.subr doesn't accomodate
chroots

Patch applied, thanks!

okay apb@
2006-10-07 11:25:15 +00:00
he 5e1904ecea In order to handle some perl scripts running as daemons, add a
pattern which also matches "`basename $interpreter`: $command" in the
ps listing.  Should fix PR#31932.
2006-04-01 10:05:50 +00:00
lukem 3c81b28a9a * Implement
load_rc_config_var cmd var
  to load the rc.conf(5) configuration for cmd and set var in the
  current shell, using 'load_rc_config var' in a sub-shell to avoid
  unwanted side-effects.

* Improve required_vars warning message.
2004-10-12 14:45:29 +00:00
mycroft 7d2e1537c5 Add an _rc_subr_loaded variable, set to ":" by rc.subr. Scripts can use this
for a speedup by doing:
$_rc_subr_loaded . /etc/rc.subr
2004-08-13 18:08:03 +00:00
lukem 9bd9220cd7 When performing "start", "stop" or "reload" in run_rc_command(),
send any "<name> already running" or "<name> not running" messages
to stderr instead of stdout before the (existing) non-zero exit.
2004-05-03 14:52:26 +00:00
jmmv 3c8a1444d9 Introduce and use the rcvar_manpage variable, which contains the manual page
name where the user should look at for documentation about rcvar.  It defaults
to 'rc.subr(5)', as rc.subr is mainly used by rc.d scripts.

This variable is useful to let the daily, weekly, monthly and security scripts
tune the warning message shown when any of the variables they handle is not
properly set.

Closes PR misc/23908.
2004-04-02 13:13:47 +00:00