lib: Return instead of exit in net

Alters internal spdk_process_new_interface_msg() function
such that it returns a failure instead of exit()'ing.

Change-Id: I31c5dd9db43449f81dbb0f581258476a58aa8000
Signed-off-by: Lance Hartmann <lance.hartmann@oracle.com>
Reviewed-on: https://review.gerrithub.io/402165
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Lance Hartmann 2018-03-01 13:11:39 -05:00 committed by Jim Harris
parent 627bee96a4
commit 9364bee419

View File

@ -46,7 +46,7 @@ static TAILQ_HEAD(, spdk_interface) g_interface_head;
static pthread_mutex_t interface_lock = PTHREAD_MUTEX_INITIALIZER;
static uint32_t spdk_get_ifc_ipv4(void)
static int spdk_get_ifc_ipv4(void)
{
int ret;
int rtattrlen;
@ -154,7 +154,7 @@ exit:
}
static void spdk_process_new_interface_msg(struct nlmsghdr *h)
static int spdk_process_new_interface_msg(struct nlmsghdr *h)
{
int len;
struct spdk_interface *ifc;
@ -166,7 +166,7 @@ static void spdk_process_new_interface_msg(struct nlmsghdr *h)
ifc = (struct spdk_interface *) malloc(sizeof(*ifc));
if (ifc == NULL) {
SPDK_ERRLOG("%s: Malloc failed\n", __func__);
exit(1);
return 1;
}
memset(ifc, 0, sizeof(*ifc));
@ -182,7 +182,8 @@ static void spdk_process_new_interface_msg(struct nlmsghdr *h)
case IFLA_IFNAME:
if (if_indextoname(iface->ifi_index, ifc->name) == NULL) {
SPDK_ERRLOG("Indextoname failed!\n");
exit(1);
free(ifc);
return 2;
}
break;
default:
@ -190,11 +191,12 @@ static void spdk_process_new_interface_msg(struct nlmsghdr *h)
}
}
TAILQ_INSERT_TAIL(&g_interface_head, ifc, tailq);
return 0;
}
static uint32_t spdk_prepare_ifc_list(void)
static int spdk_prepare_ifc_list(void)
{
uint32_t ret = 0;
int ret = 0;
struct nl_req_s {
struct nlmsghdr hdr;
struct rtgenmsg gen;
@ -284,7 +286,10 @@ static uint32_t spdk_prepare_ifc_list(void)
end++;
break;
case RTM_NEWLINK: /* This is a RTM_NEWLINK message, which contains lots of information about a link */
spdk_process_new_interface_msg(msg_ptr);
ret = spdk_process_new_interface_msg(msg_ptr);
if (ret != 0) {
goto exit;
}
break;
default:
break;
@ -417,11 +422,15 @@ static void spdk_interface_ip_update(void)
int
spdk_interface_init(void)
{
TAILQ_INIT(&g_interface_head);
spdk_prepare_ifc_list();
spdk_get_ifc_ipv4();
int rc = 0;
return 0;
TAILQ_INIT(&g_interface_head);
rc = spdk_prepare_ifc_list();
if (!rc) {
rc = spdk_get_ifc_ipv4();
}
return rc;
}
void