On Mon, Mar 10, 2014 at 10:56:38AM -0700, Gurucharan Shetty wrote: > Windows does not have the getppid(), getuid(), getgid() functions. > We do get a random seed from CryptGenRandom(). That seed along with > process id and current time hopefully is good enough. > > Signed-off-by: Gurucharan Shetty <gshe...@nicira.com>
I see that there was a bug that 'now' wasn't getting folded in. Let's fix that for all systems, not just for Windows. I think that this could be a little nicer by adding a function like this: static void sha1_update_int(struct sha1 *sha1_ctx, uintmax_t x) { sha1_update(sha1_ctx, &x, sizeof x); } and then we can delete the variables and the assignments and the changes to windefs.h and just write: sha1_update_int(&sha1_ctx, getpid()); #ifndef _WIN32 sha1_update_int(&sha1_ctx, getppid()); sha1_update_int(&sha1_ctx, getuid()); sha1_update_int(&sha1_ctx, getgid()); #endif > --- > include/windows/windefs.h | 4 ++++ > lib/uuid.c | 6 ++++++ > 2 files changed, 10 insertions(+) > > diff --git a/include/windows/windefs.h b/include/windows/windefs.h > index 6d36adc..6fde1ea 100644 > --- a/include/windows/windefs.h > +++ b/include/windows/windefs.h > @@ -32,4 +32,8 @@ > #define u_int32_t uint32_t > #define u_int64_t uint64_t > > +typedef int pid_t; > +typedef int uid_t; > +typedef int gid_t; > + > #endif /* windefs.h */ > diff --git a/lib/uuid.c b/lib/uuid.c > index 315c851..9ac5b55 100644 > --- a/lib/uuid.c > +++ b/lib/uuid.c > @@ -220,17 +220,23 @@ do_init(void) > get_entropy_or_die(random_seed, sizeof random_seed); > xgettimeofday(&now); > pid = getpid(); > +#ifndef _WIN32 > ppid = getppid(); > uid = getuid(); > gid = getgid(); > +#endif > > /* Convert seed into key. */ > sha1_init(&sha1_ctx); > sha1_update(&sha1_ctx, random_seed, sizeof random_seed); > sha1_update(&sha1_ctx, &pid, sizeof pid); > +#ifndef _WIN32 > sha1_update(&sha1_ctx, &ppid, sizeof ppid); > sha1_update(&sha1_ctx, &uid, sizeof uid); > sha1_update(&sha1_ctx, &gid, sizeof gid); > +#else > + sha1_update(&sha1_ctx, &now, sizeof now); > +#endif > sha1_final(&sha1_ctx, sha1); > > /* Generate key. */ _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev