From 590ee44c1495ea67d057e0d21e4ebc25c0e17782 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Mon, 13 Jun 2011 19:07:52 -0400 Subject: rc.sysinit: honor blacklist, not load_modules This is some unfinished business from our removal of load-modules.sh. We call modprobe with -ab for the contents of the MODULES array, which should no longer contain ! prefixed module names. --quiet is explicitly ommitted, as users should be aware of any errors that might occur here. Signed-off-by: Dave Reisner Signed-off-by: Tom Gundersen --- rc.sysinit | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/rc.sysinit b/rc.sysinit index 9750913..dd87633 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -87,9 +87,8 @@ stat_busy "Triggering UDev uevents" stat_done # Load modules from the MODULES array defined in rc.conf -mods=${MODULES[@]/!*/} -if [[ $load_modules != off && -f /proc/modules && $mods ]]; then - status "Loading Modules" modprobe --all $mods +if [[ -f /proc/modules ]] && (( ${#MODULES[*]} )); then + status "Loading Modules" modprobe -ab "${MODULES[@]}" fi unset mods -- cgit v1.2.3 From 89a7dbb52543dd98d86440dfe8dd04e752f55337 Mon Sep 17 00:00:00 2001 From: Sebastien Luttringer Date: Sat, 18 Jun 2011 02:46:35 +0200 Subject: rc.d: Update usage Signed-off-by: Sebastien Luttringer --- rc.d | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/rc.d b/rc.d index ad0a1e9..939538e 100755 --- a/rc.d +++ b/rc.d @@ -6,9 +6,16 @@ usage() { local name=${0##*/} cat >&2 << EOF -usage: $name action daemon ... +usage: $name [daemon] ... + $name list [started|stopped] + $name help + + is the name of a script in /etc/rc.d + can be a start, stop, restart, reload, status, ... +WARNING: initscripts are free to implement or not the above actions. e.g: $name list + $name list started $name help $name start sshd gpm EOF -- cgit v1.2.3 From b1b7e18d21acb8a27912ea9e3bafef491fc16f63 Mon Sep 17 00:00:00 2001 From: Sebastien Luttringer Date: Sat, 18 Jun 2011 02:06:14 +0200 Subject: rc.d: Add started/stopped option to list This patch allow rc.d list started and rc.d list stopped which list respectively only started and stopped daemons Signed-off-by: Sebastien Luttringer --- rc.d | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rc.d b/rc.d index 939538e..f5dd652 100755 --- a/rc.d +++ b/rc.d @@ -30,13 +30,16 @@ case $1 in usage ;; list) + shift cd /etc/rc.d/ for d in *; do have_daemon "$d" || continue # print running / stopped satus if ! ck_daemon "$d"; then + [[ "$1" == stopped ]] && continue printf "${C_OTHER}[${C_DONE}STARTED${C_OTHER}]" else + [[ "$1" == started ]] && continue printf "${C_OTHER}[${C_FAIL}STOPPED${C_OTHER}]" fi # print auto / manual status @@ -47,7 +50,7 @@ case $1 in fi printf " ${C_CLEAR}$d\n" done - ;; + ;; *) # check min args count (( $# < 2 )) && usage @@ -69,6 +72,7 @@ case $1 in fi (( ret += !! $? )) # clamp exit value to 0/1 done + ;; esac exit $ret -- cgit v1.2.3 From 3b6e12a8ce903c93127914b1beb5b203b10e1547 Mon Sep 17 00:00:00 2001 From: Sebastien Luttringer Date: Sat, 18 Jun 2011 04:08:43 +0200 Subject: rc.d: Update bash and zsh completion scripts Signed-off-by: Sebastien Luttringer --- bash-completion | 8 +++++--- zsh-completion | 5 ++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/bash-completion b/bash-completion index 5151972..489b5dc 100644 --- a/bash-completion +++ b/bash-completion @@ -5,15 +5,17 @@ _rc.d () local action="help list start stop reload restart" local cur="${COMP_WORDS[COMP_CWORD]}" local caction="${COMP_WORDS[1]}" - if ((${COMP_CWORD} == 1)); then + if ((COMP_CWORD == 1)); then COMPREPLY=($(compgen -W "${action}" -- "$cur")) - elif [[ "$caction" =~ help|list ]]; then + elif [[ "$caction" == help ]]; then COMPREPLY=() + elif [[ "$caction" == list ]]; then + ((COMP_CWORD == 2)) && COMPREPLY=($(compgen -W "started stopped" -- "$cur")) || COMPREPLY=() elif [[ "$caction" == start ]]; then COMPREPLY=($(comm -23 <(cd /etc/rc.d && compgen -f -X 'functions*' "$cur"|sort) <(cd /run/daemons/ && compgen -f "$cur"|sort))) elif [[ "$caction" =~ stop|restart|reload ]]; then COMPREPLY=($(cd /run/daemons/ && compgen -f "$cur"|sort)) - elif ((${COMP_CWORD} > 1)); then + elif ((COMP_CWORD > 1)); then COMPREPLY=($(cd /etc/rc.d && compgen -f -X 'functions*' "$cur"|sort)) fi } diff --git a/zsh-completion b/zsh-completion index f1b7165..e5c2850 100644 --- a/zsh-completion +++ b/zsh-completion @@ -15,9 +15,12 @@ _rc.d () { curcontext="${curcontext%:*:*}:rc.d-${action}:" case $action in - list|help) + help) _arguments "*: :" ;; + list) + _arguments "2: :(started stopped)" + ;; start) _arguments "*: :($(comm -23 <(echo /etc/rc.d/*(N-*:t)|tr ' ' '\n') <(echo /run/daemons/*(N:t)|tr ' ' '\n')))" ;; -- cgit v1.2.3 From 042d197b4d989ec6461204b9d897054e5f5dd492 Mon Sep 17 00:00:00 2001 From: Sebastien Luttringer Date: Tue, 31 May 2011 09:16:17 +0200 Subject: Ensure rc.d scripts are run as root By default all script should be run as root. If NEED_ROOT=0 is set before loading /etc/rc.d/functions in a rc.d scripts, this will not apply. This allow script with only some part which require root level to call need_root() function at beginning of those parts. Close FS#24095 Signed-off-by: Sebastien Luttringer --- functions | 10 ++++++++++ rc.d | 1 + 2 files changed, 11 insertions(+) diff --git a/functions b/functions index adf4ea9..2ee56b4 100644 --- a/functions +++ b/functions @@ -394,5 +394,15 @@ for f in /etc/rc.d/functions.d/*; do [[ -e $f ]] && . "$f" done +# Exit current shell if user is not root +need_root() { + (( $EUID != 0 )) && printf 'You need to be root.\n' && exit 1 +} + +# Quit script if it's not running by root +# This can be disabled in scripts sourcing functions by setting NEED_ROOT=0 +# A local call to need_root can be done to ensure part of script need root privilege +(( ${NEED_ROOT:-1} == 1 )) && need_root + # End of file # vim: set ts=2 sw=2 noet: diff --git a/rc.d b/rc.d index f5dd652..6d9a9f7 100755 --- a/rc.d +++ b/rc.d @@ -1,5 +1,6 @@ #!/bin/bash +NEED_ROOT=0 # this script can be run without be root . /etc/rc.conf . /etc/rc.d/functions -- cgit v1.2.3 From 4cad51425325abf13b7a8772ff09f852238423c2 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Sat, 18 Jun 2011 11:39:59 -0400 Subject: network: support gateway-less network setup This also discards the explicit deletion of the route in network_down, as bringing down the interface will take care of this for us. Addresses FS#24690 Thanks-to: Matthias Dienstbier Signed-off-by: Dave Reisner --- network | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/network b/network index c2ad9ba..38ada9a 100755 --- a/network +++ b/network @@ -33,7 +33,7 @@ network_up() { fi done ip addr add $address/$netmask broadcast ${broadcast:-+} dev $interface || return 1 - ip route add default via $gateway || return 1 + [[ $gateway ]] && { ip route add default via $gateway || return 1; } else dhcpcd $DHCPCD_ARGS $interface || return 1 fi @@ -43,7 +43,6 @@ network_down() { if [[ -f /var/run/dhcpcd-$interface.pid ]]; then dhcpcd -k $interface || return 1 else - ip route del default || return 1 ip addr flush dev $interface || return 1 fi -- cgit v1.2.3 From fe48fab2c2c35ccbfa3eec436d40739bc4b486da Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Sun, 19 Jun 2011 09:04:24 -0400 Subject: rc.sysinit: avoid use of regex match for USE* vars Although silly, this would positively match something such as USRBTRFS=deadeyes Instead, enumerate the match as a simple glob. Signed-off-by: Dave Reisner --- rc.sysinit | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rc.sysinit b/rc.sysinit index dd87633..8158f78 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -102,12 +102,12 @@ run_hook sysinit_udevsettled status "Bringing up loopback interface" ip link set up dev lo # FakeRAID devices detection -if [[ $USEDMRAID =~ yes|YES && -x $(type -P dmraid) ]]; then +if [[ $USEDMRAID = [Yy][Ee][Ss] && -x $(type -P dmraid) ]]; then status "Activating FakeRAID arrays" dmraid -i -ay fi # BTRFS devices detection -if [[ $USEBTRFS =~ yes|YES && -x $(type -P btrfs) ]]; then +if [[ $USEBTRFS = [Yy][Ee][Ss] && -x $(type -P btrfs) ]]; then status "Activating BTRFS volumes" btrfs device scan fi @@ -280,7 +280,7 @@ stat_busy "Mounting Local Filesystems" stat_done # enable monitoring of lvm2 groups, now that the filesystems are mounted rw -if [[ $USELVM =~ yes|YES && -x $(type -P lvm) && -d /sys/block ]]; then +if [[ $USELVM = [Yy][Ee][Ss] && -x $(type -P lvm) && -d /sys/block ]]; then status "Activating monitoring of LVM2 groups" \ vgchange --monitor y >/dev/null fi -- cgit v1.2.3 From 824567cb23ed0bab4ed4568be139ee0c75d7598d Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Sun, 19 Jun 2011 10:10:45 -0400 Subject: network: don't enforce check for netmask or gateway 4cad51425325 removed the necessity for defining gateway, but we still continued to check for it. Remove this check, as well as the check for netmask. When not supplied, netmask will default to /24. Signed-off-by: Dave Reisner --- network | 8 +------- rc.conf | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/network b/network index 38ada9a..0177c04 100755 --- a/network +++ b/network @@ -26,13 +26,7 @@ network_up() { ip link set dev $interface up || return 1 if [[ $address ]]; then - for var in netmask gateway; do - if [[ -z ${!var} ]]; then - printf "${C_FAIL}Error: static address defined without $var!\n" - return 1 - fi - done - ip addr add $address/$netmask broadcast ${broadcast:-+} dev $interface || return 1 + ip addr add $address/${netmask:-24} broadcast ${broadcast:-+} dev $interface || return 1 [[ $gateway ]] && { ip route add default via $gateway || return 1; } else dhcpcd $DHCPCD_ARGS $interface || return 1 diff --git a/rc.conf b/rc.conf index c17c48c..5984171 100644 --- a/rc.conf +++ b/rc.conf @@ -64,7 +64,7 @@ HOSTNAME="myhost" # Wired network setup # - interface: name of device (required) # - address: IP address (leave blank for DHCP) -# - netmask: subnet mask (ignored for DHCP) +# - netmask: subnet mask (ignored for DHCP) (optional, defaults to 255.255.255.0) # - broadcast: broadcast address (ignored for DHCP) (optional) # - gateway: default route (ignored for DHCP) # -- cgit v1.2.3 From 60191a3cdf4923fea04ae1fb383b9367db9227a0 Mon Sep 17 00:00:00 2001 From: jofko Date: Tue, 14 Jun 2011 20:49:05 +0200 Subject: Adding hook sysinit_postmount In some cases is good to know when rc.sysinit is going to use /usr See FS#24712 Signed-off-by: jofko [tomegun: added comment to 'functions' and changed name of hook] Signed-off-by: Tom Gundersen --- functions | 1 + rc.sysinit | 1 + 2 files changed, 2 insertions(+) diff --git a/functions b/functions index 2ee56b4..d94a9ef 100644 --- a/functions +++ b/functions @@ -338,6 +338,7 @@ read_crypttab() { # sysinit_udevsettled: after uevents have settled in rc.sysinit # single_udevsettled: after uevents have settled in rc.single # sysinit_premount: before local filesystems are mounted, but after root is mounted read-write in rc.sysinit +# sysinit_postmount: after local filesystems are mounted # shutdown_prekillall: before all processes are being killed in rc.shutdown # single_prekillall: before all processes are being killed in rc.single # shutdown_postkillall: after all processes have been killed in rc.shutdown diff --git a/rc.sysinit b/rc.sysinit index 8158f78..2158f4a 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -277,6 +277,7 @@ stat_busy "Mounting Local Filesystems" run_hook sysinit_premount # now mount all the local filesystems mount -a -t $NETFS -O no_netdev + run_hook sysinit_postmount stat_done # enable monitoring of lvm2 groups, now that the filesystems are mounted rw -- cgit v1.2.3 From cc514f32d04194198e42a63d24ce2e5e9b3df031 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Sun, 19 Jun 2011 13:15:57 -0400 Subject: rc.shutdown: continuation of fe48fab2c2c35c Signed-off-by: Dave Reisner --- rc.shutdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rc.shutdown b/rc.shutdown index a040bbe..fc12958 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -47,7 +47,7 @@ halt -w status "Deactivating Swap" swapoff -a # stop monitoring of lvm2 groups before unmounting filesystems -if [[ $USELVM =~ yes|YES && -x $(type -P lvm) && -d /sys/block ]]; then +if [[ $USELVM = [Yy][Ee][Ss] && -x $(type -P lvm) && -d /sys/block ]]; then status "Deactivating monitoring of LVM2 groups" \ vgchange --monitor n >/dev/null 2>&1 fi @@ -66,7 +66,7 @@ if [[ -f /etc/crypttab && -n $CS ]] && grep -q ^[^#] /etc/crypttab; then stat_busy "Deactivating encrypted volumes:" # Maybe someone has LVM on an encrypted block device # executing an extra vgchange is errorless - if [[ $USELVM =~ yes|YES ]]; then + if [[ $USELVM = [Yy][Ee][Ss] ]]; then vgchange --sysinit -a n >/dev/null 2>&1 fi do_lock() { @@ -81,7 +81,7 @@ if [[ -f /etc/crypttab && -n $CS ]] && grep -q ^[^#] /etc/crypttab; then stat_done fi -if [[ $USELVM =~ yes|YES && -x $(type -P lvm) && -d /sys/block ]]; then +if [[ $USELVM = [Yy][Ee][Ss] && -x $(type -P lvm) && -d /sys/block ]]; then status "Deactivating LVM2 groups" vgchange --sysinit -a n >/dev/null 2>&1 fi -- cgit v1.2.3 From 3498c2a1b387fb83a960e6ed1faaa3e5fd68fa50 Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Mon, 20 Jun 2011 19:34:07 +0200 Subject: status: adjust number of columns after loading modules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In case loading modules enables a frambuffer with higher resolution than the standard 80 columns, we recalculate the number of columns after all modules have been loaded. Original-patch-by: Aaron Griffin Original-patch-by: Søren Poulsen Signed-off-by: Tom Gundersen --- functions | 60 ++++++++++++++++++++++++++++++++---------------------------- rc.sysinit | 3 +++ 2 files changed, 35 insertions(+), 28 deletions(-) diff --git a/functions b/functions index d94a9ef..d0747ba 100644 --- a/functions +++ b/functions @@ -4,26 +4,40 @@ # width: -STAT_COL=80 -if [[ ! -t 1 ]]; then - USECOLOR="" -elif [[ -t 0 ]]; then - # stty will fail when stdin isn't a terminal - STAT_COL="$(/bin/stty size)" - # stty gives "rows cols"; strip the rows number, we just want columns - STAT_COL="${STAT_COL##* }" -elif /bin/tput cols &>/dev/null; then - # is /usr/share/terminfo already mounted, and TERM recognized? - STAT_COL=$(/bin/tput cols) -fi -if ((STAT_COL==0)); then - # if output was 0 (serial console), set default width to 80 +calc_columns () { STAT_COL=80 - USECOLOR="" -fi + if [[ ! -t 1 ]]; then + USECOLOR="" + elif [[ -t 0 ]]; then + # stty will fail when stdin isn't a terminal + STAT_COL="$(/bin/stty size)" + # stty gives "rows cols"; strip the rows number, we just want columns + STAT_COL="${STAT_COL##* }" + elif /bin/tput cols &>/dev/null; then + # is /usr/share/terminfo already mounted, and TERM recognized? + STAT_COL=$(/bin/tput cols) + fi + if ((STAT_COL==0)); then + # if output was 0 (serial console), set default width to 80 + STAT_COL=80 + USECOLOR="" + fi + + # we use 13 characters for our own stuff + STAT_COL=$(($STAT_COL - 13)) + + if [[ -t 1 ]]; then + SAVE_POSITION="\e[s" + RESTORE_POSITION="\e[u" + DEL_TEXT="\e[$(($STAT_COL+4))G" + else + SAVE_POSITION="" + RESTORE_POSITION="" + DEL_TEXT="" + fi +} -# we use 13 characters for our own stuff -STAT_COL=$(($STAT_COL - 13)) +calc_columns # disable colors on broken terminals TERM_COLORS="$(/bin/tput colors 2>/dev/null)" @@ -76,16 +90,6 @@ if [[ $USECOLOR =~ yes|YES ]]; then fi fi -if [[ -t 1 ]]; then - SAVE_POSITION="\e[s" - RESTORE_POSITION="\e[u" - DEL_TEXT="\e[$(($STAT_COL+4))G" -else - SAVE_POSITION="" - RESTORE_POSITION="" - DEL_TEXT="" -fi - # prefixes: PREFIX_REG="::" diff --git a/rc.sysinit b/rc.sysinit index 2158f4a..b5d63ea 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -95,6 +95,9 @@ unset mods status "Waiting for UDev uevents to be processed" \ udevadm settle --timeout=${UDEV_TIMEOUT:-30} +# in case loading a module changed the display mode +calc_columns + run_hook sysinit_udevsettled # bring up the loopback interface -- cgit v1.2.3 From f49bb1f3cbdac7f62c69dbe1b20d87bd77cbcb6b Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Mon, 20 Jun 2011 13:54:39 -0400 Subject: network: always warn about deprecation for old funcs There's no way the ifup|ifdown|rtup|rtdown etc functions will ever hit the new iproute2 based logic. Therefore, always remind the user that this functionality is deprecated. This prevents misusage of the functionality as seen in FS#24714. Signed-off-by: Dave Reisner --- network | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network b/network index 0177c04..74fc3d1 100755 --- a/network +++ b/network @@ -292,7 +292,7 @@ case "$1" in ;; ifup|ifdown|iflist|rtup|rtdown|rtlist) # deprecation check - need_legacy && deprecated + deprecated $1 $2 ;; *) -- cgit v1.2.3 From 495832e09c060ce3327cd19c1ddc2160182e82f8 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Wed, 22 Jun 2011 12:07:43 +0200 Subject: Move fsck stuff into functions to allow custom overrides (FS#18736) --- functions | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ rc.sysinit | 51 ++------------------------------------------------- 2 files changed, 60 insertions(+), 49 deletions(-) diff --git a/functions b/functions index d0747ba..a5d87dc 100644 --- a/functions +++ b/functions @@ -316,6 +316,64 @@ read_crypttab() { return $failed } +fsck_all() { + stat_busy "Checking Filesystems" + FSCK_OUT=/dev/stdout + FSCK_ERR=/dev/stdout + FSCK_FD= + FORCEFSCK= + [[ -f /forcefsck ]] && FORCEFSCK="-- -f" + local cmdarg + for cmdarg in $(< /proc/cmdline); do + [[ "$cmdarg" == forcefsck ]] && FORCEFSCK="-- -f" && break + done + run_hook sysinit_prefsck + fsck -A -T -C$FSCK_FD -a -t "$NETFS,noopts=_netdev" $FORCEFSCK >$FSCK_OUT 2>$FSCK_ERR + local fsckret=$? + if ((fsckret > 1)); then + stat_fail + else + stat_done + fi + run_hook sysinit_postfsck + return $fsckret +} + +fsck_reboot() { + # $1 = exit code returned by fsck + local fsckret=$1 + if (( ( fsckret & 2) == 2)); then + echo + echo "********************** REBOOT REQUIRED *********************" + echo "* *" + echo "* The system will be rebooted automatically in 15 seconds. *" + echo "* *" + echo "************************************************************" + echo + sleep 15 + elif ((fsckret > 1 && fsckret != 32)); then + echo + echo "***************** FILESYSTEM CHECK FAILED ****************" + echo "* *" + echo "* Please repair manually and reboot. Note that the root *" + echo "* file system is currently mounted read-only. To remount *" + echo "* it read-write type: mount -n -o remount,rw / *" + echo "* When you exit the maintenance shell the system will *" + echo "* reboot automatically. *" + echo "* *" + echo "************************************************************" + echo + sulogin -p + else + return + fi + echo "Automatic reboot in progress..." + umount -a + mount -n -o remount,ro / + reboot -f + exit 0 +} + ############################### # Custom hooks in initscripts # ############################### diff --git a/rc.sysinit b/rc.sysinit index b5d63ea..e08adc6 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -214,55 +214,8 @@ fi NETFS="nonfs,nonfs4,nosmbfs,nocifs,nocodafs,noncpfs,nosysfs,noshfs,nofuse,nofuseblk,noglusterfs,nodavfs" if [[ -x $(type -P fsck) ]]; then - stat_busy "Checking Filesystems" - fsck_reboot() { - echo "Automatic reboot in progress..." - umount -a - mount -n -o remount,ro / - reboot -f - exit 0 - } - FSCK_OUT=/dev/stdout - FSCK_ERR=/dev/stdout - FSCK_FD= - FORCEFSCK= - [[ -f /forcefsck ]] && FORCEFSCK="-- -f" - for cmdarg in $(< /proc/cmdline); do - [[ "$cmdarg" == forcefsck ]] && FORCEFSCK="-- -f" && break - done - run_hook sysinit_prefsck - fsck -A -T -C$FSCK_FD -a -t "$NETFS,noopts=_netdev" $FORCEFSCK >$FSCK_OUT 2>$FSCK_ERR - fsckret=$? - if ((fsckret > 1)); then - stat_fail - fi - run_hook sysinit_postfsck - if (( ( fsckret & 2) == 2)); then - echo - echo "********************** REBOOT REQUIRED *********************" - echo "* *" - echo "* The system will be rebooted automatically in 15 seconds. *" - echo "* *" - echo "************************************************************" - echo - sleep 15 - fsck_reboot - elif ((fsckret > 1 && fsckret != 32)); then - echo - echo "***************** FILESYSTEM CHECK FAILED ****************" - echo "* *" - echo "* Please repair manually and reboot. Note that the root *" - echo "* file system is currently mounted read-only. To remount *" - echo "* it read-write type: mount -n -o remount,rw / *" - echo "* When you exit the maintenance shell the system will *" - echo "* reboot automatically. *" - echo "* *" - echo "************************************************************" - echo - sulogin -p - fsck_reboot - fi - stat_done + fsck_all + fsck_reboot $? fi stat_busy "Mounting Local Filesystems" -- cgit v1.2.3 From ddac0b3efd33a8e8daa79bf7c8f85ef8b5079b60 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Wed, 22 Jun 2011 12:07:44 +0200 Subject: Simplify fsck functions --- functions | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/functions b/functions index a5d87dc..9b6f695 100644 --- a/functions +++ b/functions @@ -322,11 +322,7 @@ fsck_all() { FSCK_ERR=/dev/stdout FSCK_FD= FORCEFSCK= - [[ -f /forcefsck ]] && FORCEFSCK="-- -f" - local cmdarg - for cmdarg in $(< /proc/cmdline); do - [[ "$cmdarg" == forcefsck ]] && FORCEFSCK="-- -f" && break - done + [[ -f /forcefsck ]] || in_array forcefsck $(< /proc/cmdline) && FORCEFSCK="-- -f" run_hook sysinit_prefsck fsck -A -T -C$FSCK_FD -a -t "$NETFS,noopts=_netdev" $FORCEFSCK >$FSCK_OUT 2>$FSCK_ERR local fsckret=$? @@ -341,8 +337,10 @@ fsck_all() { fsck_reboot() { # $1 = exit code returned by fsck - local fsckret=$1 - if (( ( fsckret & 2) == 2)); then + # Ignore conditions 'FS errors corrected' and 'Cancelled by the user' + if (( ($1 | 33) == 33 )); then + return 0 + elif (($1 & 2)); then echo echo "********************** REBOOT REQUIRED *********************" echo "* *" @@ -351,7 +349,7 @@ fsck_reboot() { echo "************************************************************" echo sleep 15 - elif ((fsckret > 1 && fsckret != 32)); then + else echo echo "***************** FILESYSTEM CHECK FAILED ****************" echo "* *" @@ -364,8 +362,6 @@ fsck_reboot() { echo "************************************************************" echo sulogin -p - else - return fi echo "Automatic reboot in progress..." umount -a -- cgit v1.2.3 From 06b4ed7da352248c760e6a78273ffd4ca7f435d7 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Wed, 22 Jun 2011 12:07:45 +0200 Subject: Allow custom fsck on shutdown via hook (FS#18736) --- functions | 3 +++ rc.shutdown | 2 ++ rc.sysinit | 2 -- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/functions b/functions index 9b6f695..a02bd3b 100644 --- a/functions +++ b/functions @@ -316,6 +316,8 @@ read_crypttab() { return $failed } +NETFS="nonfs,nonfs4,nosmbfs,nocifs,nocodafs,noncpfs,nosysfs,noshfs,nofuse,nofuseblk,noglusterfs,nodavfs" + fsck_all() { stat_busy "Checking Filesystems" FSCK_OUT=/dev/stdout @@ -401,6 +403,7 @@ fsck_reboot() { # single_prekillall: before all processes are being killed in rc.single # shutdown_postkillall: after all processes have been killed in rc.shutdown # single_postkillall: after all processes have been killed in rc.single +# shutdown_postumount: after filesystems are unmounted # shutdown_poweroff: directly before powering off in rc.shutdown # # Declare add_hook and run_hook as read-only to prevent overwriting them. diff --git a/rc.shutdown b/rc.shutdown index fc12958..637974f 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -61,6 +61,8 @@ else fi stat_done +run_hook shutdown_postumount + # Kill non-root encrypted partition mappings if [[ -f /etc/crypttab && -n $CS ]] && grep -q ^[^#] /etc/crypttab; then stat_busy "Deactivating encrypted volumes:" diff --git a/rc.sysinit b/rc.sysinit index e08adc6..5af74a1 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -211,8 +211,6 @@ if [[ -f /etc/crypttab && -n $CS ]] && grep -q ^[^#] /etc/crypttab; then fi fi -NETFS="nonfs,nonfs4,nosmbfs,nocifs,nocodafs,noncpfs,nosysfs,noshfs,nofuse,nofuseblk,noglusterfs,nodavfs" - if [[ -x $(type -P fsck) ]]; then fsck_all fsck_reboot $? -- cgit v1.2.3 From ccc777c28b7b420e3ceaaf2616c24d3241871292 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Wed, 22 Jun 2011 12:07:46 +0200 Subject: Move mount -a into functions to allow custom override (fsck on loop) --- functions | 8 ++++++++ rc.sysinit | 7 ++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/functions b/functions index a02bd3b..f4435b1 100644 --- a/functions +++ b/functions @@ -372,6 +372,14 @@ fsck_reboot() { exit 0 } +mount_all() { + stat_busy "Mounting Local Filesystems" + run_hook sysinit_premount + mount -a -t $NETFS -O no_netdev + run_hook sysinit_postmount + stat_done +} + ############################### # Custom hooks in initscripts # ############################### diff --git a/rc.sysinit b/rc.sysinit index 5af74a1..7bcd0a5 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -216,7 +216,7 @@ if [[ -x $(type -P fsck) ]]; then fsck_reboot $? fi -stat_busy "Mounting Local Filesystems" +status "Remounting Root Read/Write" \ mount -n -o remount,rw / # don't touch /etc/mtab if it is a symlink to /proc/self/mounts @@ -228,11 +228,8 @@ stat_busy "Mounting Local Filesystems" cat /proc/mounts >| /etc/mtab fi - run_hook sysinit_premount # now mount all the local filesystems - mount -a -t $NETFS -O no_netdev - run_hook sysinit_postmount -stat_done +mount_all # enable monitoring of lvm2 groups, now that the filesystems are mounted rw if [[ $USELVM = [Yy][Ee][Ss] && -x $(type -P lvm) && -d /sys/block ]]; then -- cgit v1.2.3 From 310c53f367c2d44f15d40c79dbb6428a0d55bcdf Mon Sep 17 00:00:00 2001 From: Andrwe Lord Weber Date: Fri, 10 Jun 2011 17:00:03 +0200 Subject: added get_pid() and ck_pidfile() (FS#18654) Implemented suggestions of Dave. get_pid: Arguments: programname Returns: PID of program ck_pidfile: Arguments: PID-file programname Returns: 0 - PID in PID-file is of program 1 - PID in PID-file is not of program Signed-off-by: Andrwe Lord Weber Signed-off-by: Tom Gundersen --- functions | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/functions b/functions index f4435b1..3e92fb0 100644 --- a/functions +++ b/functions @@ -235,6 +235,21 @@ ck_status() { fi } +# Return PID of $1 +get_pid() { + pidof -o %PPID $1 || return 1 +} + +# Check if PID-file $1 is still the active PID-file for command $2 +ck_pidfile() { + if [[ -f "$1" ]]; then + read -r fpid <"$1" + ppid=$(get_pid $2) + [[ "$fpid" = "$ppid" ]] && return 0 + fi + return 1 +} + # PIDs to be omitted by killall5 declare -a omit_pids -- cgit v1.2.3 From 38c40cb7616a785eaaf78d8643b5d73d01af5ac7 Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Thu, 23 Jun 2011 21:19:45 +0200 Subject: functions: warn if daemons are started recursively In particular, recomend against using ck_depends. Signed-off-by: Tom Gundersen --- functions | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/functions b/functions index 3e92fb0..ea5b11f 100644 --- a/functions +++ b/functions @@ -4,6 +4,14 @@ # width: +if [[ $1 == "start" ]]; then + if [[ $STARTING ]]; then + echo "A daemon is starting another daemon, this is unlikely to work as intended.\n" + else + export STARTING=1 + fi +fi + calc_columns () { STAT_COL=80 if [[ ! -t 1 ]]; then @@ -201,6 +209,8 @@ start_daemon() { have_daemon "$1" && /etc/rc.d/"$1" start } +# Never use this function, it causes daemons to be stoped in the wrong order. +# The only way to start a daemon at boot is to add it to the DAEMONS array. ck_depends() { for daemon in "$@"; do ck_daemon "$daemon" && start_daemon "$daemon" -- cgit v1.2.3 From 31e27d48c25495857d052964b59ba387cb809bba Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Thu, 23 Jun 2011 19:52:03 +0200 Subject: Fix hwclock comments --- rc.conf | 2 +- rc.sysinit | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/rc.conf b/rc.conf index 5984171..b217ddb 100644 --- a/rc.conf +++ b/rc.conf @@ -9,7 +9,7 @@ # LOCALE: available languages can be listed with the 'locale -a' command # DAEMON_LOCALE: If set to 'yes', use $LOCALE as the locale during daemon # startup and during the boot process. If set to 'no', the C locale is used. -# HARDWARECLOCK: set to "UTC" or "localtime", any other value will result +# HARDWARECLOCK: set to "", "UTC" or "localtime", any other value will result # in the hardware clock being left untouched (useful for virtualization) # Note: Using "localtime" is discouraged. # TIMEZONE: timezones are found in /usr/share/zoneinfo diff --git a/rc.sysinit b/rc.sysinit index 7bcd0a5..e4c1c36 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -70,8 +70,7 @@ if [[ $HWCLOCK_PARAMS ]]; then # 3. This will set the clock, if using non-UTC, off the last known # configured timezone. Any new timezone put in rc.conf is copied over at # a later time. - # This does *NOT* take into account a time adjustment file as /var may not be - # mounted yet. A second set may occur in rc.d/hwclock to match rc.conf. + # This also sets the kernel time zone. if [[ -f /etc/localtime ]]; then hwclock $HWCLOCK_PARAMS fi -- cgit v1.2.3 From 727acff0c55abdacde0cc8832f18fed729bccc5a Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Fri, 24 Jun 2011 11:46:36 +0200 Subject: Simplify timezone copying Error/stat_fail when $TIMEZONE is invalid instead of skipping silently. --- rc.shutdown | 5 ++--- rc.sysinit | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/rc.shutdown b/rc.shutdown index 637974f..4014df2 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -35,10 +35,9 @@ fi dd if=/dev/urandom of=$RANDOM_SEED count=1 bs=$POOL_SIZE &> /dev/null stat_done -if [[ $TIMEZONE && -e /usr/share/zoneinfo/$TIMEZONE ]]; then - rm -f /etc/localtime +if [[ $TIMEZONE ]]; then status "Saving Time Zone" \ - cp "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime + cp --remove-destination "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime fi # Write to wtmp file before unmounting diff --git a/rc.sysinit b/rc.sysinit index e4c1c36..6c1fef9 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -238,10 +238,9 @@ fi status "Activating Swap" swapon -a -if [[ $TIMEZONE && -e /usr/share/zoneinfo/$TIMEZONE ]]; then - rm -f /etc/localtime +if [[ $TIMEZONE ]]; then status "Configuring Time Zone" \ - cp "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime + cp --remove-destination "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime fi RANDOM_SEED=/var/lib/misc/random-seed -- cgit v1.2.3 From d19b31f04339ed50061e4c7d21288491f2f9ebd6 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Thu, 23 Jun 2011 19:54:23 +0200 Subject: Simplify creating files by using /bin/install --- rc.sysinit | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/rc.sysinit b/rc.sysinit index 6c1fef9..13d789f 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -257,9 +257,7 @@ stat_busy "Removing Leftover Files" [[ ! -L /var/run && ! -L /var/run/daemons ]] && rm -rf /var/run/daemons && ln -s /run/daemons /var/run/daemons - : >| /var/run/utmp - chmod 0664 /var/run/utmp - chown root:utmp /var/run/utmp + install -Tm 0664 -o root -g utmp <(:) /var/run/utmp # Keep {x,k,g}dm happy with xorg mkdir -m1777 /tmp/.{X11,ICE}-unix stat_done @@ -272,8 +270,7 @@ fi stat_busy "Setting Locale: ${LOCALE:=en_US}" # Flush old locale settings - : >| /etc/profile.d/locale.sh - chmod 755 /etc/profile.d/locale.sh + install -Tm 0755 <(:) /etc/profile.d/locale.sh # Set user defined locale echo "export LANG=$LOCALE" >>/etc/profile.d/locale.sh stat_done @@ -306,13 +303,10 @@ fi set_consolefont if [[ -e /proc/sys/kernel/dmesg_restrict && $(< /proc/sys/kernel/dmesg_restrict) -eq 1 ]]; then - : >| /var/log/dmesg.log - chmod 600 /var/log/dmesg.log + install -Tm 0600 <( dmesg ) /var/log/dmesg.log else - : >| /var/log/dmesg.log - chmod 644 /var/log/dmesg.log + install -Tm 0644 <( dmesg ) /var/log/dmesg.log fi -dmesg >| /var/log/dmesg.log run_hook sysinit_end -- cgit v1.2.3 From fa8d09e1fb7057332eac795aa346763c11476b4b Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Thu, 23 Jun 2011 20:05:09 +0200 Subject: Simplify keyboard map loading by using loadkeys autodetection --- rc.sysinit | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rc.sysinit b/rc.sysinit index 13d789f..5dc3da6 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -286,7 +286,6 @@ if [[ ${LOCALE,,} =~ utf ]]; then done echo 1 > /sys/module/vt/parameters/default_utf8 stat_done - [[ $KEYMAP ]] && status "Loading Keyboard Map: $KEYMAP" loadkeys -q -u $KEYMAP else stat_busy "Setting Consoles to legacy mode" # make non-UTF-8 consoles work on 2.6.24 and newer kernels @@ -296,8 +295,9 @@ else done echo 0 > /sys/module/vt/parameters/default_utf8 stat_done - [[ $KEYMAP ]] && status "Loading Keyboard Map: $KEYMAP" loadkeys -q $KEYMAP fi +[[ $KEYMAP ]] && \ + status "Loading Keyboard Map: $KEYMAP" loadkeys -q $KEYMAP # Set console font if required set_consolefont -- cgit v1.2.3 From ad707c4fcd2ea15bade2c37ce47527072f2a41bc Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Fri, 24 Jun 2011 08:35:17 +0200 Subject: Simplify API filesystems mounting --- rc.sysinit | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/rc.sysinit b/rc.sysinit index 5dc3da6..2b86011 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -20,15 +20,10 @@ export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" mountpoint -q /proc || mount -n -t proc proc /proc -o nosuid,noexec,nodev mountpoint -q /sys || mount -n -t sysfs sys /sys -o nosuid,noexec,nodev mountpoint -q /run || mount -n -t tmpfs run /run -o mode=755,size=10M,nosuid,nodev -if ! mountpoint -q /dev; then - if grep -q devtmpfs /proc/filesystems &>/dev/null; then - mount -n -t devtmpfs udev /dev -o mode=0755,size=10M,nosuid - else - mount -n -t tmpfs udev /dev -o mode=0755,size=10M,nosuid - fi -fi -mkdir -p /run/lock /dev/{pts,shm} -chmod 1777 /run/lock +mountpoint -q /dev || mount -n -t devtmpfs udev /dev -o mode=0755,size=10M,nosuid &>/dev/null \ + || mount -n -t tmpfs udev /dev -o mode=0755,size=10M,nosuid +mkdir -p -m 1777 /run/lock +mkdir -p /dev/{pts,shm} mountpoint -q /dev/pts || mount -n /dev/pts &> /dev/null \ || mount -n -t devpts devpts /dev/pts -o mode=620,gid=5,nosuid,noexec mountpoint -q /dev/shm || mount -n /dev/shm &> /dev/null \ -- cgit v1.2.3 From 6b5fe69bb65b1584272bc1161a85e07fb95b66cb Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Fri, 24 Jun 2011 09:28:25 +0200 Subject: Some cosmetics --- functions | 51 ++++++++++++++++++++++++++------------------------- rc.shutdown | 17 +++++++++-------- rc.sysinit | 39 +++++++++++++++++++-------------------- 3 files changed, 54 insertions(+), 53 deletions(-) diff --git a/functions b/functions index ea5b11f..d57fe16 100644 --- a/functions +++ b/functions @@ -25,14 +25,14 @@ calc_columns () { # is /usr/share/terminfo already mounted, and TERM recognized? STAT_COL=$(/bin/tput cols) fi - if ((STAT_COL==0)); then + if (( STAT_COL == 0 )); then # if output was 0 (serial console), set default width to 80 STAT_COL=80 USECOLOR="" fi # we use 13 characters for our own stuff - STAT_COL=$(($STAT_COL - 13)) + STAT_COL=$(( $STAT_COL - 13 )) if [[ -t 1 ]]; then SAVE_POSITION="\e[s" @@ -49,7 +49,7 @@ calc_columns # disable colors on broken terminals TERM_COLORS="$(/bin/tput colors 2>/dev/null)" -if (($? != 3)); then +if (( $? != 3 )); then case $TERM_COLORS in *[!0-9]*) USECOLOR="";; [0-7]) USECOLOR="";; @@ -65,14 +65,14 @@ unset TZ unset LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY \ LC_MESSAGES LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE \ LC_MEASUREMENT LC_IDENTIFICATION LC_ALL -if [[ $DAEMON_LOCALE =~ yes|YES && -n $LOCALE ]]; then +if [[ $DAEMON_LOCALE = [yY][eE][sS] && $LOCALE ]]; then export LANG="${LOCALE}" else export LANG=C fi # set colors -if [[ $USECOLOR =~ yes|YES ]]; then +if [[ $USECOLOR = [yY][eE][sS] ]]; then if /bin/tput setaf 0 &>/dev/null; then C_CLEAR="$(tput sgr0)" # clear text C_MAIN="${C_CLEAR}$(/bin/tput bold)" # main text @@ -247,17 +247,17 @@ ck_status() { # Return PID of $1 get_pid() { - pidof -o %PPID $1 || return 1 + pidof -o %PPID $1 || return 1 } # Check if PID-file $1 is still the active PID-file for command $2 ck_pidfile() { - if [[ -f "$1" ]]; then - read -r fpid <"$1" - ppid=$(get_pid $2) - [[ "$fpid" = "$ppid" ]] && return 0 - fi - return 1 + if [[ -f "$1" ]]; then + read -r fpid <"$1" + ppid=$(get_pid $2) + [[ "$fpid" = "$ppid" ]] && return 0 + fi + return 1 } # PIDs to be omitted by killall5 @@ -279,9 +279,9 @@ kill_everything() { done # Shutdown daemons in reverse order - for ((i=${#DAEMONS[@]}-1; i>=0; i--)); do - [[ ${DAEMONS[$i]:0:1} = '!' ]] && continue - ck_daemon ${DAEMONS[$i]#@} || stop_daemon ${DAEMONS[$i]#@} + for (( i=${#DAEMONS[@]}-1; i>=0; i-- )); do + [[ ${DAEMONS[i]} = '!'* ]] && continue + ck_daemon ${DAEMONS[i]#@} || stop_daemon ${DAEMONS[i]#@} done # Terminate all processes @@ -291,12 +291,12 @@ kill_everything() { for pid in ${omit_pids[@]}; do k5args+=" -o $pid" done - /sbin/killall5 -15 $k5args &> /dev/null + /sbin/killall5 -15 $k5args &>/dev/null /bin/sleep 5 stat_done stat_busy "Sending SIGKILL To Processes" - /sbin/killall5 -9 $k5args &> /dev/null + /sbin/killall5 -9 $k5args &>/dev/null /bin/sleep 1 stat_done @@ -304,7 +304,7 @@ kill_everything() { } activate_vgs() { - [[ $USELVM =~ yes|YES && -x /sbin/lvm && -d /sys/block ]] || return + [[ $USELVM = [yY][eE][sS] && -x $(type -P lvm) && -d /sys/block ]] || return # Kernel 2.6.x, LVM2 groups /sbin/modprobe -q dm-mod 2>/dev/null stat_busy "Activating LVM2 groups" @@ -330,7 +330,7 @@ read_crypttab() { # $1 = function to call with the split out line from the crypttab local line nspo failed=0 while read line; do - [[ $line && ${line:0:1} != '#' ]] || continue + [[ $line && $line != '#'* ]] || continue eval nspo=("${line%#*}") if $1 "${nspo[0]}" "${nspo[1]}" "${nspo[2]}" "${nspo[*]:3}"; then crypto_unlocked=1 @@ -353,7 +353,7 @@ fsck_all() { run_hook sysinit_prefsck fsck -A -T -C$FSCK_FD -a -t "$NETFS,noopts=_netdev" $FORCEFSCK >$FSCK_OUT 2>$FSCK_ERR local fsckret=$? - if ((fsckret > 1)); then + if (( fsckret > 1 )); then stat_fail else stat_done @@ -367,7 +367,7 @@ fsck_reboot() { # Ignore conditions 'FS errors corrected' and 'Cancelled by the user' if (( ($1 | 33) == 33 )); then return 0 - elif (($1 & 2)); then + elif (( $1 & 2 )); then echo echo "********************** REBOOT REQUIRED *********************" echo "* *" @@ -442,7 +442,7 @@ mount_all() { # Declare add_hook and run_hook as read-only to prevent overwriting them. # Too bad we cannot do the same thing with hook_funcs -if [[ $RC_FUNCTIONS_HOOK_FUNCS_DEFINED -ne 1 ]]; then +if (( RC_FUNCTIONS_HOOK_FUNCS_DEFINED != 1 )); then declare -A hook_funcs add_hook() { @@ -468,11 +468,12 @@ set_consolefont() { stat_busy "Loading Console Font: $CONSOLEFONT" #CONSOLEMAP in UTF-8 shouldn't be used [[ $CONSOLEMAP && ${LOCALE,,} =~ utf ]] && CONSOLEMAP="" + local i for i in /dev/tty[0-9]*; do /usr/bin/setfont ${CONSOLEMAP:+-m ${CONSOLEMAP}} \ - $CONSOLEFONT -C ${i} >/dev/null 2>&1 + $CONSOLEFONT -C ${i} &>/dev/null done - if (($? != 0)); then + if (( $? )); then stat_fail elif [[ $CONSOLEMAP ]]; then cat <<"EOF" >>/etc/profile.d/locale.sh @@ -491,7 +492,7 @@ done # Exit current shell if user is not root need_root() { - (( $EUID != 0 )) && printf 'You need to be root.\n' && exit 1 + (( EUID )) && printf 'You need to be root.\n' && exit 1 } # Quit script if it's not running by root diff --git a/rc.shutdown b/rc.shutdown index 4014df2..2d23554 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -32,7 +32,7 @@ if [[ -r $POOL_FILE ]]; then else POOL_SIZE=512 fi -dd if=/dev/urandom of=$RANDOM_SEED count=1 bs=$POOL_SIZE &> /dev/null +dd if=/dev/urandom of=$RANDOM_SEED count=1 bs=$POOL_SIZE &>/dev/null stat_done if [[ $TIMEZONE ]]; then @@ -48,7 +48,7 @@ status "Deactivating Swap" swapoff -a # stop monitoring of lvm2 groups before unmounting filesystems if [[ $USELVM = [Yy][Ee][Ss] && -x $(type -P lvm) && -d /sys/block ]]; then status "Deactivating monitoring of LVM2 groups" \ - vgchange --monitor n >/dev/null 2>&1 + vgchange --monitor n &>/dev/null fi stat_busy "Unmounting Filesystems" @@ -63,16 +63,16 @@ stat_done run_hook shutdown_postumount # Kill non-root encrypted partition mappings -if [[ -f /etc/crypttab && -n $CS ]] && grep -q ^[^#] /etc/crypttab; then +if [[ -f /etc/crypttab && $CS ]] && grep -q ^[^#] /etc/crypttab; then stat_busy "Deactivating encrypted volumes:" # Maybe someone has LVM on an encrypted block device # executing an extra vgchange is errorless if [[ $USELVM = [Yy][Ee][Ss] ]]; then - vgchange --sysinit -a n >/dev/null 2>&1 + vgchange --sysinit -a n &>/dev/null fi do_lock() { stat_append "${1}.." - if $CS remove "$1" >/dev/null 2>&1; then + if $CS remove "$1" &>/dev/null; then stat_append "ok " else stat_append "failed " @@ -83,10 +83,11 @@ if [[ -f /etc/crypttab && -n $CS ]] && grep -q ^[^#] /etc/crypttab; then fi if [[ $USELVM = [Yy][Ee][Ss] && -x $(type -P lvm) && -d /sys/block ]]; then - status "Deactivating LVM2 groups" vgchange --sysinit -a n >/dev/null 2>&1 + status "Deactivating LVM2 groups" vgchange --sysinit -a n &>/dev/null fi -status "Remounting Root Filesystem Read-only" mount -n -o remount,ro / +status "Remounting Root Filesystem Read-only" \ + mount -n -o remount,ro / run_hook shutdown_poweroff @@ -98,7 +99,7 @@ if [[ $RUNLEVEL = 0 ]]; then else printhl "${C_H2}REBOOTING" # if kexec is installed and a kernel is loaded, use it - [[ -x $(type -P kexec) ]] && kexec -e > /dev/null 2>&1 + [[ -x $(type -P kexec) ]] && kexec -e &>/dev/null reboot -d -f -i fi diff --git a/rc.sysinit b/rc.sysinit index 2b86011..5167a14 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -19,14 +19,14 @@ export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" # mount /proc, /sys, /run, /dev, /run/lock, /dev/pts, /dev/shm (the api filesystems) mountpoint -q /proc || mount -n -t proc proc /proc -o nosuid,noexec,nodev mountpoint -q /sys || mount -n -t sysfs sys /sys -o nosuid,noexec,nodev -mountpoint -q /run || mount -n -t tmpfs run /run -o mode=755,size=10M,nosuid,nodev +mountpoint -q /run || mount -n -t tmpfs run /run -o mode=0755,size=10M,nosuid,nodev mountpoint -q /dev || mount -n -t devtmpfs udev /dev -o mode=0755,size=10M,nosuid &>/dev/null \ || mount -n -t tmpfs udev /dev -o mode=0755,size=10M,nosuid mkdir -p -m 1777 /run/lock mkdir -p /dev/{pts,shm} -mountpoint -q /dev/pts || mount -n /dev/pts &> /dev/null \ - || mount -n -t devpts devpts /dev/pts -o mode=620,gid=5,nosuid,noexec -mountpoint -q /dev/shm || mount -n /dev/shm &> /dev/null \ +mountpoint -q /dev/pts || mount -n /dev/pts &>/dev/null \ + || mount -n -t devpts devpts /dev/pts -o mode=0620,gid=5,nosuid,noexec +mountpoint -q /dev/shm || mount -n /dev/shm &>/dev/null \ || mount -n -t tmpfs shm /dev/shm -o mode=1777,nosuid,nodev # remount root ro to allow for fsck later on, we remount now to @@ -84,7 +84,6 @@ stat_done if [[ -f /proc/modules ]] && (( ${#MODULES[*]} )); then status "Loading Modules" modprobe -ab "${MODULES[@]}" fi -unset mods status "Waiting for UDev uevents to be processed" \ udevadm settle --timeout=${UDEV_TIMEOUT:-30} @@ -111,7 +110,7 @@ fi activate_vgs # Set up non-root encrypted partition mappings -if [[ -f /etc/crypttab && -n $CS ]] && grep -q ^[^#] /etc/crypttab; then +if [[ -f /etc/crypttab && $CS ]] && grep -q ^[^#] /etc/crypttab; then modprobe -q dm-crypt 2>/dev/null stat_busy "Unlocking encrypted volumes:" do_unlock() { @@ -143,11 +142,11 @@ if [[ -f /etc/crypttab && -n $CS ]] && grep -q ^[^#] /etc/crypttab; then # This sanity check _should_ be sufficient, but it might not. # This may cause dataloss if it is not used carefully. blkid -p "$2" &>/dev/null - if [[ $? -eq 2 ]]; then + if (( $? == 2 )); then _overwriteokay=1 fi fi - if [[ $_overwriteokay -eq 0 ]]; then + if (( _overwriteokay == 0 )); then false elif $CS -d /dev/urandom $4 $open "$a" "$b" >/dev/null; then stat_append "creating swapspace.." @@ -185,7 +184,7 @@ if [[ -f /etc/crypttab && -n $CS ]] && grep -q ^[^#] /etc/crypttab; then *) echo "$3" | $CS $4 $open "$a" "$b" >/dev/null;; esac - if (($? != 0)); then + if (( $? )); then failed=1 stat_append "failed " else @@ -199,7 +198,7 @@ if [[ -f /etc/crypttab && -n $CS ]] && grep -q ^[^#] /etc/crypttab; then else stat_fail fi - if [[ ${crypto_unlocked} -eq 1 ]]; then + if (( crypto_unlocked == 1 )); then # Maybe someone has LVM on an encrypted block device activate_vgs fi @@ -213,16 +212,16 @@ fi status "Remounting Root Read/Write" \ mount -n -o remount,rw / - # don't touch /etc/mtab if it is a symlink to /proc/self/mounts - if [[ -L /etc/mtab ]]; then - : - elif [[ -x $(type -P findmnt) && -e /proc/self/mountinfo ]]; then - findmnt -rnu -o SOURCE,TARGET,FSTYPE,OPTIONS >| /etc/mtab - else - cat /proc/mounts >| /etc/mtab - fi +# don't touch /etc/mtab if it is a symlink to /proc/self/mounts +if [[ -L /etc/mtab ]]; then + : +elif [[ -x $(type -P findmnt) && -e /proc/self/mountinfo ]]; then + findmnt -rnu -o SOURCE,TARGET,FSTYPE,OPTIONS >| /etc/mtab +else + cat /proc/mounts >| /etc/mtab +fi - # now mount all the local filesystems +# now mount all the local filesystems mount_all # enable monitoring of lvm2 groups, now that the filesystems are mounted rw @@ -254,7 +253,7 @@ stat_busy "Removing Leftover Files" ln -s /run/daemons /var/run/daemons install -Tm 0664 -o root -g utmp <(:) /var/run/utmp # Keep {x,k,g}dm happy with xorg - mkdir -m1777 /tmp/.{X11,ICE}-unix + mkdir -m 1777 /tmp/.{X11,ICE}-unix stat_done if [[ $HOSTNAME ]]; then -- cgit v1.2.3 From 3c39d6fccf743febec3cb1cba9b8e0ed4c8fd8a3 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Fri, 24 Jun 2011 09:36:13 +0200 Subject: Simplify rc.single udevadm stuff as in rc.sysinit --- rc.single | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/rc.single b/rc.single index bb27ddf..dc9687e 100755 --- a/rc.single +++ b/rc.single @@ -12,22 +12,20 @@ run_hook single_start if [[ $PREVLEVEL != N ]]; then kill_everything single + status "Starting UDev Daemon" udevd --daemon + run_hook single_udevlaunched # Trigger udev uevents - if pidof -o %PPID /udevd >/dev/null; then - stat_busy "Triggering UDev uevents" + stat_busy "Triggering UDev uevents" udevadm trigger --action=add --type=subsystems udevadm trigger --action=add --type=devices - stat_done - fi + stat_done # Wait for udev uevents - if pidof -o %PPID udevd >/dev/null; then - status "Waiting for UDev uevents to be processed" \ - udevadm settle --quiet --timeout=${UDEV_TIMEOUT:-30} - fi + status "Waiting for UDev uevents to be processed" \ + udevadm settle --quiet --timeout=${UDEV_TIMEOUT:-30} run_hook single_udevsettled -- cgit v1.2.3 From 1e5360b4c9df3ef626410520c2c347dda01782f5 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Fri, 24 Jun 2011 09:44:02 +0200 Subject: Simplify unmounting filesystems This also keeps all tmpfs allways. Some might be in still in use because of a running splash daemon etc. --- rc.shutdown | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/rc.shutdown b/rc.shutdown index 2d23554..39adaad 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -52,12 +52,8 @@ if [[ $USELVM = [Yy][Ee][Ss] && -x $(type -P lvm) && -d /sys/block ]]; then fi stat_busy "Unmounting Filesystems" -if grep -q devtmpfs /proc/filesystems &>/dev/null; then - umount -a -r -t nosysfs,noproc,nodevtmpfs,nodevpts -O no_netdev -else # if we don't have devtmpfs support, /dev is mounted as tmpfs, so don't unmount it - umount -a -r -t notmpfs,nosysfs,noproc,nodevpts -O no_netdev -fi + umount -a -r -t nodevtmpfs,notmpfs,nosysfs,noproc,nodevpts -O no_netdev stat_done run_hook shutdown_postumount -- cgit v1.2.3 From 3d21e687f1b3b652fd70b59e8fe67736091a40be Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Fri, 24 Jun 2011 09:50:35 +0200 Subject: rc.single: Avoid rc.multi syslog start error - use minilogd as in rc.sysinit --- rc.single | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/rc.single b/rc.single index dc9687e..1a95ee9 100755 --- a/rc.single +++ b/rc.single @@ -29,13 +29,8 @@ if [[ $PREVLEVEL != N ]]; then run_hook single_udevsettled - # try syslog-NG first, then fall back to good ol' syslogd - if [[ -x /etc/rc.d/syslog-ng ]]; then - /etc/rc.d/syslog-ng start - elif [[ -x /etc/rc.d/syslogd ]]; then - /etc/rc.d/syslogd start - [[ -x /etc/rc.d/klogd ]] && /etc/rc.d/klogd start - fi + # start up our mini logger until syslog takes over + minilogd fi run_hook single_end -- cgit v1.2.3 From d27d1290a8967c8884fdc4aff766b4b3d922f606 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Fri, 24 Jun 2011 09:59:32 +0200 Subject: Fix bootlogd not stopped when booting into runlevel '1' --- rc.single | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/rc.single b/rc.single index 1a95ee9..74368fd 100755 --- a/rc.single +++ b/rc.single @@ -35,14 +35,6 @@ fi run_hook single_end -if [[ $RUNLEVEL = 1 ]]; then - printsep - printhl "Entering single-user mode..." - # make sure /dev/initctl is in place - kill -HUP 1 - exec init -t1 S -fi - if [[ -f /run/bootlogd.pid ]]; then touch /var/log/boot kill $(< /run/bootlogd.pid) @@ -51,5 +43,13 @@ if [[ -f /run/bootlogd.pid ]]; then -e 's/\^\[(\[151|%)G//g' /var/log/boot fi +if [[ $RUNLEVEL = 1 ]]; then + printsep + printhl "Entering single-user mode..." + # make sure /dev/initctl is in place + kill -HUP 1 + exec init -t1 S +fi + # End of file # vim: set ts=2 sw=2 noet: -- cgit v1.2.3 From 7cd8819a634c8438efcd6861b6a234913ff8a8c6 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Fri, 24 Jun 2011 10:04:24 +0200 Subject: Simplify random seed file creation --- rc.shutdown | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/rc.shutdown b/rc.shutdown index 39adaad..b0b97d6 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -23,9 +23,7 @@ kill_everything shutdown stat_busy "Saving Random Seed" RANDOM_SEED=/var/lib/misc/random-seed -[[ -d ${RANDOM_SEED%/*} ]] || mkdir -p ${RANDOM_SEED%/*} -: > $RANDOM_SEED -chmod 0600 $RANDOM_SEED +install -TDm 0600 <(:) $RANDOM_SEED POOL_FILE=/proc/sys/kernel/random/poolsize if [[ -r $POOL_FILE ]]; then read POOL_SIZE <$POOL_FILE -- cgit v1.2.3 From 171da3d79b0494af47e8c8c3815e8abec385b7d3 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Fri, 24 Jun 2011 10:56:31 +0200 Subject: Some more cosmetics --- functions | 4 ++-- rc.shutdown | 2 +- rc.sysinit | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/functions b/functions index d57fe16..a29eb7f 100644 --- a/functions +++ b/functions @@ -32,7 +32,7 @@ calc_columns () { fi # we use 13 characters for our own stuff - STAT_COL=$(( $STAT_COL - 13 )) + STAT_COL=$(( STAT_COL - 13 )) if [[ -t 1 ]]; then SAVE_POSITION="\e[s" @@ -154,7 +154,7 @@ stat_die() { status() { stat_busy "$1" shift - if "$@" >/dev/null 2>&1; then + if "$@" &>/dev/null; then stat_done return 0 fi diff --git a/rc.shutdown b/rc.shutdown index b0b97d6..473953f 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -26,7 +26,7 @@ RANDOM_SEED=/var/lib/misc/random-seed install -TDm 0600 <(:) $RANDOM_SEED POOL_FILE=/proc/sys/kernel/random/poolsize if [[ -r $POOL_FILE ]]; then - read POOL_SIZE <$POOL_FILE + read POOL_SIZE < $POOL_FILE else POOL_SIZE=512 fi diff --git a/rc.sysinit b/rc.sysinit index 5167a14..52d9d4b 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -244,8 +244,7 @@ if [[ -f $RANDOM_SEED ]]; then fi stat_busy "Removing Leftover Files" - rm -rf /etc/{nologin,shutdownpid} /forcefsck &>/dev/null - rm -rf /tmp/* /tmp/.* &>/dev/null + rm -rf /etc/{nologin,shutdownpid} /forcefsck /tmp/* /tmp/.* [[ ! -L /var/lock ]] && rm -rf /var/lock/* [[ ! -L /var/run && -d /var/run ]] && find /var/run/ \! -type d -delete [[ ! -L /var/run && ! -L /var/run/daemons ]] && @@ -258,7 +257,7 @@ stat_done if [[ $HOSTNAME ]]; then stat_busy "Setting Hostname: $HOSTNAME" - echo $HOSTNAME > /proc/sys/kernel/hostname + echo "$HOSTNAME" > /proc/sys/kernel/hostname stat_done fi @@ -296,7 +295,8 @@ fi # Set console font if required set_consolefont -if [[ -e /proc/sys/kernel/dmesg_restrict && $(< /proc/sys/kernel/dmesg_restrict) -eq 1 ]]; then +if [[ -e /proc/sys/kernel/dmesg_restrict ]] && + (( $(< /proc/sys/kernel/dmesg_restrict) == 1 )); then install -Tm 0600 <( dmesg ) /var/log/dmesg.log else install -Tm 0644 <( dmesg ) /var/log/dmesg.log -- cgit v1.2.3 From 18516c50897e1be65c83ccc3f60284b0bc67526f Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Fri, 24 Jun 2011 11:00:09 +0200 Subject: Simplify in_array function --- functions | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/functions b/functions index a29eb7f..4e184f6 100644 --- a/functions +++ b/functions @@ -165,12 +165,10 @@ status() { # usage : in_array( $needle, $haystack ) # return : 0 - found # 1 - not found -# Copied from makepkg in_array() { - [[ $2 ]] || return 1 local needle=$1; shift local item - for item in "$@"; do + for item; do [[ ${item#@} = $needle ]] && return 0 done return 1 # Not Found -- cgit v1.2.3 From 5f1447418e83de7aec8b82eccf645446e28ea771 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Fri, 24 Jun 2011 16:50:33 +0200 Subject: rc.sysinit/rc.single: Merge UDev stuff into a function rc.single changes (when coming from multi-user): * avoid settling UDev quietly as in rc.sysinit * modules defined in rc.conf are loaded if missing * minilogd is started before udevd as in rc.sysinit rc.sysinit behaviour is unchanged --- functions | 27 +++++++++++++++++++++++++++ rc.single | 19 +++---------------- rc.sysinit | 23 ++--------------------- 3 files changed, 32 insertions(+), 37 deletions(-) diff --git a/functions b/functions index 4e184f6..0c34cb9 100644 --- a/functions +++ b/functions @@ -301,6 +301,33 @@ kill_everything() { run_hook "$1_postkillall" } +# Start/trigger UDev, load MODULES and settle UDev +udevd_modprobe() { + # $1 = where we are being called from. + # This is used to determine which hooks to run. + status "Starting UDev Daemon" udevd --daemon + + run_hook "${1}_udevlaunched" + + stat_busy "Triggering UDev uevents" + udevadm trigger --action=add --type=subsystems + udevadm trigger --action=add --type=devices + stat_done + + # Load modules from the MODULES array defined in rc.conf + if [[ -f /proc/modules ]] && (( ${#MODULES[*]} )); then + status "Loading Modules" modprobe -ab "${MODULES[@]}" + fi + + status "Waiting for UDev uevents to be processed" \ + udevadm settle --timeout=${UDEV_TIMEOUT:-30} + + run_hook "${1}_udevsettled" + + # in case loading a module changed the display mode + calc_columns +} + activate_vgs() { [[ $USELVM = [yY][eE][sS] && -x $(type -P lvm) && -d /sys/block ]] || return # Kernel 2.6.x, LVM2 groups diff --git a/rc.single b/rc.single index 74368fd..46b502c 100755 --- a/rc.single +++ b/rc.single @@ -13,24 +13,11 @@ run_hook single_start if [[ $PREVLEVEL != N ]]; then kill_everything single - status "Starting UDev Daemon" udevd --daemon - - run_hook single_udevlaunched - - # Trigger udev uevents - stat_busy "Triggering UDev uevents" - udevadm trigger --action=add --type=subsystems - udevadm trigger --action=add --type=devices - stat_done - - # Wait for udev uevents - status "Waiting for UDev uevents to be processed" \ - udevadm settle --quiet --timeout=${UDEV_TIMEOUT:-30} - - run_hook single_udevsettled - # start up our mini logger until syslog takes over minilogd + + # Start/trigger UDev, load MODULES and settle UDev + udevd_modprobe single fi run_hook single_end diff --git a/rc.sysinit b/rc.sysinit index 52d9d4b..0d99aa3 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -71,27 +71,8 @@ if [[ $HWCLOCK_PARAMS ]]; then fi fi -status "Starting UDev Daemon" udevd --daemon - -run_hook sysinit_udevlaunched - -stat_busy "Triggering UDev uevents" - udevadm trigger --action=add --type=subsystems - udevadm trigger --action=add --type=devices -stat_done - -# Load modules from the MODULES array defined in rc.conf -if [[ -f /proc/modules ]] && (( ${#MODULES[*]} )); then - status "Loading Modules" modprobe -ab "${MODULES[@]}" -fi - -status "Waiting for UDev uevents to be processed" \ - udevadm settle --timeout=${UDEV_TIMEOUT:-30} - -# in case loading a module changed the display mode -calc_columns - -run_hook sysinit_udevsettled +# Start/trigger UDev, load MODULES and settle UDev +udevd_modprobe sysinit # bring up the loopback interface [[ -d /sys/class/net/lo ]] && -- cgit v1.2.3 From 339d0a10258a8cf862c84b5f26cdd042dfeca8c2 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Fri, 24 Jun 2011 16:56:36 +0200 Subject: rc.multi/rc.single: Merge duplicated bootlogd stop code into a function --- functions | 9 +++++++++ rc.multi | 8 +------- rc.single | 8 +------- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/functions b/functions index 0c34cb9..b64f78b 100644 --- a/functions +++ b/functions @@ -430,6 +430,15 @@ mount_all() { stat_done } +bootlogd_stop() { + [[ -f /run/bootlogd.pid ]] || return 0 + touch /var/log/boot + kill $(< /run/bootlogd.pid) + rm -f /run/bootlogd.pid + sed -i -r -e 's/\^\[\[[0-9]?;?[0-9]?[0-9]?;?[0-9]?[0-9]?[ms]//g' \ + -e 's/\^\[(\[151|%)G//g' /var/log/boot +} + ############################### # Custom hooks in initscripts # ############################### diff --git a/rc.multi b/rc.multi index 1160ab4..4b55a27 100755 --- a/rc.multi +++ b/rc.multi @@ -26,12 +26,6 @@ fi run_hook multi_end -if [[ -f /run/bootlogd.pid ]]; then - touch /var/log/boot - kill $(< /run/bootlogd.pid) - rm -f /run/bootlogd.pid - sed -i -r -e 's/\^\[\[[0-9]?;?[0-9]?[0-9]?;?[0-9]?[0-9]?[ms]//g' \ - -e 's/\^\[(\[151|%)G//g' /var/log/boot -fi +bootlogd_stop # vim: set ts=2 sw=2 noet: diff --git a/rc.single b/rc.single index 46b502c..d630736 100755 --- a/rc.single +++ b/rc.single @@ -22,13 +22,7 @@ fi run_hook single_end -if [[ -f /run/bootlogd.pid ]]; then - touch /var/log/boot - kill $(< /run/bootlogd.pid) - rm -f /run/bootlogd.pid - sed -i -r -e 's/\^\[\[[0-9]?;?[0-9]?[0-9]?;?[0-9]?[0-9]?[ms]//g' \ - -e 's/\^\[(\[151|%)G//g' /var/log/boot -fi +bootlogd_stop if [[ $RUNLEVEL = 1 ]]; then printsep -- cgit v1.2.3 From cd4b6dde21fde2a461dbbe42db649cc83fac303b Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Fri, 24 Jun 2011 21:12:56 +0200 Subject: Get rid of simple if-constucts by using '&&' --- rc.multi | 4 +--- rc.shutdown | 58 ++++++++++++++++++++++++++-------------------------------- rc.sysinit | 33 +++++++++++---------------------- 3 files changed, 38 insertions(+), 57 deletions(-) diff --git a/rc.multi b/rc.multi index 4b55a27..b801fb6 100755 --- a/rc.multi +++ b/rc.multi @@ -20,9 +20,7 @@ for daemon in "${DAEMONS[@]}"; do esac done -if [[ -x /etc/rc.local ]]; then - /etc/rc.local -fi +[[ -x /etc/rc.local ]] && /etc/rc.local run_hook multi_end diff --git a/rc.shutdown b/rc.shutdown index 473953f..9eb0b31 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -22,21 +22,20 @@ echo " " kill_everything shutdown stat_busy "Saving Random Seed" -RANDOM_SEED=/var/lib/misc/random-seed -install -TDm 0600 <(:) $RANDOM_SEED -POOL_FILE=/proc/sys/kernel/random/poolsize -if [[ -r $POOL_FILE ]]; then - read POOL_SIZE < $POOL_FILE -else - POOL_SIZE=512 -fi -dd if=/dev/urandom of=$RANDOM_SEED count=1 bs=$POOL_SIZE &>/dev/null + RANDOM_SEED=/var/lib/misc/random-seed + install -TDm 0600 <(:) $RANDOM_SEED + POOL_FILE=/proc/sys/kernel/random/poolsize + if [[ -r $POOL_FILE ]]; then + read POOL_SIZE < $POOL_FILE + else + POOL_SIZE=512 + fi + dd if=/dev/urandom of=$RANDOM_SEED count=1 bs=$POOL_SIZE &>/dev/null stat_done -if [[ $TIMEZONE ]]; then +[[ $TIMEZONE ]] && status "Saving Time Zone" \ cp --remove-destination "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime -fi # Write to wtmp file before unmounting halt -w @@ -44,41 +43,36 @@ halt -w status "Deactivating Swap" swapoff -a # stop monitoring of lvm2 groups before unmounting filesystems -if [[ $USELVM = [Yy][Ee][Ss] && -x $(type -P lvm) && -d /sys/block ]]; then +[[ $USELVM = [Yy][Ee][Ss] && -x $(type -P lvm) && -d /sys/block ]] && status "Deactivating monitoring of LVM2 groups" \ vgchange --monitor n &>/dev/null -fi -stat_busy "Unmounting Filesystems" - # if we don't have devtmpfs support, /dev is mounted as tmpfs, so don't unmount it +# if we don't have devtmpfs support, /dev is mounted as tmpfs, so don't unmount it +status "Unmounting Filesystems" \ umount -a -r -t nodevtmpfs,notmpfs,nosysfs,noproc,nodevpts -O no_netdev -stat_done run_hook shutdown_postumount # Kill non-root encrypted partition mappings if [[ -f /etc/crypttab && $CS ]] && grep -q ^[^#] /etc/crypttab; then stat_busy "Deactivating encrypted volumes:" - # Maybe someone has LVM on an encrypted block device - # executing an extra vgchange is errorless - if [[ $USELVM = [Yy][Ee][Ss] ]]; then - vgchange --sysinit -a n &>/dev/null - fi - do_lock() { - stat_append "${1}.." - if $CS remove "$1" &>/dev/null; then - stat_append "ok " - else - stat_append "failed " - fi - } - read_crypttab do_lock + # Maybe someone has LVM on an encrypted block device + # executing an extra vgchange is errorless + [[ $USELVM = [Yy][Ee][Ss] ]] && vgchange --sysinit -a n &>/dev/null + do_lock() { + stat_append "${1}.." + if $CS remove "$1" &>/dev/null; then + stat_append "ok " + else + stat_append "failed " + fi + } + read_crypttab do_lock stat_done fi -if [[ $USELVM = [Yy][Ee][Ss] && -x $(type -P lvm) && -d /sys/block ]]; then +[[ $USELVM = [Yy][Ee][Ss] && -x $(type -P lvm) && -d /sys/block ]] && status "Deactivating LVM2 groups" vgchange --sysinit -a n &>/dev/null -fi status "Remounting Root Filesystem Read-only" \ mount -n -o remount,ro / diff --git a/rc.sysinit b/rc.sysinit index 0d99aa3..c0a35df 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -66,9 +66,7 @@ if [[ $HWCLOCK_PARAMS ]]; then # configured timezone. Any new timezone put in rc.conf is copied over at # a later time. # This also sets the kernel time zone. - if [[ -f /etc/localtime ]]; then - hwclock $HWCLOCK_PARAMS - fi + [[ -f /etc/localtime ]] && hwclock $HWCLOCK_PARAMS fi # Start/trigger UDev, load MODULES and settle UDev @@ -79,14 +77,12 @@ udevd_modprobe sysinit status "Bringing up loopback interface" ip link set up dev lo # FakeRAID devices detection -if [[ $USEDMRAID = [Yy][Ee][Ss] && -x $(type -P dmraid) ]]; then +[[ $USEDMRAID = [Yy][Ee][Ss] && -x $(type -P dmraid) ]] && status "Activating FakeRAID arrays" dmraid -i -ay -fi # BTRFS devices detection -if [[ $USEBTRFS = [Yy][Ee][Ss] && -x $(type -P btrfs) ]]; then +[[ $USEBTRFS = [Yy][Ee][Ss] && -x $(type -P btrfs) ]] && status "Activating BTRFS volumes" btrfs device scan -fi activate_vgs @@ -123,9 +119,7 @@ if [[ -f /etc/crypttab && $CS ]] && grep -q ^[^#] /etc/crypttab; then # This sanity check _should_ be sufficient, but it might not. # This may cause dataloss if it is not used carefully. blkid -p "$2" &>/dev/null - if (( $? == 2 )); then - _overwriteokay=1 - fi + (( $? == 2 )) && _overwriteokay=1 fi if (( _overwriteokay == 0 )); then false @@ -206,23 +200,20 @@ fi mount_all # enable monitoring of lvm2 groups, now that the filesystems are mounted rw -if [[ $USELVM = [Yy][Ee][Ss] && -x $(type -P lvm) && -d /sys/block ]]; then +[[ $USELVM = [Yy][Ee][Ss] && -x $(type -P lvm) && -d /sys/block ]] && status "Activating monitoring of LVM2 groups" \ vgchange --monitor y >/dev/null -fi status "Activating Swap" swapon -a -if [[ $TIMEZONE ]]; then +[[ $TIMEZONE ]] && status "Configuring Time Zone" \ cp --remove-destination "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime -fi RANDOM_SEED=/var/lib/misc/random-seed -if [[ -f $RANDOM_SEED ]]; then +[[ -f $RANDOM_SEED ]] && status "Initializing Random Seed" \ cat $RANDOM_SEED > /dev/urandom -fi stat_busy "Removing Leftover Files" rm -rf /etc/{nologin,shutdownpid} /forcefsck /tmp/* /tmp/.* @@ -236,11 +227,9 @@ stat_busy "Removing Leftover Files" mkdir -m 1777 /tmp/.{X11,ICE}-unix stat_done -if [[ $HOSTNAME ]]; then - stat_busy "Setting Hostname: $HOSTNAME" - echo "$HOSTNAME" > /proc/sys/kernel/hostname - stat_done -fi +[[ $HOSTNAME ]] && + status "Setting Hostname: $HOSTNAME" \ + eval 'echo "$HOSTNAME" > /proc/sys/kernel/hostname' stat_busy "Setting Locale: ${LOCALE:=en_US}" # Flush old locale settings @@ -270,7 +259,7 @@ else echo 0 > /sys/module/vt/parameters/default_utf8 stat_done fi -[[ $KEYMAP ]] && \ +[[ $KEYMAP ]] && status "Loading Keyboard Map: $KEYMAP" loadkeys -q $KEYMAP # Set console font if required -- cgit v1.2.3 From 0a71757f7eeb359293b72af8a1ae299953b865b2 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Fri, 24 Jun 2011 21:14:44 +0200 Subject: Simplify /etc/profile.d/locale.sh creation --- rc.sysinit | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/rc.sysinit b/rc.sysinit index c0a35df..01f83f0 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -231,12 +231,9 @@ stat_done status "Setting Hostname: $HOSTNAME" \ eval 'echo "$HOSTNAME" > /proc/sys/kernel/hostname' -stat_busy "Setting Locale: ${LOCALE:=en_US}" - # Flush old locale settings - install -Tm 0755 <(:) /etc/profile.d/locale.sh - # Set user defined locale - echo "export LANG=$LOCALE" >>/etc/profile.d/locale.sh -stat_done +# Flush old locale settings and set user defined locale +status "Setting Locale: ${LOCALE:=en_US}" \ + install -Tm 0755 <(echo "export LANG=$LOCALE") /etc/profile.d/locale.sh if [[ ${LOCALE,,} =~ utf ]]; then stat_busy "Setting Consoles to UTF-8 mode" -- cgit v1.2.3 From 5b19b901c6b00dd9b2b3a39e983b88ddd5eb874f Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Sat, 25 Jun 2011 00:28:42 +0200 Subject: trivial: silence errors This is a cleanup of a commit 171da3d. We get errors because /tmp/. and /tmp/.. cannot be deleted on boot. Send them to /dev/null. Signed-off-by: Tom Gundersen --- rc.sysinit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rc.sysinit b/rc.sysinit index 01f83f0..3773beb 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -216,7 +216,7 @@ RANDOM_SEED=/var/lib/misc/random-seed cat $RANDOM_SEED > /dev/urandom stat_busy "Removing Leftover Files" - rm -rf /etc/{nologin,shutdownpid} /forcefsck /tmp/* /tmp/.* + rm -rf /etc/{nologin,shutdownpid} /forcefsck /tmp/* /tmp/.* &>/dev/null [[ ! -L /var/lock ]] && rm -rf /var/lock/* [[ ! -L /var/run && -d /var/run ]] && find /var/run/ \! -type d -delete [[ ! -L /var/run && ! -L /var/run/daemons ]] && -- cgit v1.2.3 From ac55830ea6cfa2c130275ebd6b4f2c0fea80130e Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Sat, 25 Jun 2011 00:53:05 +0200 Subject: hwclock: use correct timezone To avoid setting the kernel timezone with an out-of-date /etc/localtime, we pass TZ directly to hwclock. Also document how TIMEZONE and HARDWARECLOCK are optional in rc.conf Signed-off-by: Tom Gundersen --- rc.conf | 4 +++- rc.sysinit | 11 ++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/rc.conf b/rc.conf index b217ddb..9700480 100644 --- a/rc.conf +++ b/rc.conf @@ -11,8 +11,10 @@ # startup and during the boot process. If set to 'no', the C locale is used. # HARDWARECLOCK: set to "", "UTC" or "localtime", any other value will result # in the hardware clock being left untouched (useful for virtualization) -# Note: Using "localtime" is discouraged. +# Note: Using "localtime" is discouraged, using "" makes hwclock fall back +# to the value in /var/lib/hwclock/adjfile # TIMEZONE: timezones are found in /usr/share/zoneinfo +# Note: if unset, the value in /etc/localtime is used unchanged # KEYMAP: keymaps are found in /usr/share/kbd/keymaps # CONSOLEFONT: found in /usr/share/kbd/consolefonts (only needed for non-US) # CONSOLEMAP: found in /usr/share/kbd/consoletrans diff --git a/rc.sysinit b/rc.sysinit index 3773beb..0fca20e 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -62,11 +62,12 @@ if [[ $HWCLOCK_PARAMS ]]; then # Adjust the system time for timezone offset if rtc is not in UTC # 1. Make creation time on udev nodes sane (FS#8665) # 2. Filesystem checks can depend on system time - # 3. This will set the clock, if using non-UTC, off the last known - # configured timezone. Any new timezone put in rc.conf is copied over at - # a later time. - # This also sets the kernel time zone. - [[ -f /etc/localtime ]] && hwclock $HWCLOCK_PARAMS + # 3. This also sets the kernel time zone, used by e.g. vfat + # If TIMEZONE is not set in rc.conf, the timezone stored in /etc/localtime + # is used. If HARDWARECLOCK is not set in rc.conf, the value in + # /var/lib/hwclock/adjfile is used (in this case /var can not be a separate + # partition). + TZ=$TIMEZONE && hwclock $HWCLOCK_PARAMS fi # Start/trigger UDev, load MODULES and settle UDev -- cgit v1.2.3 From 713213c19395fd1541cdaa025ac5f977d062108a Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Sat, 25 Jun 2011 00:55:17 +0200 Subject: hwclock: show status Signed-off-by: Tom Gundersen --- rc.sysinit | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/rc.sysinit b/rc.sysinit index 0fca20e..a2c775f 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -47,27 +47,32 @@ case $HARDWARECLOCK in esac if [[ $HWCLOCK_PARAMS ]]; then - # enable rtc access - modprobe -q -a rtc-cmos rtc genrtc - # If devtmpfs is used, the required RTC device already exists now - # Otherwise, create whatever device is available - if ! [[ -c /dev/rtc || -c /dev/rtc0 ]]; then - for dev in /sys/class/rtc/rtc0/dev /sys/class/misc/rtc/dev; do - [[ -e $dev ]] || continue - IFS=: read -r major minor < "$dev" - mknod /dev/rtc c $major $minor - done - fi - - # Adjust the system time for timezone offset if rtc is not in UTC - # 1. Make creation time on udev nodes sane (FS#8665) - # 2. Filesystem checks can depend on system time - # 3. This also sets the kernel time zone, used by e.g. vfat - # If TIMEZONE is not set in rc.conf, the timezone stored in /etc/localtime - # is used. If HARDWARECLOCK is not set in rc.conf, the value in - # /var/lib/hwclock/adjfile is used (in this case /var can not be a separate - # partition). - TZ=$TIMEZONE && hwclock $HWCLOCK_PARAMS + stat_busy "Adjusting system time and setting kernel timezone" + # enable rtc access + modprobe -q -a rtc-cmos rtc genrtc + # If devtmpfs is used, the required RTC device already exists now + # Otherwise, create whatever device is available + if ! [[ -c /dev/rtc || -c /dev/rtc0 ]]; then + for dev in /sys/class/rtc/rtc0/dev /sys/class/misc/rtc/dev; do + [[ -e $dev ]] || continue + IFS=: read -r major minor < "$dev" + mknod /dev/rtc c $major $minor + done + fi + + # Adjust the system time for timezone offset if rtc is not in UTC + # 1. Make creation time on udev nodes sane (FS#8665) + # 2. Filesystem checks can depend on system time + # 3. This also sets the kernel time zone, used by e.g. vfat + # If TIMEZONE is not set in rc.conf, the timezone stored in /etc/localtime + # is used. If HARDWARECLOCK is not set in rc.conf, the value in + # /var/lib/hwclock/adjfile is used (in this case /var can not be a separate + # partition). + if TZ=$TIMEZONE hwclock $HWCLOCK_PARAMS; then + stat_done + else + stat_fail + fi fi # Start/trigger UDev, load MODULES and settle UDev -- cgit v1.2.3 From fc9ce46483fc4df673c4f2f23eeeb405d1040c4b Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Sat, 25 Jun 2011 13:46:09 -0400 Subject: network: don't warn for deprecation with no settings Signed-off-by: Dave Reisner --- network | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/network b/network index 74fc3d1..868780e 100755 --- a/network +++ b/network @@ -9,7 +9,8 @@ done # helper function to determine if legacy network support is needed need_legacy() { - if [[ -z $interface ]]; then + # complain when `interface' is unset and `INTERFACES' has profiles enabled + if [[ -z $interface && ${INTERFACES[@]##!*} ]]; then return 0 # need legacy fi -- cgit v1.2.3 From 0ab093ba1cfc2d0aeadfc5a0c2af59f80781b5fa Mon Sep 17 00:00:00 2001 From: Sebastien Luttringer Date: Mon, 27 Jun 2011 00:23:20 +0200 Subject: Use _get_comp_words_by_ref in bash completion Thanks Dave Reisner for suggestion Signed-off-by: Sebastien Luttringer --- bash-completion | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/bash-completion b/bash-completion index 489b5dc..e63e880 100644 --- a/bash-completion +++ b/bash-completion @@ -2,18 +2,18 @@ _rc.d () { - local action="help list start stop reload restart" - local cur="${COMP_WORDS[COMP_CWORD]}" - local caction="${COMP_WORDS[1]}" + local action cur prev + action="help list start stop reload restart" + _get_comp_words_by_ref cur prev if ((COMP_CWORD == 1)); then COMPREPLY=($(compgen -W "${action}" -- "$cur")) - elif [[ "$caction" == help ]]; then + elif [[ "$prev" == help ]]; then COMPREPLY=() - elif [[ "$caction" == list ]]; then + elif [[ "$prev" == list ]]; then ((COMP_CWORD == 2)) && COMPREPLY=($(compgen -W "started stopped" -- "$cur")) || COMPREPLY=() - elif [[ "$caction" == start ]]; then + elif [[ "$prev" == start ]]; then COMPREPLY=($(comm -23 <(cd /etc/rc.d && compgen -f -X 'functions*' "$cur"|sort) <(cd /run/daemons/ && compgen -f "$cur"|sort))) - elif [[ "$caction" =~ stop|restart|reload ]]; then + elif [[ "$prev" =~ stop|restart|reload ]]; then COMPREPLY=($(cd /run/daemons/ && compgen -f "$cur"|sort)) elif ((COMP_CWORD > 1)); then COMPREPLY=($(cd /etc/rc.d && compgen -f -X 'functions*' "$cur"|sort)) -- cgit v1.2.3 From ec9532312b746c987a9b8a4570288f1233ee63f2 Mon Sep 17 00:00:00 2001 From: Jacob Okamoto Date: Mon, 27 Jun 2011 03:04:23 +0200 Subject: rc.d: clear text formatting after error Patch to fix FS#24879, clearing terminal text formatting after nonexistent daemon script failure in rc.d. Signed-off-by: Jacob Okamoto Signed-off-by: Tom Gundersen --- rc.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rc.d b/rc.d index 6d9a9f7..a7b214e 100755 --- a/rc.d +++ b/rc.d @@ -69,7 +69,7 @@ case $1 in if [[ -x "/etc/rc.d/$i" ]]; then env -i "${ENV[@]}" "/etc/rc.d/$i" "$action" else - printf "${C_OTHER}:: ${C_FAIL}Error: ${C_DONE}Daemon script $i does not exist.\n" + printf "${C_OTHER}:: ${C_FAIL}Error: ${C_DONE}Daemon script $i does not exist.${C_CLEAR}\n" fi (( ret += !! $? )) # clamp exit value to 0/1 done -- cgit v1.2.3 From d5cd39a27758d7768732fe252da40899021decf7 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Mon, 27 Jun 2011 14:55:24 +0200 Subject: Fix whitespace --- rc.shutdown | 2 +- rc.sysinit | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/rc.shutdown b/rc.shutdown index 9eb0b31..6d43229 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -58,7 +58,7 @@ if [[ -f /etc/crypttab && $CS ]] && grep -q ^[^#] /etc/crypttab; then stat_busy "Deactivating encrypted volumes:" # Maybe someone has LVM on an encrypted block device # executing an extra vgchange is errorless - [[ $USELVM = [Yy][Ee][Ss] ]] && vgchange --sysinit -a n &>/dev/null + [[ $USELVM = [Yy][Ee][Ss] ]] && vgchange --sysinit -a n &>/dev/null do_lock() { stat_append "${1}.." if $CS remove "$1" &>/dev/null; then diff --git a/rc.sysinit b/rc.sysinit index a2c775f..864d2c7 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -65,8 +65,8 @@ if [[ $HWCLOCK_PARAMS ]]; then # 2. Filesystem checks can depend on system time # 3. This also sets the kernel time zone, used by e.g. vfat # If TIMEZONE is not set in rc.conf, the timezone stored in /etc/localtime - # is used. If HARDWARECLOCK is not set in rc.conf, the value in - # /var/lib/hwclock/adjfile is used (in this case /var can not be a separate + # is used. If HARDWARECLOCK is not set in rc.conf, the value in + # /var/lib/hwclock/adjfile is used (in this case /var can not be a separate # partition). if TZ=$TIMEZONE hwclock $HWCLOCK_PARAMS; then stat_done @@ -270,9 +270,9 @@ set_consolefont if [[ -e /proc/sys/kernel/dmesg_restrict ]] && (( $(< /proc/sys/kernel/dmesg_restrict) == 1 )); then - install -Tm 0600 <( dmesg ) /var/log/dmesg.log + install -Tm 0600 <( dmesg ) /var/log/dmesg.log else - install -Tm 0644 <( dmesg ) /var/log/dmesg.log + install -Tm 0644 <( dmesg ) /var/log/dmesg.log fi run_hook sysinit_end -- cgit v1.2.3 From ad7799c8e5df020595e5aed5b0a9a51b7c1b4065 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Sat, 25 Jun 2011 10:19:02 +0200 Subject: functions: Fix indentation --- functions | 54 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/functions b/functions index b64f78b..ef014e3 100644 --- a/functions +++ b/functions @@ -284,18 +284,18 @@ kill_everything() { # Terminate all processes stat_busy "Sending SIGTERM To Processes" - run_hook "$1_prekillall" - local pid k5args="" - for pid in ${omit_pids[@]}; do - k5args+=" -o $pid" - done - /sbin/killall5 -15 $k5args &>/dev/null - /bin/sleep 5 + run_hook "$1_prekillall" + local pid k5args="" + for pid in ${omit_pids[@]}; do + k5args+=" -o $pid" + done + /sbin/killall5 -15 $k5args &>/dev/null + /bin/sleep 5 stat_done stat_busy "Sending SIGKILL To Processes" - /sbin/killall5 -9 $k5args &>/dev/null - /bin/sleep 1 + /sbin/killall5 -9 $k5args &>/dev/null + /bin/sleep 1 stat_done run_hook "$1_postkillall" @@ -370,14 +370,14 @@ NETFS="nonfs,nonfs4,nosmbfs,nocifs,nocodafs,noncpfs,nosysfs,noshfs,nofuse,nofuse fsck_all() { stat_busy "Checking Filesystems" - FSCK_OUT=/dev/stdout - FSCK_ERR=/dev/stdout - FSCK_FD= - FORCEFSCK= - [[ -f /forcefsck ]] || in_array forcefsck $(< /proc/cmdline) && FORCEFSCK="-- -f" - run_hook sysinit_prefsck - fsck -A -T -C$FSCK_FD -a -t "$NETFS,noopts=_netdev" $FORCEFSCK >$FSCK_OUT 2>$FSCK_ERR - local fsckret=$? + FSCK_OUT=/dev/stdout + FSCK_ERR=/dev/stdout + FSCK_FD= + FORCEFSCK= + [[ -f /forcefsck ]] || in_array forcefsck $(< /proc/cmdline) && FORCEFSCK="-- -f" + run_hook sysinit_prefsck + fsck -A -T -C$FSCK_FD -a -t "$NETFS,noopts=_netdev" $FORCEFSCK >$FSCK_OUT 2>$FSCK_ERR + local fsckret=$? if (( fsckret > 1 )); then stat_fail else @@ -424,9 +424,9 @@ fsck_reboot() { mount_all() { stat_busy "Mounting Local Filesystems" - run_hook sysinit_premount - mount -a -t $NETFS -O no_netdev - run_hook sysinit_postmount + run_hook sysinit_premount + mount -a -t $NETFS -O no_netdev + run_hook sysinit_postmount stat_done } @@ -500,13 +500,13 @@ fi set_consolefont() { [[ $CONSOLEFONT ]] || return 0 stat_busy "Loading Console Font: $CONSOLEFONT" - #CONSOLEMAP in UTF-8 shouldn't be used - [[ $CONSOLEMAP && ${LOCALE,,} =~ utf ]] && CONSOLEMAP="" - local i - for i in /dev/tty[0-9]*; do - /usr/bin/setfont ${CONSOLEMAP:+-m ${CONSOLEMAP}} \ - $CONSOLEFONT -C ${i} &>/dev/null - done + #CONSOLEMAP in UTF-8 shouldn't be used + [[ $CONSOLEMAP && ${LOCALE,,} =~ utf ]] && CONSOLEMAP="" + local i + for i in /dev/tty[0-9]*; do + /usr/bin/setfont ${CONSOLEMAP:+-m ${CONSOLEMAP}} \ + $CONSOLEFONT -C ${i} &>/dev/null + done if (( $? )); then stat_fail elif [[ $CONSOLEMAP ]]; then -- cgit v1.2.3 From 3dc96aaa74d7e886adfb097955d39b716001348b Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Mon, 27 Jun 2011 16:30:28 +0200 Subject: rc.sysinit: Fix writing to /dev/urandom Note: The code status "$text" $command > $file writes nothing because there's a &>/dev/null within status(). --- rc.sysinit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rc.sysinit b/rc.sysinit index 864d2c7..fca8b43 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -219,7 +219,7 @@ status "Activating Swap" swapon -a RANDOM_SEED=/var/lib/misc/random-seed [[ -f $RANDOM_SEED ]] && status "Initializing Random Seed" \ - cat $RANDOM_SEED > /dev/urandom + cp $RANDOM_SEED /dev/urandom stat_busy "Removing Leftover Files" rm -rf /etc/{nologin,shutdownpid} /forcefsck /tmp/* /tmp/.* &>/dev/null -- cgit v1.2.3 From 8decd5c4c71ed0ac0df54eba70a4a52c44f08395 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Tue, 28 Jun 2011 14:11:31 +0200 Subject: rc.sysinit: Fix setting locale When using process substitution with status(), the resulting /dev/fd/* might get lost before it is actualy used. This happens in case a custom stat_busy() forks a subshell. --- rc.sysinit | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rc.sysinit b/rc.sysinit index fca8b43..a63da9b 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -238,8 +238,9 @@ stat_done eval 'echo "$HOSTNAME" > /proc/sys/kernel/hostname' # Flush old locale settings and set user defined locale -status "Setting Locale: ${LOCALE:=en_US}" \ - install -Tm 0755 <(echo "export LANG=$LOCALE") /etc/profile.d/locale.sh +stat_busy "Setting Locale: ${LOCALE:=en_US}" + echo "export LANG=$LOCALE" > /etc/profile.d/locale.sh && + chmod 0755 /etc/profile.d/locale.sh && stat_done || stat_fail if [[ ${LOCALE,,} =~ utf ]]; then stat_busy "Setting Consoles to UTF-8 mode" -- cgit v1.2.3 From 52299efc246f6f83aac76b39330845aa93742542 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Mon, 27 Jun 2011 16:17:59 +0200 Subject: Fix '>|' not used allways when redirecting to files This avoids errors if one should set the noclobber shell option somewhere (within a daemon script or some custom function). We already had this, but it seems gone lost mostly. --- functions | 4 ++-- rc.sysinit | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/functions b/functions index ef014e3..c6416d9 100644 --- a/functions +++ b/functions @@ -178,7 +178,7 @@ in_array() { add_daemon() { [[ -d /run/daemons ]] || /bin/mkdir -p /run/daemons - > /run/daemons/"$1" + >| /run/daemons/"$1" } rm_daemon() { @@ -376,7 +376,7 @@ fsck_all() { FORCEFSCK= [[ -f /forcefsck ]] || in_array forcefsck $(< /proc/cmdline) && FORCEFSCK="-- -f" run_hook sysinit_prefsck - fsck -A -T -C$FSCK_FD -a -t "$NETFS,noopts=_netdev" $FORCEFSCK >$FSCK_OUT 2>$FSCK_ERR + fsck -A -T -C$FSCK_FD -a -t "$NETFS,noopts=_netdev" $FORCEFSCK >|$FSCK_OUT 2>|$FSCK_ERR local fsckret=$? if (( fsckret > 1 )); then stat_fail diff --git a/rc.sysinit b/rc.sysinit index a63da9b..f415895 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -251,7 +251,7 @@ if [[ ${LOCALE,,} =~ utf ]]; then kbd_mode -u < ${i} printf "\e%%G" > ${i} done - echo 1 > /sys/module/vt/parameters/default_utf8 + echo 1 >| /sys/module/vt/parameters/default_utf8 stat_done else stat_busy "Setting Consoles to legacy mode" @@ -260,7 +260,7 @@ else kbd_mode -a < ${i} printf "\e%%@" > ${i} done - echo 0 > /sys/module/vt/parameters/default_utf8 + echo 0 >| /sys/module/vt/parameters/default_utf8 stat_done fi [[ $KEYMAP ]] && -- cgit v1.2.3 From 7a37977456afa9b11467cfb9feef450274346202 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Sat, 25 Jun 2011 11:00:12 +0200 Subject: Fix local statements missing in ck_depends, ck_pidfile, do_unlock, kill_everything --- functions | 4 ++++ rc.sysinit | 12 ++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/functions b/functions index c6416d9..6e4fc3a 100644 --- a/functions +++ b/functions @@ -210,6 +210,7 @@ start_daemon() { # Never use this function, it causes daemons to be stoped in the wrong order. # The only way to start a daemon at boot is to add it to the DAEMONS array. ck_depends() { + local daemon for daemon in "$@"; do ck_daemon "$daemon" && start_daemon "$daemon" done @@ -251,6 +252,7 @@ get_pid() { # Check if PID-file $1 is still the active PID-file for command $2 ck_pidfile() { if [[ -f "$1" ]]; then + local fpid ppid read -r fpid <"$1" ppid=$(get_pid $2) [[ "$fpid" = "$ppid" ]] && return 0 @@ -270,6 +272,7 @@ kill_everything() { # $1 = where we are being called from. # This is used to determine which hooks to run. # Find daemons NOT in the DAEMONS array. Shut these down first + local daemon for daemon in /run/daemons/*; do [[ -f $daemon ]] || continue daemon=${daemon##*/} @@ -277,6 +280,7 @@ kill_everything() { done # Shutdown daemons in reverse order + local i for (( i=${#DAEMONS[@]}-1; i>=0; i-- )); do [[ ${DAEMONS[i]} = '!'* ]] && continue ck_daemon ${DAEMONS[i]#@} || stop_daemon ${DAEMONS[i]#@} diff --git a/rc.sysinit b/rc.sysinit index f415895..9f9eb0c 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -137,12 +137,12 @@ if [[ -f /etc/crypttab && $CS ]] && grep -q ^[^#] /etc/crypttab; then printf "\nOpening '$1' volume:\n" $CS $4 $open "$a" "$b" < /dev/console;; /dev*) - ckdev=${3%%:*} - cka=${3#*:} - ckb=${cka#*:} - cka=${cka%:*} - ckfile=/dev/ckfile - ckdir=/dev/ckdir + local ckdev=${3%%:*} + local cka=${3#*:} + local ckb=${cka#*:} + local cka=${cka%:*} + local ckfile=/dev/ckfile + local ckdir=/dev/ckdir case ${cka} in *[!0-9]*) # Use a file on the device -- cgit v1.2.3 From 31c5c35e85c235a388705e08850693fd2bfda979 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Mon, 27 Jun 2011 16:27:04 +0200 Subject: functions: Define $fsckret read-only because exposed to hook --- functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions b/functions index 6e4fc3a..46aebf2 100644 --- a/functions +++ b/functions @@ -381,7 +381,7 @@ fsck_all() { [[ -f /forcefsck ]] || in_array forcefsck $(< /proc/cmdline) && FORCEFSCK="-- -f" run_hook sysinit_prefsck fsck -A -T -C$FSCK_FD -a -t "$NETFS,noopts=_netdev" $FORCEFSCK >|$FSCK_OUT 2>|$FSCK_ERR - local fsckret=$? + local -r fsckret=$? if (( fsckret > 1 )); then stat_fail else -- cgit v1.2.3 From e93e5269ebd2e3a82a67cfe1ad517354eb34c41b Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Sat, 25 Jun 2011 09:33:37 +0200 Subject: Add some comments --- functions | 2 ++ rc.sysinit | 3 +++ 2 files changed, 5 insertions(+) diff --git a/functions b/functions index 46aebf2..e71ee1f 100644 --- a/functions +++ b/functions @@ -372,6 +372,7 @@ read_crypttab() { NETFS="nonfs,nonfs4,nosmbfs,nocifs,nocodafs,noncpfs,nosysfs,noshfs,nofuse,nofuseblk,noglusterfs,nodavfs" +# Check local filesystems fsck_all() { stat_busy "Checking Filesystems" FSCK_OUT=/dev/stdout @@ -391,6 +392,7 @@ fsck_all() { return $fsckret } +# Single-user login and/or automatic reboot after fsck (if needed) fsck_reboot() { # $1 = exit code returned by fsck # Ignore conditions 'FS errors corrected' and 'Cancelled by the user' diff --git a/rc.sysinit b/rc.sysinit index 9f9eb0c..27e603b 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -90,6 +90,7 @@ udevd_modprobe sysinit [[ $USEBTRFS = [Yy][Ee][Ss] && -x $(type -P btrfs) ]] && status "Activating BTRFS volumes" btrfs device scan +# Activate LVM2 groups if any activate_vgs # Set up non-root encrypted partition mappings @@ -186,7 +187,9 @@ if [[ -f /etc/crypttab && $CS ]] && grep -q ^[^#] /etc/crypttab; then fi if [[ -x $(type -P fsck) ]]; then + # Check filesystems fsck_all + # Single-user login and/or automatic reboot if needed fsck_reboot $? fi -- cgit v1.2.3 From 49ba4ef0f1155d0d7ca267664adda3aaeb98364b Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Mon, 27 Jun 2011 15:23:41 +0200 Subject: functions: Simplify ck_depends() for statement --- functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions b/functions index e71ee1f..9d75fbf 100644 --- a/functions +++ b/functions @@ -211,7 +211,7 @@ start_daemon() { # The only way to start a daemon at boot is to add it to the DAEMONS array. ck_depends() { local daemon - for daemon in "$@"; do + for daemon; do ck_daemon "$daemon" && start_daemon "$daemon" done } -- cgit v1.2.3 From 714ebaa6661be59e8d68c08bbdf09bbfb64ff210 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Mon, 27 Jun 2011 16:03:18 +0200 Subject: functions: Simplify kill_everything() omit_pid handling All credits go to: Dave Reisner --- functions | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/functions b/functions index 9d75fbf..ec82c6c 100644 --- a/functions +++ b/functions @@ -289,16 +289,12 @@ kill_everything() { # Terminate all processes stat_busy "Sending SIGTERM To Processes" run_hook "$1_prekillall" - local pid k5args="" - for pid in ${omit_pids[@]}; do - k5args+=" -o $pid" - done - /sbin/killall5 -15 $k5args &>/dev/null + /sbin/killall5 -15 ${omit_pids[@]/#/-o } &>/dev/null /bin/sleep 5 stat_done stat_busy "Sending SIGKILL To Processes" - /sbin/killall5 -9 $k5args &>/dev/null + /sbin/killall5 -9 ${omit_pids[@]/#/-o } &>/dev/null /bin/sleep 1 stat_done -- cgit v1.2.3 From 1f53c07a82b4b873c33884ddcbdebed2b7ee9558 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Mon, 27 Jun 2011 15:29:39 +0200 Subject: Refactor to get rid of simple if-constucts --- functions | 27 +++++++-------------------- rc.sysinit | 18 ++++-------------- 2 files changed, 11 insertions(+), 34 deletions(-) diff --git a/functions b/functions index ec82c6c..4c4ca0e 100644 --- a/functions +++ b/functions @@ -237,11 +237,7 @@ status_stopped() { } ck_status() { - if ! ck_daemon "$1"; then - status_started - else - status_stopped - fi + ! ck_daemon "$1" && status_started || status_stopped } # Return PID of $1 @@ -315,9 +311,8 @@ udevd_modprobe() { stat_done # Load modules from the MODULES array defined in rc.conf - if [[ -f /proc/modules ]] && (( ${#MODULES[*]} )); then + [[ -f /proc/modules ]] && (( ${#MODULES[*]} )) && status "Loading Modules" modprobe -ab "${MODULES[@]}" - fi status "Waiting for UDev uevents to be processed" \ udevadm settle --timeout=${UDEV_TIMEOUT:-30} @@ -333,11 +328,8 @@ activate_vgs() { # Kernel 2.6.x, LVM2 groups /sbin/modprobe -q dm-mod 2>/dev/null stat_busy "Activating LVM2 groups" - if /sbin/vgchange --sysinit -a y >/dev/null; then - stat_done - else - stat_fail - fi + /sbin/vgchange --sysinit -a y >/dev/null + (( $? == 0 )) && stat_done || stat_fail } # Arch cryptsetup packages traditionally contained the binaries @@ -379,11 +371,7 @@ fsck_all() { run_hook sysinit_prefsck fsck -A -T -C$FSCK_FD -a -t "$NETFS,noopts=_netdev" $FORCEFSCK >|$FSCK_OUT 2>|$FSCK_ERR local -r fsckret=$? - if (( fsckret > 1 )); then - stat_fail - else - stat_done - fi + (( fsckret <= 1 )) && stat_done || stat_fail run_hook sysinit_postfsck return $fsckret } @@ -392,9 +380,8 @@ fsck_all() { fsck_reboot() { # $1 = exit code returned by fsck # Ignore conditions 'FS errors corrected' and 'Cancelled by the user' - if (( ($1 | 33) == 33 )); then - return 0 - elif (( $1 & 2 )); then + (( ($1 | 33) == 33 )) && return 0 + if (( $1 & 2 )); then echo echo "********************** REBOOT REQUIRED *********************" echo "* *" diff --git a/rc.sysinit b/rc.sysinit index 27e603b..06b287c 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -68,11 +68,7 @@ if [[ $HWCLOCK_PARAMS ]]; then # is used. If HARDWARECLOCK is not set in rc.conf, the value in # /var/lib/hwclock/adjfile is used (in this case /var can not be a separate # partition). - if TZ=$TIMEZONE hwclock $HWCLOCK_PARAMS; then - stat_done - else - stat_fail - fi + TZ=$TIMEZONE hwclock $HWCLOCK_PARAMS && stat_done || stat_fail fi # Start/trigger UDev, load MODULES and settle UDev @@ -175,15 +171,9 @@ if [[ -f /etc/crypttab && $CS ]] && grep -q ^[^#] /etc/crypttab; then return $failed } crypto_unlocked=0 - if read_crypttab do_unlock; then - stat_done - else - stat_fail - fi - if (( crypto_unlocked == 1 )); then - # Maybe someone has LVM on an encrypted block device - activate_vgs - fi + read_crypttab do_unlock && stat_done || stat_fail + # Maybe someone has LVM on an encrypted block device + (( crypto_unlocked == 1 )) && activate_vgs fi if [[ -x $(type -P fsck) ]]; then -- cgit v1.2.3 From 7788571a9854b58c9bee058a36db4b1d0d41f614 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Mon, 27 Jun 2011 23:26:19 +0200 Subject: rc.sysinit: Get rid of eval --- rc.sysinit | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/rc.sysinit b/rc.sysinit index 06b287c..9b2a009 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -226,9 +226,10 @@ stat_busy "Removing Leftover Files" mkdir -m 1777 /tmp/.{X11,ICE}-unix stat_done -[[ $HOSTNAME ]] && - status "Setting Hostname: $HOSTNAME" \ - eval 'echo "$HOSTNAME" > /proc/sys/kernel/hostname' +if [[ $HOSTNAME ]]; then + stat_busy "Setting Hostname: $HOSTNAME" + echo "$HOSTNAME" >| /proc/sys/kernel/hostname && stat_done || stat_fail +fi # Flush old locale settings and set user defined locale stat_busy "Setting Locale: ${LOCALE:=en_US}" -- cgit v1.2.3 From fac564337b20eb7b4b1a6163a8290c1058d116b1 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Sat, 25 Jun 2011 11:08:05 +0200 Subject: Move fsck executable check into fsck_all() for consistency --- functions | 1 + rc.sysinit | 10 ++++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/functions b/functions index 4c4ca0e..14b7a7b 100644 --- a/functions +++ b/functions @@ -362,6 +362,7 @@ NETFS="nonfs,nonfs4,nosmbfs,nocifs,nocodafs,noncpfs,nosysfs,noshfs,nofuse,nofuse # Check local filesystems fsck_all() { + [[ -x $(type -P fsck) ]] || return 0 stat_busy "Checking Filesystems" FSCK_OUT=/dev/stdout FSCK_ERR=/dev/stdout diff --git a/rc.sysinit b/rc.sysinit index 9b2a009..3fe7185 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -176,12 +176,10 @@ if [[ -f /etc/crypttab && $CS ]] && grep -q ^[^#] /etc/crypttab; then (( crypto_unlocked == 1 )) && activate_vgs fi -if [[ -x $(type -P fsck) ]]; then - # Check filesystems - fsck_all - # Single-user login and/or automatic reboot if needed - fsck_reboot $? -fi +# Check filesystems +fsck_all +# Single-user login and/or automatic reboot if needed +fsck_reboot $? status "Remounting Root Read/Write" \ mount -n -o remount,rw / -- cgit v1.2.3 From c4f66215ed3fc9dba67241feb404d271a689030c Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Sat, 25 Jun 2011 10:04:23 +0200 Subject: Move activate_vgs and crypt stat_busy to the top for consistency --- functions | 2 +- rc.sysinit | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/functions b/functions index 14b7a7b..861fcbe 100644 --- a/functions +++ b/functions @@ -326,8 +326,8 @@ udevd_modprobe() { activate_vgs() { [[ $USELVM = [yY][eE][sS] && -x $(type -P lvm) && -d /sys/block ]] || return # Kernel 2.6.x, LVM2 groups - /sbin/modprobe -q dm-mod 2>/dev/null stat_busy "Activating LVM2 groups" + /sbin/modprobe -q dm-mod 2>/dev/null /sbin/vgchange --sysinit -a y >/dev/null (( $? == 0 )) && stat_done || stat_fail } diff --git a/rc.sysinit b/rc.sysinit index 3fe7185..b34d4ad 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -91,8 +91,8 @@ activate_vgs # Set up non-root encrypted partition mappings if [[ -f /etc/crypttab && $CS ]] && grep -q ^[^#] /etc/crypttab; then - modprobe -q dm-crypt 2>/dev/null stat_busy "Unlocking encrypted volumes:" + modprobe -q dm-crypt 2>/dev/null do_unlock() { # $1 = requested name # $2 = source device -- cgit v1.2.3 From e408a6177eadc6db5f64333cb6fb34c533f7f230 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Mon, 27 Jun 2011 15:27:01 +0200 Subject: functions: Make activate_vgs return 0 if noop for consistency --- functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions b/functions index 861fcbe..2eb4f72 100644 --- a/functions +++ b/functions @@ -324,7 +324,7 @@ udevd_modprobe() { } activate_vgs() { - [[ $USELVM = [yY][eE][sS] && -x $(type -P lvm) && -d /sys/block ]] || return + [[ $USELVM = [yY][eE][sS] && -x $(type -P lvm) && -d /sys/block ]] || return 0 # Kernel 2.6.x, LVM2 groups stat_busy "Activating LVM2 groups" /sbin/modprobe -q dm-mod 2>/dev/null -- cgit v1.2.3 From ad1713018daa1905908c7e26bfa976eff3a8459f Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Sat, 25 Jun 2011 12:02:01 +0200 Subject: Move export PATH into functions Also sanitze the PATH for rc.single, rc.multi, rc.local and daemons. --- functions | 4 +++- rc.shutdown | 2 -- rc.sysinit | 3 --- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/functions b/functions index 2eb4f72..bcc97c1 100644 --- a/functions +++ b/functions @@ -2,7 +2,8 @@ # initscripts functions # -# width: +# sanitize PATH (will be overridden later when /etc/profile is sourced, but is useful for UDev) +export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" if [[ $1 == "start" ]]; then if [[ $STARTING ]]; then @@ -12,6 +13,7 @@ if [[ $1 == "start" ]]; then fi fi +# width: calc_columns () { STAT_COL=80 if [[ ! -t 1 ]]; then diff --git a/rc.shutdown b/rc.shutdown index 6d43229..fe42797 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -6,8 +6,6 @@ . /etc/rc.conf . /etc/rc.d/functions -export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" - run_hook shutdown_start # avoid staircase effect diff --git a/rc.sysinit b/rc.sysinit index b34d4ad..89cbd55 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -13,9 +13,6 @@ printsep run_hook sysinit_start -# export standard PATH (will be overridden later when /etc/profile is sourced, but is useful for UDev) -export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" - # mount /proc, /sys, /run, /dev, /run/lock, /dev/pts, /dev/shm (the api filesystems) mountpoint -q /proc || mount -n -t proc proc /proc -o nosuid,noexec,nodev mountpoint -q /sys || mount -n -t sysfs sys /sys -o nosuid,noexec,nodev -- cgit v1.2.3 From dc2e0226f91cee87b1c4157f91215caac8b6d929 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Tue, 28 Jun 2011 00:20:15 +0200 Subject: rc.sysinit: Refactor /etc/mtab symlink detection to avoid empty if clause --- rc.sysinit | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/rc.sysinit b/rc.sysinit index 89cbd55..7f1089e 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -182,12 +182,12 @@ status "Remounting Root Read/Write" \ mount -n -o remount,rw / # don't touch /etc/mtab if it is a symlink to /proc/self/mounts -if [[ -L /etc/mtab ]]; then - : -elif [[ -x $(type -P findmnt) && -e /proc/self/mountinfo ]]; then - findmnt -rnu -o SOURCE,TARGET,FSTYPE,OPTIONS >| /etc/mtab -else - cat /proc/mounts >| /etc/mtab +if [[ ! -L /etc/mtab ]]; then + if [[ -x $(type -P findmnt) && -e /proc/self/mountinfo ]]; then + findmnt -rnu -o SOURCE,TARGET,FSTYPE,OPTIONS >| /etc/mtab + else + cat /proc/mounts >| /etc/mtab + fi fi # now mount all the local filesystems -- cgit v1.2.3 From 9abda43474520dbc98674fed13bb647322e3c30f Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Tue, 28 Jun 2011 00:22:52 +0200 Subject: rc.sysinit: Add status output for mtab and dmesg.log creation --- rc.sysinit | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/rc.sysinit b/rc.sysinit index 7f1089e..7b086fa 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -183,11 +183,13 @@ status "Remounting Root Read/Write" \ # don't touch /etc/mtab if it is a symlink to /proc/self/mounts if [[ ! -L /etc/mtab ]]; then - if [[ -x $(type -P findmnt) && -e /proc/self/mountinfo ]]; then - findmnt -rnu -o SOURCE,TARGET,FSTYPE,OPTIONS >| /etc/mtab - else - cat /proc/mounts >| /etc/mtab - fi + stat_busy "Creating mtab" + if [[ -x $(type -P findmnt) && -e /proc/self/mountinfo ]]; then + findmnt -rnu -o SOURCE,TARGET,FSTYPE,OPTIONS >| /etc/mtab + else + cat /proc/mounts >| /etc/mtab + fi + (( $? == 0 )) && stat_done || stat_fail fi # now mount all the local filesystems @@ -258,12 +260,14 @@ fi # Set console font if required set_consolefont -if [[ -e /proc/sys/kernel/dmesg_restrict ]] && - (( $(< /proc/sys/kernel/dmesg_restrict) == 1 )); then - install -Tm 0600 <( dmesg ) /var/log/dmesg.log -else - install -Tm 0644 <( dmesg ) /var/log/dmesg.log -fi +stat_busy "Saving dmesg Log" + if [[ -e /proc/sys/kernel/dmesg_restrict ]] && + (( $(< /proc/sys/kernel/dmesg_restrict) == 1 )); then + install -Tm 0600 <( dmesg ) /var/log/dmesg.log + else + install -Tm 0644 <( dmesg ) /var/log/dmesg.log + fi +(( $? == 0 )) && stat_done || stat_fail run_hook sysinit_end -- cgit v1.2.3 From 7e54af25d4d97150d508d8edba8614718988fc3c Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Sat, 2 Jul 2011 17:10:35 +0200 Subject: functions/rc.single: Clean up whitespace --- functions | 2 +- rc.single | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/functions b/functions index bcc97c1..f82110d 100644 --- a/functions +++ b/functions @@ -320,7 +320,7 @@ udevd_modprobe() { udevadm settle --timeout=${UDEV_TIMEOUT:-30} run_hook "${1}_udevsettled" - + # in case loading a module changed the display mode calc_columns } diff --git a/rc.single b/rc.single index d630736..d1efd41 100755 --- a/rc.single +++ b/rc.single @@ -12,10 +12,10 @@ run_hook single_start if [[ $PREVLEVEL != N ]]; then kill_everything single - + # start up our mini logger until syslog takes over minilogd - + # Start/trigger UDev, load MODULES and settle UDev udevd_modprobe single fi -- cgit v1.2.3 From 356eb55dc1594ce0ce2714b3debfeaaca9926c0d Mon Sep 17 00:00:00 2001 From: derhoch Date: Thu, 7 Jul 2011 03:13:28 -0700 Subject: changing _rd.d to _rc_d to avoid: /etc/bash_completion.d/rc.d: line 19: `_rc.d': not a valid identifier Signed-off-by: Sebastien Luttringer --- bash-completion | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bash-completion b/bash-completion index e63e880..d78484e 100644 --- a/bash-completion +++ b/bash-completion @@ -1,6 +1,6 @@ # rc.d bash completion by Seblu -_rc.d () +_rc_d() { local action cur prev action="help list start stop reload restart" @@ -19,6 +19,6 @@ _rc.d () COMPREPLY=($(cd /etc/rc.d && compgen -f -X 'functions*' "$cur"|sort)) fi } -complete -F _rc.d rc.d +complete -F _rc_d rc.d # vim: set ts=2 sw=2 ft=sh noet: -- cgit v1.2.3 From 1259ab3a31e619b755424e226ca4ddf0dcc2410d Mon Sep 17 00:00:00 2001 From: Sebastien Luttringer Date: Thu, 7 Jul 2011 13:59:40 +0200 Subject: Remove usage of head in PKGBUILD Signed-off-by: Sebastien Luttringer --- PKGBUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PKGBUILD b/PKGBUILD index 5c9764c..d8b4717 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -1,6 +1,6 @@ pkgname=initscripts-git pkgver=$(date +%s) -pkgrel=$(git log --pretty=format:%h |head -n 1) +pkgrel=$(git log -1 --pretty=format:%h) pkgdesc="System initialization/bootup scripts" arch=('i686' 'x86_64') url="http://www.archlinux.org" -- cgit v1.2.3 From fee9a12c24c058adcf79051ffe0431dda0b1600d Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Sun, 3 Jul 2011 20:15:32 +0200 Subject: rc.sysinit: Fix stat_busy block indentation The general rule is now: Align stat_{fail,done} with stat_busy --- rc.sysinit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rc.sysinit b/rc.sysinit index 7b086fa..cb0144c 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -231,7 +231,7 @@ fi # Flush old locale settings and set user defined locale stat_busy "Setting Locale: ${LOCALE:=en_US}" echo "export LANG=$LOCALE" > /etc/profile.d/locale.sh && - chmod 0755 /etc/profile.d/locale.sh && stat_done || stat_fail +chmod 0755 /etc/profile.d/locale.sh && stat_done || stat_fail if [[ ${LOCALE,,} =~ utf ]]; then stat_busy "Setting Consoles to UTF-8 mode" -- cgit v1.2.3 From cd34f837bfe3cc4798aeb5789f7717000ccdbf60 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Sat, 2 Jul 2011 17:48:57 +0200 Subject: functions: Get rid of superfluous braces in udevd_modprobe() Braces are not needed in this case as a variable name can not begin with a number. --- functions | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/functions b/functions index f82110d..71b49e3 100644 --- a/functions +++ b/functions @@ -305,7 +305,7 @@ udevd_modprobe() { # This is used to determine which hooks to run. status "Starting UDev Daemon" udevd --daemon - run_hook "${1}_udevlaunched" + run_hook "$1_udevlaunched" stat_busy "Triggering UDev uevents" udevadm trigger --action=add --type=subsystems @@ -319,7 +319,7 @@ udevd_modprobe() { status "Waiting for UDev uevents to be processed" \ udevadm settle --timeout=${UDEV_TIMEOUT:-30} - run_hook "${1}_udevsettled" + run_hook "$1_udevsettled" # in case loading a module changed the display mode calc_columns -- cgit v1.2.3 From f036700f0e4c112e533d0468da91ffa5e06929b9 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Sun, 3 Jul 2011 18:46:56 +0200 Subject: functions: Add missing quotes in mount_all() Prevent any word splitting where not intended. --- functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions b/functions index 71b49e3..ec043b6 100644 --- a/functions +++ b/functions @@ -417,7 +417,7 @@ fsck_reboot() { mount_all() { stat_busy "Mounting Local Filesystems" run_hook sysinit_premount - mount -a -t $NETFS -O no_netdev + mount -a -t "$NETFS" -O no_netdev run_hook sysinit_postmount stat_done } -- cgit v1.2.3 From d36c8a882bfdb863693d749db980af18d49e4e86 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Sat, 2 Jul 2011 18:10:24 +0200 Subject: functions/rc.multi: Strip paths from binaries Now that we set PATH in functions, we can use is everywhere. --- functions | 42 +++++++++++++++++++++--------------------- rc.multi | 2 +- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/functions b/functions index ec043b6..7acb855 100644 --- a/functions +++ b/functions @@ -20,12 +20,12 @@ calc_columns () { USECOLOR="" elif [[ -t 0 ]]; then # stty will fail when stdin isn't a terminal - STAT_COL="$(/bin/stty size)" + STAT_COL="$(stty size)" # stty gives "rows cols"; strip the rows number, we just want columns STAT_COL="${STAT_COL##* }" - elif /bin/tput cols &>/dev/null; then + elif tput cols &>/dev/null; then # is /usr/share/terminfo already mounted, and TERM recognized? - STAT_COL=$(/bin/tput cols) + STAT_COL=$(tput cols) fi if (( STAT_COL == 0 )); then # if output was 0 (serial console), set default width to 80 @@ -50,7 +50,7 @@ calc_columns () { calc_columns # disable colors on broken terminals -TERM_COLORS="$(/bin/tput colors 2>/dev/null)" +TERM_COLORS="$(tput colors 2>/dev/null)" if (( $? != 3 )); then case $TERM_COLORS in *[!0-9]*) USECOLOR="";; @@ -75,17 +75,17 @@ fi # set colors if [[ $USECOLOR = [yY][eE][sS] ]]; then - if /bin/tput setaf 0 &>/dev/null; then + if tput setaf 0 &>/dev/null; then C_CLEAR="$(tput sgr0)" # clear text - C_MAIN="${C_CLEAR}$(/bin/tput bold)" # main text - C_OTHER="${C_MAIN}$(/bin/tput setaf 4)" # prefix & brackets - C_SEPARATOR="${C_MAIN}$(/bin/tput setaf 0)" # separator - C_BUSY="${C_CLEAR}$(/bin/tput setaf 6)" # busy - C_FAIL="${C_MAIN}$(/bin/tput setaf 1)" # failed + C_MAIN="${C_CLEAR}$(tput bold)" # main text + C_OTHER="${C_MAIN}$(tput setaf 4)" # prefix & brackets + C_SEPARATOR="${C_MAIN}$(tput setaf 0)" # separator + C_BUSY="${C_CLEAR}$(tput setaf 6)" # busy + C_FAIL="${C_MAIN}$(tput setaf 1)" # failed C_DONE="${C_MAIN}" # completed - C_BKGD="${C_MAIN}$(/bin/tput setaf 5)" # backgrounded + C_BKGD="${C_MAIN}$(tput setaf 5)" # backgrounded C_H1="${C_MAIN}" # highlight text 1 - C_H2="${C_MAIN}$(/bin/tput setaf 6)" # highlight text 2 + C_H2="${C_MAIN}$(tput setaf 6)" # highlight text 2 else C_CLEAR="\e[m" # clear text C_MAIN="\e[;1m" # main text @@ -179,12 +179,12 @@ in_array() { # daemons: add_daemon() { - [[ -d /run/daemons ]] || /bin/mkdir -p /run/daemons + [[ -d /run/daemons ]] || mkdir -p /run/daemons >| /run/daemons/"$1" } rm_daemon() { - /bin/rm -f /run/daemons/"$1" + rm -f /run/daemons/"$1" } ck_daemon() { @@ -287,13 +287,13 @@ kill_everything() { # Terminate all processes stat_busy "Sending SIGTERM To Processes" run_hook "$1_prekillall" - /sbin/killall5 -15 ${omit_pids[@]/#/-o } &>/dev/null - /bin/sleep 5 + killall5 -15 ${omit_pids[@]/#/-o } &>/dev/null + sleep 5 stat_done stat_busy "Sending SIGKILL To Processes" - /sbin/killall5 -9 ${omit_pids[@]/#/-o } &>/dev/null - /bin/sleep 1 + killall5 -9 ${omit_pids[@]/#/-o } &>/dev/null + sleep 1 stat_done run_hook "$1_postkillall" @@ -329,8 +329,8 @@ activate_vgs() { [[ $USELVM = [yY][eE][sS] && -x $(type -P lvm) && -d /sys/block ]] || return 0 # Kernel 2.6.x, LVM2 groups stat_busy "Activating LVM2 groups" - /sbin/modprobe -q dm-mod 2>/dev/null - /sbin/vgchange --sysinit -a y >/dev/null + modprobe -q dm-mod 2>/dev/null + vgchange --sysinit -a y >/dev/null (( $? == 0 )) && stat_done || stat_fail } @@ -496,7 +496,7 @@ set_consolefont() { [[ $CONSOLEMAP && ${LOCALE,,} =~ utf ]] && CONSOLEMAP="" local i for i in /dev/tty[0-9]*; do - /usr/bin/setfont ${CONSOLEMAP:+-m ${CONSOLEMAP}} \ + setfont ${CONSOLEMAP:+-m ${CONSOLEMAP}} \ $CONSOLEFONT -C ${i} &>/dev/null done if (( $? )); then diff --git a/rc.multi b/rc.multi index b801fb6..16fa83a 100755 --- a/rc.multi +++ b/rc.multi @@ -9,7 +9,7 @@ run_hook multi_start # Load sysctl variables if sysctl.conf is present -[[ -r /etc/sysctl.conf ]] && /sbin/sysctl -q -p &>/dev/null +[[ -r /etc/sysctl.conf ]] && sysctl -q -p &>/dev/null # Start daemons for daemon in "${DAEMONS[@]}"; do -- cgit v1.2.3 From 02de29190c10dab4d1b43062d71eff11b9c980b5 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Sat, 2 Jul 2011 17:28:10 +0200 Subject: Refactor kill_everything, fsck_all and mount_all code Genaral scheme for hook positions is now: run_hook pre_foo if [[$WE_WANT_TO_DO_FOO]]]; then stat_busy "Doing foo" if [[$PRECONDITIONS_FOR_FOO_NOT_SATISFIED]]; then stat_fail else ... stat_done fi fi run hook post_foo rc.sysinit ----------- run_hook pre_foo [[$WE_WANT_TO_DO_FOO]] && status "Doing foo" foo run hook post_foo functions ------------ foo() { [[$PRECONDITIONS_FOR_FOO_NOT_SATISFIED]] && return 1 ... } Rationale Following this scheme as close as possible (without duplicating code and status messages) makes stuff more readable and uniform. Splitting kill_everything() into two new functions stop_all_daemons() and kill_all() also allows customization of either daemons stopping or process killing in an easy way. Suggested-by: Tom Gundersen --- functions | 36 +++++++++++------------------------- rc.shutdown | 8 +++++++- rc.single | 9 ++++++++- rc.sysinit | 24 +++++++++++++++++++++--- 4 files changed, 47 insertions(+), 30 deletions(-) diff --git a/functions b/functions index 7acb855..fd18694 100644 --- a/functions +++ b/functions @@ -265,10 +265,10 @@ add_omit_pids() { omit_pids+=( $@ ) } - -kill_everything() { - # $1 = where we are being called from. - # This is used to determine which hooks to run. +# Stop all daemons +# This function should *never* ever perform any other actions beside calling stop_daemon()! +# It might be used by a splash system etc. to get a list of daemons to be stopped. +stop_all_daemons() { # Find daemons NOT in the DAEMONS array. Shut these down first local daemon for daemon in /run/daemons/*; do @@ -283,10 +283,11 @@ kill_everything() { [[ ${DAEMONS[i]} = '!'* ]] && continue ck_daemon ${DAEMONS[i]#@} || stop_daemon ${DAEMONS[i]#@} done +} +kill_all() { # Terminate all processes stat_busy "Sending SIGTERM To Processes" - run_hook "$1_prekillall" killall5 -15 ${omit_pids[@]/#/-o } &>/dev/null sleep 5 stat_done @@ -295,8 +296,6 @@ kill_everything() { killall5 -9 ${omit_pids[@]/#/-o } &>/dev/null sleep 1 stat_done - - run_hook "$1_postkillall" } # Start/trigger UDev, load MODULES and settle UDev @@ -360,23 +359,14 @@ read_crypttab() { return $failed } +# Filesystem functions +# These can be overridden/reused for customizations like shutdown/loop-fsck. NETFS="nonfs,nonfs4,nosmbfs,nocifs,nocodafs,noncpfs,nosysfs,noshfs,nofuse,nofuseblk,noglusterfs,nodavfs" # Check local filesystems fsck_all() { - [[ -x $(type -P fsck) ]] || return 0 - stat_busy "Checking Filesystems" - FSCK_OUT=/dev/stdout - FSCK_ERR=/dev/stdout - FSCK_FD= - FORCEFSCK= - [[ -f /forcefsck ]] || in_array forcefsck $(< /proc/cmdline) && FORCEFSCK="-- -f" - run_hook sysinit_prefsck - fsck -A -T -C$FSCK_FD -a -t "$NETFS,noopts=_netdev" $FORCEFSCK >|$FSCK_OUT 2>|$FSCK_ERR - local -r fsckret=$? - (( fsckret <= 1 )) && stat_done || stat_fail - run_hook sysinit_postfsck - return $fsckret + fsck -A -T -C$FSCK_FD -a -t "$NETFS,noopts=_netdev" $FORCEFSCK >|$FSCK_OUT 2>|$FSCK_ERR + return $? } # Single-user login and/or automatic reboot after fsck (if needed) @@ -415,11 +405,7 @@ fsck_reboot() { } mount_all() { - stat_busy "Mounting Local Filesystems" - run_hook sysinit_premount - mount -a -t "$NETFS" -O no_netdev - run_hook sysinit_postmount - stat_done + mount -a -t "$NETFS" -O no_netdev } bootlogd_stop() { diff --git a/rc.shutdown b/rc.shutdown index fe42797..ed87eec 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -17,7 +17,13 @@ echo " " [[ -x /etc/rc.local.shutdown ]] && /etc/rc.local.shutdown -kill_everything shutdown +stop_all_daemons + +run_hook shutdown_prekillall + +kill_all + +run_hook shutdown_postkillall stat_busy "Saving Random Seed" RANDOM_SEED=/var/lib/misc/random-seed diff --git a/rc.single b/rc.single index d1efd41..21fe3be 100755 --- a/rc.single +++ b/rc.single @@ -11,7 +11,14 @@ export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" run_hook single_start if [[ $PREVLEVEL != N ]]; then - kill_everything single + + stop_all_daemons + + run_hook single_prekillall + + kill_all + + run_hook single_postkillall # start up our mini logger until syslog takes over minilogd diff --git a/rc.sysinit b/rc.sysinit index cb0144c..c3610dc 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -174,9 +174,24 @@ if [[ -f /etc/crypttab && $CS ]] && grep -q ^[^#] /etc/crypttab; then fi # Check filesystems -fsck_all +FSCK_OUT=/dev/stdout +FSCK_ERR=/dev/stdout +FSCK_FD= +FORCEFSCK= +[[ -f /forcefsck ]] || is_in_array forcefsck $(< /proc/cmdline) && FORCEFSCK="-- -f" +run_hook sysinit_prefsck +if [[ -x $(type -P fsck) ]]; then + stat_busy "Checking Filesystems" + fsck_all + declare -r fsckret=$? + (( fsckret <= 1 )) && stat_done || stat_fail +else + declare -r fsckret=0 +fi +run_hook sysinit_postfsck + # Single-user login and/or automatic reboot if needed -fsck_reboot $? +fsck_reboot $fsckret status "Remounting Root Read/Write" \ mount -n -o remount,rw / @@ -193,7 +208,10 @@ if [[ ! -L /etc/mtab ]]; then fi # now mount all the local filesystems -mount_all +run_hook sysinit_premount +status "Mounting Local Filesystems" \ + mount_all +run_hook sysinit_postmount # enable monitoring of lvm2 groups, now that the filesystems are mounted rw [[ $USELVM = [Yy][Ee][Ss] && -x $(type -P lvm) && -d /sys/block ]] && -- cgit v1.2.3 From d1f4307c2e7fb56a6f699bf2bfaa3e67197c46ef Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Sun, 3 Jul 2011 18:44:53 +0200 Subject: rc.sysinit: Declare $FORCEFSCK read-only This prevents sysinit_prefsck hooks from overwriting the value. --- rc.sysinit | 1 + 1 file changed, 1 insertion(+) diff --git a/rc.sysinit b/rc.sysinit index c3610dc..f64c9ad 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -179,6 +179,7 @@ FSCK_ERR=/dev/stdout FSCK_FD= FORCEFSCK= [[ -f /forcefsck ]] || is_in_array forcefsck $(< /proc/cmdline) && FORCEFSCK="-- -f" +declare -r FORCEFSCK run_hook sysinit_prefsck if [[ -x $(type -P fsck) ]]; then stat_busy "Checking Filesystems" -- cgit v1.2.3 From 328e15f698f4c280d61bfce1f27bf21c1a7f057d Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Sun, 3 Jul 2011 21:13:50 +0200 Subject: functions/rc.sysinit: Refactor fsck-redirection to prevent breakage $FSCK_OUT/$FSCK_ERR might not be set when: * unset in some custom sysinit_prefsck hook * calling fsck() from a shutdown hook --- functions | 2 +- rc.sysinit | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/functions b/functions index fd18694..202db30 100644 --- a/functions +++ b/functions @@ -365,7 +365,7 @@ NETFS="nonfs,nonfs4,nosmbfs,nocifs,nocodafs,noncpfs,nosysfs,noshfs,nofuse,nofuse # Check local filesystems fsck_all() { - fsck -A -T -C$FSCK_FD -a -t "$NETFS,noopts=_netdev" $FORCEFSCK >|$FSCK_OUT 2>|$FSCK_ERR + fsck -A -T -C$FSCK_FD -a -t "$NETFS,noopts=_netdev" $FORCEFSCK return $? } diff --git a/rc.sysinit b/rc.sysinit index f64c9ad..5814007 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -174,8 +174,8 @@ if [[ -f /etc/crypttab && $CS ]] && grep -q ^[^#] /etc/crypttab; then fi # Check filesystems -FSCK_OUT=/dev/stdout -FSCK_ERR=/dev/stdout +FSCK_OUT= +FSCK_ERR= FSCK_FD= FORCEFSCK= [[ -f /forcefsck ]] || is_in_array forcefsck $(< /proc/cmdline) && FORCEFSCK="-- -f" @@ -183,7 +183,7 @@ declare -r FORCEFSCK run_hook sysinit_prefsck if [[ -x $(type -P fsck) ]]; then stat_busy "Checking Filesystems" - fsck_all + fsck_all >|${FSCK_OUT:-/dev/stdout} 2>|${FSCK_ERR:-/dev/stdout} declare -r fsckret=$? (( fsckret <= 1 )) && stat_done || stat_fail else -- cgit v1.2.3 From ed0a943cc9762a1ccaf38bd3c36c31bf56f60fd9 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Sun, 10 Jul 2011 18:12:53 +0200 Subject: rc.sysinit: Remove unneeded variables initializations Variables should be empty anyway here. --- rc.sysinit | 4 ---- 1 file changed, 4 deletions(-) diff --git a/rc.sysinit b/rc.sysinit index 5814007..4132b8c 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -174,10 +174,6 @@ if [[ -f /etc/crypttab && $CS ]] && grep -q ^[^#] /etc/crypttab; then fi # Check filesystems -FSCK_OUT= -FSCK_ERR= -FSCK_FD= -FORCEFSCK= [[ -f /forcefsck ]] || is_in_array forcefsck $(< /proc/cmdline) && FORCEFSCK="-- -f" declare -r FORCEFSCK run_hook sysinit_prefsck -- cgit v1.2.3 From 834d47fedd68a5adbd6152649363d99b6ad642b4 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Sun, 3 Jul 2011 19:36:29 +0200 Subject: functions: Make status() return the actual exit code The exit code returned by the given command might be useful/expected, so don't discard but return it. --- functions | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/functions b/functions index 202db30..6efcd52 100644 --- a/functions +++ b/functions @@ -156,12 +156,10 @@ stat_die() { status() { stat_busy "$1" shift - if "$@" &>/dev/null; then - stat_done - return 0 - fi - stat_fail - return 1 + "$@" &>/dev/null + local ret=$? + (( $ret == 0 )) && stat_done || stat_fail + return $ret } # usage : in_array( $needle, $haystack ) -- cgit v1.2.3 From 540e6b39885ccbcb11b8622f902bb9462368501c Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Sat, 2 Jul 2011 18:40:09 +0200 Subject: functions: Speed up reboot/shutdown by recognizing killall5 exit code 2 killall5 returns 2 if it didn't find any processes to send to. Using this avoids sleeping longer than needed. This saves another up to six seconds of reboot/shutdown/go-single time. --- functions | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/functions b/functions index 6efcd52..2f10e01 100644 --- a/functions +++ b/functions @@ -285,14 +285,25 @@ stop_all_daemons() { kill_all() { # Terminate all processes + # and wait until killall5 reports all done or timeout + # Unfortunately killall5 does not support the 0 signal, so just + # use SIGCONT for checking (which should be ignored). stat_busy "Sending SIGTERM To Processes" + local i killall5 -15 ${omit_pids[@]/#/-o } &>/dev/null - sleep 5 + for (( i=0; i<20 && $?!=2; i++ )); do + sleep .25 # 1/4 second + killall5 -18 ${omit_pids[@]/#/-o } &>/dev/null + done stat_done stat_busy "Sending SIGKILL To Processes" + local i killall5 -9 ${omit_pids[@]/#/-o } &>/dev/null - sleep 1 + for (( i=0; i<4 && $?!=2; i++ )); do + sleep .25 # 1/4 second + killall5 -18 ${omit_pids[@]/#/-o } &>/dev/null + done stat_done } -- cgit v1.2.3 From 4cc6dba9c7c709c40b8e70df68569cc9a34e4b69 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Sun, 10 Jul 2011 11:21:26 +0200 Subject: netfs: cleanup whitespace --- netfs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netfs b/netfs index 2bcec6c..8b42cd8 100755 --- a/netfs +++ b/netfs @@ -37,7 +37,7 @@ case "$1" in $0 start ;; *) - echo "usage: $0 {start|stop|restart}" + echo "usage: $0 {start|stop|restart}" esac # vim: set ts=2 noet: -- cgit v1.2.3 From 89a56bde72418c289155b3eb5725f10f146899f6 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Tue, 5 Jul 2011 22:53:20 +0200 Subject: netfs: Strip paths from binaries We set $PATH in functions now, so use it. --- netfs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/netfs b/netfs index 8b42cd8..fff8482 100755 --- a/netfs +++ b/netfs @@ -9,9 +9,9 @@ rc=0 case "$1" in start) stat_busy "Mounting Network Filesystems" - /bin/mount -a -t nfs,nfs4,smbfs,codafs,ncpfs,cifs,shfs,glusterfs,fuse,fuseblk,fuse.glusterfs,davfs + mount -a -t nfs,nfs4,smbfs,codafs,ncpfs,cifs,shfs,glusterfs,fuse,fuseblk,fuse.glusterfs,davfs rc=$? - /bin/mount -a -O _netdev + mount -a -O _netdev if ((rc + $? > 0)); then stat_fail else @@ -21,9 +21,9 @@ case "$1" in ;; stop) stat_busy "Unmounting Network Filesystems" - /bin/umount -a -O _netdev + umount -a -O _netdev rc=$? - /bin/umount -a -t nfs,nfs4,smbfs,codafs,ncpfs,cifs,shfs,glusterfs,fuse,fuseblk,fuse.glusterfs,davfs + umount -a -t nfs,nfs4,smbfs,codafs,ncpfs,cifs,shfs,glusterfs,fuse,fuseblk,fuse.glusterfs,davfs if ((rc + $? > 0)); then stat_fail else -- cgit v1.2.3 From a16cbaeda9ee38d581e8556cc31cc9aa10afb9d2 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Tue, 5 Jul 2011 23:01:06 +0200 Subject: netfs: Refactor to provide meaningful exit code Get rid of simple if-clauses and provide meaningfull exit code. Maybe someone wants to abort suspend to disk/ram or something if umount fails or even start this in a loop. --- netfs | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/netfs b/netfs index fff8482..ffda681 100755 --- a/netfs +++ b/netfs @@ -4,32 +4,24 @@ . /etc/rc.conf . /etc/rc.d/functions -rc=0 - case "$1" in start) stat_busy "Mounting Network Filesystems" mount -a -t nfs,nfs4,smbfs,codafs,ncpfs,cifs,shfs,glusterfs,fuse,fuseblk,fuse.glusterfs,davfs rc=$? mount -a -O _netdev - if ((rc + $? > 0)); then - stat_fail - else - add_daemon netfs - stat_done - fi + (( rc || $? )) && stat_die + add_daemon netfs + stat_done ;; stop) stat_busy "Unmounting Network Filesystems" umount -a -O _netdev rc=$? umount -a -t nfs,nfs4,smbfs,codafs,ncpfs,cifs,shfs,glusterfs,fuse,fuseblk,fuse.glusterfs,davfs - if ((rc + $? > 0)); then - stat_fail - else - rm_daemon netfs - stat_done - fi + (( rc || $? )) && stat_die + rm_daemon netfs + stat_done ;; restart) $0 stop @@ -38,6 +30,7 @@ case "$1" in ;; *) echo "usage: $0 {start|stop|restart}" + exit 1 esac # vim: set ts=2 noet: -- cgit v1.2.3 From 98363ca955850c62064934265c56a7ca159b0035 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Tue, 5 Jul 2011 23:35:07 +0200 Subject: functions/netfs: Refactor filesystem type lists and $NETFS Currently $NETFS is used only for fsck and mount in rc.sysinit. Since we moved it into functions, we can use it in netfs too to get rid of redundancy. functions: * Move 'nosysfs' from $NETFS into the mount -a type list because thats obviously the only meaningfull place. * Add 'nofuse.glusterfs' to $NETFS to match the lists in netfs. * Remove all 'no'-prefixes from $NETFS to make it more useful and readable. * Add 'no'-prefixes to fsck and mount -a commands by parameter substitution. netfs: * Instead of the literals use $NETFS from functions which contains the same types now --- functions | 6 +++--- netfs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/functions b/functions index 2f10e01..5bfeb77 100644 --- a/functions +++ b/functions @@ -370,11 +370,11 @@ read_crypttab() { # Filesystem functions # These can be overridden/reused for customizations like shutdown/loop-fsck. -NETFS="nonfs,nonfs4,nosmbfs,nocifs,nocodafs,noncpfs,nosysfs,noshfs,nofuse,nofuseblk,noglusterfs,nodavfs" +NETFS="nfs,nfs4,smbfs,cifs,codafs,ncpfs,shfs,fuse,fuseblk,glusterfs,davfs,fuse.glusterfs" # Check local filesystems fsck_all() { - fsck -A -T -C$FSCK_FD -a -t "$NETFS,noopts=_netdev" $FORCEFSCK + fsck -A -T -C$FSCK_FD -a -t "no${NETFS//,/,no},noopts=_netdev" $FORCEFSCK return $? } @@ -414,7 +414,7 @@ fsck_reboot() { } mount_all() { - mount -a -t "$NETFS" -O no_netdev + mount -a -t "nosysfs,no${NETFS//,/,no}" -O no_netdev } bootlogd_stop() { diff --git a/netfs b/netfs index ffda681..ea7e4eb 100755 --- a/netfs +++ b/netfs @@ -7,7 +7,7 @@ case "$1" in start) stat_busy "Mounting Network Filesystems" - mount -a -t nfs,nfs4,smbfs,codafs,ncpfs,cifs,shfs,glusterfs,fuse,fuseblk,fuse.glusterfs,davfs + mount -a -t "$NETFS" rc=$? mount -a -O _netdev (( rc || $? )) && stat_die @@ -18,7 +18,7 @@ case "$1" in stat_busy "Unmounting Network Filesystems" umount -a -O _netdev rc=$? - umount -a -t nfs,nfs4,smbfs,codafs,ncpfs,cifs,shfs,glusterfs,fuse,fuseblk,fuse.glusterfs,davfs + umount -a -t "$NETFS" (( rc || $? )) && stat_die rm_daemon netfs stat_done -- cgit v1.2.3 From 71e8540921bba7df926a3af9714d380c5af2b538 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Thu, 7 Jul 2011 01:23:45 +0200 Subject: rc.sysinit: Simplify /var/run/daemons workaround There are only two possible situations: a) /var/run is a symlink to /run: Conditional result is always 'false' even without checking /var/run/daemons (which doesn't exist). b) /var/run is a directory: Conditional result is always 'true' because any symlink was removed when cleaning /var/run. So following changes can be made: * /var/run/daemons can be removed unconditionally because a symlink doesn't survive cleaning of /var/run anyway. * The check whether /var/run/daemons is a symlink can be dropped because it has actually no effect. Furthermore we can refactor to use the same conditional used for cleaning /var/run because we can't create the symlink if /var/run is not a directory. --- rc.sysinit | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rc.sysinit b/rc.sysinit index 4132b8c..7357582 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -227,12 +227,12 @@ RANDOM_SEED=/var/lib/misc/random-seed cp $RANDOM_SEED /dev/urandom stat_busy "Removing Leftover Files" - rm -rf /etc/{nologin,shutdownpid} /forcefsck /tmp/* /tmp/.* &>/dev/null + rm -rf /etc/{nologin,shutdownpid} /forcefsck /tmp/* /tmp/.* /var/run/daemons &>/dev/null [[ ! -L /var/lock ]] && rm -rf /var/lock/* - [[ ! -L /var/run && -d /var/run ]] && find /var/run/ \! -type d -delete - [[ ! -L /var/run && ! -L /var/run/daemons ]] && - rm -rf /var/run/daemons && + if [[ ! -L /var/run && -d /var/run ]]; then + find /var/run/ \! -type d -delete ln -s /run/daemons /var/run/daemons + fi install -Tm 0664 -o root -g utmp <(:) /var/run/utmp # Keep {x,k,g}dm happy with xorg mkdir -m 1777 /tmp/.{X11,ICE}-unix -- cgit v1.2.3 From 8a445c6d35f75eac1b13ace4a855934c597e9982 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Sat, 9 Jul 2011 20:02:05 +0200 Subject: rc.single: Remove $PATH assignment No need to set $PATH any more now that is in functions --- rc.single | 2 -- 1 file changed, 2 deletions(-) diff --git a/rc.single b/rc.single index 21fe3be..7a87c72 100755 --- a/rc.single +++ b/rc.single @@ -6,8 +6,6 @@ . /etc/rc.conf . /etc/rc.d/functions -export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" - run_hook single_start if [[ $PREVLEVEL != N ]]; then -- cgit v1.2.3 From bc7f1cd2690ded42cc68f620065c17eaf3140dd4 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Mon, 11 Jul 2011 16:43:21 +0200 Subject: rc.sysinit: fixup fsck refactoring Revert to using in_array() instead of is_in_array() which actually doesn't exist. --- rc.sysinit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rc.sysinit b/rc.sysinit index 7357582..bfaaf1b 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -174,7 +174,7 @@ if [[ -f /etc/crypttab && $CS ]] && grep -q ^[^#] /etc/crypttab; then fi # Check filesystems -[[ -f /forcefsck ]] || is_in_array forcefsck $(< /proc/cmdline) && FORCEFSCK="-- -f" +[[ -f /forcefsck ]] || in_array forcefsck $(< /proc/cmdline) && FORCEFSCK="-- -f" declare -r FORCEFSCK run_hook sysinit_prefsck if [[ -x $(type -P fsck) ]]; then -- cgit v1.2.3 From 7cc6e8dc3254e4e061db822511522634d329c2b3 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Mon, 11 Jul 2011 16:35:54 +0200 Subject: functions: Use ck_autostart in stop_all_daemons() This is just a bit simpler. in_array() should be fixed to be non daemon specific in a later patch. --- functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions b/functions index 5bfeb77..f564f3d 100644 --- a/functions +++ b/functions @@ -272,7 +272,7 @@ stop_all_daemons() { for daemon in /run/daemons/*; do [[ -f $daemon ]] || continue daemon=${daemon##*/} - in_array "$daemon" "${DAEMONS[@]}" || stop_daemon "$daemon" + ck_autostart "$daemon" && stop_daemon "$daemon" done # Shutdown daemons in reverse order -- cgit v1.2.3 From 67a8cea19a353af71227eb077d433e4b9cbe8cd4 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Mon, 11 Jul 2011 16:47:31 +0200 Subject: functions: Make in_array() non DAEMONS specific For checking whether a daemon is started via the DAEMONS array we use ck_autostart() now. So make in_array() generic as the name suggests instead of removing '@'-prefixes from array members behind ones back. Suggested-by: Dave Reisner --- functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions b/functions index f564f3d..000ee0e 100644 --- a/functions +++ b/functions @@ -169,7 +169,7 @@ in_array() { local needle=$1; shift local item for item; do - [[ ${item#@} = $needle ]] && return 0 + [[ $item = $needle ]] && return 0 done return 1 # Not Found } -- cgit v1.2.3 From b58d073ecd10315931c34d5177b9ce956b310375 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Mon, 11 Jul 2011 22:37:04 +0200 Subject: rc.sysinit: Fix /tmp/.* pattern Use correct patterns and get rid of the /dev/null redirection workaround needed when trying to remove '..'. --- rc.sysinit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rc.sysinit b/rc.sysinit index bfaaf1b..6af105f 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -227,7 +227,7 @@ RANDOM_SEED=/var/lib/misc/random-seed cp $RANDOM_SEED /dev/urandom stat_busy "Removing Leftover Files" - rm -rf /etc/{nologin,shutdownpid} /forcefsck /tmp/* /tmp/.* /var/run/daemons &>/dev/null + rm -rf /etc/{nologin,shutdownpid} /forcefsck /tmp/* /tmp/.[^.]* /tmp/..?* /var/run/daemons [[ ! -L /var/lock ]] && rm -rf /var/lock/* if [[ ! -L /var/run && -d /var/run ]]; then find /var/run/ \! -type d -delete -- cgit v1.2.3 From d980c23c0a5e9020402cd944c701f4e1f44d208d Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Mon, 11 Jul 2011 22:46:15 +0200 Subject: functions/rc.sysinit: Refactor 'Removing Leftover Files' code Move it into a function to allow clean error detection of all steps performed and also to be able to reuse this in rc.single. --- functions | 14 ++++++++++++++ rc.sysinit | 13 ++----------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/functions b/functions index 000ee0e..fdf30fd 100644 --- a/functions +++ b/functions @@ -417,6 +417,20 @@ mount_all() { mount -a -t "nosysfs,no${NETFS//,/,no}" -O no_netdev } +remove_leftover() { + stat_busy "Removing Leftover Files" + rm -rf /etc/{nologin,shutdownpid} /forcefsck /tmp/* /tmp/.[^.]* /tmp/..?* /var/run/daemons + [[ ! -L /var/lock ]] && rm -rf /var/lock/* + if [[ ! -L /var/run && -d /var/run ]]; then + find /var/run/ \! -type d -delete + ln -s /run/daemons /var/run/daemons + fi + install -Tm 0664 -o root -g utmp <(:) /var/run/utmp + # Keep {x,k,g}dm happy with xorg + mkdir -m 1777 /tmp/.{X11,ICE}-unix + stat_done +} + bootlogd_stop() { [[ -f /run/bootlogd.pid ]] || return 0 touch /var/log/boot diff --git a/rc.sysinit b/rc.sysinit index 6af105f..1516fba 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -226,17 +226,8 @@ RANDOM_SEED=/var/lib/misc/random-seed status "Initializing Random Seed" \ cp $RANDOM_SEED /dev/urandom -stat_busy "Removing Leftover Files" - rm -rf /etc/{nologin,shutdownpid} /forcefsck /tmp/* /tmp/.[^.]* /tmp/..?* /var/run/daemons - [[ ! -L /var/lock ]] && rm -rf /var/lock/* - if [[ ! -L /var/run && -d /var/run ]]; then - find /var/run/ \! -type d -delete - ln -s /run/daemons /var/run/daemons - fi - install -Tm 0664 -o root -g utmp <(:) /var/run/utmp - # Keep {x,k,g}dm happy with xorg - mkdir -m 1777 /tmp/.{X11,ICE}-unix -stat_done +# Remove leftover files +remove_leftover if [[ $HOSTNAME ]]; then stat_busy "Setting Hostname: $HOSTNAME" -- cgit v1.2.3 From 8a8163bf69ac0966e7a8b6eec49196e2d366b7a6 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Mon, 11 Jul 2011 22:56:21 +0200 Subject: rc.single: Call remove_leftover() when going single-user This avoids trouble because of stale /run/daemons/* files. --- rc.single | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rc.single b/rc.single index 7a87c72..3527a99 100755 --- a/rc.single +++ b/rc.single @@ -23,6 +23,9 @@ if [[ $PREVLEVEL != N ]]; then # Start/trigger UDev, load MODULES and settle UDev udevd_modprobe single + + # Removing leftover files + remove_leftover fi run_hook single_end -- cgit v1.2.3 From 66dd870039a49348516fc68a7e515f370f6a4702 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Tue, 12 Jul 2011 09:48:40 +0200 Subject: functions: Remove useless '$' within '(( ))' --- functions | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/functions b/functions index fdf30fd..8c0d3a2 100644 --- a/functions +++ b/functions @@ -39,7 +39,7 @@ calc_columns () { if [[ -t 1 ]]; then SAVE_POSITION="\e[s" RESTORE_POSITION="\e[u" - DEL_TEXT="\e[$(($STAT_COL+4))G" + DEL_TEXT="\e[$((STAT_COL+4))G" else SAVE_POSITION="" RESTORE_POSITION="" @@ -158,7 +158,7 @@ status() { shift "$@" &>/dev/null local ret=$? - (( $ret == 0 )) && stat_done || stat_fail + (( ret == 0 )) && stat_done || stat_fail return $ret } -- cgit v1.2.3 From f5641931faa2f6cc29985d70b90cc79bf752d62e Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Tue, 12 Jul 2011 09:49:58 +0200 Subject: functions: Unify whitespace inside '(( ))' --- functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions b/functions index 8c0d3a2..ff9a05c 100644 --- a/functions +++ b/functions @@ -39,7 +39,7 @@ calc_columns () { if [[ -t 1 ]]; then SAVE_POSITION="\e[s" RESTORE_POSITION="\e[u" - DEL_TEXT="\e[$((STAT_COL+4))G" + DEL_TEXT="\e[$(( STAT_COL + 4 ))G" else SAVE_POSITION="" RESTORE_POSITION="" -- cgit v1.2.3 From 81c36b2f88b03b098bcf41a9036dfe06d081c74f Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Tue, 12 Jul 2011 08:56:11 +0200 Subject: Fix/unify quoting The rules should be: * Use quotes when literal strings are involved. * Use quotes when ever using a substitution which might produce blanks as a possitional parameter unless word splitting is intended. * Use quotes on the right hand side within '[[ = ]]' unless pattern matching is intended. * Don't use quotes for substitutions where not needed as in assignments. --- functions | 50 +++++++++++++++++++++++++------------------------- rc.sysinit | 8 ++++---- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/functions b/functions index ff9a05c..79da659 100644 --- a/functions +++ b/functions @@ -20,9 +20,9 @@ calc_columns () { USECOLOR="" elif [[ -t 0 ]]; then # stty will fail when stdin isn't a terminal - STAT_COL="$(stty size)" + STAT_COL=$(stty size) # stty gives "rows cols"; strip the rows number, we just want columns - STAT_COL="${STAT_COL##* }" + STAT_COL=${STAT_COL##* } elif tput cols &>/dev/null; then # is /usr/share/terminfo already mounted, and TERM recognized? STAT_COL=$(tput cols) @@ -50,7 +50,7 @@ calc_columns () { calc_columns # disable colors on broken terminals -TERM_COLORS="$(tput colors 2>/dev/null)" +TERM_COLORS=$(tput colors 2>/dev/null) if (( $? != 3 )); then case $TERM_COLORS in *[!0-9]*) USECOLOR="";; @@ -76,16 +76,16 @@ fi # set colors if [[ $USECOLOR = [yY][eE][sS] ]]; then if tput setaf 0 &>/dev/null; then - C_CLEAR="$(tput sgr0)" # clear text - C_MAIN="${C_CLEAR}$(tput bold)" # main text - C_OTHER="${C_MAIN}$(tput setaf 4)" # prefix & brackets - C_SEPARATOR="${C_MAIN}$(tput setaf 0)" # separator - C_BUSY="${C_CLEAR}$(tput setaf 6)" # busy - C_FAIL="${C_MAIN}$(tput setaf 1)" # failed - C_DONE="${C_MAIN}" # completed - C_BKGD="${C_MAIN}$(tput setaf 5)" # backgrounded - C_H1="${C_MAIN}" # highlight text 1 - C_H2="${C_MAIN}$(tput setaf 6)" # highlight text 2 + C_CLEAR=$(tput sgr0) # clear text + C_MAIN=${C_CLEAR}$(tput bold) # main text + C_OTHER=${C_MAIN}$(tput setaf 4) # prefix & brackets + C_SEPARATOR=${C_MAIN}$(tput setaf 0) # separator + C_BUSY=${C_CLEAR}$(tput setaf 6) # busy + C_FAIL=${C_MAIN}$(tput setaf 1) # failed + C_DONE=${C_MAIN} # completed + C_BKGD=${C_MAIN}$(tput setaf 5) # backgrounded + C_H1=${C_MAIN} # highlight text 1 + C_H2=${C_MAIN}$(tput setaf 6) # highlight text 2 else C_CLEAR="\e[m" # clear text C_MAIN="\e[;1m" # main text @@ -93,9 +93,9 @@ if [[ $USECOLOR = [yY][eE][sS] ]]; then C_SEPARATOR="\e[1;30m" # separator C_BUSY="\e[;36m" # busy C_FAIL="\e[1;31m" # failed - C_DONE="${C_MAIN}" # completed + C_DONE=${C_MAIN} # completed C_BKGD="\e[1;35m" # backgrounded - C_H1="${C_MAIN}" # highlight text 1 + C_H1=${C_MAIN} # highlight text 1 C_H2="\e[1;36m" # highlight text 2 fi fi @@ -169,7 +169,7 @@ in_array() { local needle=$1; shift local item for item; do - [[ $item = $needle ]] && return 0 + [[ $item = "${needle}" ]] && return 0 done return 1 # Not Found } @@ -198,7 +198,7 @@ have_daemon() { ck_autostart() { local d for d in "${DAEMONS[@]}"; do - [[ "$1" = ${d#@} ]] && return 1 + [[ $1 = "${d#@}" ]] && return 1 done return 0 } @@ -247,11 +247,11 @@ get_pid() { # Check if PID-file $1 is still the active PID-file for command $2 ck_pidfile() { - if [[ -f "$1" ]]; then + if [[ -f $1 ]]; then local fpid ppid read -r fpid <"$1" - ppid=$(get_pid $2) - [[ "$fpid" = "$ppid" ]] && return 0 + ppid=$(get_pid "$2") + [[ $fpid = "${ppid}" ]] && return 0 fi return 1 } @@ -279,7 +279,7 @@ stop_all_daemons() { local i for (( i=${#DAEMONS[@]}-1; i>=0; i-- )); do [[ ${DAEMONS[i]} = '!'* ]] && continue - ck_daemon ${DAEMONS[i]#@} || stop_daemon ${DAEMONS[i]#@} + ck_daemon "${DAEMONS[i]#@}" || stop_daemon "${DAEMONS[i]#@}" done } @@ -374,7 +374,7 @@ NETFS="nfs,nfs4,smbfs,cifs,codafs,ncpfs,shfs,fuse,fuseblk,glusterfs,davfs,fuse.g # Check local filesystems fsck_all() { - fsck -A -T -C$FSCK_FD -a -t "no${NETFS//,/,no},noopts=_netdev" $FORCEFSCK + fsck -A -T -C"$FSCK_FD" -a -t "no${NETFS//,/,no},noopts=_netdev" $FORCEFSCK return $? } @@ -482,7 +482,7 @@ if (( RC_FUNCTIONS_HOOK_FUNCS_DEFINED != 1 )); then add_hook() { [[ $1 && $2 ]] || return 1 - hook_funcs["$1"]+=" $2" + hook_funcs[$1]+=" $2" } run_hook() { @@ -505,8 +505,8 @@ set_consolefont() { [[ $CONSOLEMAP && ${LOCALE,,} =~ utf ]] && CONSOLEMAP="" local i for i in /dev/tty[0-9]*; do - setfont ${CONSOLEMAP:+-m ${CONSOLEMAP}} \ - $CONSOLEFONT -C ${i} &>/dev/null + setfont ${CONSOLEMAP:+-m "${CONSOLEMAP}"} \ + "$CONSOLEFONT" -C ${i} &>/dev/null done if (( $? )); then stat_fail diff --git a/rc.sysinit b/rc.sysinit index 1516fba..fe1b7e6 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -96,14 +96,14 @@ if [[ -f /etc/crypttab && $CS ]] && grep -q ^[^#] /etc/crypttab; then # $3 = password # $4 = options stat_append "${1}.." - local open=create a="$1" b="$2" failed=0 + local open=create a=$1 b=$2 failed=0 # Ordering of options is different if you are using LUKS vs. not. # Use ugly swizzling to deal with it. # isLuks only gives an exit code but no output to stdout or stderr. if $CS isLuks "$2" 2>/dev/null; then open=luksOpen - a="$2" - b="$1" + a=$2 + b=$1 fi case $3 in SWAP) @@ -179,7 +179,7 @@ declare -r FORCEFSCK run_hook sysinit_prefsck if [[ -x $(type -P fsck) ]]; then stat_busy "Checking Filesystems" - fsck_all >|${FSCK_OUT:-/dev/stdout} 2>|${FSCK_ERR:-/dev/stdout} + fsck_all >|"${FSCK_OUT:-/dev/stdout}" 2>|"${FSCK_ERR:-/dev/stdout}" declare -r fsckret=$? (( fsckret <= 1 )) && stat_done || stat_fail else -- cgit v1.2.3 From 1ff5031122b1d16fbeb9c5e00ef366e4527c00ef Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Tue, 12 Jul 2011 17:38:27 +0200 Subject: functions: Cosmetics: Refactor usage of local daemon variables --- functions | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/functions b/functions index 79da659..1cfcf28 100644 --- a/functions +++ b/functions @@ -196,9 +196,9 @@ have_daemon() { # Check if $1 is started at boot ck_autostart() { - local d - for d in "${DAEMONS[@]}"; do - [[ $1 = "${d#@}" ]] && return 1 + local daemon + for daemon in "${DAEMONS[@]}"; do + [[ $1 = "${daemon#@}" ]] && return 1 done return 0 } @@ -276,10 +276,11 @@ stop_all_daemons() { done # Shutdown daemons in reverse order - local i + local i daemon for (( i=${#DAEMONS[@]}-1; i>=0; i-- )); do [[ ${DAEMONS[i]} = '!'* ]] && continue - ck_daemon "${DAEMONS[i]#@}" || stop_daemon "${DAEMONS[i]#@}" + daemon=${DAEMONS[i]#@} + ck_daemon "$daemon" || stop_daemon "$daemon" done } -- cgit v1.2.3 From 1f358f911a0237f4224169c4d225a9ae306e0853 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Wed, 13 Jul 2011 11:08:59 +0200 Subject: rc.sysinit: Move 'run_hook sysinit_start' after mount root read-only Rationale Currently we have to duplicate at least the mount /proc code line into a custom sysinit_start hook to be able to start a splash daemon or something in case no initcpio is used. Moreover we want to make sure nothing can open files read/write on root which would block the read-only remount. So running the sysinit_start hook a bit later appears to be more save. --- rc.sysinit | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rc.sysinit b/rc.sysinit index fe1b7e6..45e64b6 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -11,8 +11,6 @@ printhl "Arch Linux\n" printhl "${C_H2}http://www.archlinux.org" printsep -run_hook sysinit_start - # mount /proc, /sys, /run, /dev, /run/lock, /dev/pts, /dev/shm (the api filesystems) mountpoint -q /proc || mount -n -t proc proc /proc -o nosuid,noexec,nodev mountpoint -q /sys || mount -n -t sysfs sys /sys -o nosuid,noexec,nodev @@ -31,6 +29,8 @@ mountpoint -q /dev/shm || mount -n /dev/shm &>/dev/null \ findmnt / --options ro &>/dev/null || status "Mounting Root Read-Only" mount -n -o remount,ro / +run_hook sysinit_start + # start up our mini logger until syslog takes over minilogd bootlogd -p /run/bootlogd.pid -- cgit v1.2.3 From a4a47cfb5b97ddbf771959f1744c81167bc6b6f7 Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Fri, 22 Jul 2011 08:07:49 +0200 Subject: rc.shutdown: Move 'run_hook shutdown_start' after "Initiating Shutdown..." Rationale Avoid printing any start hook status messages above the head line. --- rc.shutdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rc.shutdown b/rc.shutdown index ed87eec..ebfc22c 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -6,8 +6,6 @@ . /etc/rc.conf . /etc/rc.d/functions -run_hook shutdown_start - # avoid staircase effect stty onlcr @@ -15,6 +13,8 @@ echo " " printhl "Initiating Shutdown..." echo " " +run_hook shutdown_start + [[ -x /etc/rc.local.shutdown ]] && /etc/rc.local.shutdown stop_all_daemons -- cgit v1.2.3 From e6c21e612838581c53c7742eb6071697f2d9e5a3 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Sat, 23 Jul 2011 22:21:35 -0400 Subject: arch-tmpfiles: add new script to handle volatile file control This is the same concept as systemd's tmpfiles handling, slightly simplified to avoid timed re-triggering of file cleaning. Most of our current file cleaning that takes place in rc.single and rc.sysinit is replaced by this, with the exception that we hold onto the /var/lock and /var/run for finer control, since we still check for the possibility of these directories being symlinks and adjust accordingly. Signed-off-by: Dave Reisner --- Makefile | 13 ++++- arch-tmpfiles | 156 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ functions | 7 +-- tmpfiles.conf | 20 ++++++++ 4 files changed, 190 insertions(+), 6 deletions(-) create mode 100755 arch-tmpfiles create mode 100644 tmpfiles.conf diff --git a/Makefile b/Makefile index c568b13..9fd2347 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,14 @@ VER := $(shell git describe) -DIRS := /etc/rc.d /etc/conf.d /etc/rc.d/functions.d /etc/logrotate.d /sbin /etc/bash_completion.d /usr/share/zsh/site-functions +DIRS := \ + /etc/rc.d \ + /etc/conf.d \ + /etc/rc.d/functions.d \ + /etc/logrotate.d \ + /sbin \ + /usr/lib/tmpfiles.d \ + /usr/lib/initscripts \ + /etc/bash_completion.d \ + /usr/share/zsh/site-functions minilogd: minilogd.o @@ -13,6 +22,8 @@ install: minilogd installdirs install -m644 -t $(DESTDIR)/etc/rc.d functions install -m755 -t $(DESTDIR)/etc/rc.d hwclock network netfs install -m755 -t $(DESTDIR)/sbin minilogd rc.d + install -m755 -t $(DESTDIR)/usr/lib/initscripts arch-tmpfiles + install -m644 tmpfiles.conf $(DESTDIR)/usr/lib/tmpfiles.d/arch.conf install -m644 -T bash-completion $(DESTDIR)/etc/bash_completion.d/rc.d install -m644 -T zsh-completion $(DESTDIR)/usr/share/zsh/site-functions/_rc.d diff --git a/arch-tmpfiles b/arch-tmpfiles new file mode 100755 index 0000000..b80aafa --- /dev/null +++ b/arch-tmpfiles @@ -0,0 +1,156 @@ +#!/bin/bash +# +# /usr/lib/initscripts/arch-tmpfiles +# +# Control creation, deletion, and cleaning of volatile and temporary files +# + +_f() { + # Create a file if it doesn't exist yet + local path=$1 mode=$2 uid=$3 gid=$4 + + if [[ ! -e $path ]]; then + install -m"$mode" -o"$uid" -g"$gid" <(:) "$path" + fi +} + +_F() { + # Create or truncate a file + local path=$1 mode=$2 uid=$3 gid=$4 + + install -m"$mode" -o"$uid" -g"$gid" <(:) "$path" +} + +_d() { + # Create a directory if it doesn't exist yet + local path=$1 mode=$2 uid=$3 gid=$4 + + if [[ ! -d "$path" ]]; then + install -d -m"$mode" -o"$uid" -g"$gid" "$path" + fi +} + +_D() { + # Create or empty a directory + local path=$1 mode=$2 uid=$3 gid=$4 + + if [[ -d $path ]]; then + find "$path" -mindepth 1 -maxdepth 1 -xdev -print0 | xargs -r0 rm -rf + fi + install -d -m"$mode" -o"$uid" -g"$gid" "$path" +} + +_p() { + # Create a named pipe (FIFO) if it doesn't exist yet + local path=$1 mode=$2 uid=$3 gid=$4 + + if [[ ! -p "$path" ]]; then + mkfifo -m$mode "$path" + chown "$uid:$gid" "$path" + fi +} + +_x() { + # Ignore a path during cleaning. Use this type to exclude paths from clean-up as + # controlled with the Age parameter. Note that lines of this type do not + # influence the effect of r or R lines. Lines of this type accept shell-style + # globs in place of of normal path names. + : + # XXX: we don't implement this +} + +_r() { + # Remove a file or directory if it exists. This may not be used to remove + # non-empty directories, use R for that. Lines of this type accept shell-style + # globs in place of normal path names. + local path + local -a paths=($1) + + for path in "${paths[@]}"; do + if [[ -f $path ]]; then + rm -f "$path" + elif [[ -d $path ]]; then + rmdir "$path" + fi + done +} + +_R() { + # Recursively remove a path and all its subdirectories (if it is a directory). + # Lines of this type accept shell-style globs in place of normal path names. + local path + local -a paths=($1) + + for path in "${paths[@]}"; do + [[ -d $path ]] && rm -rf --one-file-system "$path" + done +} + +shopt -s nullglob + +# catch errors in functions so we can exit with something meaningful +set -E +trap '(( ++error ))' ERR + +declare -i error=0 +declare -A fragments +declare -a tmpfiles_d=( + /usr/lib/tmpfiles.d/*.conf + /etc/tmpfiles.d/*.conf + /run/tmpfiles.d/*.conf +) + +# directories declared later in the tmpfiles_d array will override earlier +# directories, on a per file basis. +# Example: `/etc/tmpfiles.d/foo.conf' supersedes `/usr/lib/tmpfiles.d/foo.conf'. +for path in "${tmpfiles_d[@]}"; do + fragments[${path##*/}]=${path%/*} +done + +# loop through the gathered fragments, sorted globally by filename. +# `/run/tmpfiles/foo.conf' will always be read after `/etc/tmpfiles.d/bar.conf' +while read -d '' fragment; do + declare -i i=0 + + printf -v file '%s/%s' "${fragments[$fragment]}" "$fragment" + + ### FILE FORMAT ### + # XXX: We ignore the final 'Age' parameter + # 0 1 2 3 4 5 + # Type Path Mode UID GID Age + # d /run/user 0755 root root 10d + + # omit read's -r flag to honor escapes here, so that whitespace can be + # escaped for paths. We will _not_ honor quoted paths. + while read -a line; do + (( ++i )) + + # skip over comments and empty lines + if (( ! ${#line[*]} )) || [[ ${line[0]:0:1} = '#' ]]; then + continue + fi + + # whine about invalid entries + if ! type -t _${line[0]} >/dev/null; then + printf "arch-tmpfiles: skipping malformed entry on line %d of \`%s'\n" "$i" "$file" + (( ++error )) + continue + fi + + # fall back on defaults when parameters are passed as '-' + if [[ ${line[2]} = '-' ]]; then + case ${line[0]} in + p|f|F) line[2]=0644 ;; + d|D) line[2]=0755 ;; + esac + fi + [[ ${line[3]} = '-' ]] && line[3]=0 + [[ ${line[4]} = '-' ]] && line[4]=0 + + _${line[0]} "${line[@]:1}" + done <"$file" +done < <(printf '%s\0' "${!fragments[@]}" | sort -z) + +exit $error + +# vim: set ts=2 sw=2 noet: diff --git a/functions b/functions index 1cfcf28..16cf898 100644 --- a/functions +++ b/functions @@ -420,16 +420,13 @@ mount_all() { remove_leftover() { stat_busy "Removing Leftover Files" - rm -rf /etc/{nologin,shutdownpid} /forcefsck /tmp/* /tmp/.[^.]* /tmp/..?* /var/run/daemons + # handle this separately until we declare the non-symlinks obsoleted [[ ! -L /var/lock ]] && rm -rf /var/lock/* if [[ ! -L /var/run && -d /var/run ]]; then find /var/run/ \! -type d -delete ln -s /run/daemons /var/run/daemons fi - install -Tm 0664 -o root -g utmp <(:) /var/run/utmp - # Keep {x,k,g}dm happy with xorg - mkdir -m 1777 /tmp/.{X11,ICE}-unix - stat_done + /usr/lib/initscripts/arch-tmpfiles && stat_done || stat_fail } bootlogd_stop() { diff --git a/tmpfiles.conf b/tmpfiles.conf new file mode 100644 index 0000000..d47a028 --- /dev/null +++ b/tmpfiles.conf @@ -0,0 +1,20 @@ +# +# /usr/lib/tmpfiles.d/arch.conf +# + +d /tmp/.X11-unix 1777 root root 10d +d /tmp/.ICE-unix 1777 root root 10d +d /tmp/.XIM-unix 1777 root root 10d +d /tmp/.font-unix 1777 root root 10d +d /tmp/.Test-unix 1777 root root 10d + +f /var/run/tmp 0664 - utmp + +r /tmp/.X[0-9]-lock +r /etc/nologin +r /etc/shutdownpid +r /forcefsck + +D /tmp/ +D /var/run/daemons + -- cgit v1.2.3 From 7e39dc717edd4690772059ad4d5a7550dbf65019 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Sun, 24 Jul 2011 11:05:36 -0400 Subject: arch-tmpfiles: check args, warn on invalid entries Introduces the checkparams functions, which thoroughly checks arguments for presence, length, and some amount of data validation. Signed-off-by: Dave Reisner --- arch-tmpfiles | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++------ tmpfiles.conf | 18 ++++++------- 2 files changed, 84 insertions(+), 17 deletions(-) diff --git a/arch-tmpfiles b/arch-tmpfiles index b80aafa..827bc54 100755 --- a/arch-tmpfiles +++ b/arch-tmpfiles @@ -5,10 +5,47 @@ # Control creation, deletion, and cleaning of volatile and temporary files # +warninvalid() { + printf "arch-tmpfiles: ignoring invalid entry on line %d of \`%s'\n" "$LINENUM" "$FILE" + (( ++error )) +} >&2 + +checkparams() { + local parmreq=$1; shift + local path=$1 mode=$2 uid=$3 gid=$4 + + # parmcount must be >= parmreq + if (( $# < parmreq )); then + return 1 + fi + + # mode must be valid octal and 3 or 4 digits + if [[ $mode && ! $mode =~ ^[0-7]{3,4}$ ]]; then + return 1 + fi + + # uid must be numeric or a valid user name + if [[ $uid && $uid != +([[:digit:]]) ]] && ! getent passwd "$uid" >/dev/null; then + return 1 + fi + + # gid must be numeric or a valid group name + if [[ $gid && $gid != +([[:digit:]]) ]] && ! getent group "$gid" >/dev/null; then + return 1 + fi + + return 0 +} + _f() { # Create a file if it doesn't exist yet local path=$1 mode=$2 uid=$3 gid=$4 + if ! checkparams 4 "$@"; then + warninvalid + return + fi + if [[ ! -e $path ]]; then install -m"$mode" -o"$uid" -g"$gid" <(:) "$path" fi @@ -18,6 +55,11 @@ _F() { # Create or truncate a file local path=$1 mode=$2 uid=$3 gid=$4 + if ! checkparams 4 "$@"; then + warninvalid + return + fi + install -m"$mode" -o"$uid" -g"$gid" <(:) "$path" } @@ -25,6 +67,11 @@ _d() { # Create a directory if it doesn't exist yet local path=$1 mode=$2 uid=$3 gid=$4 + if ! checkparams 4 "$@"; then + warninvalid + return + fi + if [[ ! -d "$path" ]]; then install -d -m"$mode" -o"$uid" -g"$gid" "$path" fi @@ -34,6 +81,11 @@ _D() { # Create or empty a directory local path=$1 mode=$2 uid=$3 gid=$4 + if ! checkparams 4 "$@"; then + warninvalid + return + fi + if [[ -d $path ]]; then find "$path" -mindepth 1 -maxdepth 1 -xdev -print0 | xargs -r0 rm -rf fi @@ -44,6 +96,11 @@ _p() { # Create a named pipe (FIFO) if it doesn't exist yet local path=$1 mode=$2 uid=$3 gid=$4 + if ! checkparams 4 "$@"; then + warninvalid + return + fi + if [[ ! -p "$path" ]]; then mkfifo -m$mode "$path" chown "$uid:$gid" "$path" @@ -66,6 +123,11 @@ _r() { local path local -a paths=($1) + if ! checkparams 1 "$@"; then + warninvalid + return + fi + for path in "${paths[@]}"; do if [[ -f $path ]]; then rm -f "$path" @@ -81,6 +143,11 @@ _R() { local path local -a paths=($1) + if ! checkparams 1 "$@"; then + warninvalid + return + fi + for path in "${paths[@]}"; do [[ -d $path ]] && rm -rf --one-file-system "$path" done @@ -92,7 +159,8 @@ shopt -s nullglob set -E trap '(( ++error ))' ERR -declare -i error=0 +declare -i error=0 LINENO=0 +declare FILE= declare -A fragments declare -a tmpfiles_d=( /usr/lib/tmpfiles.d/*.conf @@ -104,15 +172,15 @@ declare -a tmpfiles_d=( # directories, on a per file basis. # Example: `/etc/tmpfiles.d/foo.conf' supersedes `/usr/lib/tmpfiles.d/foo.conf'. for path in "${tmpfiles_d[@]}"; do - fragments[${path##*/}]=${path%/*} + [[ -f $path ]] && fragments[${path##*/}]=${path%/*} done # loop through the gathered fragments, sorted globally by filename. # `/run/tmpfiles/foo.conf' will always be read after `/etc/tmpfiles.d/bar.conf' while read -d '' fragment; do - declare -i i=0 + LINENUM=0 - printf -v file '%s/%s' "${fragments[$fragment]}" "$fragment" + printf -v FILE '%s/%s' "${fragments[$fragment]}" "$fragment" ### FILE FORMAT ### # XXX: We ignore the final 'Age' parameter @@ -123,7 +191,7 @@ while read -d '' fragment; do # omit read's -r flag to honor escapes here, so that whitespace can be # escaped for paths. We will _not_ honor quoted paths. while read -a line; do - (( ++i )) + (( ++LINENUM )) # skip over comments and empty lines if (( ! ${#line[*]} )) || [[ ${line[0]:0:1} = '#' ]]; then @@ -132,8 +200,7 @@ while read -d '' fragment; do # whine about invalid entries if ! type -t _${line[0]} >/dev/null; then - printf "arch-tmpfiles: skipping malformed entry on line %d of \`%s'\n" "$i" "$file" - (( ++error )) + warninvalid continue fi @@ -148,7 +215,7 @@ while read -d '' fragment; do [[ ${line[4]} = '-' ]] && line[4]=0 _${line[0]} "${line[@]:1}" - done <"$file" + done <"$FILE" done < <(printf '%s\0' "${!fragments[@]}" | sort -z) exit $error diff --git a/tmpfiles.conf b/tmpfiles.conf index d47a028..f7db5a0 100644 --- a/tmpfiles.conf +++ b/tmpfiles.conf @@ -2,19 +2,19 @@ # /usr/lib/tmpfiles.d/arch.conf # -d /tmp/.X11-unix 1777 root root 10d -d /tmp/.ICE-unix 1777 root root 10d -d /tmp/.XIM-unix 1777 root root 10d -d /tmp/.font-unix 1777 root root 10d -d /tmp/.Test-unix 1777 root root 10d +D /tmp 1777 root root +D /run/daemons 0755 root root -f /var/run/tmp 0664 - utmp +d /tmp/.X11-unix 1777 root root +d /tmp/.ICE-unix 1777 root root +d /tmp/.XIM-unix 1777 root root +d /tmp/.font-unix 1777 root root +d /tmp/.Test-unix 1777 root root + +f /var/run/tmp 0664 root utmp r /tmp/.X[0-9]-lock r /etc/nologin r /etc/shutdownpid r /forcefsck -D /tmp/ -D /var/run/daemons - -- cgit v1.2.3 From 370dd6573143fb9b9a7d368badbd3f2bb40ad6cf Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Sun, 24 Jul 2011 15:04:36 -0400 Subject: arch-tmpfiles: add cmdline parameters Categorize actions as 'create' or 'remove', for finer control. Signed-off-by: Dave Reisner --- arch-tmpfiles | 37 ++++++++++++++++++++++++++++++++----- functions | 2 +- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/arch-tmpfiles b/arch-tmpfiles index 827bc54..c646ecd 100755 --- a/arch-tmpfiles +++ b/arch-tmpfiles @@ -41,6 +41,8 @@ _f() { # Create a file if it doesn't exist yet local path=$1 mode=$2 uid=$3 gid=$4 + (( CREATE )) || return 0 + if ! checkparams 4 "$@"; then warninvalid return @@ -55,6 +57,8 @@ _F() { # Create or truncate a file local path=$1 mode=$2 uid=$3 gid=$4 + (( CREATE )) || return 0 + if ! checkparams 4 "$@"; then warninvalid return @@ -67,6 +71,8 @@ _d() { # Create a directory if it doesn't exist yet local path=$1 mode=$2 uid=$3 gid=$4 + (( CREATE )) || return 0 + if ! checkparams 4 "$@"; then warninvalid return @@ -81,6 +87,8 @@ _D() { # Create or empty a directory local path=$1 mode=$2 uid=$3 gid=$4 + (( CREATE )) || return 0 + if ! checkparams 4 "$@"; then warninvalid return @@ -96,6 +104,8 @@ _p() { # Create a named pipe (FIFO) if it doesn't exist yet local path=$1 mode=$2 uid=$3 gid=$4 + (( CREATE )) || return 0 + if ! checkparams 4 "$@"; then warninvalid return @@ -123,6 +133,8 @@ _r() { local path local -a paths=($1) + (( REMOVE )) || return 0 + if ! checkparams 1 "$@"; then warninvalid return @@ -143,6 +155,8 @@ _R() { local path local -a paths=($1) + (( REMOVE )) || return 0 + if ! checkparams 1 "$@"; then warninvalid return @@ -155,11 +169,7 @@ _R() { shopt -s nullglob -# catch errors in functions so we can exit with something meaningful -set -E -trap '(( ++error ))' ERR - -declare -i error=0 LINENO=0 +declare -i CREATE=0 REMOVE=0 CLEAN=0 error=0 LINENO=0 declare FILE= declare -A fragments declare -a tmpfiles_d=( @@ -168,6 +178,19 @@ declare -a tmpfiles_d=( /run/tmpfiles.d/*.conf ) +while (( $# )); do + case $1 in + --create) CREATE=1 ;; + --remove) REMOVE=1 ;; + esac + shift +done + +if (( !(CREATE + REMOVE) )); then + printf 'usage: %s [--create] [--remove]\n' "${0##*/}" + exit 1 +fi + # directories declared later in the tmpfiles_d array will override earlier # directories, on a per file basis. # Example: `/etc/tmpfiles.d/foo.conf' supersedes `/usr/lib/tmpfiles.d/foo.conf'. @@ -175,6 +198,10 @@ for path in "${tmpfiles_d[@]}"; do [[ -f $path ]] && fragments[${path##*/}]=${path%/*} done +# catch errors in functions so we can exit with something meaningful +set -E +trap '(( ++error ))' ERR + # loop through the gathered fragments, sorted globally by filename. # `/run/tmpfiles/foo.conf' will always be read after `/etc/tmpfiles.d/bar.conf' while read -d '' fragment; do diff --git a/functions b/functions index 16cf898..a35e45e 100644 --- a/functions +++ b/functions @@ -426,7 +426,7 @@ remove_leftover() { find /var/run/ \! -type d -delete ln -s /run/daemons /var/run/daemons fi - /usr/lib/initscripts/arch-tmpfiles && stat_done || stat_fail + /usr/lib/initscripts/arch-tmpfiles --create --remove && stat_done || stat_fail } bootlogd_stop() { -- cgit v1.2.3 From 895d0944e622aac9a9446e6f727dadd07370677c Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Mon, 25 Jul 2011 21:31:19 +0200 Subject: network: reword depracation message Make it clear that the message refers to network settings, as some users found this confusing. Signed-off-by: Tom Gundersen --- network | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network b/network index 868780e..4fafb97 100755 --- a/network +++ b/network @@ -18,7 +18,7 @@ need_legacy() { } deprecated() { - printf "${C_FAIL}Warning:${C_CLEAR} This functionality is deprecated.\n" + printf "${C_FAIL}Warning:${C_CLEAR} Your network settings are deprecated.\n" printf " Please refer to /etc/rc.conf on how to define a single wired\n" printf " connection, or use a utility such as netcfg.\n" } -- cgit v1.2.3 From ff59fce20fb27911fca66c6f6574056365917fa1 Mon Sep 17 00:00:00 2001 From: Sebastien Luttringer Date: Tue, 26 Jul 2011 01:33:38 +0200 Subject: Add /etc/tmpfiles.d into makefile This add a /etc/tmpfiles.d inside makefile to automatically create directory with package. /etc is a better place to store user specific tmpfiles config where /usr/lib is better for shipped with package config. As Dave as already included this path inside his arch-tmpfiles, it would be a shame to miss out. Signed-off-by: Sebastien Luttringer --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 9fd2347..b2256ec 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,7 @@ DIRS := \ /etc/rc.d/functions.d \ /etc/logrotate.d \ /sbin \ + /etc/tmpfiles.d \ /usr/lib/tmpfiles.d \ /usr/lib/initscripts \ /etc/bash_completion.d \ -- cgit v1.2.3 From 91cd22c4fbbeabb4f64571511a009c572a9bb120 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Tue, 26 Jul 2011 00:22:37 -0400 Subject: tmpfiles.conf: fix improper creation of /var/run/utmp Signed-off-by: Dave Reisner --- tmpfiles.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmpfiles.conf b/tmpfiles.conf index f7db5a0..7dd1358 100644 --- a/tmpfiles.conf +++ b/tmpfiles.conf @@ -11,7 +11,7 @@ d /tmp/.XIM-unix 1777 root root d /tmp/.font-unix 1777 root root d /tmp/.Test-unix 1777 root root -f /var/run/tmp 0664 root utmp +F /var/run/utmp 0664 root utmp r /tmp/.X[0-9]-lock r /etc/nologin -- cgit v1.2.3 From b7432d25cba680c785269509245f394dfa6b9dd0 Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Mon, 25 Jul 2011 14:58:57 +0200 Subject: shutdown: pivot into a shutdown ramfs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Assume that a shutdown executable has been created in /run/initramfs by either dracut or mkinitramfs. Setup /run/initramfs to be a new root and pivot into it. Making sure that nothing is using our old root anymore. In particular this means we have to reexec init in the new root and make sure stdio is using the new /dev/console. This is inspired by Harald Hoyers work for systemd as well as Thomas Bächlers deinitramfs. Signed-off-by: Tom Gundersen --- rc.shutdown | 51 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/rc.shutdown b/rc.shutdown index ebfc22c..72f2edd 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -78,21 +78,48 @@ fi [[ $USELVM = [Yy][Ee][Ss] && -x $(type -P lvm) && -d /sys/block ]] && status "Deactivating LVM2 groups" vgchange --sysinit -a n &>/dev/null -status "Remounting Root Filesystem Read-only" \ +if [[ -x /run/initramfs/shutdown ]]; then + # make /run/initrafs a mount + mount --bind /run/initramfs /run/initramfs + + # in case someone has shared our mountpoints, unshare them + mount --make-private /run/initramfs + mount --make-private / + + # bind all api mounts + mkdir -p /run/initramfs/{sys,proc,dev,run,oldroot} + mount --bind /sys /run/initramfs/sys + mount --bind /proc /run/initramfs/proc + mount --bind /dev /run/initramfs/dev + mount --bind /run /run/initramfs/run + + # enter shutdownramfs + cd /run/initramfs + pivot_root . oldroot + + #reexec init + cp /oldroot/sbin/init /sbin + /oldroot/sbin/init u + + # run /shutdown in the new root + exec chroot . /shutdown /dev/console 2>&1 +else + status "Remounting Root Filesystem Read-only" \ mount -n -o remount,ro / -run_hook shutdown_poweroff + run_hook shutdown_poweroff -# Power off or reboot -printsep -if [[ $RUNLEVEL = 0 ]]; then - printhl "${C_H2}POWER OFF" - poweroff -d -f -h -i -else - printhl "${C_H2}REBOOTING" - # if kexec is installed and a kernel is loaded, use it - [[ -x $(type -P kexec) ]] && kexec -e &>/dev/null - reboot -d -f -i + # Power off or reboot + printsep + if [[ $RUNLEVEL = 0 ]]; then + printhl "${C_H2}POWER OFF" + poweroff -d -f -h -i + else + printhl "${C_H2}REBOOTING" + # if kexec is installed and a kernel is loaded, use it + [[ -x $(type -P kexec) ]] && kexec -e &>/dev/null + reboot -d -f -i + fi fi # End of file -- cgit v1.2.3 From 92ef85ff23d548f6dc9be3fb9b73a050f596941f Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Thu, 28 Jul 2011 14:21:07 +0200 Subject: NEED_ROOT: default to off This keeps the functionality, but disables it by default. Individual scripts/functions can turn it on if they want. Signed-off-by: Tom Gundersen --- functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions b/functions index a35e45e..f42c21e 100644 --- a/functions +++ b/functions @@ -531,7 +531,7 @@ need_root() { # Quit script if it's not running by root # This can be disabled in scripts sourcing functions by setting NEED_ROOT=0 # A local call to need_root can be done to ensure part of script need root privilege -(( ${NEED_ROOT:-1} == 1 )) && need_root +(( ${NEED_ROOT:-0} == 1 )) && need_root # End of file # vim: set ts=2 sw=2 noet: -- cgit v1.2.3 From 880e68141f27ea3295509bc51fee5179cdfa7695 Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Tue, 2 Aug 2011 21:43:40 +0200 Subject: /usr: warn on separate usr We check for /usr/lib being present. If it is not, we assume /usr is not yet mounted and warn. Signed-off-by: Tom Gundersen --- rc.sysinit | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rc.sysinit b/rc.sysinit index 45e64b6..a7daad9 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -35,6 +35,10 @@ run_hook sysinit_start minilogd bootlogd -p /run/bootlogd.pid +if [[ ! -a /usr/lib ]] ; then + printf "${C_FAIL}/usr is on a separate partition. This is not supported.${C_OTHER}\n" +fi + HWCLOCK_PARAMS="--systz" case $HARDWARECLOCK in "") ;; -- cgit v1.2.3 From 4ac0e23b1813eebbd9cad148193801cf2ce3f67c Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Tue, 26 Jul 2011 17:05:18 -0400 Subject: arch-tmpfiles: avoid subshell in creating empty files install /dev/null as the new file instead of creating an empty file via a no-op process substitution. Signed-off-by: Dave Reisner [tomegun: the commit also adds a similar fix to rc.shutdown] Signed-off-by: Tom Gundersen --- arch-tmpfiles | 4 ++-- rc.shutdown | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch-tmpfiles b/arch-tmpfiles index c646ecd..f133a40 100755 --- a/arch-tmpfiles +++ b/arch-tmpfiles @@ -49,7 +49,7 @@ _f() { fi if [[ ! -e $path ]]; then - install -m"$mode" -o"$uid" -g"$gid" <(:) "$path" + install -m"$mode" -o"$uid" -g"$gid" /dev/null "$path" fi } @@ -64,7 +64,7 @@ _F() { return fi - install -m"$mode" -o"$uid" -g"$gid" <(:) "$path" + install -m"$mode" -o"$uid" -g"$gid" /dev/null "$path" } _d() { diff --git a/rc.shutdown b/rc.shutdown index 72f2edd..d11aeee 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -27,7 +27,7 @@ run_hook shutdown_postkillall stat_busy "Saving Random Seed" RANDOM_SEED=/var/lib/misc/random-seed - install -TDm 0600 <(:) $RANDOM_SEED + install -TDm 0600 /dev/null $RANDOM_SEED POOL_FILE=/proc/sys/kernel/random/poolsize if [[ -r $POOL_FILE ]]; then read POOL_SIZE < $POOL_FILE -- cgit v1.2.3 From 0964929a57076d1edc9f74498aae5e2f7b87d912 Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Thu, 4 Aug 2011 12:52:42 +0200 Subject: /usr: move all executables from /sbin to /usr/sbin At worst this will give an error message if /usr is not mounted, which is fine as we are warning against this anyway. It will not break boot. Signed-off-by: Tom Gundersen --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index b2256ec..2d68ee3 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ DIRS := \ /etc/conf.d \ /etc/rc.d/functions.d \ /etc/logrotate.d \ - /sbin \ + /usr/sbin \ /etc/tmpfiles.d \ /usr/lib/tmpfiles.d \ /usr/lib/initscripts \ @@ -22,7 +22,7 @@ install: minilogd installdirs install -m644 -t $(DESTDIR)/etc/logrotate.d bootlog install -m644 -t $(DESTDIR)/etc/rc.d functions install -m755 -t $(DESTDIR)/etc/rc.d hwclock network netfs - install -m755 -t $(DESTDIR)/sbin minilogd rc.d + install -m755 -t $(DESTDIR)/usr/sbin minilogd rc.d install -m755 -t $(DESTDIR)/usr/lib/initscripts arch-tmpfiles install -m644 tmpfiles.conf $(DESTDIR)/usr/lib/tmpfiles.d/arch.conf install -m644 -T bash-completion $(DESTDIR)/etc/bash_completion.d/rc.d -- cgit v1.2.3 From b94d35b9a2325d822dede0a72fca561f7a7daf7a Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Thu, 4 Aug 2011 12:55:48 +0200 Subject: /usr: clarify warning a bit We still support a separate /usr if it was somehow mounted by the initrd. Signed-off-by: Tom Gundersen --- rc.sysinit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rc.sysinit b/rc.sysinit index a7daad9..86febfa 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -36,7 +36,7 @@ minilogd bootlogd -p /run/bootlogd.pid if [[ ! -a /usr/lib ]] ; then - printf "${C_FAIL}/usr is on a separate partition. This is not supported.${C_OTHER}\n" + printf "${C_FAIL}/usr is not mounted. This is not supported.${C_OTHER}\n" fi HWCLOCK_PARAMS="--systz" -- cgit v1.2.3 From 4ef7a256acddfdd0cbb54e9018f0d8fadbc0cae1 Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Fri, 5 Aug 2011 00:33:10 +0200 Subject: locale: make /etc/profile.d/locale.sh dynamic locale.sh parses rc.conf at runtime and sets the LOCALE accordingly, rather than writing a static file at every boot. This eliminates yet another write to /etc. Signed-off-by: Tom Gundersen --- Makefile | 2 ++ rc.sysinit | 5 ----- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 2d68ee3..4916387 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ DIRS := \ /etc/conf.d \ /etc/rc.d/functions.d \ /etc/logrotate.d \ + /etc/profile.d \ /usr/sbin \ /etc/tmpfiles.d \ /usr/lib/tmpfiles.d \ @@ -22,6 +23,7 @@ install: minilogd installdirs install -m644 -t $(DESTDIR)/etc/logrotate.d bootlog install -m644 -t $(DESTDIR)/etc/rc.d functions install -m755 -t $(DESTDIR)/etc/rc.d hwclock network netfs + install -m755 -t $(DESTDIR)/etc/profile.d locale.sh install -m755 -t $(DESTDIR)/usr/sbin minilogd rc.d install -m755 -t $(DESTDIR)/usr/lib/initscripts arch-tmpfiles install -m644 tmpfiles.conf $(DESTDIR)/usr/lib/tmpfiles.d/arch.conf diff --git a/rc.sysinit b/rc.sysinit index 86febfa..9f215c4 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -238,11 +238,6 @@ if [[ $HOSTNAME ]]; then echo "$HOSTNAME" >| /proc/sys/kernel/hostname && stat_done || stat_fail fi -# Flush old locale settings and set user defined locale -stat_busy "Setting Locale: ${LOCALE:=en_US}" - echo "export LANG=$LOCALE" > /etc/profile.d/locale.sh && -chmod 0755 /etc/profile.d/locale.sh && stat_done || stat_fail - if [[ ${LOCALE,,} =~ utf ]]; then stat_busy "Setting Consoles to UTF-8 mode" # UTF-8 consoles are default since 2.6.24 kernel -- cgit v1.2.3 From a5967ed214a194b54647342f38ae78d695d497a1 Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Thu, 18 Aug 2011 23:56:08 +0200 Subject: functions: fix typo in warning message Fixes #25623. Reported-by: Segej Puykin Signed-off-by: Tom Gundersen --- functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions b/functions index f42c21e..bd05fa8 100644 --- a/functions +++ b/functions @@ -7,7 +7,7 @@ export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" if [[ $1 == "start" ]]; then if [[ $STARTING ]]; then - echo "A daemon is starting another daemon, this is unlikely to work as intended.\n" + echo "A daemon is starting another daemon, this is unlikely to work as intended." else export STARTING=1 fi -- cgit v1.2.3 From 7f840b99aa649eb899aa11f5e91e1e81f4f3672a Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Fri, 19 Aug 2011 12:17:25 +0200 Subject: locale.sh: added missing file to git Reported-by: Dave Reisner Signed-off-by: Tom Gundersen --- locale.sh | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 locale.sh diff --git a/locale.sh b/locale.sh new file mode 100644 index 0000000..611a797 --- /dev/null +++ b/locale.sh @@ -0,0 +1,3 @@ +. /etc/rc.conf + +export LANG=${LOCALE:=en_US} -- cgit v1.2.3 From 3ee7b326ad6d60b0d713cfd5c958c18e111b9e28 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Fri, 19 Aug 2011 13:17:41 -0400 Subject: network: error out on missing or unknown interface This was caused by commit fc9ce46483fc4d -- if the user has no interface defined but also has no legacy variables defined, our legacy check fails, and we try to bring up the network using an empty declaration. Add in an additional safeguard of checking sysfs to see that the interface really does exist. Fixes FS#25671 Signed-off-by: Dave Reisner --- network | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/network b/network index 4fafb97..b94d170 100755 --- a/network +++ b/network @@ -23,7 +23,21 @@ deprecated() { printf " connection, or use a utility such as netcfg.\n" } +have_interface() { + if [[ -z $1 ]]; then + printf "\n${C_FAIL}Error:${C_CLEAR} \`interface' is undefined in /etc/rc.conf\n" + return 1 + fi + + if [[ ! -d /sys/class/net/$1 ]]; then + printf "\n${C_FAIL}Error:${C_CLEAR} unknown interface in /etc/rc.conf: \`%s'\n" "$1" + return 1 + fi +} + network_up() { + have_interface "$interface" || return 1 + ip link set dev $interface up || return 1 if [[ $address ]]; then @@ -35,6 +49,8 @@ network_up() { } network_down() { + have_interface "$interface" || return 1 + if [[ -f /var/run/dhcpcd-$interface.pid ]]; then dhcpcd -k $interface || return 1 else -- cgit v1.2.3 From a1e44e2633596e7f12364ec3e33b4012332046bb Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Fri, 19 Aug 2011 13:29:16 -0400 Subject: rc.d: clarify error when [[ -x /etc/rc.d/$i ]] fails A script marked a-x will be reported as missing, when in fact it's only non-executable. Signed-off-by: Dave Reisner --- rc.d | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rc.d b/rc.d index a7b214e..5cb03f8 100755 --- a/rc.d +++ b/rc.d @@ -69,7 +69,8 @@ case $1 in if [[ -x "/etc/rc.d/$i" ]]; then env -i "${ENV[@]}" "/etc/rc.d/$i" "$action" else - printf "${C_OTHER}:: ${C_FAIL}Error: ${C_DONE}Daemon script $i does not exist.${C_CLEAR}\n" + printf "${C_OTHER}:: ${C_FAIL}Error: ${C_DONE}Daemon script \`%s' does not exist or is not executable.${C_CLEAR}\n" \ + "$i" fi (( ret += !! $? )) # clamp exit value to 0/1 done -- cgit v1.2.3 From d4723155ff86d49d1e98e05d04d20fd058340704 Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Sat, 20 Aug 2011 11:23:15 +0200 Subject: boot.log: clean ANSI codes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Suggested-by: Karol B?a?ewicz Suggested-by: Eric Bélanger Signed-off-by: Tom Gundersen --- functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions b/functions index bd05fa8..7beffb3 100644 --- a/functions +++ b/functions @@ -435,7 +435,7 @@ bootlogd_stop() { kill $(< /run/bootlogd.pid) rm -f /run/bootlogd.pid sed -i -r -e 's/\^\[\[[0-9]?;?[0-9]?[0-9]?;?[0-9]?[0-9]?[ms]//g' \ - -e 's/\^\[(\[151|%)G//g' /var/log/boot + -e 's/\^\[(\[1[0-9]1|%)G//g' /var/log/boot } ############################### -- cgit v1.2.3 From abd2fa8211a58761782c0b396f8e9c9d8a516abc Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Sat, 20 Aug 2011 13:43:51 +0200 Subject: Clean up more ANSI codes from /var/log/boot (close FS#25682) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Eric Bélanger Signed-off-by: Tom Gundersen --- functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions b/functions index 7beffb3..f68c088 100644 --- a/functions +++ b/functions @@ -435,7 +435,7 @@ bootlogd_stop() { kill $(< /run/bootlogd.pid) rm -f /run/bootlogd.pid sed -i -r -e 's/\^\[\[[0-9]?;?[0-9]?[0-9]?;?[0-9]?[0-9]?[ms]//g' \ - -e 's/\^\[(\[1[0-9]1|%)G//g' /var/log/boot + -e 's/\^\[(\[1[0-9]1|%)G//g' -e 's/\^\[\[0;1//g' /var/log/boot } ############################### -- cgit v1.2.3 From 8271087636e09ff40c10a8911250fd37af467bc0 Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Tue, 23 Aug 2011 19:45:16 +0200 Subject: sutdown: support both poweroff and reboot Tell the /run/initramfs/shutdown what action to preform. Still no kexec support though. Signed-off-by: Tom Gundersen --- rc.shutdown | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/rc.shutdown b/rc.shutdown index d11aeee..22f6bcc 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -79,6 +79,14 @@ fi status "Deactivating LVM2 groups" vgchange --sysinit -a n &>/dev/null if [[ -x /run/initramfs/shutdown ]]; then + + # decide what we want to do + if [[ $RUNLEVEL = 0 ]]; then + action="poweroff" + else + action="reboot" + fi + # make /run/initrafs a mount mount --bind /run/initramfs /run/initramfs @@ -102,8 +110,10 @@ if [[ -x /run/initramfs/shutdown ]]; then /oldroot/sbin/init u # run /shutdown in the new root - exec chroot . /shutdown /dev/console 2>&1 + exec chroot . /shutdown $action /dev/console 2>&1 + else + status "Remounting Root Filesystem Read-only" \ mount -n -o remount,ro / @@ -120,6 +130,7 @@ else [[ -x $(type -P kexec) ]] && kexec -e &>/dev/null reboot -d -f -i fi + fi # End of file -- cgit v1.2.3 From 7cccf54fcb9fab459590b8b6fd5c51f2088e3b2e Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Wed, 24 Aug 2011 20:45:15 +0200 Subject: shutdown: rely on init being installed by the initrd init is now included in mkinitcpio's busybox, so we don't need to copy it. This might break compat with dracut, but it can be worked around very simply in case anyone wants to use dracut with Arch, so we don't care. Signed-off-by: Tom Gundersen --- rc.shutdown | 1 - 1 file changed, 1 deletion(-) diff --git a/rc.shutdown b/rc.shutdown index 22f6bcc..db8f50b 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -106,7 +106,6 @@ if [[ -x /run/initramfs/shutdown ]]; then pivot_root . oldroot #reexec init - cp /oldroot/sbin/init /sbin /oldroot/sbin/init u # run /shutdown in the new root -- cgit v1.2.3