patch: sleep/nanosleep bug

Eric Blake ebb9@byu.net
Wed Nov 18 20:14:00 GMT 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I see no reason why we can't sleep for more than 49.7 days (not that I
expect many programs to try that, though).  Plus, sleep was reading
uninitialized memory, giving garbage answers.

Here's an example that proves where this matters:
$ (time timeout 2 sleep 49d) 2>&1 | grep sys
sys     0m0.046s
$ (time timeout 2 sleep 50d) 2>&1 | grep sys
sys     0m1.500s

Notice how CPU utilization spikes from nearly 0% to nearly 100% once you
cross 49.7 days, because sleep(1) is now in a super-tight loop of
repeatedly calling nanosleep (which fails), then checking the current time
to see if enough elapsed time has occurred.

2009-11-18  Eric Blake  <ebb9@byu.net>

	* signal.cc (nanosleep): Support 'infinite' sleep times.
	(sleep): Avoid uninitialized memory.

- --
Don't work too hard, make some time for fun as well!

Eric Blake             ebb9@byu.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAksEVYEACgkQ84KuGfSFAYCcFgCfU2rkcgCAQ4Ywfv73mJe51AbL
xZsAnRwuA/ybkXvz+3uEQvUzyHjbWk4l
=pH2l
-----END PGP SIGNATURE-----
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: cygwin.patch33
URL: <http://cygwin.com/pipermail/cygwin-patches/attachments/20091118/00ca9eda/attachment.ksh>


More information about the Cygwin-patches mailing list