1.\" $NetBSD: rc.subr.8,v 1.12 2004/01/06 00:52:24 lukem Exp $ 2.\" 3.\" Copyright (c) 2002-2004 The NetBSD Foundation, Inc. 4.\" All rights reserved. 5.\" 6.\" This code is derived from software contributed to The NetBSD Foundation 7.\" by Luke Mewburn. 8.\" 9.\" Redistribution and use in source and binary forms, with or without 10.\" modification, are permitted provided that the following conditions 11.\" are met: 12.\" 1. Redistributions of source code must retain the above copyright 13.\" notice, this list of conditions and the following disclaimer. 14.\" 2. Redistributions in binary form must reproduce the above copyright 15.\" notice, this list of conditions and the following disclaimer in the 16.\" documentation and/or other materials provided with the distribution. 17.\" 18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28.\" POSSIBILITY OF SUCH DAMAGE. 29.\" 30.Dd June 18, 2024 31.Dt RC.SUBR 8 32.Os 33.Sh NAME 34.Nm rc.subr 35.Nd functions used by system shell scripts 36.Sh SYNOPSIS 37.Bl -item -compact 38.It 39.Ic .\& Pa /etc/rc.subr 40.Pp 41.It 42.Ic backup_file Ar action Ar file Ar current Ar backup 43.It 44.Ic checkyesno Ar var 45.It 46.Ic check_pidfile Ar pidfile Ar procname Op Ar interpreter 47.It 48.Ic check_process Ar procname Op Ar interpreter 49.It 50.Ic DebugOn Ar tag ... 51.It 52.Ic DebugOff Ar tag ... 53.It 54.Ic debug Ar message 55.It 56.Ic dot Ar file ... 57.It 58.Ic err Ar exitval Ar message 59.It 60.Ic force_depend Ar name 61.It 62.Ic info Ar message 63.It 64.Ic is_verified Ar file 65.It 66.Ic load_kld Oo Fl e Ar regex Oc Oo Fl m Ar module Oc Ar file 67.It 68.Ic load_rc_config Oo Ar flag Oc Op Ar service 69.It 70.Ic load_rc_config_var Ar name Ar var 71.It 72.Ic mount_critical_filesystems Ar type 73.It 74.Ic rc_log Ar message 75.It 76.It rc_trace Ar level Ar message 77.It 78.Ic rc_usage Ar command ... 79.It 80.Ic reverse_list Ar item ... 81.It 82.Ic run_rc_command Ar argument 83.It 84.Ic run_rc_script Ar file Ar argument 85.It 86.Ic run_rc_scripts Oo options Oc Ar file ... 87.It 88.Ic safe_dot Ar file ... 89.It 90.Ic sdot Ar file ... 91.It 92.Ic startmsg Oo Fl n Oc Ar message 93.It 94.Ic vdot Ar file ... 95.It 96.Ic wait_for_pids Op Ar pid ... 97.It 98.Ic warn Ar message 99.El 100.Sh DESCRIPTION 101The 102.Nm 103script 104contains commonly used shell script functions and variable 105definitions which are used by various scripts such as 106.Xr rc 8 . 107Scripts required by ports in 108.Pa /usr/local/etc/rc.d 109will also eventually 110be rewritten to make use of it. 111.Pp 112The 113.Nm 114functions were mostly imported from 115.Nx . 116.Pp 117They are accessed by sourcing 118.Pa /etc/rc.subr 119into the current shell. 120.Pp 121The following shell functions are available: 122.Bl -tag -width 4n 123.It Ic backup_file Ar action file current backup 124Make a backup copy of 125.Ar file 126into 127.Ar current . 128Save the previous version of 129.Ar current 130as 131.Ar backup . 132.Pp 133The 134.Ar action 135argument 136may be one of the following: 137.Bl -tag -width ".Cm remove" 138.It Cm add 139.Ar file 140is now being backed up by or possibly re-entered into this backup mechanism. 141.Ar current 142is created. 143.It Cm update 144.Ar file 145has changed and needs to be backed up. 146If 147.Ar current 148exists, it is copied to 149.Ar backup 150and then 151.Ar file 152is copied to 153.Ar current . 154.It Cm remove 155.Ar file 156is no longer being tracked by this backup mechanism. 157.Ar current 158is moved to 159.Ar backup . 160.El 161.It Ic checkyesno Ar var 162Return 0 if 163.Ar var 164is defined to 165.Dq Li YES , 166.Dq Li TRUE , 167.Dq Li ON , 168or 169.Ql 1 . 170Return 1 if 171.Ar var 172is defined to 173.Dq Li NO , 174.Dq Li FALSE , 175.Dq Li OFF , 176or 177.Ql 0 . 178Otherwise, warn that 179.Ar var 180is not set correctly. 181The values are case insensitive. 182.Em Note : 183.Ar var 184should be a variable name, not its value; 185.Ic checkyesno 186will expand the variable by itself. 187.It Ic check_pidfile Ar pidfile procname Op Ar interpreter 188Parses the first word of the first line of 189.Ar pidfile 190for a PID, and ensures that the process with that PID 191is running and its first argument matches 192.Ar procname . 193Prints the matching PID if successful, otherwise nothing. 194If 195.Ar interpreter 196is provided, parse the first line of 197.Ar procname , 198ensure that the line is of the form: 199.Pp 200.Dl "#! interpreter [...]" 201.Pp 202and use 203.Ar interpreter 204with its optional arguments and 205.Ar procname 206appended as the process string to search for. 207.It Ic check_process Ar procname Op Ar interpreter 208Prints the PIDs of any processes that are running with a first 209argument that matches 210.Ar procname . 211.Ar interpreter 212is handled as per 213.Ic check_pidfile . 214.It Ic DebugOn Ar tag ... 215Enable tracing if not already enabled, 216and any 217.Ar tag 218is found in 219.Va DEBUG_SH 220(a comma separated list of tags). 221.Pp 222Record the 223.Ar tag 224that caused it to be enabled in 225.Va DEBUG_ON , 226set 227.Va DEBUG_DO 228empty and 229.Va DEBUG_SKIP 230to 231.Ql \&: . 232.Pp 233See 234.Xr debug.sh 8 235for more details. 236.It Ic DebugOff Ar tag ... 237Disable tracing if enabled and any 238.Ar tag 239matches 240.Va DEBUG_ON , 241which means it was the reason tracing was enabled. 242.Pp 243Set 244.Va DEBUG_DO 245to 246.Ql \&: , 247and 248.Va DEBUG_ON , 249.Va DEBUG_SKIP 250empty. 251.It Ic debug Ar message 252Display a debugging message to 253.Va stderr , 254log it to the system log using 255.Xr logger 1 , 256and 257return to the caller. 258The error message consists of the script name 259(from 260.Va $0 ) , 261followed by 262.Dq Li ": DEBUG: " , 263and then 264.Ar message . 265This function is intended to be used by developers 266as an aid to debugging scripts. 267It can be turned on or off 268by the 269.Xr rc.conf 5 270variable 271.Va rc_debug . 272.It Ic dot Ar file ... 273For reading in unverified files. 274.Pp 275Ensure shell 276.Li verify 277option is off. 278This option is only meaningful when 279.Xr mac_veriexec 4 280is active. 281.Pp 282Read each 283.Ar file 284if it exists. 285.Pp 286Restore previous state of the 287.Li verify 288option. 289.It Ic err Ar exitval message 290Display an error message to 291.Va stderr , 292log it to the system log 293using 294.Xr logger 1 , 295and 296.Ic exit 297with an exit value of 298.Ar exitval . 299The error message consists of the script name 300(from 301.Va $0 ) , 302followed by 303.Dq Li ": ERROR: " , 304and then 305.Ar message . 306.It Ic force_depend Ar name 307Output an advisory message and force the 308.Ar name 309service to start. 310The 311.Ar name 312argument is the 313.Xr basename 1 314component of the path to the script located at 315.Pa /etc/rc.d 316(scripts stored in other locations such as 317.Pa /usr/local/etc/rc.d 318cannot be controlled with 319.Ic force_depend 320currently). 321If the script fails for any reason it will output a warning 322and return with a return value of 1. 323If it was successful 324it will return 0. 325.It Ic is_verified Ar file 326If 327.Xr veriexec 8 328does not exist, or 329.Xr mac_veriexec 4 330is not active, just return success. 331Otherwise use 332.Xr veriexec 8 333to check if 334.Ar file 335is verified. 336If not verified the return code will be 80 (EAUTH). 337.It Ic info Ar message 338Display an informational message to 339.Va stdout , 340and log it to the system log using 341.Xr logger 1 . 342The message consists of the script name 343(from 344.Va $0 ) , 345followed by 346.Dq Li ": INFO: " , 347and then 348.Ar message . 349The display of this informational output can be 350turned on or off by the 351.Xr rc.conf 5 352variable 353.Va rc_info . 354.It Ic load_kld Oo Fl e Ar regex Oc Oo Fl m Ar module Oc Ar file 355Load 356.Ar file 357as a kernel module unless it is already loaded. 358For the purpose of checking the module status, 359either the exact module name can be specified using 360.Fl m , 361or an 362.Xr egrep 1 363regular expression matching the module name can be supplied via 364.Fl e . 365By default, the module is assumed to have the same name as 366.Ar file , 367which is not always the case. 368.It Ic load_rc_config Oo Ar flag Oc Op Ar service 369Source in the configuration file(s) for 370.Ar service . 371If no 372.Ar service 373is specified, 374only the global configuration file(s) will be loaded. 375First, 376.Pa /etc/rc.conf 377is sourced if it has not yet been read in. 378Then, 379.Pa /etc/rc.conf.d/ Ns Ar service 380is sourced if it is an existing file. 381The latter may also contain other variable assignments to override 382.Ic run_rc_command 383arguments defined by the calling script, to provide an easy 384mechanism for an administrator to override the behaviour of a given 385.Xr rc.d 8 386script without requiring the editing of that script. 387.Pp 388The function named by 389.Va load_rc_config_reader 390(default is 391.Ic dot ) 392is used to read configuration unless 393.Ar flag 394is: 395.Bl -tag -width Ds 396.It Fl s 397use 398.Ic sdot 399to read configuration, 400because we want verified configuration or 401to use 402.Ic safe_dot 403to read an unverified configuration. 404.It Fl v 405use 406.Ic vdot 407to read in configuration only if it is verified. 408.El 409.Pp 410.Ic DebugOn 411will be called with tags derived from 412.Ar name 413to enable tracing if any appear in 414.Va DEBUG_SH . 415.It Ic load_rc_config_var Ar name Ar var 416Read the 417.Xr rc.conf 5 418variable 419.Ar var 420for 421.Ar name 422and set in the current shell, using 423.Ic load_rc_config 424in a sub-shell to prevent unwanted side effects from other variable 425assignments. 426.It Ic mount_critical_filesystems Ar type 427Go through a list of critical file systems, 428as found in the 429.Xr rc.conf 5 430variable 431.Va critical_filesystems_ Ns Ar type , 432mounting each one that 433is not currently mounted. 434.It Ic rc_log Ar message 435Output 436.Ar message 437with a timestamp, which is both human readable and 438easily parsed for post processing, using: 439.Bd -literal -offset indent 440date "+@ %s [%Y-%m-%d %H:%M:%S %Z] $*" 441.Ed 442.It Ic rc_trace Ar level Ar message 443If the file 444.Pa /etc/rc.conf.d/rc_trace 445exists and is not empty attempt to set 446.Va RC_LEVEL 447based on its content. 448If the file is empty or does not contain 449a value for 450.Va RC_LEVEL , 451set it to 452.Li 0 . 453.Pp 454If 455.Ar level 456is greater than or equal to 457.Va RC_LEVEL 458pass 459.Ar message 460to 461.Ic rc_log . 462.It Ic rc_usage Ar command ... 463Print a usage message for 464.Va $0 , 465with 466.Ar commands 467being the list of valid arguments 468prefixed by 469.Sm off 470.Dq Bq Li fast | force | one | quiet . 471.Sm on 472.It Ic reverse_list Ar item ... 473Print the list of 474.Ar items 475in reverse order. 476.It Ic run_rc_command Ar argument 477Run the 478.Ar argument 479method for the current 480.Xr rc.d 8 481script, based on the settings of various shell variables. 482.Ic run_rc_command 483is extremely flexible, and allows fully functional 484.Xr rc.d 8 485scripts to be implemented in a small amount of shell code. 486.Pp 487.Ar argument 488is searched for in the list of supported commands, which may be one 489of: 490.Bl -tag -width ".Cm restart" -offset indent 491.It Cm start 492Start the service. 493This should check that the service is to be started as specified by 494.Xr rc.conf 5 . 495Also checks if the service is already running and refuses to start if 496it is. 497This latter check is not performed by standard 498.Fx 499scripts if the system is starting directly to multi-user mode, to 500speed up the boot process. 501.It Cm stop 502If the service is to be started as specified by 503.Xr rc.conf 5 , 504stop the service. 505This should check that the service is running and complain if it is not. 506.It Cm restart 507Perform a 508.Cm stop 509then a 510.Cm start . 511Defaults to displaying the process ID of the program (if running). 512.It Cm enabled 513Return 0 if the service is enabled and 1 if it is not. 514This command does not print anything. 515.It Cm rcvar 516Display which 517.Xr rc.conf 5 518variables are used to control the startup of the service (if any). 519.El 520.Pp 521If 522.Va pidfile 523or 524.Va procname 525is set, also support: 526.Bl -tag -width ".Cm restart" -offset indent 527.It Cm poll 528Wait for the command to exit. 529.It Cm status 530Show the status of the process. 531.El 532.Pp 533Other supported commands are listed in the optional variable 534.Va extra_commands . 535.Pp 536.Ar argument 537may have one of the following prefixes which alters its operation: 538.Bl -tag -width ".Li force" -offset indent 539.It Li fast 540Skip the check for an existing running process, 541and sets 542.Va rc_fast Ns = Ns Li YES . 543.It Li force 544Skip the checks for 545.Va rcvar 546being set to 547.Dq Li YES , 548and sets 549.Va rc_force Ns = Ns Li YES . 550This ignores 551.Ar argument Ns Va _precmd 552returning non-zero, and ignores any of the 553.Va required_* 554tests failing, and always returns a zero exit status. 555.It Li one 556Skip the checks for 557.Va rcvar 558being set to 559.Dq Li YES , 560but performs all the other prerequisite tests. 561.It Li quiet 562Inhibits some verbose diagnostics. 563Currently, this includes messages 564.Qq Starting ${name} 565(as checked by 566.Ic check_startmsgs 567inside 568.Nm ) 569and errors about usage of services that are not enabled in 570.Xr rc.conf 5 . 571This prefix also sets 572.Va rc_quiet Ns = Ns Li YES . 573.Em Note : 574.Va rc_quiet 575is not intended to completely mask all debug and warning messages, 576but only certain small classes of them. 577.El 578.Pp 579.Ic run_rc_command 580uses the following shell variables to control its behaviour. 581Unless otherwise stated, these are optional. 582.Bl -tag -width ".Va procname" -offset indent 583.It Va name 584The name of this script. 585This is not optional. 586.It Va rcvar 587The value of 588.Va rcvar 589is checked with 590.Ic checkyesno 591to determine if this method should be run. 592.It Va command 593Full path to the command. 594Not required if 595.Ar argument Ns Va _cmd 596is defined for each supported keyword. 597Can be overridden by 598.Va ${name}_program . 599.It Va command_args 600Optional arguments and/or shell directives for 601.Va command . 602.It Va command_interpreter 603.Va command 604is started with: 605.Pp 606.Dl "#! command_interpreter [...]" 607.Pp 608which results in its 609.Xr ps 1 610command being: 611.Pp 612.Dl "command_interpreter [...] command" 613.Pp 614so use that string to find the PID(s) of the running command 615rather than 616.Va command . 617.It Va extra_commands 618Extra commands/keywords/arguments supported. 619.It Va pidfile 620Path to PID file. 621Used to determine the PID(s) of the running command. 622If 623.Va pidfile 624is set, use: 625.Pp 626.Dl "check_pidfile $pidfile $procname" 627.Pp 628to find the PID. 629Otherwise, if 630.Va command 631is set, use: 632.Pp 633.Dl "check_process $procname" 634.Pp 635to find the PID. 636.It Va procname 637Process name to check for. 638Defaults to the value of 639.Va command . 640.It Va required_dirs 641Check for the existence of the listed directories 642before running the 643.Cm start 644method. 645The list is checked before running 646.Va start_precmd . 647.It Va required_files 648Check for the readability of the listed files 649before running the 650.Cm start 651method. 652The list is checked before running 653.Va start_precmd . 654.It Va required_modules 655Ensure that the listed kernel modules are loaded 656before running the 657.Cm start 658method. 659The list is checked after running 660.Va start_precmd . 661This is done after invoking the commands from 662.Va start_precmd 663so that the missing modules are not loaded in vain 664if the preliminary commands indicate a error condition. 665A word in the list can have an optional 666.Dq Li \&: Ns Ar modname 667or 668.Dq Li ~ Ns Ar pattern 669suffix. 670The 671.Ar modname 672or 673.Ar pattern 674parameter is passed to 675.Ic load_kld 676through a 677.Fl m 678or 679.Fl e 680option, respectively. 681See the description of 682.Ic load_kld 683in this document for details. 684.It Va required_vars 685Perform 686.Ic checkyesno 687on each of the list variables 688before running the 689.Cm start 690method. 691The list is checked after running 692.Va start_precmd . 693.It Va ${name}_chdir 694Directory to 695.Ic cd 696to before running 697.Va command , 698if 699.Va ${name}_chroot 700is not provided. 701.It Va ${name}_chroot 702Directory to 703.Xr chroot 8 704to before running 705.Va command . 706Only supported after 707.Pa /usr 708is mounted. 709.It Va ${name}_env 710A list of environment variables to run 711.Va command 712with. 713Those variables will be passed as arguments to the 714.Xr env 1 715utility unless 716.Ar argument Ns Va _cmd 717is defined. 718In that case the contents of 719.Va ${name}_env 720will be exported via the 721.Xr export 1 722builtin of 723.Xr sh 1 , 724which puts some limitations on the names of variables 725(e.g., a variable name may not start with a digit). 726.It Va ${name}_env_file 727A file to source for environmental variables to run 728.Va command 729with. 730.Em Note : 731all the variables which are being assigned in this file are going 732to be exported into the environment of 733.Va command . 734.It Va ${name}_fib 735FIB 736.Pa Routing Table 737number to run 738.Va command 739with. 740See 741.Xr setfib 1 742for more details. 743.It Va ${name}_flags 744Arguments to call 745.Va command 746with. 747This is usually set in 748.Xr rc.conf 5 , 749and not in the 750.Xr rc.d 8 751script. 752The environment variable 753.Sq Ev flags 754can be used to override this. 755.It Va ${name}_nice 756.Xr nice 1 757level to run 758.Va command 759as. 760Only supported after 761.Pa /usr 762is mounted. 763.It Va ${name}_limits 764Resource limits to apply to 765.Va command . 766This will be passed as arguments to the 767.Xr limits 1 768utility. 769By default, the resource limits are based on the login class defined in 770.Va ${name}_login_class . 771.It Va ${name}_login_class 772Login class to use with 773.Va ${name}_limits . 774Defaults to 775.Dq Li daemon . 776.It Va ${name}_offcmd 777Shell commands to run during start if a service is not enabled. 778.It Va ${name}_oomprotect 779.Xr protect 1 780.Va command 781from being killed when swap space is exhausted. 782If 783.Dq Li YES 784is used, no child processes are protected. 785If 786.Dq Li ALL , 787protect all child processes. 788.It Va ${name}_program 789Full path to the command. 790Overrides 791.Va command 792if both are set, but has no effect if 793.Va command 794is unset. 795As a rule, 796.Va command 797should be set in the script while 798.Va ${name}_program 799should be set in 800.Xr rc.conf 5 . 801.It Va ${name}_user 802User to run 803.Va command 804as, using 805.Xr chroot 8 806if 807.Va ${name}_chroot 808is set, otherwise 809uses 810.Xr su 1 . 811Only supported after 812.Pa /usr 813is mounted. 814.It Va ${name}_group 815Group to run the chrooted 816.Va command 817as. 818.It Va ${name}_groups 819Comma separated list of supplementary groups to run the chrooted 820.Va command 821with. 822.It Va ${name}_prepend 823Commands to be prepended to 824.Va command . 825This is a generic version of 826.Va ${name}_env , 827.Va ${name}_fib , 828or 829.Va ${name}_nice . 830.It Va ${name}_setup 831Optional command to be run during 832.Cm start , 833.Cm restart , 834and 835.Cm reload 836prior to the respective 837.Ar argument Ns Va _precmd . 838If the command fails for any reason it will output a warning, 839but execution will continue. 840.It Ar argument Ns Va _cmd 841Shell commands which override the default method for 842.Ar argument . 843.It Ar argument Ns Va _precmd 844Shell commands to run just before running 845.Ar argument Ns Va _cmd 846or the default method for 847.Ar argument . 848If this returns a non-zero exit code, the main method is not performed. 849If the default method is being executed, this check is performed after 850the 851.Va required_* 852checks and process (non-)existence checks. 853.It Ar argument Ns Va _postcmd 854Shell commands to run if running 855.Ar argument Ns Va _cmd 856or the default method for 857.Ar argument 858returned a zero exit code. 859.It Va sig_stop 860Signal to send the processes to stop in the default 861.Cm stop 862method. 863Defaults to 864.Dv SIGTERM . 865.It Va sig_reload 866Signal to send the processes to reload in the default 867.Cm reload 868method. 869Defaults to 870.Dv SIGHUP . 871.El 872.Pp 873For a given method 874.Ar argument , 875if 876.Ar argument Ns Va _cmd 877is not defined, then a default method is provided by 878.Ic run_rc_command : 879.Bl -tag -width ".Sy Argument" -offset indent 880.It Sy Argument 881.Sy Default method 882.It Cm start 883If 884.Va command 885is not running and 886.Ic checkyesno Va rcvar 887succeeds, start 888.Va command . 889.It Cm stop 890Determine the PIDs of 891.Va command 892with 893.Ic check_pidfile 894or 895.Ic check_process 896(as appropriate), 897.Ic kill Va sig_stop 898those PIDs, and run 899.Ic wait_for_pids 900on those PIDs. 901.It Cm reload 902Similar to 903.Cm stop , 904except that it uses 905.Va sig_reload 906instead, and does not run 907.Ic wait_for_pids . 908Another difference from 909.Cm stop 910is that 911.Cm reload 912is not provided by default. 913It can be enabled via 914.Va extra_commands 915if appropriate: 916.Pp 917.Dl "extra_commands=reload" 918.It Cm restart 919Runs the 920.Cm stop 921method, then the 922.Cm start 923method. 924.It Cm status 925Show the PID of 926.Va command , 927or some other script specific status operation. 928.It Cm poll 929Wait for 930.Va command 931to exit. 932.It Cm rcvar 933Display which 934.Xr rc.conf 5 935variable is used (if any). 936This method always works, even if the appropriate 937.Xr rc.conf 5 938variable is set to 939.Dq Li NO . 940.El 941.Pp 942The following variables are available to the methods 943(such as 944.Ar argument Ns Va _cmd ) 945as well as after 946.Ic run_rc_command 947has completed: 948.Bl -tag -width ".Va rc_service" -offset indent 949.It Va rc_arg 950Argument provided to 951.Ic run_rc_command , 952after fast and force processing has been performed. 953.It Va rc_flags 954Flags to start the default command with. 955Defaults to 956.Va ${name}_flags , 957unless overridden by the environment variable 958.Sq Ev flags . 959This variable may be changed by the 960.Ar argument Ns Va _precmd 961method. 962.It Va rc_service 963Path to the service script being executed, in case it needs to re-invoke itself. 964.It Va rc_pid 965PID of 966.Va command 967(if appropriate). 968.It Va rc_fast 969Not empty if 970.Dq Li fast 971prefix was used. 972.It Va rc_force 973Not empty if 974.Dq Li force 975prefix was used. 976.El 977.It Ic run_rc_script Ar file argument 978Start the script 979.Ar file 980with an argument of 981.Ar argument , 982and handle the return value from the script. 983.Pp 984Various shell variables are unset before 985.Ar file 986is started: 987.Bd -ragged -offset indent 988.Va name , 989.Va command , 990.Va command_args , 991.Va command_interpreter , 992.Va extra_commands , 993.Va pidfile , 994.Va rcvar , 995.Va required_dirs , 996.Va required_files , 997.Va required_vars , 998.Ar argument Ns Va _cmd , 999.Ar argument Ns Va _precmd . 1000.Ar argument Ns Va _postcmd . 1001.Ed 1002.Pp 1003Call 1004.Ic rc_trace 1005to indicate that 1006.Ar file 1007is to be run. 1008.Pp 1009However, if 1010.Ic is_verified Ar file 1011fails, just return. 1012.Pp 1013.Ic DebugOn 1014will be called with tags derrived from 1015.Va name 1016and 1017.Va rc_arg 1018to enable tracing if any of those tags appear in 1019.Va DEBUG_SH . 1020.Pp 1021The startup behaviour of 1022.Ar file 1023depends upon the following checks: 1024.Bl -enum 1025.It 1026If 1027.Ar file 1028ends in 1029.Pa .sh , 1030it is sourced into the current shell. 1031.It 1032If 1033.Ar file 1034appears to be a backup or scratch file 1035(e.g., with a suffix of 1036.Pa ~ , # , .OLD , 1037or 1038.Pa .orig ) , 1039ignore it. 1040.It 1041If 1042.Ar file 1043is not executable, ignore it. 1044.It 1045If the 1046.Xr rc.conf 5 1047variable 1048.Va rc_fast_and_loose 1049is empty, 1050source 1051.Ar file 1052in a sub shell, 1053otherwise source 1054.Ar file 1055into the current shell. 1056.El 1057.It Ic run_rc_scripts Oo options Oc file ... 1058Call 1059.Ic run_rc_script 1060for each 1061.Ar file , 1062unless it is already recorded as having been run. 1063.Pp 1064The 1065.Ar options 1066are: 1067.Bl -tag -width "--break break" 1068.It Ic --arg Ar arg 1069Pass 1070.Ar arg 1071to 1072.Ic run_rc_script , 1073default is 1074.Ar _boot 1075set by 1076.Xr rc 8 . 1077.It Ic --break Ar break 1078Stop processing if any 1079.Ar file 1080matches any 1081.Ar break 1082.El 1083.It Ic safe_dot Ar file ... 1084Used by 1085.Ic sdot 1086when 1087.Xr mac_veriexec 4 1088is active and 1089.Ar file 1090is not verified. 1091.Pp 1092This function limits the input from 1093.Ar file 1094to simple variable assignments with any 1095non-alphanumeric characters replaced with 1096.Ql _ . 1097.It Ic sdot Ar file ... 1098For reading in configuration files. 1099Skip files that do not exist or are empty. 1100Try using 1101.Ic vdot 1102and if that fails (the file is unverified) 1103fall back to using 1104.Ic safe_dot . 1105.It Ic startmsg Oo Fl n Oc Ar message 1106Display a start message to 1107.Va stdout . 1108It should be used instead of 1109.Xr echo 1 . 1110The display of this output can be turned off if the 1111.Xr rc.conf 5 1112variable 1113.Va rc_startmsgs 1114is set to 1115.Dq Li NO . 1116.It Ic stop_boot Op Ar always 1117Prevent booting to multiuser mode. 1118If the 1119.Va autoboot 1120variable is set to 1121.Ql yes 1122(see 1123.Xr rc 8 1124to learn more about 1125.Va autoboot ) , 1126or 1127.Ic checkyesno Ar always 1128indicates a truth value, then a 1129.Dv SIGTERM 1130signal is sent to the parent 1131process, which is assumed to be 1132.Xr rc 8 . 1133Otherwise, the shell exits with a non-zero status. 1134.It Ic vdot Ar file ... 1135For reading in only verified files. 1136.Pp 1137Ensure shell 1138.Li verify 1139option is on. 1140This option is only meaningful when 1141.Xr mac_veriexec 4 1142is active, 1143otherwise this function is effectively the same as 1144.Ic dot . 1145.Pp 1146Read in each 1147.Ar file 1148if it exists and 1149.Ic is_verfied Ar file 1150is successful, otherwise set return code to 80 (EAUTH). 1151.Pp 1152Restore previous state of the 1153.Li verify 1154option. 1155.It Ic wait_for_pids Op Ar pid ... 1156Wait until all of the provided 1157.Ar pids 1158do not exist any more, printing the list of outstanding 1159.Ar pids 1160every two seconds. 1161.It Ic warn Ar message 1162Display a warning message to 1163.Va stderr 1164and log it to the system log 1165using 1166.Xr logger 1 . 1167The warning message consists of the script name 1168(from 1169.Va $0 ) , 1170followed by 1171.Dq Li ": WARNING: " , 1172and then 1173.Ar message . 1174.El 1175.Sh FILES 1176.Bl -tag -width ".Pa /etc/rc.subr" -compact 1177.It Pa /etc/rc.subr 1178The 1179.Nm 1180file resides in 1181.Pa /etc . 1182.El 1183.Sh SEE ALSO 1184.Xr debug.sh 8 , 1185.Xr rc.conf 5 , 1186.Xr rc 8 1187.Sh HISTORY 1188The 1189.Nm 1190script 1191appeared in 1192.Nx 1.3 . 1193The 1194.Xr rc.d 8 1195support functions appeared in 1196.Nx 1.5 . 1197The 1198.Nm 1199script 1200first appeared in 1201.Fx 5.0 . 1202