]> git.pld-linux.org Git - packages/libnl1.git/blob - libnl-1.1-threadsafe-port-allocation.patch
- release 4 (by relup.sh)
[packages/libnl1.git] / libnl-1.1-threadsafe-port-allocation.patch
1 From Stefan Berger <stefanb@us.ibm.com>
2 https://bugzilla.redhat.com/show_bug.cgi?id=677527
3
4 --- libnl-1.1/lib/socket.c      
5 +++ libnl-1.1/lib/socket.c      
6 @@ -89,6 +89,8 @@ 
7   * @{
8   */
9  
10 +#include <pthread.h>
11 +
12  #include <netlink-local.h>
13  #include <netlink/netlink.h>
14  #include <netlink/utils.h>
15 @@ -117,12 +119,15 @@ static void __init init_default_cb(void)
16  }
17  
18  static uint32_t used_ports_map[32];
19 +static pthread_mutex_t port_map_mutex = PTHREAD_MUTEX_INITIALIZER;
20  
21  static uint32_t generate_local_port(void)
22  {
23         int i, n;
24         uint32_t pid = getpid() & 0x3FFFFF;
25  
26 +       pthread_mutex_lock(&port_map_mutex);
27 +
28         for (i = 0; i < 32; i++) {
29                 if (used_ports_map[i] == 0xFFFFFFFF)
30                         continue;
31 @@ -136,11 +141,15 @@ static uint32_t generate_local_port(void
32  
33                         /* PID_MAX_LIMIT is currently at 2^22, leaving 10 bit
34                          * to, i.e. 1024 unique ports per application. */
35 -                       return pid + (n << 22);
36  
37 +                       pthread_mutex_unlock(&port_map_mutex);
38 +
39 +                       return pid + (n << 22);
40                 }
41         }
42  
43 +       pthread_mutex_unlock(&port_map_mutex);
44 +
45         /* Out of sockets in our own PID namespace, what to do? FIXME */
46         return UINT_MAX;
47  }
48 @@ -153,7 +162,10 @@ static void release_local_port(uint32_t 
49                 return;
50         
51         nr = port >> 22;
52 -       used_ports_map[nr / 32] &= ~(1 << (nr % 32));
53 +       
54 +       pthread_mutex_lock(&port_map_mutex);
55 +       used_ports_map[nr / 32] &= ~(1 << (nr % 32));
56 +       pthread_mutex_unlock(&port_map_mutex);
57  }
58  
59  /**
60 --- libnl-1.1/lib/Makefile      
61 +++ libnl-1.1/lib/Makefile      
62 @@ -53,7 +53,7 @@ all:
63         $(MAKE) $(targets)
64  
65  $(OUT_SLIB): ../Makefile.opts $(OBJ)
66 -       $(CC) -shared -Wl,-soname,libnl.so.1 -o $(OUT_SLIB) $(OBJ) $(LIBNL_LIB) -lc
67 +       $(CC) -shared -Wl,-soname,libnl.so.1 -o $(OUT_SLIB) $(OBJ) $(LIBNL_LIB) -lc -lpthread
68         rm -f $(LN1_SLIB) ; $(LN) -s $(OUT_SLIB) $(LN1_SLIB)
69         rm -f $(LN_SLIB) ; $(LN) -s $(LN1_SLIB) $(LN_SLIB)
70  
71
This page took 0.083615 seconds and 3 git commands to generate.