summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnoop C S <anoopcs@redhat.com>2018-09-19 13:41:49 +0530
committerAndreas Schneider <asn@samba.org>2018-10-23 15:39:12 +0200
commit0b1a43e384e2173de0bafefd000127f3cef5b139 (patch)
treec78829640f40bad93379c15f6f7248233e78dc99
parenta2a8a804405c439082af3083b2ec4c804ca71049 (diff)
downloadsocket_wrapper-0b1a43e384e2173de0bafefd000127f3cef5b139.tar.gz
socket_wrapper-0b1a43e384e2173de0bafefd000127f3cef5b139.tar.xz
socket_wrapper-0b1a43e384e2173de0bafefd000127f3cef5b139.zip
swrap: Fix helgrind errors
Signed-off-by: Anoop C S <anoopcs@redhat.com> Reviewed-by: Andreas Schneider <asn@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
-rw-r--r--src/socket_wrapper.c36
1 files changed, 32 insertions, 4 deletions
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 7a27b40..4f8d218 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -310,6 +310,12 @@ static pthread_mutex_t sockets_mutex;
/* Mutex to synchronize access to first free index in socket_info array */
static pthread_mutex_t first_free_mutex;
+/* Mutex to synchronize access to packet capture dump file */
+static pthread_mutex_t pcap_dump_mutex;
+
+/* Mutex for synchronizing mtu value fetch*/
+static pthread_mutex_t mtu_update_mutex;
+
/* Function prototypes */
bool socket_wrapper_enabled(void);
@@ -1250,8 +1256,10 @@ static unsigned int socket_wrapper_mtu(void)
const char *s;
char *endp;
+ swrap_mutex_lock(&mtu_update_mutex);
+
if (max_mtu != 0) {
- return max_mtu;
+ goto done;
}
max_mtu = SOCKET_WRAPPER_MTU_DEFAULT;
@@ -1272,6 +1280,7 @@ static unsigned int socket_wrapper_mtu(void)
max_mtu = tmp;
done:
+ swrap_mutex_unlock(&mtu_update_mutex);
return max_mtu;
}
@@ -1406,6 +1415,20 @@ static void socket_wrapper_init_sockets(void)
goto done;
}
+ ret = socket_wrapper_init_mutex(&pcap_dump_mutex);
+ if (ret != 0) {
+ SWRAP_LOG(SWRAP_LOG_ERROR,
+ "Failed to initialize pthread mutex");
+ goto done;
+ }
+
+ ret = socket_wrapper_init_mutex(&mtu_update_mutex);
+ if (ret != 0) {
+ SWRAP_LOG(SWRAP_LOG_ERROR,
+ "Failed to initialize pthread mutex");
+ goto done;
+ }
+
done:
swrap_mutex_unlock(&first_free_mutex);
swrap_mutex_unlock(&sockets_mutex);
@@ -2896,9 +2919,11 @@ static void swrap_pcap_dump_packet(struct socket_info *si,
size_t packet_len = 0;
int fd;
+ swrap_mutex_lock(&pcap_dump_mutex);
+
file_name = swrap_pcap_init_file();
if (!file_name) {
- return;
+ goto done;
}
packet = swrap_pcap_marshall_packet(si,
@@ -2908,18 +2933,21 @@ static void swrap_pcap_dump_packet(struct socket_info *si,
len,
&packet_len);
if (packet == NULL) {
- return;
+ goto done;
}
fd = swrap_pcap_get_fd(file_name);
if (fd != -1) {
if (write(fd, packet, packet_len) != (ssize_t)packet_len) {
free(packet);
- return;
+ goto done;
}
}
free(packet);
+
+done:
+ swrap_mutex_unlock(&pcap_dump_mutex);
}
/****************************************************************************