diff options
author | dimitri staessens <dimitri.staessens@ugent.be> | 2017-04-03 14:47:24 +0000 |
---|---|---|
committer | Sander Vrijders <sander.vrijders@ugent.be> | 2017-04-03 14:47:24 +0000 |
commit | e38e34017b4a7667e11c08e9947e72dfc0b87474 (patch) | |
tree | ed204b5d6f653f6ccb3a12a18c53abab0dad7fa9 /src/ipcpd/shim-udp/main.c | |
parent | 1d4728bcf572c3ebc1632fec9a6751d6644087ce (diff) | |
parent | 0f30eaa3d4dd573f9af30a9fd0c5d22bad63c560 (diff) | |
download | ouroboros-e38e34017b4a7667e11c08e9947e72dfc0b87474.tar.gz ouroboros-e38e34017b4a7667e11c08e9947e72dfc0b87474.zip |
Merged in dstaesse/ouroboros/be-ipcp-req-arr (pull request #456)
ipcpd: Fix some bad locking
Diffstat (limited to 'src/ipcpd/shim-udp/main.c')
-rw-r--r-- | src/ipcpd/shim-udp/main.c | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/src/ipcpd/shim-udp/main.c b/src/ipcpd/shim-udp/main.c index 3bbce79d..71f1270b 100644 --- a/src/ipcpd/shim-udp/main.c +++ b/src/ipcpd/shim-udp/main.c @@ -269,19 +269,17 @@ static int ipcp_udp_port_req(struct sockaddr_in * c_saddr, return -1; } - pthread_rwlock_rdlock(&ipcpi.state_lock); - pthread_rwlock_wrlock(&udp_data.flows_lock); - /* reply to IRM */ fd = ipcp_flow_req_arr(getpid(), dst_name, cube); if (fd < 0) { - pthread_rwlock_unlock(&udp_data.flows_lock); - pthread_rwlock_unlock(&ipcpi.state_lock); log_err("Could not get new flow from IRMd."); close(skfd); return -1; } + pthread_rwlock_rdlock(&ipcpi.state_lock); + pthread_rwlock_wrlock(&udp_data.flows_lock); + udp_data.uf_to_fd[skfd] = fd; udp_data.fd_to_uf[fd].skfd = skfd; udp_data.fd_to_uf[fd].udp = f_saddr.sin_port; @@ -464,10 +462,11 @@ static void * ipcp_udp_sdu_reader(void * o) pthread_rwlock_rdlock(&udp_data.flows_lock); fd = udp_data.uf_to_fd[skfd]; - flow_write(fd, buf, n); pthread_rwlock_unlock(&udp_data.flows_lock); pthread_rwlock_unlock(&ipcpi.state_lock); + + flow_write(fd, buf, n); } } @@ -483,34 +482,34 @@ static void * ipcp_udp_sdu_loop(void * o) (void) o; while (flow_event_wait(udp_data.np1_flows, udp_data.fq, &timeout)) { - pthread_rwlock_rdlock(&ipcpi.state_lock); - - if (ipcp_get_state() != IPCP_OPERATIONAL) { - pthread_rwlock_unlock(&ipcpi.state_lock); - return (void *) -1; /* -ENOTENROLLED */ - } - - - pthread_rwlock_rdlock(&udp_data.flows_lock); - while ((fd = fqueue_next(udp_data.fq)) >= 0) { if (ipcp_flow_read(fd, &sdb)) { log_err("Bad read from fd %d.", fd); continue; } - if (send(udp_data.fd_to_uf[fd].skfd, - shm_du_buff_head(sdb), + pthread_rwlock_rdlock(&ipcpi.state_lock); + + if (ipcp_get_state() != IPCP_OPERATIONAL) { + pthread_rwlock_unlock(&ipcpi.state_lock); + ipcp_flow_del(sdb); + return (void *) -1; /* -ENOTENROLLED */ + } + + pthread_rwlock_rdlock(&udp_data.flows_lock); + + fd = udp_data.fd_to_uf[fd].skfd; + + pthread_rwlock_unlock(&udp_data.flows_lock); + pthread_rwlock_unlock(&ipcpi.state_lock); + + if (send(fd, shm_du_buff_head(sdb), shm_du_buff_tail(sdb) - shm_du_buff_head(sdb), 0) < 0) log_err("Failed to send SDU."); ipcp_flow_del(sdb); } - - - pthread_rwlock_unlock(&udp_data.flows_lock); - pthread_rwlock_unlock(&ipcpi.state_lock); } return (void *) 1; @@ -1143,11 +1142,11 @@ static int ipcp_udp_flow_dealloc(int fd) clr_fd(skfd); - flow_dealloc(fd); - pthread_rwlock_unlock(&udp_data.flows_lock); pthread_rwlock_unlock(&ipcpi.state_lock); + flow_dealloc(fd); + log_dbg("Flow with fd %d deallocated.", fd); return 0; |