备忘 startx执行过程
2011-5-1的记录。由于跨墙工具失效,当时没传上来,后来就忘了。今日补上。
重温关于x-window中x、wm的关系
X 是协议
xinit 启动图形界面但不启动wm ,也就是说只启动了x server(也叫显示管理器)而没有启动x client(比如wm) 。
twm、gnome-session 和 startkde 都属于wm(窗口管理器) 。
kde (KING DESKTOP ENVIRMENT),gnome(GNU Network Object Model Envirment)不只是wm,还包含了配套的应用软件和桌面环境比如任务栏/开始菜单/桌面图标等等,因此是图形界面操作环境。
gnome启动过程分析:
1) /usr/bin/startx 确定 x server 和 x client 的配置文件路径和程序
默认为:
userclientrc=$HOME/.xinitrc # 用户指定的 x client 配置脚本,优先级高
sysclientrc=/etc/X11/xinit/xinitrc # 系统的 x client 配置脚本
userserverrc=$HOME/.xserverrc # 用户指定的 x server 配置脚本,优先级高
sysserverrc=/etc/X11/xinit/xserverrc # 默认的 x server 配置脚本
defaultclient=/usr/bin/xterm # 系统默认的 x client 程序
defaultserver=/usr/bin/X # 系统默认的 x server 程序
最后以确定的 x server/client 程序/选项为参数调用xinit
2) /usr/bin/xinit 根据传过来的 x server/client 或选项脚本启动x server 和 x client
3) 在 /etc/X11/xinit/xinitrc(只简单执行 /etc/X11/Xsession) 中启动 x client 也就是 gnome-session
/etc/X11/Xsession 中主要是依次执行 SYSSESSIONDIR 中的启动脚本
默认:
SYSSESSIONDIR=/etc/X11/Xsession.d # 默认的 session 文件目录
USERXSESSION=$HOME/.xsession # 默认的用户session 文件目录
USERXSESSIONRC=$HOME/.xsessionrc # 默认的用户session配置文件
也就是说,/etc/X11/Xsession.d/ 下面的脚本将被顺序执行(运行 run-parts --list /etc/X11/Xsession.d/ 可以列出这些脚本)
kevin@localhost:/etc/X11$ run-parts --list /etc/X11/Xsession.d/
/etc/X11/Xsession.d//00_handle_guest_session
/etc/X11/Xsession.d//10fglrx
/etc/X11/Xsession.d//20x11-common_process-args
/etc/X11/Xsession.d//30x11-common_xresources
/etc/X11/Xsession.d//40x11-common_xsessionrc
/etc/X11/Xsession.d//50x11-common_determine-startup
/etc/X11/Xsession.d//52libcanberra-gtk-module_add-to-gtk-modules
/etc/X11/Xsession.d//55gnome-session_gnomerc
/etc/X11/Xsession.d//60x11-common_localhost
/etc/X11/Xsession.d//60xdg-user-dirs-update
/etc/X11/Xsession.d//60xdg_path-on-session
/etc/X11/Xsession.d//65compiz_profile-on-session
/etc/X11/Xsession.d//70gconfd_path-on-session
/etc/X11/Xsession.d//75dbus_dbus-launch
/etc/X11/Xsession.d//80appmenu
/etc/X11/Xsession.d//80im-switch
/etc/X11/Xsession.d//90consolekit
/etc/X11/Xsession.d//90x11-common_ssh-agent
/etc/X11/Xsession.d//99x11-common_start
kevin@localhost:/etc/X11$ cat /etc/X11/Xsession.d//50x11-common_determine-startup
# $Id: 50x11-common_determine-startup 305 2005-07-03 18:51:43Z dnusinow $
# This file is sourced by Xsession(5), not executed.
# If no X session startup program was passed to the Xsession script as an
# argument (e.g., by the display manager), or if that program was not
# executable, fall back to looking for a user's custom X session script, if
# allowed by the options file.
if [ -z "$STARTUP" ]; then
if has_option allow-user-xsession; then
for STARTUPFILE in "$USERXSESSION" "$ALTUSERXSESSION"; do
if [ -e "$STARTUPFILE" ]; then
if [ -x "$STARTUPFILE" ]; then
STARTUP="$STARTUPFILE"
else
shell=${SHELL:-sh}
STARTUP="$shell $STARTUPFILE"
fi
break
fi
done
fi
fi
# If there is still nothing to use for a startup program, try the system
# default session manager, window manager, and terminal emulator.
if [ -z "$STARTUP" ]; then
if [ -x /usr/bin/x-session-manager ]; then
STARTUP=x-session-manager
elif [ -x /usr/bin/x-window-manager ]; then
STARTUP=x-window-manager
elif [ -x /usr/bin/x-terminal-emulator ]; then
STARTUP=x-terminal-emulator
fi
fi
# If we still have not found a startup program, give up.
if [ -z "$STARTUP" ]; then
ERRMSG="unable to start X session ---"
if has_option allow-user-xsession; then
ERRMSG="$ERRMSG no \"$USERXSESSION\" file, no \"$ALTUSERXSESSION\" file,"
fi
errormsg "$ERRMSG no session managers, no window managers, and no terminal" \
"emulators found; aborting."
fi
# vim:set ai et sts=2 sw=2 tw=80:
kevin@localhost:/etc/X11$
在上面脚本/etc/X11/Xsession.d//50x11-common_determine-startup里 /usr/bin/x-session-manager /usr/bin/x-window-manager /usr/bin/x-terminal-emulator 依次被检查是否存在,第一个存在的将被确定为STARTUP:
kevin@localhost:/etc/X11$ ll /usr/bin/x-session-manager
lrwxrwxrwx 1 root root 35 2011-02-11 05:23 /usr/bin/x-session-manager -> /etc/alternatives/x-session-manager*
kevin@localhost:/etc/X11$ ll /etc/alternatives/x-session-manager
lrwxrwxrwx 1 root root 22 2011-02-11 05:23 /etc/alternatives/x-session-manager -> /usr/bin/gnome-session*
kevin@localhost:/etc/X11$
kevin@localhost:/etc/X11$ cat /etc/X11/Xsession.d//99x11-common_start
# $Id: 99x11-common_start 305 2005-07-03 18:51:43Z dnusinow $
# This file is sourced by Xsession(5), not executed.
exec $STARTUP
# vim:set ai et sts=2 sw=2 tw=80:
kevin@localhost:/etc/X11$
可见脚本/etc/X11/Xsession.d//99x11-common_start 中,STARTUP 也就是 gnome-session 最终被执行。
最简单的自定义x server/client:
在~/.xserverrc 里写入/usr/bin/X11/X :1
在~/.xinitrc 里写入/usr/bin/X11/xeyes -display localhost:1
这就是最简单的X server + X client了,只不过把屏幕编号从默认的0改为了1 。