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

Re: nice xserver



On Mon, Feb 23, 2004 at 07:35:11PM -0800, Nano Nano wrote:
> Last summer there was a priority=low debconf question to nice -10 the X 
> server.  It appears to be gone.
> 
> I ask because in "top" XFree86 seems to be one of the top programs.
> 
> Where did it go and do I want it?

Still there as far as I know.  Attaching evidence thereof.

-- 
G. Branden Robinson                |     You are not angry with people when
Debian GNU/Linux                   |     you laugh at them.  Humor teaches
branden@debian.org                 |     them tolerance.
http://people.debian.org/~branden/ |     -- W. Somerset Maugham
#!/bin/sh
# Debian xserver-common package configuration script
# Copyright 2000--2003 Branden Robinson.
# Licensed under the GNU General Public License, version 2.  See the file
# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.

# $Id: xserver-common.config.in 1044 2004-02-16 17:40:33Z branden $

set -e

# source debconf library
. /usr/share/debconf/confmodule

THIS_PACKAGE=xserver-common
THIS_SCRIPT=config

#INCLUDE_SHELL_LIB#

CONFIG_DIR=/etc/X11
XWRAPPER_CONFIG="$CONFIG_DIR/Xwrapper.config"
OLD_CONFIG_FILE="$CONFIG_DIR/Xserver"

allowed_users_english_to_actual () {
  case "$1" in
    "Root Only")
      echo "rootonly"
      ;;
    "Console Users Only")
      echo "console"
      ;;
    "Anybody")
      echo "anybody"
      ;;
    *)
      # garbage input; return default
      observe "allowed_users_english_to_actual(): unrecognized input \"$1\";" \
              "using default"
      echo "console"
      ;;
  esac
}

allowed_users_actual_to_english () {
  case "$1" in
    "rootonly")
      echo "Root Only"
      ;;
    "console")
      echo "Console Users Only"
      ;;
    "anybody")
      echo "Anybody"
      ;;
    *)
      # garbage input; return default
      observe "allowed_users_actual_to_english(): unrecognized input \"$1\";" \
              "using default"
      echo "Console Users Only"
      ;;
  esac
}

validate_nice_value () {
  local retval

  retval=1
  # first, try to subtract number from itself to validate numeric input
  # (expr is noisy, always throw away its output)
  set +e
  expr "$1" - "$1" > /dev/null 2>&1
  if [ $? -ne 2 ]; then
    # now check for valid range
    if expr "$1" ">=" "-20" > /dev/null 2>&1 &&
       expr "$1" "<=" "19" > /dev/null 2>&1; then
       retval=0
    fi
  fi
  set -e
  return $retval
}

# set the default nice value based on what Linux kernel version is being used;
# the new process scheduler in 2.5, to be released in 2.6, makes a default of
# -10 a bad idea; with that scheduler, the X server should run with priority 0
NICE_DEFAULT=-10
if [ "$(uname -s)" = "Linux" ]; then
  LINUX_KERNEL_FLAVOR=$(uname -r)
  LINUX_KERNEL_VERSION=${LINUX_KERNEL_FLAVOR%%-*}
  # it kinda sucks that I have to use dpkg for this
  if dpkg --compare-versions "$LINUX_KERNEL_VERSION" gt "2.5"; then
    observe "Linux kernel > 2.5 detected; using 0 as default nice value"
    NICE_DEFAULT=0
  fi
fi

# debconf is not a registry; use the current contents of the default display
# manager to pre-answer the question if possible
CURRENT_ALLOWED_USERS=
CURRENT_NICE_VALUE=

# scan the X wrapper config file for existing settings, if it exists
if [ -e "$XWRAPPER_CONFIG" ]; then
  if MATCHES=$(grep "^allowed_users=.\+" "$XWRAPPER_CONFIG"); then
    CURRENT_ALLOWED_USERS=$(echo "${MATCHES##*=}" | head -n 1)
  fi
  if MATCHES=$(grep "^nice_value=.\+" "$XWRAPPER_CONFIG"); then
    CURRENT_NICE_VALUE=$(echo "${MATCHES##*=}" | head -n 1)
  fi
else
  # if upgrading from xserver-common prior to 4.0.1-6, scan old wrapper config
  # file for a default setting of allowed users (nice value support wasn't
  # implemented back then)
  if dpkg --compare-versions "$2" lt "4.1.0-6"; then
    if [ -e "$OLD_CONFIG_FILE" ]; then
      CURRENT_ALLOWED_USERS=$(sed -n '2p' < "$OLD_CONFIG_FILE" |
                              tr '[[:upper:]]' '[[:lower:]]')
    fi
  fi
fi

if [ -n "$CURRENT_ALLOWED_USERS" ]; then
  observe "setting xserver-common/xwrapper/allowed_users from configuration" \
          "file"
  safe_debconf db_set xserver-common/xwrapper/allowed_users \
                      $(allowed_users_actual_to_english \
                      "$CURRENT_ALLOWED_USERS")
fi

if [ -n "$CURRENT_NICE_VALUE" ]; then
  observe "setting xserver-common/xwrapper/nice_value from configuration file"
  if validate_nice_value "$CURRENT_NICE_VALUE"; then
    safe_debconf db_set xserver-common/xwrapper/nice_value \
                        "$CURRENT_NICE_VALUE"
  fi
fi

safe_debconf db_input low xserver-common/xwrapper/allowed_users
safe_debconf db_go

RET=
if db_get xserver-common/xwrapper/allowed_users; then
  if [ -n "$RET" ]; then
    safe_debconf db_set xserver-common/xwrapper/actual_allowed_users \
                        $(allowed_users_english_to_actual "$RET")
  fi
fi

# next question requires input validation; assume safe valid value already
# present (possibly the template default)
SAFE=
if db_get xserver-common/xwrapper/nice_value; then
  SAFE="$RET"
fi

# make sure it's really safe; if not, use the default
if ! validate_nice_value "$RET"; then
  SAFE="$NICE_DEFAULT"
  safe_debconf db_set xserver-common/xwrapper/nice_value "$SAFE"
fi

set +e
while :; do
  safe_debconf db_input low xserver-common/xwrapper/nice_value
  # is the question going to be asked?
  if [ $? -eq 30 ]; then
    break # no; bail out of validation loop
  fi
  safe_debconf db_go
  RET=
  if db_get xserver-common/xwrapper/nice_value; then
    # string, needs input validation
    if validate_nice_value "$RET"; then
      # valid input from user
      break
    else
      # the input was invalid; restore the known good value in case we are
      # interrupted before the user provides a valid one
      safe_debconf db_set xserver-common/xwrapper/nice_value "$SAFE"
      safe_debconf db_fset xserver-common/xwrapper/nice_value seen false
      # now display the error message
      safe_debconf db_fset xserver-common/xwrapper/nice_value/error seen false
      safe_debconf db_input critical xserver-common/xwrapper/nice_value/error
      safe_debconf db_go
    fi
  fi
done
set -e

exit 0

# vim:set ai et sts=2 sw=2 tw=0:
Template: xserver-common/xwrapper/allowed_users
Type: select
_Choices: Root Only, Console Users Only, Anybody
Default: Console Users Only
_Description: Select what type of user has permission to start the X server.
 Because the X server runs with superuser privileges, it may be unwise to
 permit any user to start it, for security reasons.  On the other hand, it is
 even more unwise to run general-purpose X client programs as root, which is
 what may happen if only root is permitted to start the X server.  A good
 compromise is to permit the X server to be started only by users logged in to
 one of the virtual consoles.

Template: xserver-common/xwrapper/actual_allowed_users
Type: string
Description: internal use only
 This template is never shown to the user and does not require translation.

Template: xserver-common/xwrapper/nice_value
Type: string
_Description: Enter the desired nice value for the X server to use.
 When using operating system kernels with a particular scheduling strategy,
 it has been widely noted that the X server's performance improves when it
 is run at a higher process priority than the default; a process's priority
 is known as its "nice" value.  They range from -20 (extremely high
 priority, or "not nice" to other processes) to 19 (extremely low
 priority).  The default nice value for ordinary processes is 0.  -10 is a
 good default for a single-user workstation; 0 is a good default for a
 machine that has duties other than interacting with the console user (such
 as a web server).
 .
 The above is not true of Linux kernel version 2.6 (nor of the 2.5 series
 after the "O(1) scheduler" was included); on such systems, the nice value
 of the X server should be set to 0.
 .
 Values outside the range of -10 to 0 are not recommended; too negative,
 and the X server will interfere with important system tasks.  Too
 positive, and the X server will be sluggish and unresponsive.

Template: xserver-common/xwrapper/nice_value/error
Type: note
_Description: Please enter an integer between -20 and 19.

Attachment: signature.asc
Description: Digital signature


Reply to: