summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordimitri staessens <[email protected]>2016-05-20 07:34:41 +0200
committerdimitri staessens <[email protected]>2016-05-20 07:34:41 +0200
commit129b15eea7a790bff0a83d1668b8d666fe0e6f35 (patch)
tree0272b1c35bd3dddaa380a8c8169767445b66a56b /src
parente0f5fbea688a6e9b19c79d16b41076fc7c508df6 (diff)
downloadouroboros-129b15eea7a790bff0a83d1668b8d666fe0e6f35.tar.gz
ouroboros-129b15eea7a790bff0a83d1668b8d666fe0e6f35.zip
ipcpd: shim-udp: read fd on client side
There could be a theoretical race condition that the server sends a message before the FD is set on the client side, which is resolved.
Diffstat (limited to 'src')
-rw-r--r--src/ipcpd/shim-udp/main.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/ipcpd/shim-udp/main.c b/src/ipcpd/shim-udp/main.c
index a75f3ce3..3ef783c4 100644
--- a/src/ipcpd/shim-udp/main.c
+++ b/src/ipcpd/shim-udp/main.c
@@ -1124,6 +1124,7 @@ static int ipcp_udp_flow_alloc(pid_t n_pid,
int fd;
struct hostent * h;
uint32_t ip_addr = 0;
+ bool fd_wait = true;
#ifdef CONFIG_OUROBOROS_ENABLE_DNS
uint32_t dns_addr = 0;
#endif
@@ -1220,8 +1221,20 @@ static int ipcp_udp_flow_alloc(pid_t n_pid,
rw_lock_rdlock(&_ipcp->state_lock);
rw_lock_wrlock(&_ap_instance->flows_lock);
+ pthread_mutex_lock(&_ap_instance->fd_set_lock);
+
+ _ap_instance->fd_set_sync = true;
FD_SET(fd, &shim_data(_ipcp)->flow_fd_s);
+ pthread_mutex_unlock(&_ap_instance->fd_set_lock);
+
+ while (fd_wait) {
+ sched_yield();
+ pthread_mutex_lock(&_ap_instance->fd_set_lock);
+ fd_wait = _ap_instance->fd_set_sync;
+ pthread_mutex_unlock(&_ap_instance->fd_set_lock);
+ }
+
_ap_instance->flows[fd].port_id = port_id;
_ap_instance->flows[fd].state = FLOW_PENDING;
_ap_instance->flows[fd].rb = rb;