I was reading through the init scripts "functions" file and noticed some very minor speedups, a bug fix, and some relatively obscure security holes - possibly they should go back to the mantainers, but I think they may be Mandrake-specific.
Speeding up these scripts seems desireable... the security stuff is to do with unquoted shell variables - probably IFS should be set somewhere, too, for the case where someone does su from a malicious user's terminal, then runs an init script. hmm, evolution crashes if I attach a file, I'll paste it... and if that fails, back to mutt :-) Liam -- Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/ Ankh: irc.sorcery.net www.valinor.sorcery.net irc.gnome.org www.advogato.org Author, Open Source XML Database Toolkit, Wiley August 2000 Co-author: The XML Specification Guide, Wiley 1999; Mastering XML, Sybex 2001 *** pre-liam/functions 2002-05-21 23:46:34.000000000 -1000 --- functions 2002-05-22 00:27:14.000000000 -1000 *************** *** 11,53 **** # # i18n originally by: Arnaldo Carvalho de Melo <[EMAIL PROTECTED]>, # Wanderlei Antonio Cavassin TEXTDOMAIN=initscripts TEXTDOMAINDIR=/etc/locale LOCPATH=/etc/locale - export TEXTDOMAINDIR LOCPATH # Make sure umask is sane umask 022 # First set up a default search path. ! export PATH="/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin" # Get a sane screen width [ -z "${COLUMNS:-}" ] && COLUMNS=80 ! if [ -z "$GP_LANG" -a -z "$LANGUAGE" -a -f /etc/sysconfig/i18n -a -z "$NOLOCALE" ]; then . /etc/sysconfig/i18n ! [ -n "$LANGUAGE" ] && GP_LANG=$LANGUAGE || GP_LANG=$LANG ! if [ "${LANG:-}" = "ja_JP.eucJP" -a "`/sbin/consoletype`" != "pty" ]; then ! unset LANG else export LANG fi - fi - if [ -f /etc/sysconfig/i18n -a -z "${NOLOCALE:-}" ] ; then . /etc/sysconfig/i18n ! if [ "${LANG:-}" = "ja_JP.eucJP" -a "`/sbin/consoletype`" != "pty" ]; then ! unset LANG ! elif [ "${LANG:-}" = "ko_KR.eucKR" -a "`/sbin/consoletype`" != "pty" ]; then ! unset LANG ! elif [ "${LANG:-}" = "zh_CN.GB2312" -a "`/sbin/consoletype`" != "pty" ]; then ! unset LANG ! elif [ "${LANG:-}" = "zh_TW.Big5" -a "`/sbin/consoletype`" != "pty" ]; then unset LANG - else - export LANG fi fi # Currently Aurora can only display latin1 text, as it uses an 8bit --- 11,57 ---- # # i18n originally by: Arnaldo Carvalho de Melo <[EMAIL PROTECTED]>, # Wanderlei Antonio Cavassin + TEXTDOMAIN=initscripts TEXTDOMAINDIR=/etc/locale LOCPATH=/etc/locale # Make sure umask is sane umask 022 # First set up a default search path. ! PATH="/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin" ! ! export TEXTDOMAINDIR LOCPATH PATH ! # why is TEXTFOMAIN not exported? - Liam ! ! TEXTDOMAIN=initscripts # Get a sane screen width [ -z "${COLUMNS:-}" ] && COLUMNS=80 ! if [ -z "$NOLOCALE" -a -f /etc/sysconfig/i18n ] ; then ! if [ -z "$GP_LANG" -a -z "$LANGUAGE" ]; then . /etc/sysconfig/i18n ! if [ -n "$LANGUAGE" ] ; then ! GP_LANG="$LANGUAGE" else + GP_LANG="$LANG" + fi + export LANG fi . /etc/sysconfig/i18n ! ! # only use 16-bit locales on the physical console ! case "${LANG:-}" in ! "ja_JP.eucJP"|"ko_KR.eucKR"|"zh_CN.GB2312"|"zh_TW.Big5") ! if [ "`/sbin/consoletype`" != "pty" ]; then unset LANG fi + ;; + esac fi # Currently Aurora can only display latin1 text, as it uses an 8bit *************** *** 60,66 **** esac fi - # Read in our configuration if [ -z "${BOOTUP:-}" ]; then if [ -f /etc/sysconfig/init ]; then --- 64,69 ---- *************** *** 153,165 **** # Check if $pid (could be plural) are running checkpid() { while [ "$1" ]; do [ -d /proc/$1 ] && return 0 shift done return 1 } - # A function to start a program. daemon() { # Test syntax. --- 156,168 ---- # Check if $pid (could be plural) are running checkpid() { while [ "$1" ]; do + # relies on /proc - would it be better to use kill -0? -- Liam [ -d /proc/$1 ] && return 0 shift done return 1 } # A function to start a program. daemon() { # Test syntax. *************** *** 201,206 **** --- 204,211 ---- [ -z $gotbase ] && base=${1##*/} # See if it's already running. Look *only* at the pid file. + # why? what if it's running but the pidfile was removed? this + # seems fragile - Liam pid=`pidfileofproc $base` [ -n "${pid:-}" ] && return *************** *** 309,315 **** # First try "/var/run/*.pid" files if [ -f /var/run/${base}.pid ] ; then ! read pid < /var/run/${base}.pid for p in $line ; do [ -z "${p//[0-9]/}" -a -d /proc/$p ] && pid="$pid $p" done --- 314,321 ---- # First try "/var/run/*.pid" files if [ -f /var/run/${base}.pid ] ; then ! local line p pid= ! read line < /var/run/${base}.pid for p in $line ; do [ -z "${p//[0-9]/}" -a -d /proc/$p ] && pid="$pid $p" done *************** *** 344,351 **** fi # Next try "pidof" ! pidof -o $$ -o $PPID -o %PPID -x $1 || \ ! pidof -o $$ -o $PPID -o %PPID -x ${base} } status() { --- 350,357 ---- fi # Next try "pidof" ! pidof -o $$ -o $PPID -o %PPID -x "$1" || \ ! pidof -o $$ -o $PPID -o %PPID -x "${base}" } status() { *************** *** 359,368 **** fi # First try "pidof" ! pid=`pidof -o $$ -o $PPID -o %PPID -x $1 || \ ! pidof -o $$ -o $PPID -o %PPID -x ${base}` ! if [ "$pid" != "" ] ; then ! gprintf "%s (pid %s) is running...\n" ${base} $pid return 0 fi --- 365,374 ---- fi # First try "pidof" ! pid=`pidof -o $$ -o $PPID -o %PPID -x "$1" || \ ! pidof -o $$ -o $PPID -o %PPID -x "${base}"` ! if [ -n "$pid" ] ; then ! gprintf "%s (pid %s) is running...\n" "${base}" "$pid" return 0 fi
