Hello again, argh, I just realized that the previous patch would catch commented options as well, sorry for the blunder! This updated patch defines a new function "has_options" which encapsulates the option parsing, and thus makes the code easier to read. Thanks, Martin -- Martin Pitt | http://www.piware.de Ubuntu Developer (www.ubuntu.com) | Debian Developer (www.debian.org)
diff -Nru xorg-7.5+1ubuntu2/debian/changelog xorg-7.5+1ubuntu3/debian/changelog
--- xorg-7.5+1ubuntu2/debian/changelog 2010-01-26 00:38:13.000000000 +0100
+++ xorg-7.5+1ubuntu3/debian/changelog 2010-02-18 23:14:11.000000000 +0100
@@ -1,3 +1,18 @@
+xorg (1:7.5+1ubuntu3) lucid; urgency=low
+
+ * Improve startup speed of Xsession.d scripts by eliminating all unnecessary
+ external program calls:
+ - In 20x11-common_process-args, cat $OPTIONFILE once into a variable and
+ use POSIX variable substitution in all scripts instead of calling grep
+ for every single test.
+ - Use shell built in "type" instead of external "which" to test for
+ programs.
+ - 30x11-common_xresources: Swap the order of tests to keep the most
+ unlikely (like "~/.Xresources exists") outside, to avoid running the
+ other tests (like "xrdb exists") on systems which don't use Xresources.
+
+ -- Martin Pitt <martin.pitt@ubuntu.com> Thu, 18 Feb 2010 23:02:22 +0100
diff -Nru xorg-7.5+1ubuntu2/debian/changelog xorg-7.5+1ubuntu4/debian/changelog
--- xorg-7.5+1ubuntu2/debian/local/Xsession.d/20x11-common_process-args 2010-01-25 10:53:09.000000000 +0100
+++ xorg-7.5+1ubuntu4/debian/local/Xsession.d/20x11-common_process-args 2010-02-19 06:27:51.000000000 +0100
@@ -2,6 +2,18 @@
# This file is sourced by Xsession(5), not executed.
+# read OPTIONFILE
+OPTIONS=$(cat "$OPTIONFILE") || true
+
+has_option() {
+ if [ "${OPTIONS#*
+$1}" != "$OPTIONS" ]; then
+ return 0
+ else
+ return 1
+ fi
+}
+
# Determine how many arguments were provided.
case $# in
0)
@@ -12,7 +24,7 @@
case "$1" in
failsafe)
# Failsafe session was requested.
- if grep -qs ^allow-failsafe "$OPTIONFILE"; then
+ if has_option allow-failsafe; then
if [ -e /usr/bin/x-terminal-emulator ]; then
if [ -x /usr/bin/x-terminal-emulator ]; then
exec x-terminal-emulator -geometry +1+1
diff -Nru xorg-7.5+1ubuntu2/debian/local/Xsession.d/30x11-common_xresources xorg-7.5+1ubuntu4/debian/local/Xsession.d/30x11-common_xresources
--- xorg-7.5+1ubuntu2/debian/local/Xsession.d/30x11-common_xresources 2008-06-25 04:05:17.000000000 +0200
+++ xorg-7.5+1ubuntu4/debian/local/Xsession.d/30x11-common_xresources 2010-02-19 06:28:19.000000000 +0100
@@ -4,25 +4,23 @@
# If xrdb (from xbase-clients) is installed, merge system-wide X resources.
# Then merge the user's X resources, if the options file is so configured.
-if /usr/bin/which xrdb >/dev/null 2>&1; then
- if [ -d "$SYSRESOURCES" ]; then
- RESOURCEFILES=$(run-parts --list $SYSRESOURCES)
- if [ -n "$RESOURCEFILES" ]; then
- for RESOURCEFILE in $RESOURCEFILES; do
- xrdb -merge $RESOURCEFILE
- done
- fi
+if [ -d "$SYSRESOURCES" ] && type xrdb >/dev/null 2>&1; then
+ RESOURCEFILES=$(run-parts --list $SYSRESOURCES)
+ if [ -n "$RESOURCEFILES" ]; then
+ for RESOURCEFILE in $RESOURCEFILES; do
+ xrdb -merge $RESOURCEFILE
+ done
fi
+fi
- if grep -qs ^allow-user-resources "$OPTIONFILE"; then
- if [ -f "$USRRESOURCES" ]; then
- xrdb -merge $USRRESOURCES
- fi
+if has_option allow-user-resources && [ -f "$USRRESOURCES" ]; then
+ if type xrdb >/dev/null 2>&1; then
+ xrdb -merge $USRRESOURCES
+ else
+ # Comment out this command if you desire a legacy-free X environment, and find
+ # the warning spurious.
+ message "warning: xrdb command not found; X resources not merged."
fi
-else
- # Comment out this command if you desire a legacy-free X environment, and find
- # the warning spurious.
- message "warning: xrdb command not found; X resources not merged."
fi
# vim:set ai et sts=2 sw=2 tw=80:
diff -Nru xorg-7.5+1ubuntu2/debian/local/Xsession.d/50x11-common_determine-startup xorg-7.5+1ubuntu4/debian/local/Xsession.d/50x11-common_determine-startup
--- xorg-7.5+1ubuntu2/debian/local/Xsession.d/50x11-common_determine-startup 2008-06-25 04:05:17.000000000 +0200
+++ xorg-7.5+1ubuntu4/debian/local/Xsession.d/50x11-common_determine-startup 2010-02-19 06:28:57.000000000 +0100
@@ -7,7 +7,7 @@
# executable, fall back to looking for a user's custom X session script, if
# allowed by the options file.
if [ -z "$STARTUP" ]; then
- if grep -qs ^allow-user-xsession "$OPTIONFILE"; then
+ if has_option allow-user-session; then
for STARTUPFILE in "$USERXSESSION" "$ALTUSERXSESSION"; do
if [ -e "$STARTUPFILE" ]; then
if [ -x "$STARTUPFILE" ]; then
@@ -36,7 +36,7 @@
# If we still have not found a startup program, give up.
if [ -z "$STARTUP" ]; then
ERRMSG="unable to start X session ---"
- if grep -qs ^allow-user-xsession "$OPTIONFILE"; then
+ if has_option allow-user-session; then
ERRMSG="$ERRMSG no \"$USERXSESSION\" file, no \"$ALTUSERXSESSION\" file,"
fi
errormsg "$ERRMSG no session managers, no window managers, and no terminal" \
diff -Nru xorg-7.5+1ubuntu2/debian/local/Xsession.d/90x11-common_ssh-agent xorg-7.5+1ubuntu4/debian/local/Xsession.d/90x11-common_ssh-agent
--- xorg-7.5+1ubuntu2/debian/local/Xsession.d/90x11-common_ssh-agent 2008-08-06 01:37:18.000000000 +0200
+++ xorg-7.5+1ubuntu4/debian/local/Xsession.d/90x11-common_ssh-agent 2010-02-19 06:29:09.000000000 +0100
@@ -6,7 +6,7 @@
SSHAGENT=/usr/bin/ssh-agent
SSHAGENTARGS=
-if grep -qs ^use-ssh-agent "$OPTIONFILE"; then
+if has_option use-ssh-agent; then
if [ -x "$SSHAGENT" ] && [ -z "$SSH_AUTH_SOCK" ] \
&& [ -z "$SSH2_AUTH_SOCK" ]; then
STARTSSH=yes
Attachment:
signature.asc
Description: Digital signature