rc.subr revision 1.58
1# $NetBSD: rc.subr,v 1.58 2003/06/27 05:01:21 lukem Exp $ 2# 3# Copyright (c) 1997-2002 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# 3. All advertising materials mentioning features or use of this software 18# must display the following acknowledgement: 19# This product includes software developed by the NetBSD 20# Foundation, Inc. and its contributors. 21# 4. Neither the name of The NetBSD Foundation nor the names of its 22# contributors may be used to endorse or promote products derived 23# from this software without specific prior written permission. 24# 25# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 26# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 29# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35# POSSIBILITY OF SUCH DAMAGE. 36# 37# rc.subr 38# functions used by various rc scripts 39# 40 41if ${_rc_subr_loaded:-false}; then 42 return 43else 44 _rc_subr_loaded=true 45fi 46 47# 48# functions 49# --------- 50 51# 52# checkyesno var 53# Test $1 variable, and warn if not set to YES or NO. 54# Return 0 if it's "yes" (et al), nonzero otherwise. 55# 56checkyesno() 57{ 58 eval _value=\$${1} 59 case $_value in 60 61 # "yes", "true", "on", or "1" 62 [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) 63 return 0 64 ;; 65 66 # "no", "false", "off", or "0" 67 [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) 68 return 1 69 ;; 70 *) 71 warn "\$${1} is not set properly - see rc.conf(5)." 72 return 1 73 ;; 74 esac 75} 76 77# reverse_list list 78# print the list in reverse order 79# 80reverse_list() 81{ 82 _revlist= 83 for _revfile; do 84 _revlist="$_revfile $_revlist" 85 done 86 echo $_revlist 87} 88 89# 90# mount_critical_filesystems type 91# Go through the list of critical filesystems as provided in 92# the rc.conf(5) variable $critical_filesystems_${type}, checking 93# each one to see if it is mounted, and if it is not, mounting it. 94# 95mount_critical_filesystems() 96{ 97 eval _fslist=\$critical_filesystems_${1} 98 for _fs in $_fslist; do 99 mount | ( 100 _ismounted=false 101 while read what _on on _type type; do 102 if [ $on = $_fs ]; then 103 _ismounted=true 104 fi 105 done 106 if $_ismounted; then 107 : 108 else 109 mount $_fs >/dev/null 2>&1 110 fi 111 ) 112 done 113} 114 115# 116# check_pidfile pidfile procname [interpreter] 117# Parses the first line of pidfile for a PID, and ensures 118# that the process is running and matches procname. 119# Prints the matching PID upon success, nothing otherwise. 120# interpreter is optional; see _find_processes() for details. 121# 122check_pidfile() 123{ 124 _pidfile=$1 125 _procname=$2 126 _interpreter=$3 127 if [ -z "$_pidfile" -o -z "$_procname" ]; then 128 err 3 'USAGE: check_pidfile pidfile procname [interpreter]' 129 fi 130 if [ ! -f $_pidfile ]; then 131 return 132 fi 133 read _pid _junk < $_pidfile 134 if [ -z "$_pid" ]; then 135 return 136 fi 137 _find_processes $_procname ${_interpreter:-.} '-p '"$_pid" 138} 139 140# 141# check_process procname [interpreter] 142# Ensures that a process (or processes) named procname is running. 143# Prints a list of matching PIDs. 144# interpreter is optional; see _find_processes() for details. 145# 146check_process() 147{ 148 _procname=$1 149 _interpreter=$2 150 if [ -z "$_procname" ]; then 151 err 3 'USAGE: check_process procname [interpreter]' 152 fi 153 _find_processes $_procname ${_interpreter:-.} '-ax' 154} 155 156# 157# _find_processes procname interpreter psargs 158# Search for procname in the output of ps generated by psargs. 159# Prints the PIDs of any matching processes, space separated. 160# 161# If interpreter == ".", check the following variations of procname 162# against the first word of each command: 163# procname 164# `basename procname` 165# `basename procname` + ":" 166# "(" + `basename procname` + ")" 167# 168# If interpreter != ".", read the first line of procname, remove the 169# leading #!, normalise whitespace, append procname, and attempt to 170# match that against each command, either as is, or with extra words 171# at the end. 172# 173_find_processes() 174{ 175 if [ $# -ne 3 ]; then 176 err 3 'USAGE: _find_processes procname interpreter psargs' 177 fi 178 _procname=$1 179 _interpreter=$2 180 _psargs=$3 181 182 _pref= 183 if [ $_interpreter != "." ]; then # an interpreted script 184 read _interp < $_procname # read interpreter name 185 _interp=${_interp#\#!} # strip #! 186 set -- $_interp 187 if [ $_interpreter != $1 ]; then 188 warn "\$command_interpreter $_interpreter != $1" 189 fi 190 _interp="$* $_procname" # cleanup spaces, add _procname 191 _fp_args='_argv' 192 _fp_match='case "$_argv" in 193 ${_interp}|"${_interp} "*)' 194 else # a normal daemon 195 _procnamebn=${_procname##*/} 196 _fp_args='_arg0 _argv' 197 _fp_match='case "$_arg0" in 198 $_procname|$_procnamebn|${_procnamebn}:|"(${_procnamebn})")' 199 fi 200 201 _proccheck=' 202 ps -o "pid,command" '"$_psargs"' | 203 while read _npid '"$_fp_args"'; do 204 case "$_npid" in 205 PID) 206 continue ;; 207 esac ; '"$_fp_match"' 208 echo -n "$_pref$_npid" ; 209 _pref=" " 210 ;; 211 esac 212 done' 213 214#echo 1>&2 "proccheck is :$_proccheck:" 215 eval $_proccheck 216} 217 218# 219# wait_for_pids pid [pid ...] 220# spins until none of the pids exist 221# 222wait_for_pids() 223{ 224 _list="$@" 225 if [ -z "$_list" ]; then 226 return 227 fi 228 _prefix= 229 while true; do 230 _nlist=""; 231 for _j in $_list; do 232 if kill -0 $_j 2>/dev/null; then 233 _nlist="${_nlist}${_nlist:+ }$_j" 234 fi 235 done 236 if [ -z "$_nlist" ]; then 237 break 238 fi 239 _list=$_nlist 240 echo -n ${_prefix:-"Waiting for PIDS: "}$_list 241 _prefix=", " 242 sleep 2 243 done 244 if [ -n "$_prefix" ]; then 245 echo "." 246 fi 247} 248 249# 250# run_rc_command argument 251# Search for argument in the list of supported commands, which is: 252# "start stop restart rcvar status poll ${extra_commands}" 253# If there's a match, run ${argument}_cmd or the default method 254# (see below). 255# 256# If argument has a given prefix, then change the operation as follows: 257# Prefix Operation 258# ------ --------- 259# fast Skip the pid check, and set rc_fast=yes 260# force Set ${rcvar} to YES, and set rc_force=yes 261# 262# The following globals are used: 263# 264# Name Needed Purpose 265# ---- ------ ------- 266# name y Name of script. 267# 268# command n Full path to command. 269# Not needed if ${rc_arg}_cmd is set for 270# each keyword. 271# 272# command_args n Optional args/shell directives for command. 273# 274# command_interpreter n If not empty, command is interpreted, so 275# call check_{pidfile,process}() appropriately. 276# 277# extra_commands n List of extra commands supported. 278# 279# pidfile n If set, use check_pidfile $pidfile $command, 280# otherwise use check_process $command. 281# In either case, only check if $command is set. 282# 283# procname n Process name to check for instead of $command. 284# 285# rcvar n This is checked with checkyesno to determine 286# if the action should be run. 287# 288# ${name}_chroot n Directory to chroot to before running ${command} 289# Requires /usr to be mounted. 290# 291# ${name}_chdir n Directory to cd to before running ${command} 292# (if not using ${name}_chroot). 293# 294# ${name}_flags n Arguments to call ${command} with. 295# NOTE: $flags from the parent environment 296# can be used to override this. 297# 298# ${name}_nice n Nice level to run ${command} at. 299# 300# ${name}_user n User to run ${command} as, using su(1) if not 301# using ${name}_chroot. 302# Requires /usr to be mounted. 303# 304# ${name}_group n Group to run chrooted ${command} as. 305# Requires /usr to be mounted. 306# 307# ${name}_groups n Comma separated list of supplementary groups 308# to run the chrooted ${command} with. 309# Requires /usr to be mounted. 310# 311# ${name}_systrace n Flags passed to systrace(1) if it is used. 312# Setting this variable enables systracing 313# of the given program. The use of "-a" is 314# recommended so that the boot process is not 315# stalled. In order to pass no flags to 316# systrace, set this variable to "--". 317# 318# ${rc_arg}_cmd n If set, use this as the method when invoked; 319# Otherwise, use default command (see below) 320# 321# ${rc_arg}_precmd n If set, run just before performing the 322# ${rc_arg}_cmd method in the default 323# operation (i.e, after checking for required 324# bits and process (non)existence). 325# If this completes with a non-zero exit code, 326# don't run ${rc_arg}_cmd. 327# 328# ${rc_arg}_postcmd n If set, run just after performing the 329# ${rc_arg}_cmd method, if that method 330# returned a zero exit code. 331# 332# required_dirs n If set, check for the existence of the given 333# directories before running the default 334# (re)start command. 335# 336# required_files n If set, check for the readability of the given 337# files before running the default (re)start 338# command. 339# 340# required_vars n If set, perform checkyesno on each of the 341# listed variables before running the default 342# (re)start command. 343# 344# Default behaviour for a given argument, if no override method is 345# provided: 346# 347# Argument Default behaviour 348# -------- ----------------- 349# start if !running && checkyesno ${rcvar} 350# ${command} 351# 352# stop if ${pidfile} 353# rc_pid=$(check_pidfile $pidfile $command) 354# else 355# rc_pid=$(check_process $command) 356# kill $sig_stop $rc_pid 357# wait_for_pids $rc_pid 358# ($sig_stop defaults to TERM.) 359# 360# reload Similar to stop, except use $sig_reload instead, 361# and doesn't wait_for_pids. 362# $sig_reload defaults to HUP. 363# 364# restart Run `stop' then `start'. 365# 366# status Show if ${command} is running, etc. 367# 368# poll Wait for ${command} to exit. 369# 370# rcvar Display what rc.conf variable is used (if any). 371# 372# Variables available to methods, and after run_rc_command() has 373# completed: 374# 375# Variable Purpose 376# -------- ------- 377# rc_arg Argument to command, after fast/force processing 378# performed 379# 380# rc_flags Flags to start the default command with. 381# Defaults to ${name}_flags, unless overridden 382# by $flags from the environment. 383# This variable may be changed by the precmd method. 384# 385# rc_pid PID of command (if appropriate) 386# 387# rc_fast Not empty if "fast" was provided (q.v.) 388# 389# rc_force Not empty if "force" was provided (q.v.) 390# 391# 392run_rc_command() 393{ 394 rc_arg=$1 395 if [ -z "$name" ]; then 396 err 3 'run_rc_command: $name is not set.' 397 fi 398 399 case "$rc_arg" in 400 fast*) # "fast" prefix; don't check pid 401 rc_arg=${rc_arg#fast} 402 rc_fast=yes 403 ;; 404 force*) # "force prefix; always start 405 rc_arg=${rc_arg#force} 406 rc_force=yes 407 if [ -n "${rcvar}" ]; then 408 eval ${rcvar}=YES 409 fi 410 ;; 411 esac 412 413 _keywords="start stop restart rcvar $extra_commands" 414 rc_pid= 415 _pidcmd= 416 _procname=${procname:-${command}} 417 418 # setup pid check command if not fast 419 if [ -z "$rc_fast" -a -n "$_procname" ]; then 420 if [ -n "$pidfile" ]; then 421 _pidcmd='rc_pid=$(check_pidfile '"$pidfile $_procname $command_interpreter"')' 422 else 423 _pidcmd='rc_pid=$(check_process '"$_procname $command_interpreter"')' 424 fi 425 if [ -n "$_pidcmd" ]; then 426 _keywords="${_keywords} status poll" 427 fi 428 fi 429 430 if [ -z "$rc_arg" ]; then 431 rc_usage "$_keywords" 432 fi 433 434 if [ -n "$flags" ]; then # allow override from environment 435 rc_flags=$flags 436 else 437 eval rc_flags=\$${name}_flags 438 fi 439 eval _chdir=\$${name}_chdir _chroot=\$${name}_chroot \ 440 _nice=\$${name}_nice _user=\$${name}_user \ 441 _group=\$${name}_group _groups=\$${name}_groups \ 442 _systrace=\$${name}_systrace 443 444 if [ -n "$_user" ]; then # unset $_user if running as that user 445 if [ "$_user" = "$(id -un)" ]; then 446 unset _user 447 fi 448 fi 449 450 # if ${rcvar} is set, and $1 is not 451 # "rcvar", then run 452 # checkyesno ${rcvar} 453 # and return if that failed 454 # 455 if [ -n "${rcvar}" -a "$rc_arg" != "rcvar" ]; then 456 if ! checkyesno ${rcvar}; then 457 return 0 458 fi 459 fi 460 461 eval $_pidcmd # determine the pid if necessary 462 463 for _elem in $_keywords; do 464 if [ "$_elem" != "$rc_arg" ]; then 465 continue 466 fi 467 468 # if there's a custom ${XXX_cmd}, 469 # run that instead of the default 470 # 471 eval _cmd=\$${rc_arg}_cmd _precmd=\$${rc_arg}_precmd \ 472 _postcmd=\$${rc_arg}_postcmd 473 if [ -n "$_cmd" ]; then 474 # if the precmd failed and force 475 # isn't set, exit 476 # 477 if ! eval $_precmd && [ -z "$rc_force" ]; then 478 return 1 479 fi 480 481 if ! eval $_cmd && [ -z "$rc_force" ]; then 482 return 1 483 fi 484 eval $_postcmd 485 return 0 486 fi 487 488 case "$rc_arg" in # default operations... 489 490 status) 491 if [ -n "$rc_pid" ]; then 492 echo "${name} is running as pid $rc_pid." 493 else 494 echo "${name} is not running." 495 return 1 496 fi 497 ;; 498 499 start) 500 if [ -n "$rc_pid" ]; then 501 echo "${name} already running? (pid=$rc_pid)." 502 exit 1 503 fi 504 505 if [ ! -x ${_chroot}${command} ]; then 506 return 0 507 fi 508 509 # check for required variables, 510 # directories, and files 511 # 512 for _f in $required_vars; do 513 if ! checkyesno $_f; then 514 warn "\$${_f} is not set." 515 if [ -z "$rc_force" ]; then 516 return 1 517 fi 518 fi 519 done 520 for _f in $required_dirs; do 521 if [ ! -d "${_f}/." ]; then 522 warn "${_f} is not a directory." 523 if [ -z "$rc_force" ]; then 524 return 1 525 fi 526 fi 527 done 528 for _f in $required_files; do 529 if [ ! -r "${_f}" ]; then 530 warn "${_f} is not readable." 531 if [ -z "$rc_force" ]; then 532 return 1 533 fi 534 fi 535 done 536 537 # if the precmd failed and force 538 # isn't set, exit 539 # 540 if ! eval $_precmd && [ -z "$rc_force" ]; then 541 return 1 542 fi 543 544 # setup the command to run, and run it 545 # 546 echo "Starting ${name}." 547 if [ -n "$_chroot" ]; then 548 _doit="\ 549${_nice:+nice -n $_nice }\ 550${_systrace:+systrace $_systrace }\ 551chroot ${_user:+-u $_user }${_group:+-g $_group }${_groups:+-G $_groups }\ 552$_chroot $command $rc_flags $command_args" 553 else 554 _doit="\ 555${_chdir:+cd $_chdir; }\ 556${_nice:+nice -n $_nice }\ 557${_systrace:+systrace $_systrace }\ 558$command $rc_flags $command_args" 559 if [ -n "$_user" ]; then 560 _doit="su -m $_user -c 'sh -c \"$_doit\"'" 561 fi 562 fi 563 564 # if the cmd failed and force 565 # isn't set, exit 566 # 567 if ! eval $_doit && [ -z "$rc_force" ]; then 568 return 1 569 fi 570 571 # finally, run postcmd 572 # 573 eval $_postcmd 574 ;; 575 576 stop) 577 if [ -z "$rc_pid" ]; then 578 if [ -n "$pidfile" ]; then 579 echo \ 580 "${name} not running? (check $pidfile)." 581 else 582 echo "${name} not running?" 583 fi 584 exit 1 585 fi 586 587 # if the precmd failed and force 588 # isn't set, exit 589 # 590 if ! eval $_precmd && [ -z "$rc_force" ]; then 591 return 1 592 fi 593 594 # send the signal to stop 595 # 596 echo "Stopping ${name}." 597 _doit="kill -${sig_stop:-TERM} $rc_pid" 598 if [ -n "$_user" ]; then 599 _doit="su -m $_user -c 'sh -c \"$_doit\"'" 600 fi 601 602 # if the stop cmd failed and force 603 # isn't set, exit 604 # 605 if ! eval $_doit && [ -z "$rc_force" ]; then 606 return 1 607 fi 608 609 # wait for the command to exit, 610 # and run postcmd. 611 wait_for_pids $rc_pid 612 eval $_postcmd 613 ;; 614 615 reload) 616 if [ -z "$rc_pid" ]; then 617 if [ -n "$pidfile" ]; then 618 echo \ 619 "${name} not running? (check $pidfile)." 620 else 621 echo "${name} not running?" 622 fi 623 exit 1 624 fi 625 echo "Reloading ${name} config files." 626 if ! eval $_precmd && [ -z "$rc_force" ]; then 627 return 1 628 fi 629 _doit="kill -${sig_reload:-HUP} $rc_pid" 630 if [ -n "$_user" ]; then 631 _doit="su -m $_user -c 'sh -c \"$_doit\"'" 632 fi 633 if ! eval $_doit && [ -z "$rc_force" ]; then 634 return 1 635 fi 636 eval $_postcmd 637 ;; 638 639 restart) 640 if ! eval $_precmd && [ -z "$rc_force" ]; then 641 return 1 642 fi 643 # prevent restart being called more 644 # than once by any given script 645 # 646 if ${_rc_restart_done:-false}; then 647 return 0 648 fi 649 _rc_restart_done=true 650 651 ( $0 ${rc_force:+force}stop ) 652 $0 ${rc_force:+force}start 653 654 eval $_postcmd 655 ;; 656 657 poll) 658 if [ -n "$rc_pid" ]; then 659 wait_for_pids $rc_pid 660 fi 661 ;; 662 663 rcvar) 664 echo "# $name" 665 if [ -n "$rcvar" ]; then 666 if checkyesno ${rcvar}; then 667 echo "\$${rcvar}=YES" 668 else 669 echo "\$${rcvar}=NO" 670 fi 671 fi 672 ;; 673 674 *) 675 rc_usage "$_keywords" 676 ;; 677 678 esac 679 return 0 680 done 681 682 echo 1>&2 "$0: unknown directive '$rc_arg'." 683 rc_usage "$_keywords" 684 exit 1 685} 686 687# 688# run_rc_script file arg 689# Start the script `file' with `arg', and correctly handle the 690# return value from the script. If `file' ends with `.sh', it's 691# sourced into the current environment. If `file' appears to be 692# a backup or scratch file, ignore it. Otherwise if it's 693# executable run as a child process. 694# 695run_rc_script() 696{ 697 _file=$1 698 _arg=$2 699 if [ -z "$_file" -o -z "$_arg" ]; then 700 err 3 'USAGE: run_rc_script file arg' 701 fi 702 703 unset name command command_args command_interpreter \ 704 extra_commands pidfile procname \ 705 rcvar required_dirs required_files required_vars 706 eval unset ${_arg}_cmd ${_arg}_precmd ${_arg}_postcmd 707 708 case "$_file" in 709 *.sh) # run in current shell 710 set $_arg ; . $_file 711 ;; 712 *[~#]|*.OLD|*.orig) # scratch file; skip 713 warn "Ignoring scratch file $_file" 714 ;; 715 *) # run in subshell 716 if [ -x $_file ]; then 717 if [ -n "$rc_fast_and_loose" ]; then 718 set $_arg ; . $_file 719 else 720 ( set $_arg ; . $_file ) 721 fi 722 fi 723 ;; 724 esac 725} 726 727# 728# load_rc_config 729# Source in the configuration file for a given command. 730# 731load_rc_config() 732{ 733 _command=$1 734 if [ -z "$_command" ]; then 735 err 3 'USAGE: load_rc_config command' 736 fi 737 738 if ${_rc_conf_loaded:-false}; then 739 : 740 else 741 . /etc/rc.conf 742 _rc_conf_loaded=true 743 fi 744 if [ -f /etc/rc.conf.d/"$_command" ]; then 745 . /etc/rc.conf.d/"$_command" 746 fi 747} 748 749 750# 751# rc_usage commands 752# Print a usage string for $0, with `commands' being a list of 753# valid commands. 754# 755rc_usage() 756{ 757 echo -n 1>&2 "Usage: $0 [fast|force](" 758 759 _sep= 760 for _elem; do 761 echo -n 1>&2 "$_sep$_elem" 762 _sep="|" 763 done 764 echo 1>&2 ")" 765 exit 1 766} 767 768# 769# err exitval message 770# Display message to stderr and log to the syslog, and exit with exitval. 771# 772err() 773{ 774 exitval=$1 775 shift 776 777 if [ -x /usr/bin/logger ]; then 778 logger "$0: ERROR: $*" 779 fi 780 echo 1>&2 "$0: ERROR: $*" 781 exit $exitval 782} 783 784# 785# warn message 786# Display message to stderr and log to the syslog. 787# 788warn() 789{ 790 if [ -x /usr/bin/logger ]; then 791 logger "$0: WARNING: $*" 792 fi 793 echo 1>&2 "$0: WARNING: $*" 794} 795 796# 797# backup_file action file cur backup 798# Make a backup copy of `file' into `cur', and save the previous 799# version of `cur' as `backup' or use rcs for archiving. 800# 801# This routine checks the value of the backup_uses_rcs variable, 802# which can be either YES or NO. 803# 804# The `action' keyword can be one of the following: 805# 806# add `file' is now being backed up (and is possibly 807# being reentered into the backups system). `cur' 808# is created and RCS files, if necessary, are 809# created as well. 810# 811# update `file' has changed and needs to be backed up. 812# If `cur' exists, it is copied to to `back' or 813# checked into RCS (if the repository file is old), 814# and then `file' is copied to `cur'. Another RCS 815# check in done here if RCS is being used. 816# 817# remove `file' is no longer being tracked by the backups 818# system. If RCS is not being used, `cur' is moved 819# to `back', otherwise an empty file is checked in, 820# and then `cur' is removed. 821# 822# 823backup_file() 824{ 825 _action=$1 826 _file=$2 827 _cur=$3 828 _back=$4 829 830 if checkyesno backup_uses_rcs; then 831 _msg0="backup archive" 832 _msg1="update" 833 834 # ensure that history file is not locked 835 if [ -f $_cur,v ]; then 836 rcs -q -u -U -M $_cur 837 fi 838 839 # ensure after switching to rcs that the 840 # current backup is not lost 841 if [ -f $_cur ]; then 842 # no archive, or current newer than archive 843 if [ ! -f $_cur,v -o $_cur -nt $_cur,v ]; then 844 ci -q -f -u -t-"$_msg0" -m"$_msg1" $_cur 845 rcs -q -kb -U $_cur 846 co -q -f -u $_cur 847 fi 848 fi 849 850 case $_action in 851 add|update) 852 cp -p $_file $_cur 853 ci -q -f -u -t-"$_msg0" -m"$_msg1" $_cur 854 rcs -q -kb -U $_cur 855 co -q -f -u $_cur 856 chown root:wheel $_cur $_cur,v 857 ;; 858 remove) 859 cp /dev/null $_cur 860 ci -q -f -u -t-"$_msg0" -m"$_msg1" $_cur 861 rcs -q -kb -U $_cur 862 chown root:wheel $_cur $_cur,v 863 rm $_cur 864 ;; 865 esac 866 else 867 case $_action in 868 add|update) 869 if [ -f $_cur ]; then 870 cp -p $_cur $_back 871 fi 872 cp -p $_file $_cur 873 chown root:wheel $_cur 874 ;; 875 remove) 876 mv -f $_cur $_back 877 ;; 878 esac 879 fi 880} 881