🐞 fix: 修复fd泄露
This commit is contained in:
@@ -239,7 +239,7 @@ uint64_t health_check_session_add(int profile_id, const struct health_check *pol
|
||||
bfd_vtysh_close(&client);
|
||||
}
|
||||
|
||||
LOG_DEBUG("health check session table insert: session id [%lu] success", session_id);
|
||||
LOG_DEBUG("health check session table insert: profile id [%d] session id [%lu] address [%s] success", profile_id, session_id, policy->address);
|
||||
return session_id;
|
||||
}
|
||||
|
||||
@@ -338,22 +338,18 @@ static int get_mac_by_addr(char *addr, uint8_t *buf)
|
||||
snprintf(arp_req.arp_dev, IFNAMSIZ, hc_dev_name);
|
||||
|
||||
sfd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
|
||||
saved_errno = errno;
|
||||
ret = ioctl(sfd, SIOCGARP, &arp_req);
|
||||
if (ret < 0) {
|
||||
LOG_ERROR("Get IP [%s] MAC failed : %s", addr, strerror(errno));
|
||||
if (sfd == -1)
|
||||
return -1;
|
||||
}
|
||||
errno = saved_errno;
|
||||
|
||||
if (arp_req.arp_flags & ATF_COM)
|
||||
memcpy(buf, arp_req.arp_ha.sa_data, HC_MAC_LEN);
|
||||
else
|
||||
ret = ioctl(sfd, SIOCGARP, &arp_req);
|
||||
if (ret < 0)
|
||||
memcpy(buf, default_gw_mac, HC_MAC_LEN);
|
||||
else
|
||||
memcpy(buf, arp_req.arp_ha.sa_data, HC_MAC_LEN);
|
||||
|
||||
LOG_DEBUG("IP:%s, MAC: %02x:%02x:%02x:%02x:%02x:%02x\n",
|
||||
LOG_DEBUG("IP:%s, MAC: %02x:%02x:%02x:%02x:%02x:%02x",
|
||||
addr, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
|
||||
close(sfd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -381,21 +377,26 @@ static void *_health_check_session_foreach(void *arg)
|
||||
if (node->policy.method != HEALTH_CHECK_METHOD_BFD)
|
||||
continue;
|
||||
|
||||
is_active = bfd_vtysh_get_dev_active(&client, node->policy.address);
|
||||
if (is_active == -1) {
|
||||
bfd_vtysh_close(&client);
|
||||
health_check_session_recover_bfd(&client);
|
||||
bfd_vtysh_connect(&client);
|
||||
if (strlen(node->policy.address) != 0) {
|
||||
is_active = bfd_vtysh_get_dev_active(&client, node->policy.address);
|
||||
if (is_active == -1)
|
||||
is_active = 0;
|
||||
if (is_active == -1) {
|
||||
bfd_vtysh_close(&client);
|
||||
health_check_session_recover_bfd(&client);
|
||||
bfd_vtysh_connect(&client);
|
||||
is_active = bfd_vtysh_get_dev_active(&client, node->policy.address);
|
||||
if (is_active == -1)
|
||||
is_active = 0;
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
is_active = 0;
|
||||
}
|
||||
|
||||
sf_status_update(g_sf_status, node->profile_id, is_active, 0);
|
||||
if (node->is_active != is_active) {
|
||||
node->is_active = is_active;
|
||||
if (node->is_active == 1) {
|
||||
get_mac_by_addr(node->policy.address, node->mac);
|
||||
get_mac_by_addr(node->policy.address, node->mac);
|
||||
}
|
||||
else {
|
||||
memset(node->mac, 0, sizeof(node->mac));
|
||||
|
||||
Reference in New Issue
Block a user