[merge] catch exceptions while opening /dev/urandom

Martin Pool mbp at canonical.com
Tue Oct 10 08:06:55 BST 2006


On 10 Oct 2006, John Arbash Meinel <john at arbash-meinel.com> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> This patch is just meant to close this bug:
> https://launchpad.net/products/bzr/+bug/56883
> 
> It works on the existing patch, only it prefers to catch specifically
> IOError and OSError, rather than catching any error.
> 
> Also, it might be better if we checked e.errno to be in a specific set
> (such as ENOENT), but since the bug report didn't indicate what the
> actual error was, I'm just submitting it as is.

+1

> # Bazaar revision bundle v0.8
> #
> # message:
> #   Catch an exception while opening /dev/urandom rather than using os.path.exists()
> # committer: John Arbash Meinel <john at arbash-meinel.com>
> # date: Tue 2006-10-10 01:26:39.661999941 -0500
> 
> === modified file bzrlib/osutils.py
> --- bzrlib/osutils.py
> +++ bzrlib/osutils.py
> @@ -659,10 +659,10 @@
>  except (NotImplementedError, AttributeError):
>      # If python doesn't have os.urandom, or it doesn't work,
>      # then try to first pull random data from /dev/urandom
> -    if os.path.exists("/dev/urandom"):
> +    try:
>          rand_bytes = file('/dev/urandom', 'rb').read
>      # Otherwise, use this hack as a last resort
> -    else:
> +    except (IOError, OSError):
>          # not well seeded, but better than nothing
>          def rand_bytes(n):
>              import random
> 
> === modified directory  // last-changed:john at arbash-meinel.com-20061010062639-6
> ... d527d0f9a3401d8
> # revision id: john at arbash-meinel.com-20061010062639-6d527d0f9a3401d8
> # sha1: 88dd76100638be03ea0100e2cd8b5a1c545992f5
> # inventory sha1: e6f2f8e3125ff92880cbede13c62fba873be8e31
> # parent ids:
> #   pqm at pqm.ubuntu.com-20061010030628-7945de26f2489e6f
> # base id: pqm at pqm.ubuntu.com-20061010030628-7945de26f2489e6f
> # properties:
> #   branch-nick: urandom-56883
> 

-- 
Martin




More information about the bazaar mailing list