Author: igalic
Date: Sat Sep 17 21:53:22 2011
New Revision: 1172074
URL: http://svn.apache.org/viewvc?rev=1172074&view=rev
Log:
TS-953: consolidate string copy/concat for mgmt/cluster
Modified:
trafficserver/traffic/trunk/mgmt/cluster/ClusterCom.cc
trafficserver/traffic/trunk/mgmt/cluster/VMap.cc
Modified: trafficserver/traffic/trunk/mgmt/cluster/ClusterCom.cc
URL:
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/mgmt/cluster/ClusterCom.cc?rev=1172074&r1=1172073&r2=1172074&view=diff
==============================================================================
--- trafficserver/traffic/trunk/mgmt/cluster/ClusterCom.cc (original)
+++ trafficserver/traffic/trunk/mgmt/cluster/ClusterCom.cc Sat Sep 17 21:53:22
2011
@@ -341,7 +341,7 @@ ClusterCom::ClusterCom(unsigned long oip
memset(&broadcast_addr, 0, sizeof(broadcast_addr));
memset(&receive_addr, 0, sizeof(receive_addr));
- ink_strncpy(our_host, host, sizeof(our_host));
+ ink_strlcpy(our_host, host, sizeof(our_host));
our_ip = oip;
/* Get the cluster type */
@@ -404,7 +404,7 @@ ClusterCom::ClusterCom(unsigned long oip
mgmt_fatal(stderr, "[ClusterCom::ClusterCom] mc group length to large!\n");
}
- ink_strncpy(mc_group, group, sizeof(mc_group));
+ ink_strlcpy(mc_group, group, sizeof(mc_group));
mc_port = port;
reliable_server_port = sport;
@@ -479,7 +479,7 @@ ClusterCom::checkPeers(time_t * ticker)
struct in_addr addr;
addr.s_addr = tmp->inet_address;
- ink_strncpy(cip, inet_ntoa(addr), sizeof(cip));
+ ink_strlcpy(cip, inet_ntoa(addr), sizeof(cip));
Debug("ccom",
"[ClusterCom::checkPeers] DEAD! %s idle since: %ld naddrs:
%d\n", cip, idle_since, tmp->num_virt_addrs);
@@ -956,7 +956,7 @@ ClusterCom::handleMultiCastStatPacket(ch
ats_free(rec->data.rec_string);
int rec_string_size = strlen(tmp_msg_val) + 1;
ink_assert((rec->data.rec_string =
(RecString)ats_malloc(rec_string_size)));
- ink_strncpy(rec->data.rec_string, tmp_msg_val, rec_string_size);
+ ink_strlcpy(rec->data.rec_string, tmp_msg_val, rec_string_size);
}
break;
}
@@ -1006,9 +1006,7 @@ extract_locals(MgmtHashTable * local_ht,
q++;
// is this line a LOCAL?
if (strncmp(q, "LOCAL", strlen("LOCAL")) == 0) {
- int line_cp_len = strlen(line) + 1;
- line_cp = (char *)ats_malloc(line_cp_len);
- ink_strncpy(line_cp, line, line_cp_len);
+ line_cp = ats_strdup(line);
q += strlen("LOCAL");
while ((*q == ' ') || (*q == '\t'))
q++;
@@ -1145,7 +1143,6 @@ ClusterCom::handleMultiCastFilePacket(ch
if (!file_update_failure && (strcmp(file, "records.config") == 0)) {
textBuffer *our_rec_cfg;
char *our_rec_cfg_cp;
- int our_rec_cfg_cp_len;
textBuffer *reply_new;
MgmtHashTable *our_locals_ht;
@@ -1153,9 +1150,7 @@ ClusterCom::handleMultiCastFilePacket(ch
file_update_failure = true;
} else {
our_locals_ht = NEW(new MgmtHashTable("our_locals_ht", true,
InkHashTableKeyType_String));
- our_rec_cfg_cp_len = our_rec_cfg->spaceUsed();
- our_rec_cfg_cp = (char *)ats_malloc(our_rec_cfg_cp_len + 1);
- ink_strncpy(our_rec_cfg_cp, our_rec_cfg->bufPtr(),
(our_rec_cfg_cp_len + 1));
+ our_rec_cfg_cp = ats_strdup(our_rec_cfg->bufPtr());
extract_locals(our_locals_ht, our_rec_cfg_cp);
reply_new = NEW(new textBuffer(reply->spaceUsed()));
if (!insert_locals(reply_new, reply, our_locals_ht)) {
@@ -1320,7 +1315,7 @@ ClusterCom::sendSharedData(bool send_pro
/* Alarm Message */
memset(message, 0, 61440);
resolved_addr.s_addr = our_ip;
- ink_strncpy(addr, inet_ntoa(resolved_addr), sizeof(addr));
+ ink_strlcpy(addr, inet_ntoa(resolved_addr), sizeof(addr));
lmgmt->alarm_keeper->constructAlarmMessage(addr, message, 61440);
sendOutgoingMessage(message, strlen(message));
@@ -1367,7 +1362,7 @@ ClusterCom::constructSharedGenericPacket
running_sum = constructSharedPacketHeader(message, inet_ntoa(resolved_addr),
max);
if (packet_type == RECT_NODE) {
- ink_strncpy(&message[running_sum], "type: stat\n", (max - running_sum));
+ ink_strlcpy(&message[running_sum], "type: stat\n", (max - running_sum));
running_sum += strlen("type: stat\n");
ink_release_assert(running_sum < max);
} else {
@@ -1380,7 +1375,7 @@ ClusterCom::constructSharedGenericPacket
} else {
snprintf(tmp, sizeof(tmp), "os: unknown\n");
}
- ink_strncpy(&message[running_sum], tmp, (max - running_sum));
+ ink_strlcpy(&message[running_sum], tmp, (max - running_sum));
running_sum += strlen(tmp);
ink_release_assert(running_sum < max);
@@ -1390,29 +1385,29 @@ ClusterCom::constructSharedGenericPacket
} else {
snprintf(tmp, sizeof(tmp), "rel: unknown\n");
}
- ink_strncpy(&message[running_sum], tmp, (max - running_sum));
+ ink_strlcpy(&message[running_sum], tmp, (max - running_sum));
running_sum += strlen(tmp);
ink_release_assert(running_sum < max);
snprintf(tmp, sizeof(tmp), "hostname: %s\n", our_host);
- ink_strncpy(&message[running_sum], tmp, (max - running_sum));
+ ink_strlcpy(&message[running_sum], tmp, (max - running_sum));
running_sum += strlen(tmp);
ink_release_assert(running_sum < max);
snprintf(tmp, sizeof(tmp), "port: %d\n", cluster_port);
- ink_strncpy(&message[running_sum], tmp, (max - running_sum));
+ ink_strlcpy(&message[running_sum], tmp, (max - running_sum));
running_sum += strlen(tmp);
ink_release_assert(running_sum < max);
snprintf(tmp, sizeof(tmp), "ccomport: %d\n", reliable_server_port);
- ink_strncpy(&message[running_sum], tmp, (max - running_sum));
+ ink_strlcpy(&message[running_sum], tmp, (max - running_sum));
running_sum += strlen(tmp);
ink_release_assert(running_sum < max);
/* Current time stamp, for xntp like synching */
if (time(NULL) > 0) {
snprintf(tmp, sizeof(tmp), "time: %" PRId64 "\n", (int64_t)time(NULL));
- ink_strncpy(&message[running_sum], tmp, (max - running_sum));
+ ink_strlcpy(&message[running_sum], tmp, (max - running_sum));
running_sum += strlen(tmp);
} else {
mgmt_elog(stderr, "[ClusterCom::constructSharedPacket] time failed\n");
@@ -1427,17 +1422,17 @@ ClusterCom::constructSharedGenericPacket
switch (rec->data_type) {
case RECD_COUNTER:
snprintf(tmp, sizeof(tmp), "%d:%d: %" PRId64 "\n", cnt,
rec->data_type, rec->data.rec_counter);
- ink_strncpy(&message[running_sum], tmp, (max - running_sum));
+ ink_strlcpy(&message[running_sum], tmp, (max - running_sum));
running_sum += strlen(tmp);
break;
case RECD_INT:
snprintf(tmp, sizeof(tmp), "%d:%d: %" PRId64 "\n", cnt,
rec->data_type, rec->data.rec_int);
- ink_strncpy(&message[running_sum], tmp, (max - running_sum));
+ ink_strlcpy(&message[running_sum], tmp, (max - running_sum));
running_sum += strlen(tmp);
break;
case RECD_FLOAT:
snprintf(tmp, sizeof(tmp), "%d:%d: %f\n", cnt, rec->data_type,
rec->data.rec_float);
- ink_strncpy(&message[running_sum], tmp, (max - running_sum));
+ ink_strlcpy(&message[running_sum], tmp, (max - running_sum));
running_sum += strlen(tmp);
break;
case RECD_STRING:
@@ -1446,7 +1441,7 @@ ClusterCom::constructSharedGenericPacket
} else {
snprintf(tmp, sizeof(tmp), "%d:%d: NULL\n", cnt, rec->data_type);
}
- ink_strncpy(&message[running_sum], tmp, (max - running_sum));
+ ink_strlcpy(&message[running_sum], tmp, (max - running_sum));
running_sum += strlen(tmp);
break;
default:
@@ -1508,7 +1503,7 @@ ClusterCom::constructSharedFilePacket(ch
resolved_addr.s_addr = our_ip;
running_sum = constructSharedPacketHeader(message, inet_ntoa(resolved_addr),
max);
- ink_strncpy(&message[running_sum], "type: files\n", (max - running_sum));
+ ink_strlcpy(&message[running_sum], "type: files\n", (max - running_sum));
running_sum += strlen("type: files\n");
ink_release_assert(running_sum < max);
@@ -1547,7 +1542,7 @@ ClusterCom::constructSharedFilePacket(ch
time_t mod = 0;
snprintf(tmp, sizeof(tmp), "%s %d %" PRId64 "\n", line, ver,
(int64_t)mod);
- ink_strncpy(&message[running_sum], tmp, (max - running_sum));
+ ink_strlcpy(&message[running_sum], tmp, (max - running_sum));
running_sum += strlen(tmp);
ink_release_assert(running_sum < max);
} else {
@@ -1911,7 +1906,7 @@ ClusterCom::rl_sendReliableMessage(unsig
address.s_addr = addr;
- ink_strncpy(string_addr, inet_ntoa(address), sizeof(string_addr));
+ ink_strlcpy(string_addr, inet_ntoa(address), sizeof(string_addr));
if (ink_hash_table_lookup(peers, string_addr, &hash_value) == 0) {
return false;
}
@@ -1968,7 +1963,7 @@ ClusterCom::sendReliableMessage(unsigned
if (take_lock) {
ink_mutex_acquire(&mutex);
}
- ink_strncpy(string_addr, inet_ntoa(address), sizeof(string_addr));
+ ink_strlcpy(string_addr, inet_ntoa(address), sizeof(string_addr));
if (ink_hash_table_lookup(peers, string_addr, &hash_value) == 0) {
if (take_lock) {
ink_mutex_release(&mutex);
@@ -2052,7 +2047,7 @@ ClusterCom::sendReliableMessageReadTillC
address.s_addr = addr;
ink_mutex_acquire(&mutex);
- ink_strncpy(string_addr, inet_ntoa(address), sizeof(string_addr));
+ ink_strlcpy(string_addr, inet_ntoa(address), sizeof(string_addr));
if (ink_hash_table_lookup(peers, string_addr, &hash_value) == 0) {
ink_mutex_release(&mutex);
return false;
@@ -2393,7 +2388,7 @@ checkBackDoor(int req_fd, char *message)
}
// TODO: I think this is correct, it used to do lmgmt->record_data-> ...
if (RecSetRecordConvert(variable, value) == REC_ERR_OKAY) {
- ink_strncpy(reply, "\nRecord Updated\n\n", sizeof(reply));
+ ink_strlcpy(reply, "\nRecord Updated\n\n", sizeof(reply));
mgmt_writeline(req_fd, reply, strlen(reply));
} else {
mgmt_elog("[checkBackDoor] Assignment to unknown variable requested
'%s'\n", variable);
@@ -2417,7 +2412,7 @@ checkBackDoor(int req_fd, char *message)
mgmt_writeline(req_fd, tmp_msg, strlen(tmp_msg));
addr.s_addr = tmp->inet_address;
- ink_strncpy(ip_addr, inet_ntoa(addr), sizeof(ip_addr));
+ ink_strlcpy(ip_addr, inet_ntoa(addr), sizeof(ip_addr));
snprintf(reply, sizeof(reply), "Peer: %s naddrs: %d", ip_addr,
tmp->num_virt_addrs);
mgmt_writeline(req_fd, reply, strlen(reply));
@@ -2438,9 +2433,9 @@ checkBackDoor(int req_fd, char *message)
return true;
} else if (strstr(message, "dump: lm")) {
- ink_strncpy(reply, "---------------------------", sizeof(reply));
+ ink_strlcpy(reply, "---------------------------", sizeof(reply));
mgmt_writeline(req_fd, reply, strlen(reply));
- ink_strncpy(reply, "Local Manager:\n", sizeof(reply));
+ ink_strlcpy(reply, "Local Manager:\n", sizeof(reply));
mgmt_writeline(req_fd, reply, strlen(reply));
snprintf(reply, sizeof(reply), "\tproxy_running: %s",
(lmgmt->proxy_running ? "true" : "false"));
@@ -2477,7 +2472,7 @@ checkBackDoor(int req_fd, char *message)
mgmt_writeline(req_fd, reply, strlen(reply));
#endif
- ink_strncpy(reply, "---------------------------\n", sizeof(reply));
+ ink_strlcpy(reply, "---------------------------\n", sizeof(reply));
mgmt_writeline(req_fd, reply, strlen(reply));
return true;
} else if (strstr(message, "cluster: ")) {
Modified: trafficserver/traffic/trunk/mgmt/cluster/VMap.cc
URL:
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/mgmt/cluster/VMap.cc?rev=1172074&r1=1172073&r2=1172074&view=diff
==============================================================================
--- trafficserver/traffic/trunk/mgmt/cluster/VMap.cc (original)
+++ trafficserver/traffic/trunk/mgmt/cluster/VMap.cc Sat Sep 17 21:53:22 2011
@@ -74,7 +74,7 @@ VMap::init()
// RecordType type;
if (enabled) {
- ink_strncpy(vip_conf, "vip_config", sizeof(vip_conf));
+ ink_strlcpy(vip_conf, "vip_config", sizeof(vip_conf));
snprintf(absolute_vipconf_binary, sizeof(absolute_vipconf_binary),
"%s/%s", lmgmt->bin_path, vip_conf);
/* Make sure vip_config is setuid root */
@@ -320,7 +320,7 @@ VMap::lt_runGambit()
for (i = 0; i < num_addrs; i++) { /* See if there is an unbound
interface */
virtual_addr.s_addr = addr_list[i];
- ink_strncpy(vaddr, inet_ntoa(virtual_addr), sizeof(vaddr));
+ ink_strlcpy(vaddr, inet_ntoa(virtual_addr), sizeof(vaddr));
if (rl_boundAddr(vaddr) == 0) {
mgmt_log(stderr, "[VMap::lt_runGambit] Unmapped vaddr: '%s'\n", vaddr);
break;
@@ -337,7 +337,7 @@ VMap::lt_runGambit()
}
if (init && ((no < num_interfaces) || (no == num_interfaces &&
real_addr.s_addr < our_ip))) {
- ink_strncpy(raddr, inet_ntoa(real_addr), sizeof(raddr));
+ ink_strlcpy(raddr, inet_ntoa(real_addr), sizeof(raddr));
rl_remote_map(vaddr, raddr);
} else if (!rl_map(vaddr)) { /* We are the winner, map it to us */
mgmt_elog(stderr, "[VMap::lt_runGambit] Map failed for vaddr: %s\n",
vaddr);
@@ -350,7 +350,7 @@ VMap::lt_runGambit()
for (i = 0; i < num_addrs; i++) { /* Check for conflicts with your
interfaces */
virtual_addr.s_addr = addr_list[i];
- ink_strncpy(vaddr, inet_ntoa(virtual_addr), sizeof(vaddr));
+ ink_strlcpy(vaddr, inet_ntoa(virtual_addr), sizeof(vaddr));
if ((conf_addr = rl_checkConflict(vaddr))) {
mgmt_log(stderr, "[VMap::lt_runGambit] Conflict w/addr: '%s'\n", vaddr);
@@ -437,13 +437,8 @@ VMap::lt_readAListFile(char *data)
tmp_val = (VIPInfo *)ats_malloc(sizeof(VIPInfo));
- strncpy(tmp_val->interface, tmp_interface, MAX_INTERFACE - 2);
- strncpy(tmp_val->sub_interface_id, tmp_id, MAX_SUB_ID - 2);
-
- tmp_val->interface[MAX_INTERFACE - 1] = '\0';
- tmp_val->sub_interface_id[MAX_SUB_ID - 1] = '\0';
-
-
+ ink_strlcpy(tmp_val->interface, tmp_interface, sizeof(tmp_val->interface));
+ ink_strlcpy(tmp_val->sub_interface_id, tmp_id,
sizeof(tmp_val->sub_interface_id));
ink_hash_table_insert(id_map, tmp_addr, (void *) tmp_val);
// we don't need to do mgmt ping stuff on NT the way its done on UNIX
@@ -581,7 +576,7 @@ VMap::rl_map(char *virt_ip, char *real_i
snprintf(buf, sizeof(buf), "%s %s", virt_ip, real_ip);
} else {
tmp = our_map;
- ink_strncpy(buf, virt_ip, sizeof(buf));
+ ink_strlcpy(buf, virt_ip, sizeof(buf));
}
if (ink_hash_table_lookup(tmp, buf, &hash_value) != 0) {
@@ -618,7 +613,7 @@ VMap::rl_unmap(char *virt_ip, char *real
snprintf(buf, sizeof(buf), "%s %s", virt_ip, real_ip);
} else {
tmp = our_map;
- ink_strncpy(buf, virt_ip, sizeof(buf));
+ ink_strlcpy(buf, virt_ip, sizeof(buf));
}
if (ink_hash_table_lookup(tmp, buf, &hash_value) == 0) {
@@ -671,18 +666,15 @@ VMap::rl_checkConflict(char *virt_ip)
}
if (in_our_map && in_ext_map) {
- char *buf, buf2[80], *buf3;
+ char *buf, buf2[80];
if ((buf = strstr(key, " ")) != NULL) {
buf++;
- ink_strncpy(buf2, buf, sizeof(buf2));
+ ink_strlcpy(buf2, buf, sizeof(buf2));
} else {
mgmt_fatal(stderr, "[VMap::rl_checkConflict] Corrupt VMap entry('%s'),
bailing\n", key);
}
- size_t buf3_len = strlen(buf2) * sizeof(char) + 1;
- buf3 = (char *)ats_malloc(buf3_len);
- ink_strncpy(buf3, buf2, buf3_len);
- return buf3;
+ return ats_strdup(buf2);
}
return NULL;
} /* End VMap::rl_checkConflict */
@@ -773,7 +765,7 @@ VMap::rl_remap(char *virt_ip, char *cur_
struct in_addr addr;
addr.s_addr = our_ip;
- ink_strncpy(buf, inet_ntoa(addr), sizeof(buf));
+ ink_strlcpy(buf, inet_ntoa(addr), sizeof(buf));
tmp = our_map;
}
@@ -862,7 +854,7 @@ VMap::rl_boundTo(char *virt_ip)
char *buf, buf2[80];
if ((buf = strstr(key, " ")) != NULL) {
buf++;
- ink_strncpy(buf2, buf, sizeof(buf2));
+ ink_strlcpy(buf2, buf, sizeof(buf2));
} else {
mgmt_fatal(stderr, "[VMap::rl_boundTo] Corrupt VMap entry('%s'),
bailing\n", key);
}
@@ -897,7 +889,7 @@ VMap::lt_constructVMapMessage(char *ip,
return;
}
- ink_strncpy(&message[n], "type: vmap\n", max - n);
+ ink_strlcpy(&message[n], "type: vmap\n", max - n);
n += strlen("type: vmap\n");
bsum = n;
@@ -912,7 +904,7 @@ VMap::lt_constructVMapMessage(char *ip,
if (!((n + (int) strlen(buf)) < max)) {
break;
}
- ink_strncpy(&message[n], buf, max - n);
+ ink_strlcpy(&message[n], buf, max - n);
n += strlen(buf);
}
ink_mutex_release(mutex);
@@ -924,7 +916,7 @@ VMap::lt_constructVMapMessage(char *ip,
}
return;
}
- ink_strncpy(&message[n], "virt: none\n", max - n);
+ ink_strlcpy(&message[n], "virt: none\n", max - n);
n += strlen("virt: none\n");
}
return;
@@ -947,9 +939,9 @@ VMap::rl_rebalance()
low = lmgmt->ccom->lowestPeer(&naddr_low);
high = lmgmt->ccom->highestPeer(&naddr_high);
tmp_addr.s_addr = high;
- ink_strncpy(high_ip, inet_ntoa(tmp_addr), sizeof(high_ip));
+ ink_strlcpy(high_ip, inet_ntoa(tmp_addr), sizeof(high_ip));
tmp_addr.s_addr = low;
- ink_strncpy(low_ip, inet_ntoa(tmp_addr), sizeof(low_ip));
+ ink_strlcpy(low_ip, inet_ntoa(tmp_addr), sizeof(low_ip));
if (naddr_low == -1 || naddr_high == -1) {
return;
@@ -959,12 +951,12 @@ VMap::rl_rebalance()
naddr_low = num_interfaces;
tmp_addr.s_addr = our_ip;
low = our_ip;
- ink_strncpy(low_ip, inet_ntoa(tmp_addr), sizeof(low_ip));
+ ink_strlcpy(low_ip, inet_ntoa(tmp_addr), sizeof(low_ip));
} else if (naddr_high<num_interfaces || (naddr_high == num_interfaces &&
our_ip> high)) {
naddr_high = num_interfaces;
tmp_addr.s_addr = our_ip;
high = our_ip;
- ink_strncpy(high_ip, inet_ntoa(tmp_addr), sizeof(high_ip));
+ ink_strlcpy(high_ip, inet_ntoa(tmp_addr), sizeof(high_ip));
}
#ifdef DEBUG_VMAP
Debug("vmap",
@@ -982,7 +974,7 @@ VMap::rl_rebalance()
entry = ink_hash_table_iterator_first(our_map, &iterator_state);
key = (char *) ink_hash_table_entry_key(ext_map, entry);
- ink_strncpy(tmp_key, key, sizeof(tmp_key));
+ ink_strlcpy(tmp_key, key, sizeof(tmp_key));
mgmt_log(stderr, "[VMap::rl_rebalance] Remapping vaddr: '%s' from: '%s'
to: '%s'\n", key, high_ip, low_ip);
if (!rl_remap(key, high_ip, low_ip, naddr_high, naddr_low)) {
@@ -1135,7 +1127,7 @@ VMap::rl_downAddrs()
char str_addr[1024];
struct in_addr address;
address.s_addr = addr_list[i];
- ink_strncpy(str_addr, inet_ntoa(address), sizeof(str_addr));
+ ink_strlcpy(str_addr, inet_ntoa(address), sizeof(str_addr));
rl_unmap(str_addr);
}
return;
@@ -1156,7 +1148,7 @@ VMap::downAddrs()
char str_addr[1024];
struct in_addr address;
address.s_addr = addr_list[i];
- ink_strncpy(str_addr, inet_ntoa(address), sizeof(str_addr));
+ ink_strlcpy(str_addr, inet_ntoa(address), sizeof(str_addr));
downAddr(str_addr);
ink_hash_table_delete(our_map, str_addr); /* Make sure removed */
}
@@ -1194,7 +1186,7 @@ VMap::downOurAddrs()
char str_addr[1024];
struct in_addr address;
address.s_addr = addr_list[i];
- ink_strncpy(str_addr, inet_ntoa(address), sizeof(str_addr));
+ ink_strlcpy(str_addr, inet_ntoa(address), sizeof(str_addr));
downAddr(str_addr);
ink_hash_table_delete(our_map, str_addr); /* Make sure removed */
}