Commit Graph

101 Commits

Author SHA1 Message Date
martin 82aec3fc35 Pull up following revision(s) (requested by kre in ticket #689):
etc/rc.subr: revision 1.101

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-04 16:07:33 +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
lukem f3bab2a8fc Implement ``one'' prefix to allow a "one shot" operation as if
${rcvar}=yes yet all the other prerequisite tests are still performed.
The existing ``force'' prefix is a sledgehammer that ignores all the
prerequisite checks and always returns a zero exit status; this is a
more gentle approach to the problem of "manipulate this disabled
service without editing rc.conf(5)".
2004-01-06 00:52:24 +00:00
lukem 6d7e3e1b0d Add "*,v" to the list of scratch files to skip.
Suggested by Johnny Lam / Alistair Crooks
2003-07-26 05:13:47 +00:00
lukem 8026bccd2c Revert previous; the "return" if rc.subr had already loaded had issues
in some circumstances where run_rc_script()'s sourcing of an rc.d file
which then sourced rc.subr, the `optimisation' in rc.subr to "return as
we're already loaded" would finish more than just the inner-most sourcing.
I haven't tracked down the exact issue, but removing the `optimisation'
fixes the problem I noticed in starting up certain rc.d scripts, and
may fix [bin/22053] as well.
2003-07-04 14:14:10 +00:00
lukem 151e9a3180 If _rc_subr_loaded=true, "return" immediately, otherwise set that var
and continue as normal.
Gains ~ 2 seconds on 110 runs of ". rc.subr" on a shark.
Suggested by Andrew Cagney in [bin/18400]
2003-06-27 05:01:21 +00:00
lukem e85d25db42 run_rc_command(): when checking if ${command} exists before executing it,
be sure to check under ${name_chroot} (if set).
Fix from Ed Ravin in [bin/18523]
2003-06-27 04:06:01 +00:00
christos b224530c28 Use more concise shell syntax:
1. for i in $* -> for i
2. foo=$* -> foo="$@"
2003-06-03 14:00:45 +00:00
lukem ef98b9ddca Fix logic error I introduced recently into mount_critical_filesystems().
Noted by kilbi@rad.rwth-aachen.de in [bin/19703].
2003-01-05 22:59:35 +00:00
lukem dd2a7e0da5 'if ! command;' is not POSIX sh, even though our /bin/sh supports it 2003-01-05 11:40:29 +00:00
lukem 15388316f6 Change how internal boolean variables are used to:
if ! ${_somevar:-false}; then
		_somevar=true
	fi
(Consisent, slightly quicker, and slightly cleaner)
2003-01-04 15:27:43 +00:00
abs 9f39802939 Append ' - see rc.conf(5)' to unset variable warning:
/etc/rc.d/fu: WARNING: $fu is not set properly - see rc.conf(5).
Add a note to rc.conf that third party packages may test for additional
variables.
2002-08-26 17:46:57 +00:00