This is an automated email from the ASF dual-hosted git repository. rbulter pushed a commit to branch bugfix/fix_tcp_admin_using_ip_with_postfix in repository https://gitbox.apache.org/repos/asf/celix.git
commit 79bc4ddc308f3bfdb3ac2d99183bbb91b1c844b9 Author: Roy Bulter <[email protected]> AuthorDate: Thu Apr 30 21:26:01 2020 +0200 Fix crash in pub using ip with post fix --- .../pubsub_admin_tcp/src/pubsub_tcp_handler.c | 81 +++++++++++----------- bundles/pubsub/pubsub_utils/src/pubsub_utils_url.c | 2 +- 2 files changed, 43 insertions(+), 40 deletions(-) diff --git a/bundles/pubsub/pubsub_admin_tcp/src/pubsub_tcp_handler.c b/bundles/pubsub/pubsub_admin_tcp/src/pubsub_tcp_handler.c index 5144e01..cb4d2b2 100644 --- a/bundles/pubsub/pubsub_admin_tcp/src/pubsub_tcp_handler.c +++ b/bundles/pubsub/pubsub_admin_tcp/src/pubsub_tcp_handler.c @@ -574,52 +574,55 @@ int pubsub_tcpHandler_listen(pubsub_tcpHandler_t *handle, char *url) { // Make handler fd entry char *pUrl = pubsub_utils_url_get_url(sin, protocol); entry = pubsub_tcpHandler_createEntry(handle, fd, pUrl, NULL, sin); - entry->connected = true; - free(pUrl); - free(sin); - celixThreadRwlock_writeLock(&handle->dbLock); - rc = fd; - if (rc >= 0) { - rc = listen(fd, SOMAXCONN); - if (rc != 0) { - L_ERROR("[TCP Socket] Error listen: %s\n", strerror(errno)); - pubsub_tcpHandler_freeEntry(entry); - entry = NULL; + if (entry != NULL) { + entry->connected = true; + free(pUrl); + free(sin); + celixThreadRwlock_writeLock(&handle->dbLock); + rc = fd; + if (rc >= 0) { + rc = listen(fd, SOMAXCONN); + if (rc != 0) { + L_ERROR("[TCP Socket] Error listen: %s\n", strerror(errno)); + pubsub_tcpHandler_freeEntry(entry); + entry = NULL; + } } - } - if (rc >= 0) { - rc = pubsub_tcpHandler_makeNonBlocking(handle, fd); - if (rc < 0) { - pubsub_tcpHandler_freeEntry(entry); - entry = NULL; + if (rc >= 0) { + rc = pubsub_tcpHandler_makeNonBlocking(handle, fd); + if (rc < 0) { + pubsub_tcpHandler_freeEntry(entry); + entry = NULL; + } } - } - if ((rc >= 0) && (handle->efd >= 0)) { + if ((rc >= 0) && (handle->efd >= 0)) { #if defined(__APPLE__) - struct kevent ev; - EV_SET (&ev, fd, EVFILT_READ, EV_ADD | EV_ENABLE , 0, 0, 0); - rc = kevent (handle->efd, &ev, 1, NULL, 0, NULL); + struct kevent ev; + EV_SET (&ev, fd, EVFILT_READ, EV_ADD | EV_ENABLE, 0, 0, 0); + rc = kevent(handle->efd, &ev, 1, NULL, 0, NULL); #else - struct epoll_event event; - bzero(&event, sizeof(event)); // zero the struct - event.events = EPOLLIN | EPOLLRDHUP | EPOLLERR; - event.data.fd = fd; - rc = epoll_ctl(handle->efd, EPOLL_CTL_ADD, fd, &event); + struct epoll_event event; + bzero(&event, sizeof(event)); // zero the struct + event.events = EPOLLIN | EPOLLRDHUP | EPOLLERR; + event.data.fd = fd; + rc = epoll_ctl(handle->efd, EPOLL_CTL_ADD, fd, &event); #endif - if (rc < 0) { - L_ERROR("[TCP Socket] Cannot create poll: %s\n", strerror(errno)); - errno = 0; - pubsub_tcpHandler_freeEntry(entry); - entry = NULL; + if (rc < 0) { + L_ERROR("[TCP Socket] Cannot create poll: %s\n", strerror(errno)); + errno = 0; + pubsub_tcpHandler_freeEntry(entry); + entry = NULL; + } + if (entry) { + L_INFO("[TCP Socket] Using %s for service annunciation", entry->url); + hashMap_put(handle->interface_fd_map, (void *) (intptr_t) entry->fd, entry); + hashMap_put(handle->interface_url_map, entry->url, entry); + } } - if (entry) - L_INFO("[TCP Socket] Using %s for service annunciation", entry->url); - if (entry) - hashMap_put(handle->interface_fd_map, (void *) (intptr_t) entry->fd, entry); - if (entry) - hashMap_put(handle->interface_url_map, entry->url, entry); + celixThreadRwlock_unlock(&handle->dbLock); + } else { + L_ERROR("[TCP Socket] Error listen socket cannot bind to %s: %s\n", url ? url : "", strerror(errno)); } - celixThreadRwlock_unlock(&handle->dbLock); } return rc; } diff --git a/bundles/pubsub/pubsub_utils/src/pubsub_utils_url.c b/bundles/pubsub/pubsub_utils/src/pubsub_utils_url.c index 2ac9cfa..d8d518c 100644 --- a/bundles/pubsub/pubsub_utils/src/pubsub_utils_url.c +++ b/bundles/pubsub/pubsub_utils/src/pubsub_utils_url.c @@ -161,7 +161,7 @@ char *pubsub_utils_url_get_ip(char *_hostname) { if (subNet != NULL) { unsigned int length = strlen(subNet); if ((length > 1) && isdigit(subNet[1])) { - bool is_multicast = pubsub_utils_url_is_multicast(_hostname); + bool is_multicast = pubsub_utils_url_is_multicast(hostname); if (is_multicast) ip = pubsub_utils_url_get_multicast_ip(_hostname); else
