/etc/profile optimization and correctness

David Sastre d.sastre.medina@gmail.com
Mon Nov 29 19:12:00 GMT 2010

On Mon, Nov 29, 2010 at 05:22:56AM -0800, Daniel Colascione wrote:
> 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:
> for file in /etc/profile.d/*.{sh,zsh}; do
>   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

I'm already working in some changes in base-files to include some
bugfixes, and hopefully improve start-up performance by reorganizing how 
things are done now. I'll check your proposals.
One thing: we need to set at least a minimum PS1 in /etc/profile,
because every shell (except tcsh and zsh) fallback to that setting in
case there are no ~/.${SHELL}rc and friends. And also because not
everybody uses bash (even though it is the default one) :)

Huella de clave primaria: 0FDA C36F F110 54F4 D42B  D0EB 617D 396C 448B 31EB
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://cygwin.com/pipermail/cygwin/attachments/20101129/758d82f8/attachment.sig>

More information about the Cygwin mailing list