netdev-vport: Make pid checking in set_tunnel_config() thread-safe
authorBen Pfaff <blp@nicira.com>
Fri, 26 Apr 2013 20:20:30 +0000 (13:20 -0700)
committerBen Pfaff <blp@nicira.com>
Tue, 23 Jul 2013 18:38:17 +0000 (11:38 -0700)
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Andy Zhou <azhou@nicira.com>
lib/netdev-vport.c

index 885bf5e..4214b38 100644 (file)
@@ -413,13 +413,17 @@ set_tunnel_config(struct netdev *dev_, const struct smap *args)
     }
 
     if (tnl_cfg.ipsec) {
+        static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
         static pid_t pid = 0;
+
+        pthread_mutex_lock(&mutex);
         if (pid <= 0) {
             char *file_name = xasprintf("%s/%s", ovs_rundir(),
                                         "ovs-monitor-ipsec.pid");
             pid = read_pidfile(file_name);
             free(file_name);
         }
+        pthread_mutex_unlock(&mutex);
 
         if (pid < 0) {
             VLOG_ERR("%s: IPsec requires the ovs-monitor-ipsec daemon",