From 0d464a67b74c213deb8328d277df732565134b02 Mon Sep 17 00:00:00 2001 From: Bill Nottingham Date: Fri, 9 Mar 2012 11:31:48 -0500 Subject: If /dev/stderr also isn't readable, don't bother with consoletype. --- rc.d/init.d/functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'rc.d/init.d/functions') diff --git a/rc.d/init.d/functions b/rc.d/init.d/functions index 1437b252..7754ff21 100644 --- a/rc.d/init.d/functions +++ b/rc.d/init.d/functions @@ -54,7 +54,7 @@ systemctl_redirect () { [ -z "${COLUMNS:-}" ] && COLUMNS=80 if [ -z "${CONSOLETYPE:-}" ]; then - if [ -c "/dev/stderr" ]; then + if [ -c "/dev/stderr" -a -r "/dev/stderr" ]; then CONSOLETYPE="$(/sbin/consoletype < /dev/stderr 2>/dev/null)" else CONSOLETYPE="serial" -- cgit v1.2.1 From f4852e09cd32f33b0c496864171d8dc9e85bd0cf Mon Sep 17 00:00:00 2001 From: Bill Nottingham Date: Fri, 20 Apr 2012 15:01:24 -0400 Subject: Move default sysctl.conf to /usr/lib/sysctl.d, adjust things accordingly. (#760254) Also, update apply_sysctl to 1) use systemd-sysctl if it's there 2) imitate it if it's not. --- rc.d/init.d/functions | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'rc.d/init.d/functions') diff --git a/rc.d/init.d/functions b/rc.d/init.d/functions index 7754ff21..e9892b42 100644 --- a/rc.d/init.d/functions +++ b/rc.d/init.d/functions @@ -660,11 +660,26 @@ is_false() { # Apply sysctl settings, including files in /etc/sysctl.d apply_sysctl() { - sysctl -e -p /etc/sysctl.conf >/dev/null 2>&1 - for file in /etc/sysctl.d/* ; do - is_ignored_file "$file" && continue - test -f "$file" && sysctl -e -p "$file" >/dev/null 2>&1 - done + if [ -x /lib/systemd/systemd-sysctl ]; then + /lib/systemd/systemd-sysctl + else + for file in /usr/lib/sysctl.d/*.conf ; do + is_ignored_file "$file" && continue + [ -f /run/sysctl.d/${file##*/} ] && continue + [ -f /etc/sysctl.d/${file##*/} ] && continue + test -f "$file" && sysctl -e -p "$file" >/dev/null 2>&1 + done + for file in /run/sysctl.d/*.conf ; do + is_ignored_file "$file" && continue + [ -f /etc/sysctl.d/${file##*/} ] && continue + test -f "$file" && sysctl -e -p "$file" >/dev/null 2>&1 + done + for file in /etc/sysctl.d/*.conf ; do + is_ignored_file "$file" && continue + test -f "$file" && sysctl -e -p "$file" >/dev/null 2>&1 + done + sysctl -e -p /etc/sysctl.conf >/dev/null 2>&1 + fi } key_is_random() { -- cgit v1.2.1 From 345e4fc14c6e6a043bc3fe4eeb8c39a36957fbf8 Mon Sep 17 00:00:00 2001 From: Bill Nottingham Date: Mon, 6 Aug 2012 15:20:03 -0400 Subject: Drop fstab-decode and getkey; no longer used. Drop the umount loop from rc.d/init.d/functions. --- rc.d/init.d/functions | 65 --------------------------------------------------- 1 file changed, 65 deletions(-) (limited to 'rc.d/init.d/functions') diff --git a/rc.d/init.d/functions b/rc.d/init.d/functions index e9892b42..24447249 100644 --- a/rc.d/init.d/functions +++ b/rc.d/init.d/functions @@ -93,11 +93,6 @@ if [ -z "${BOOTUP:-}" ]; then fi fi -# Interpret escape sequences in an fstab entry -fstab_decode_str() { - fstab-decode echo "$1" -} - # Check if any of $pid (could be plural) are running checkpid() { local i @@ -124,66 +119,6 @@ __fgrep() { return 1 } -# __umount_loop awk_program fstab_file first_msg retry_msg retry_umount_args -# awk_program should process fstab_file and return a list of fstab-encoded -# paths; it doesn't have to handle comments in fstab_file. -__umount_loop() { - local remaining sig=-15 - local retry=3 count - - remaining=$(LC_ALL=C awk "/^#/ {next} $1" "$2" | sort -r) - while [ -n "$remaining" -a "$retry" -gt 0 ]; do - if [ "$retry" -eq 3 ]; then - action "$3" fstab-decode umount $remaining - else - action "$4" fstab-decode umount $5 $remaining - fi - count=4 - remaining=$(LC_ALL=C awk "/^#/ {next} $1" "$2" | sort -r) - while [ "$count" -gt 0 ]; do - [ -z "$remaining" ] && break - count=$(($count-1)) - usleep 500000 - remaining=$(LC_ALL=C awk "/^#/ {next} $1" "$2" | sort -r) - done - [ -z "$remaining" ] && break - fstab-decode /sbin/fuser -k -m $sig $remaining >/dev/null - sleep 3 - retry=$(($retry -1)) - sig=-9 - done -} - -# Similar to __umount loop above, specialized for loopback devices -__umount_loopback_loop() { - local remaining devremaining sig=-15 - local retry=3 - - remaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $2}' /proc/mounts) - devremaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $1}' /proc/mounts) - while [ -n "$remaining" -a "$retry" -gt 0 ]; do - if [ "$retry" -eq 3 ]; then - action $"Unmounting loopback filesystems: " \ - fstab-decode umount $remaining - else - action $"Unmounting loopback filesystems (retry):" \ - fstab-decode umount $remaining - fi - for dev in $devremaining ; do - losetup $dev > /dev/null 2>&1 && \ - action $"Detaching loopback device $dev: " \ - losetup -d $dev - done - remaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $2}' /proc/mounts) - devremaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $1}' /proc/mounts) - [ -z "$remaining" ] && break - fstab-decode /sbin/fuser -k -m $sig $remaining >/dev/null - sleep 3 - retry=$(($retry -1)) - sig=-9 - done -} - # __proc_pids {program} [pidfile] # Set $pid to pids from /var/run* for {program}. $pid should be declared # local in the caller. -- cgit v1.2.1 From 654187448e2b29ee2b5c8b757a37420e1ce0257b Mon Sep 17 00:00:00 2001 From: Bill Nottingham Date: Thu, 2 Aug 2012 15:11:22 -0400 Subject: Remove more now-unused functions from init.d/functions (crypto/dm) --- rc.d/init.d/functions | 180 -------------------------------------------------- 1 file changed, 180 deletions(-) (limited to 'rc.d/init.d/functions') diff --git a/rc.d/init.d/functions b/rc.d/init.d/functions index 24447249..3e8b5ae0 100644 --- a/rc.d/init.d/functions +++ b/rc.d/init.d/functions @@ -552,17 +552,6 @@ confirm() { done } -# resolve a device node to its major:minor numbers in decimal or hex -get_numeric_dev() { -( - fmt="%d:%d" - if [ "$1" = "hex" ]; then - fmt="%x:%x" - fi - ls -lH "$2" | awk '{ sub(/,/, "", $5); printf("'"$fmt"'", $5, $6); }' -) 2>/dev/null -} - # Check whether file $1 is a backup or rpm-generated file and should be ignored is_ignored_file() { case "$1" in @@ -617,175 +606,6 @@ apply_sysctl() { fi } -key_is_random() { - [ "$1" = "/dev/urandom" -o "$1" = "/dev/hw_random" \ - -o "$1" = "/dev/random" ] -} - -find_crypto_mount_point() { - local fs_spec fs_file fs_vfstype remaining_fields - local fs - while read fs_spec fs_file remaining_fields; do - if [ "$fs_spec" = "/dev/mapper/$1" ]; then - echo $fs_file - break; - fi - done < /etc/fstab -} - -# Because of a chicken/egg problem, init_crypto must be run twice. /var may be -# encrypted but /var/lib/random-seed is needed to initialize swap. -init_crypto() { - local have_random dst src key opt lsl owner params makeswap skip arg opt - local param value rc ret mke2fs mdir prompt mount_point - - ret=0 - have_random=$1 - while read dst src key opt; do - [ -z "$dst" -o "${dst#\#}" != "$dst" ] && continue - [ -b "/dev/mapper/$dst" ] && continue; - if [ "$have_random" = 0 ] && key_is_random "$key"; then - continue - fi - if [ -n "$key" -a "x$key" != "xnone" ]; then - if test -e "$key" ; then - owner=$(ls -l $key | (read a b owner rest; echo $owner)) - if ! key_is_random "$key"; then - lsl=$(ls -l "$key") - if [ "${lsl:4:6}" != "------" ]; then - echo $"INSECURE MODE FOR $key" - fi - fi - if [ "$owner" != root ]; then - echo $"INSECURE OWNER FOR $key" - fi - else - echo $"Key file for $dst not found, skipping" - ret=1 - continue - fi - else - key="" - fi - params="" - makeswap="" - mke2fs="" - skip="" - # Parse the src field for UUID= and convert to real device names - if [ "${src%%=*}" == "UUID" ]; then - src=$(/sbin/blkid -t "$src" -l -o device) - elif [ "${src/^\/dev\/disk\/by-uuid\/}" != "$src" ]; then - src=$(__readlink $src) - fi - # Is it a block device? - [ -b "$src" ] || continue - # Is it already a device mapper slave? (this is gross) - devesc=${src##/dev/} - devesc=${devesc//\//!} - for d in /sys/block/dm-*/slaves ; do - [ -e $d/$devesc ] && continue 2 - done - # Parse the options field, convert to cryptsetup parameters and - # contruct the command line - while [ -n "$opt" ]; do - arg=${opt%%,*} - opt=${opt##$arg} - opt=${opt##,} - param=${arg%%=*} - value=${arg##$param=} - - case "$param" in - cipher) - params="$params -c $value" - if [ -z "$value" ]; then - echo $"$dst: no value for cipher option, skipping" - skip="yes" - fi - ;; - size) - params="$params -s $value" - if [ -z "$value" ]; then - echo $"$dst: no value for size option, skipping" - skip="yes" - fi - ;; - hash) - params="$params -h $value" - if [ -z "$value" ]; then - echo $"$dst: no value for hash option, skipping" - skip="yes" - fi - ;; - noauto) - skip="yes" - ;; - verify) - params="$params -y" - ;; - swap) - makeswap=yes - ;; - tmp) - mke2fs=yes - esac - done - if [ "$skip" = "yes" ]; then - ret=1 - continue - fi - if [ -z "$makeswap" ] && cryptsetup isLuks "$src" 2>/dev/null ; then - if key_is_random "$key"; then - echo $"$dst: LUKS requires non-random key, skipping" - ret=1 - continue - fi - if [ -n "$params" ]; then - echo "$dst: options are invalid for LUKS partitions," \ - "ignoring them" - fi - if [ -n "$key" ]; then - /sbin/cryptsetup -d $key luksOpen "$src" "$dst" <&1 2>/dev/null && success || failure - rc=$? - else - mount_point="$(find_crypto_mount_point $dst)" - [ -n "$mount_point" ] || mount_point=${src##*/} - prompt=$(printf $"%s is password protected" "$mount_point") - plymouth ask-for-password --prompt "$prompt" --command="/sbin/cryptsetup luksOpen -T1 $src $dst" <&1 - rc=$? - fi - else - if [ -z "$key" ]; then - mount_point="$(find_crypto_mount_point $dst)" - [ -n "$mount_point" ] || mount_point=${src##*/} - prompt=$(printf $"%s is password protected" "$mount_point") - plymouth ask-for-password --prompt "$prompt" --command="/sbin/cryptsetup $params create $dst $src" <&1 - rc=$? - else - /sbin/cryptsetup $params ${key:+-d $key} create "$dst" "$src" <&1 2>/dev/null && success || failure - rc=$? - fi - fi - if [ $rc -ne 0 ]; then - ret=1 - continue - fi - if [ -b "/dev/mapper/$dst" ]; then - if [ "$makeswap" = "yes" ]; then - mkswap "/dev/mapper/$dst" 2>/dev/null >/dev/null - fi - if [ "$mke2fs" = "yes" ]; then - if mke2fs "/dev/mapper/$dst" 2>/dev/null >/dev/null \ - && mdir=$(mktemp -d /tmp/mountXXXXXX); then - mount "/dev/mapper/$dst" "$mdir" && chmod 1777 "$mdir" - umount "$mdir" - rmdir "$mdir" - fi - fi - fi - done < /etc/crypttab - return $ret -} - # A sed expression to filter out the files that is_ignored_file recognizes __sed_discard_ignored_files='/\(~\|\.bak\|\.orig\|\.rpmnew\|\.rpmorig\|\.rpmsave\)$/d' -- cgit v1.2.1 From 929b86328048d17f30f9be1ec2161b6486827e7f Mon Sep 17 00:00:00 2001 From: Bill Nottingham Date: Thu, 2 Aug 2012 15:13:40 -0400 Subject: Drop more unused functions, and drop old s-c-n profile support directories. The profile support itself was removed a while ago. --- rc.d/init.d/functions | 34 ---------------------------------- 1 file changed, 34 deletions(-) (limited to 'rc.d/init.d/functions') diff --git a/rc.d/init.d/functions b/rc.d/init.d/functions index 3e8b5ae0..19f389dd 100644 --- a/rc.d/init.d/functions +++ b/rc.d/init.d/functions @@ -103,22 +103,6 @@ checkpid() { return 1 } -__readlink() { - ls -bl "$@" 2>/dev/null| awk '{ print $NF }' -} - -__fgrep() { - s=$1 - f=$2 - while read line; do - if strstr "$line" "$s"; then - echo $line - return 0 - fi - done < $f - return 1 -} - # __proc_pids {program} [pidfile] # Set $pid to pids from /var/run* for {program}. $pid should be declared # local in the caller. @@ -534,24 +518,6 @@ strstr() { return 0 } -# Confirm whether we really want to run this service -confirm() { - [ -x /bin/plymouth ] && /bin/plymouth --hide-splash - while : ; do - echo -n $"Start service $1 (Y)es/(N)o/(C)ontinue? [Y] " - read answer - if strstr $"yY" "$answer" || [ "$answer" = "" ] ; then - return 0 - elif strstr $"cC" "$answer" ; then - rm -f /var/run/confirm - [ -x /bin/plymouth ] && /bin/plymouth --show-splash - return 2 - elif strstr $"nN" "$answer" ; then - return 1 - fi - done -} - # Check whether file $1 is a backup or rpm-generated file and should be ignored is_ignored_file() { case "$1" in -- cgit v1.2.1 From eb8425399e577b6d0a7521dd09dfafab975932d2 Mon Sep 17 00:00:00 2001 From: Lukas Nykryn Date: Fri, 3 Aug 2012 11:14:22 +0200 Subject: Killproc -d should parse same values as sleep --- rc.d/init.d/functions | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'rc.d/init.d/functions') diff --git a/rc.d/init.d/functions b/rc.d/init.d/functions index 19f389dd..8c4d2573 100644 --- a/rc.d/init.d/functions +++ b/rc.d/init.d/functions @@ -233,7 +233,7 @@ daemon() { killproc() { local RC killlevel= base pid pid_file= delay try - RC=0; delay=3 + RC=0; delay=3; try=0 # Test syntax. if [ "$#" -eq 0 ]; then echo $"Usage: killproc [-p pidfile] [ -d delay] {program} [-signal]" @@ -244,7 +244,11 @@ killproc() { shift 2 fi if [ "$1" = "-d" ]; then - delay=$2 + delay=$(echo $2 | awk -v RS=' ' -v IGNORECASE=1 '{if($1!~/^[0-9.]+[smhd]?$/) exit 1;d=$1~/s$|^[0-9.]*$/?1:$1~/m$/?60:$1~/h$/?60*60:$1~/d$/?24*60*60:-1;if(d==-1) exit 1;delay+=d*$1} END {printf("%d",delay+0.5)}') + if [ "$?" -eq 1 ]; then + echo $"Usage: killproc [-p pidfile] [ -d delay] {program} [-signal]" + return 1 + fi shift 2 fi -- cgit v1.2.1