Skip to content

Commit

Permalink
Reinitialize _create_xid state after fork.
Browse files Browse the repository at this point in the history
Programs forking and using RPC in the forks would use the same XIDs.
  • Loading branch information
Ulrich Drepper committed Nov 22, 2009
1 parent eb41573 commit c5a8b99
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
2009-11-22 Ulrich Drepper <drepper@redhat.com>

* sunrpc/create_xid.c (_create_xid): Reinitialize state after fork.

* sysdeps/unix/sysv/linux/ntp_gettimex.c: New file.
* sysdeps/unix/sysv/linux/Makefile: Add rules to build ntp_gettimex.
* sysdeps/unix/sysv/linux/Versions: Export ntp_gettimex for GLIBC_2.12.
Expand Down
12 changes: 7 additions & 5 deletions sunrpc/create_xid.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 1998, 2000 Free Software Foundation, Inc.
/* Copyright (c) 1998, 2000, 2009 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1998.
Expand Down Expand Up @@ -27,7 +27,7 @@

__libc_lock_define_initialized (static, createxid_lock)

static int is_initialized;
static pid_t is_initialized;
static struct drand48_data __rpc_lrand48_data;

unsigned long
Expand All @@ -37,13 +37,15 @@ _create_xid (void)

__libc_lock_lock (createxid_lock);

if (!is_initialized)
pid_t pid = getpid ();
if (is_initialized != pid)
{
struct timeval now;

__gettimeofday (&now, (struct timezone *) 0);
__srand48_r (now.tv_sec ^ now.tv_usec, &__rpc_lrand48_data);
is_initialized = 1;
__srand48_r (now.tv_sec ^ now.tv_usec ^ pid,
&__rpc_lrand48_data);
is_initialized = pid;
}

lrand48_r (&__rpc_lrand48_data, &res);
Expand Down

0 comments on commit c5a8b99

Please sign in to comment.