From: Abhijit Gadgil Date: Wed, 12 Apr 2023 12:05:13 +0000 (+0530) Subject: Fixes an issue with running DU sim locally X-Git-Tag: 1.8.1~11 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?p=sim%2Fo1-interface.git;a=commitdiff_plain;h=7ff0c8ce9187702caa356c0c1f30064c65c1f512 Fixes an issue with running DU sim locally When DU simulator is run locally, the function crashes due to segfault inside `nf_oran_du_init` when trying to read `ves_template.json` file. This is because `ves_template.json` file is not copied during the image creation. Also, the actual utility function `file_read_content` instead of returning a `NULL` crashes, because uninitialized `length` was used to assign a value when `buffer` was `NULL`. Fixed this as well, the `buffer[length]` value is only sent if the file exists and a valid buffer is allocated. Issue-Id: SIM-109 Change-Id: I75eb985f479331850de2e9fc4aac2ca588fa133c Signed-off-by: Abhijit Gadgil --- diff --git a/ntsimulator/deploy/o-ran-du/local.Dockerfile b/ntsimulator/deploy/o-ran-du/local.Dockerfile index 83b39fd..0c1787a 100644 --- a/ntsimulator/deploy/o-ran-du/local.Dockerfile +++ b/ntsimulator/deploy/o-ran-du/local.Dockerfile @@ -24,8 +24,7 @@ LABEL maintainer="alexandru.stancu@highstreet-technologies.com / adrian.lita@hig COPY ./yang /opt/dev/deploy/yang COPY ./data /opt/dev/deploy/data COPY ./config.json /opt/dev/ntsim-ng/config/config.json -COPY ./config.json /opt/dev/ntsim-ng/config/config.json - +COPY ./ves_template.json /opt/dev/ntsim-ng/config/ves_template.json # ntsim-ng init docker RUN /opt/dev/ntsim-ng/ntsim-ng --container-init -w /opt/dev/ntsim-ng diff --git a/ntsimulator/ntsim-ng/utils/sys_utils.c b/ntsimulator/ntsim-ng/utils/sys_utils.c index 9b49995..2b93d52 100644 --- a/ntsimulator/ntsim-ng/utils/sys_utils.c +++ b/ntsimulator/ntsim-ng/utils/sys_utils.c @@ -91,10 +91,10 @@ char *file_read_content(const char *fname) { buffer = (char*)malloc(sizeof(char) * (length + 1)); if(buffer) { fread(buffer, 1, length, f); + buffer[length] = 0; } fclose(f); } - buffer[length] = 0; return buffer; } @@ -177,7 +177,7 @@ bool get_local_ips(const char *ifname, char **ipv4, char **ipv6) { ret = false; goto get_local_ips_free; } - + *ipv4 = strdup(host); break; } @@ -195,7 +195,7 @@ bool get_local_ips(const char *ifname, char **ipv4, char **ipv6) { ret = false; goto get_local_ips_free; } - + *ipv6 = strdup(host); break; } @@ -217,7 +217,7 @@ bool check_port_open(const char *host, uint16_t port) { assert(host); int simpleSocket = 0; - int returnStatus = 0; + int returnStatus = 0; struct addrinfo simpleServer; struct addrinfo *res; @@ -243,7 +243,7 @@ bool check_port_open(const char *host, uint16_t port) { char s[INET6_ADDRSTRLEN]; switch(res->ai_addr->sa_family) { case AF_INET: { - struct sockaddr_in *addr_in = (struct sockaddr_in *)res->ai_addr; + struct sockaddr_in *addr_in = (struct sockaddr_in *)res->ai_addr; inet_ntop(AF_INET, &(addr_in->sin_addr), s, INET_ADDRSTRLEN); returnStatus = connect(simpleSocket, res->ai_addr, res->ai_addrlen); break; @@ -262,10 +262,10 @@ bool check_port_open(const char *host, uint16_t port) { freeaddrinfo(res); close(simpleSocket); - if(returnStatus == 0) { + if(returnStatus == 0) { return true; } - + return false; } @@ -455,7 +455,7 @@ char *read_key(const char *filename) { return 0; } } - + free(line); line = 0; len = 0;