Re: xfs initscript enhancements, take 5

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 9 Oct 2003, Mike A. Harris wrote:

>>What version does this patch apply to, and/or where can I download
>>the full script?
>
>It applies to the latest rawhide xfs initscript.

Assuming XFree86-4.3.0-37.src.rpm (which is huuuge).

OK; this is a revision of the patched file. The claimed improvements
are:

- Add double-quotes to all variables, for safety against evil vars e.g.
";rm -rf ..;"
- Reduction/readability. This isn't to turn the script into a write-only
Perl-style monstrosity, but I find smaller scripts easy to brain-parse.
- Layout. Might want to use diff -b to compare.
- Eliminate duplicates from chkfontpath
- Assumed that umask works correctly, and remove chmod lines

The patched script passes a basic "bash -n" check, but I haven't fully
built the packages to test. Hopefully any errors will be minor and
obvious to fix.

>If anyone is interested in debugging and/or fixing fontconfig in Red
>Hat Linux 8.0, that would be nice, however I'll likely still need the
>initscript hack anyway.

I've added a HOME, which prevents the SEGV.

I couldn't see any good reason for the "umask 133", so changed it to
022.

Is there a reason for using the -cnewer test rather than -mnewer? Is it
important to rebuild after changes to file metadata?


Cheers,
Phil
#!/bin/bash
#
# xfs:		Starts the X Font Server
#
# Version:	@(#) /etc/init.d/xfs 2.0
#
# chkconfig: 2345 90 10
# description: Starts and stops the X Font Server at boot time and shutdown. \
#	       It also takes care of (re-)generating font lists.
#
# processname: xfs
# config: /etc/X11/fs/config
# hide: true

# Source function library.
export LANG=C
. /etc/init.d/functions

umask 022

prog=xfs

# Make sure that xfs has "/" as the CWD
cd /

buildfontlist() {
   pushd . &> /dev/null
   for d in $(/usr/sbin/chkfontpath --list | cut -f 2 -d : | sort | uniq); do
      if [ -d "$d" ]; then
	 cd "$d"
	 # Check if we need to rerun mkfontdir
	 REGEN_FONTS_DIR=no
	 if ! [ -e fonts.dir ]; then
	    REGEN_FONTS_DIR=yes
	 elif [ -n "$(find . -type f -cnewer fonts.dir -not -name 'fonts.cache*')" ]; then
	    REGEN_FONTS_DIR=yes
	 fi
	 if [ "$REGEN_FONTS_DIR" = yes ]; then
	    rm -f fonts.dir
	    if ls | grep -iqs '\.tt[cf]$'; then
	       # TrueType fonts found, generate fonts.scale and fonts.dir
	       ttmkfdir
	       mkfontdir . &>/dev/null
	    fi
	    if ls | grep -iqs '\.ot[cf]$'; then
	       # Opentype fonts found, generate fonts.scale and fonts.dir
	       mkfontscale .
	       mkfontdir . &>/dev/null
	    fi
	    if ls |grep -Eiqsv '(^fonts\.(scale|alias|cache.*)$|.+(\.[ot]t[cf]|dir)$)' ; then
	       # This directory contains non-TrueType/non-Opentype fonts
	       mkfontdir . &>/dev/null
            fi
	 fi
      fi
   done
   # Recreating fonts.dir files above may result in stale fonts.cache-1
   # files since the directory mtimes change, so we run fc-cache to
   # update any necessary fonts.cache files.
   FC_CACHE=/usr/bin/fc-cache
   if [ "$REGEN_FONTS_DIR" = "yes" -a -x "$FC_CACHE" ]; then
      # fc-cache 1.0.2 as included in Red Hat Linux 8.0 will SEGV when executed
      # without HOME set, so provide it
      env HOME=/ "$FC_CACHE"
   fi
   popd &> /dev/null
}

start() {
	echo -n $"Starting $prog: "
	[ -x /usr/sbin/chkfontpath ] && buildfontlist
	rm -fr /tmp/.font-unix
	daemon xfs -droppriv -daemon
	ret="$?"
	[ "$ret" -eq 0 ] && touch /var/lock/subsys/xfs
	ret="$?"
	echo
	return "$ret"
}

stop() {
	echo -n $"Shutting down $prog: "
	killproc xfs
	ret="$?"
	[ "$ret" -eq 0 ] && rm -f /var/lock/subsys/xfs
	echo
	return "$ret"
}

rhstatus() {
	status xfs
}

reload() {
  if [ -f /var/lock/subsys/xfs ]; then
	echo -n $"Reloading $prog: "
	[ -x /usr/sbin/chkfontpath ] && buildfontlist
	killproc xfs -USR1
	ret="$?"
	echo
	return "$ret"
  else
	stop
	start
  fi
}

restart() {
	echo $"Restarting $prog:"
	stop
	start
}

case "$1" in
  start)
	start ;;
  stop)
	stop ;;
  restart)
	restart ;;
  reload)
	reload ;;
  condrestart)
	[ -f /var/lock/subsys/xfs ] && reload || : ;;
  status)
	rhstatus ;;
  *)
	echo $"Usage: $prog {start|stop|status|restart|reload|condrestart}"
	exit 1
esac

exit "$?"

[Red Hat General]     [Red Hat Watch]     [Red Hat Development]     [Kernel Development]     [Yosemite Camping]

  Powered by Linux