components/open-fabrics/libibmad/patches/002-libibmad-diskmon_trid.patch
branchs11u3-sru
changeset 6927 af9bb41e858d
equal deleted inserted replaced
6908:df2381fc3597 6927:af9bb41e858d
       
     1 #This patch was developed both in-house and from outside. We plan to submit it
       
     2 #upstream, but do not yet have a target date for doing so
       
     3 #
       
     4 # HG changeset patch
       
     5 # Parent  b0c54b9f271e37d7b605138bcdd0c26844892c3d
       
     6 22086045 libibmad used [s]random(3c) functions unsafely
       
     7 
       
     8 diff -r b0c54b9f271e src/mad.c
       
     9 --- a/src/mad.c	Mon Aug 15 14:55:29 2016 -0700
       
    10 +++ b/src/mad.c	Mon Aug 15 15:01:53 2016 -0700
       
    11 @@ -41,6 +41,9 @@
       
    12  #include <stdlib.h>
       
    13  #include <string.h>
       
    14  #include <time.h>
       
    15 +#if defined(__SVR4) && defined(__sun)
       
    16 +#include <pthread.h>
       
    17 +#endif
       
    18  #include <errno.h>
       
    19  
       
    20  #include <infiniband/umad.h>
       
    21 @@ -48,6 +51,10 @@
       
    22  
       
    23  #include "mad_internal.h"
       
    24  
       
    25 +#if defined(__SVR4) && defined(__sun)
       
    26 +static pthread_mutex_t trid_mutex = PTHREAD_MUTEX_INITIALIZER;
       
    27 +#endif
       
    28 +
       
    29  #undef DEBUG
       
    30  #define DEBUG	if (ibdebug)	IBWARN
       
    31  
       
    32 @@ -63,11 +70,17 @@
       
    33  	static uint64_t trid;
       
    34  	uint64_t next;
       
    35  
       
    36 +#if defined(__SVR4) && defined(__sun)
       
    37 +	(void) pthread_mutex_lock(&trid_mutex);
       
    38 +#endif
       
    39  	if (!trid) {
       
    40  		srandom((int)time(0) * getpid());
       
    41  		trid = random();
       
    42  	}
       
    43  	next = ++trid;
       
    44 +#if defined(__SVR4) && defined(__sun)
       
    45 +	(void) pthread_mutex_unlock(&trid_mutex);
       
    46 +#endif
       
    47  	next = GET_IB_USERLAND_TID(next);
       
    48  	return next;
       
    49  }