/etc/profile optimization and correctness
Daniel Colascione
dan.colascione@gmail.com
Mon Nov 29 15:25:00 GMT 2010
Starting a login shell on my system takes a painfully long time, mostly
because fork() is pretty slow on WOW6432 systems. I've taken a look at
the shell initialization routines and identified some potential savings:
- Can't we use USERNAME to set USER instead of running `id -un`?
- Move the /tmp chmod to the user-home-directory-doesn't-exist-case, or
better yet, get rid of it altogether and move /tmp permission setting to
install scripts
- Detect the current shell by examining BASH_VERSION, ZSH_VERSION, and
so on, not by forking for the echo|tr|sed pipeline.
- Use this code to run the profile.d scripts:
saved_LC_COLLATE=$LC_COLLATE
LC_COLLATE=C
for file in /etc/profile.d/*.{sh,zsh}; do
LC_COLLATE=$saved_LC_COLLATE
test -a "$file" && . "$file"
done
unset saved_LC_COLLATE
- The default /etc/profile exports PS1. Please don't do that: it causes
weird issues with Emacs tramp; it causes other shells that interpret PS1
differently (like zsh) to do odd things; and it uses up precious
environment-block space. Better to set PS1 in bashrc.
- There's a useless uname -s invocation: since Cygwin doesn't run on
Windows 9x anymore (and good riddance!), the first branch of the
conditional is always taken. (Saves two forks.)
- Replace the invocation of regtool with a direct read from
/proc/registry. That is, instead of
# Three forks
PRINTER="`regtool -q get '\user\Software\Microsoft\Windows
NT\CurrentVersion\Windows\Device' | sed 's/,.*$//'`"
use
# Zero forks
read -r PRINTER <
'/proc/registry/HKEY_CURRENT_USER/Software/Microsoft/Windows
NT/CurrentVersion/Windows/Device'
export PRINTER=${PRINTER%%,*}
I've modified my own /etc/profile. It ends up being an order of
magnitude faster than the stock version:
dancol@xyzzy ~
$ time . /etc/defaults/etc/profile
real 0m1.012s
user 0m0.075s
sys 0m0.318s
dancol@xyzzy ~
$ time . /etc/profile
real 0m0.104s
user 0m0.015s
sys 0m0.015s
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: OpenPGP digital signature
URL: <http://cygwin.com/pipermail/cygwin/attachments/20101129/2f742dcf/attachment.sig>
More information about the Cygwin
mailing list