Chyby ve skriptu rc?
Martin Horak
pop3MH1 na sce.cz
Středa Září 23 08:44:59 CEST 1998
Preji hezky den.
Zacinam se ucit programovat davky bashe a pri hledani inspirace ve startovacich
davkach rc.* jsem narazil na nasledujici podle mne nesrovnalosti (me komentare
oznaceny =>). Vse se tyka RedHatu 4.2.
#!/bin/bash
# rc This file is responsible for starting/stopping
# ...
#
# Source function library.
. /etc/rc.d/init.d/functions
# Now find out what the current and what the previous runlevel are. argv1="$1" set
`/sbin/runlevel`
runlevel=$2
previous=$1
export runlevel previous
# Get first argument. Set new runlevel to this argument.
[ "$1" != "" ] && runlevel="$argv1"
=> ^^
=> Prvni chyba - podle mne by zde melo byt $argv1. Funkce je (snad) takovato:
Pri spusteni s parametrem se uvazuje runlevel dana parametrem, jinak aktualni
runlevel. $1 bude pri spravne funkci /sbin/runlevel vzdy nastavena, ale
parametr nemusi byt predan.
# Is there an rc directory for this new runlevel?
if [ -d /etc/rc.d/rc$runlevel.d ]; then
# First, run the KILL scripts.
for i in /etc/rc.d/rc$runlevel.d/K*; do
# Check if the script is there.
[ ! -f $i ] && continue
# Check if the subsystem is already up.
subsys=${i#/etc/rc.d/rc$runlevel.d/K??}
[ ! -f /var/lock/subsys/$subsys ] && \
[ ! -f /var/lock/subsys/${subsys}.init ] && continue
=> Pokud bude $subsys, nebo ${subsys}.init, stopni daemona. To je v poradku.
# Bring the subsystem down.
$i stop
done
# Now run the START scripts.
for i in /etc/rc.d/rc$runlevel.d/S*; do
# Check if the script is there.
[ ! -f $i ] && continue
# Check if the subsystem is already up.
subsys=${i#/etc/rc.d/rc$runlevel.d/S??}
[ -f /var/lock/subsys/$subsys ] && \
[ -f /var/lock/subsys/${subsys}.init ] && continue
=> Chyba 2: Pokud nebudou OBA ($subsys i ${subsys}.init) nastartuj demona, coz
by vlastne melo startovat demona vzdy, protoze ten vytvori pouze jeden ze
zamykacich souboru.
# Bring the subsystem up.
$i start
done
fi
=> Treti chybu jsem objevil u lpd, ktery mel /etc/rc.d/rc?.d/S??lpd.init.
potom se v rc testuje pritomnost /var/lock/subsys/lpd.init a
/var/lock/subsys/lpd.init.init ale ne /var/lock/subsys/lpd, ktery startovaci
skript lpd vytvari.
Pripada mi to jako docela zakladni chyby na to, aby se dostaly do distribuce
Linuxu. Je to mozne, nebo je chyba u mne?
--
Ing. Martin Horak
SCE a.s. Decin
pop3MH1 na sce.cz
Další informace o konferenci Linux