Linux系统中Xwindow系统启动脚本分析

豆豆网   技术应用频道   2007年03月08日  【字号: 收藏本文

本文详细介绍Linux系统中Xwindow系统启动脚本分析

  安装了Linux后当然希望能进入XWindow,象在Windows一样方便地工作,于是大家都可能用过startx命令,也可能是直接在XWindow登录界面进入XWindow。

  这两种方式的XWindow启动过程有没有区别呢?如果你没有做过个性化设置可能体会不到,但如果你设置过中文输入法,不管是用SCIM还是fcitx,可能都有过设置输入法为随XWindow启动的经验。

  朋友们开始修改各种启动脚本,经常可能会修改到的方法有:

  1、修改/etc/X11/xinit/xinitrc

  2、修改/etc/X11/Xsession

  3、在/etc/X11/Xsession.d目录下增加一个自定义的脚本

  4、修改$HOME/.xsession

  5、修改$HOME/.xinitrc

  6、修改/etc/X11/xdm/Xsession

  ……

  总之,看起来是八仙过海各有各的神通了。这些方法有没有不同?为什么有时候明明设置好了,startx起来可以用了,但重启在XWindow管理界面登录后却不能用了?为什么有时从XWindow管理界面登录后可用,但startx后却用不了?

  下面我们一起来分析一下吧。

#!/bin/sh
#
# /etc/X11/Xsession
#
# global Xsession file -- used by display managers and xinit (startx)
# $Id: Xsession 2186 2005-02-11 07:11:05Z branden $
set -e
PROGNAME=Xsession
message () {
# pretty-print messages of arbitrary length; use xmessage if it
# is available and $DISPLAY is set
MESSAGE="$PROGNAME: $*"
echo "$MESSAGE" | fold -s -w ${COLUMNS:-80} >&2
if [ -n "$DISPLAY" ] && which xmessage > /dev/null 2>&1; then
echo "$MESSAGE" | fold -s -w ${COLUMNS:-80} | xmessage -center -file -
fi
}
message_nonl () {
# pretty-print messages of arbitrary length (no trailing newline); use
# xmessage if it is available and $DISPLAY is set
MESSAGE="$PROGNAME: $*"
echo -n "$MESSAGE" | fold -s -w ${COLUMNS:-80} >&2;
if [ -n "$DISPLAY" ] && which xmessage > /dev/null 2>&1; then
echo -n "$MESSAGE" | fold -s -w ${COLUMNS:-80} | xmessage -center -file -
fi
}
errormsg () {
# exit script with error
message "$*"
exit 1
}
internal_errormsg () {
# exit script with error; essentially a "THIS SHOULD NEVER HAPPEN" message
# One big call to message() for the sake of xmessage; if we had two then
# the user would have dismissed the error we want reported before seeing the
# request to report it.
errormsg "$*"
"Please report the installed version of the "xfree86-common""
"package and the complete text of this error message to"
"<debian-x@lists.debian.org>."
}
# initialize variables for use by all session scripts
OPTIONFILE=/etc/X11/Xsession.options
SYSRESOURCES=/etc/X11/Xresources
USRRESOURCES=$HOME/.Xresources
SYSSESSIONDIR=/etc/X11/Xsession.d
USERXSESSION=$HOME/.xsession
ALTUSERXSESSION=$HOME/.Xsession
ERRFILE=$HOME/.xsession-errors
# attempt to create an error file; abort if we cannot
if touch "$ERRFILE" 2> /dev/null && [ -w "$ERRFILE" ] &&
[ ! -L "$ERRFILE" ]; then
chmod 600 "$ERRFILE"
elif ERRFILE=$(tempfile 2> /dev/null); then
if ! ln -sf "$ERRFILE" "${TMPDIR:=/tmp}/xsession-$USER"; then
message "warning: unable to symlink "$TMPDIR/xsession-$USER" to"
""$ERRFILE"; look for session log/errors in"
""$TMPDIR/xsession-$USER"."
fi
else
errormsg "unable to create X session log/error file; aborting."
fi
exec >>"$ERRFILE" 2>&1
echo "$PROGNAME: X session started for $LOGNAME at $(date)"
# sanity check; is our session script directory present?
if [ ! -d "$SYSSESSIONDIR" ]; then
errormsg "no "$SYSSESSIONDIR" directory found; aborting."
fi
# Attempt to create a file of non-zero length in /tmp; a full filesystem can
# cause mysterious X session failures. We do not use touch, :, or test -w
# because they won't actually create a file with contents. We also let standard
# error from tempfile and echo go to the error file to aid the user in
# determining what went wrong.
WRITE_TEST=$(tempfile)
if ! echo "*" >>"$WRITE_TEST"; then
message "warning: unable to write to ${WRITE_TEST%/*}; X session may exit"
"with an error"
fi
rm -f "$WRITE_TEST"
# Use run-parts to source every file in the session directory; we source
# instead of executing so that the variables and functions defined above
# are available to the scripts, and so that they can pass variables to each
# other.
SESSIONFILES=$(run-parts --list $SYSSESSIONDIR)
if [ -n "$SESSIONFILES" ]; then
for SESSIONFILE in $SESSIONFILES; do
. $SESSIONFILE
done
fi
exit 0

  此文件的第五行“# global Xsession file -- used by display managers and xinit (startx)”已经说明/etc/X11/Xsession脚本是大家公用的,无论你是用XWindow管理器(比如kdm、gdm、xdm)进入还是通过命令行输入startx(即xinit方式)进入XWindow,都会调用此脚本程序。再看看这个脚本程序做了些什么吧。这一行“SYSSESSIONDIR=/etc/X11/Xsession.d”定义了一个变量指向了目录/etc/X11/Xsession.d,后面又出现一段代码:

责编:豆豆技术应用

正在加载评论...