diff options
Diffstat (limited to 'tools/hv/hv_kvp_daemon.c')
-rw-r--r-- | tools/hv/hv_kvp_daemon.c | 58 |
1 files changed, 43 insertions, 15 deletions
diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c index 5a1f6489d185..ca9fa4d32e07 100644 --- a/tools/hv/hv_kvp_daemon.c +++ b/tools/hv/hv_kvp_daemon.c | |||
@@ -127,7 +127,8 @@ static void kvp_acquire_lock(int pool) | |||
127 | fl.l_pid = getpid(); | 127 | fl.l_pid = getpid(); |
128 | 128 | ||
129 | if (fcntl(kvp_file_info[pool].fd, F_SETLKW, &fl) == -1) { | 129 | if (fcntl(kvp_file_info[pool].fd, F_SETLKW, &fl) == -1) { |
130 | syslog(LOG_ERR, "Failed to acquire the lock pool: %d", pool); | 130 | syslog(LOG_ERR, "Failed to acquire the lock pool: %d; error: %d %s", pool, |
131 | errno, strerror(errno)); | ||
131 | exit(EXIT_FAILURE); | 132 | exit(EXIT_FAILURE); |
132 | } | 133 | } |
133 | } | 134 | } |
@@ -138,8 +139,8 @@ static void kvp_release_lock(int pool) | |||
138 | fl.l_pid = getpid(); | 139 | fl.l_pid = getpid(); |
139 | 140 | ||
140 | if (fcntl(kvp_file_info[pool].fd, F_SETLK, &fl) == -1) { | 141 | if (fcntl(kvp_file_info[pool].fd, F_SETLK, &fl) == -1) { |
141 | perror("fcntl"); | 142 | syslog(LOG_ERR, "Failed to release the lock pool: %d; error: %d %s", pool, |
142 | syslog(LOG_ERR, "Failed to release the lock pool: %d", pool); | 143 | errno, strerror(errno)); |
143 | exit(EXIT_FAILURE); | 144 | exit(EXIT_FAILURE); |
144 | } | 145 | } |
145 | } | 146 | } |
@@ -157,8 +158,9 @@ static void kvp_update_file(int pool) | |||
157 | 158 | ||
158 | filep = fopen(kvp_file_info[pool].fname, "we"); | 159 | filep = fopen(kvp_file_info[pool].fname, "we"); |
159 | if (!filep) { | 160 | if (!filep) { |
161 | syslog(LOG_ERR, "Failed to open file, pool: %d; error: %d %s", pool, | ||
162 | errno, strerror(errno)); | ||
160 | kvp_release_lock(pool); | 163 | kvp_release_lock(pool); |
161 | syslog(LOG_ERR, "Failed to open file, pool: %d", pool); | ||
162 | exit(EXIT_FAILURE); | 164 | exit(EXIT_FAILURE); |
163 | } | 165 | } |
164 | 166 | ||
@@ -188,8 +190,9 @@ static void kvp_update_mem_state(int pool) | |||
188 | 190 | ||
189 | filep = fopen(kvp_file_info[pool].fname, "re"); | 191 | filep = fopen(kvp_file_info[pool].fname, "re"); |
190 | if (!filep) { | 192 | if (!filep) { |
193 | syslog(LOG_ERR, "Failed to open file, pool: %d; error: %d %s", pool, | ||
194 | errno, strerror(errno)); | ||
191 | kvp_release_lock(pool); | 195 | kvp_release_lock(pool); |
192 | syslog(LOG_ERR, "Failed to open file, pool: %d", pool); | ||
193 | exit(EXIT_FAILURE); | 196 | exit(EXIT_FAILURE); |
194 | } | 197 | } |
195 | for (;;) { | 198 | for (;;) { |
@@ -240,7 +243,8 @@ static int kvp_file_init(void) | |||
240 | 243 | ||
241 | if (access(KVP_CONFIG_LOC, F_OK)) { | 244 | if (access(KVP_CONFIG_LOC, F_OK)) { |
242 | if (mkdir(KVP_CONFIG_LOC, 0755 /* rwxr-xr-x */)) { | 245 | if (mkdir(KVP_CONFIG_LOC, 0755 /* rwxr-xr-x */)) { |
243 | syslog(LOG_ERR, " Failed to create %s", KVP_CONFIG_LOC); | 246 | syslog(LOG_ERR, "Failed to create '%s'; error: %d %s", KVP_CONFIG_LOC, |
247 | errno, strerror(errno)); | ||
244 | exit(EXIT_FAILURE); | 248 | exit(EXIT_FAILURE); |
245 | } | 249 | } |
246 | } | 250 | } |
@@ -257,12 +261,15 @@ static int kvp_file_init(void) | |||
257 | 261 | ||
258 | 262 | ||
259 | filep = fopen(fname, "re"); | 263 | filep = fopen(fname, "re"); |
260 | if (!filep) | 264 | if (!filep) { |
265 | close(fd); | ||
261 | return 1; | 266 | return 1; |
267 | } | ||
262 | 268 | ||
263 | record = malloc(alloc_unit * num_blocks); | 269 | record = malloc(alloc_unit * num_blocks); |
264 | if (record == NULL) { | 270 | if (record == NULL) { |
265 | fclose(filep); | 271 | fclose(filep); |
272 | close(fd); | ||
266 | return 1; | 273 | return 1; |
267 | } | 274 | } |
268 | for (;;) { | 275 | for (;;) { |
@@ -286,6 +293,7 @@ static int kvp_file_init(void) | |||
286 | num_blocks); | 293 | num_blocks); |
287 | if (record == NULL) { | 294 | if (record == NULL) { |
288 | fclose(filep); | 295 | fclose(filep); |
296 | close(fd); | ||
289 | return 1; | 297 | return 1; |
290 | } | 298 | } |
291 | continue; | 299 | continue; |
@@ -765,7 +773,9 @@ static void kvp_process_ipconfig_file(char *cmd, | |||
765 | break; | 773 | break; |
766 | 774 | ||
767 | x = strchr(p, '\n'); | 775 | x = strchr(p, '\n'); |
768 | *x = '\0'; | 776 | if (x) |
777 | *x = '\0'; | ||
778 | |||
769 | strcat(config_buf, p); | 779 | strcat(config_buf, p); |
770 | strcat(config_buf, ";"); | 780 | strcat(config_buf, ";"); |
771 | } | 781 | } |
@@ -1274,7 +1284,8 @@ static int kvp_set_ip_info(char *if_name, struct hv_kvp_ipaddr_value *new_val) | |||
1274 | file = fopen(if_file, "w"); | 1284 | file = fopen(if_file, "w"); |
1275 | 1285 | ||
1276 | if (file == NULL) { | 1286 | if (file == NULL) { |
1277 | syslog(LOG_ERR, "Failed to open config file"); | 1287 | syslog(LOG_ERR, "Failed to open config file; error: %d %s", |
1288 | errno, strerror(errno)); | ||
1278 | return HV_E_FAIL; | 1289 | return HV_E_FAIL; |
1279 | } | 1290 | } |
1280 | 1291 | ||
@@ -1441,7 +1452,8 @@ int main(void) | |||
1441 | 1452 | ||
1442 | fd = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_CONNECTOR); | 1453 | fd = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_CONNECTOR); |
1443 | if (fd < 0) { | 1454 | if (fd < 0) { |
1444 | syslog(LOG_ERR, "netlink socket creation failed; error:%d", fd); | 1455 | syslog(LOG_ERR, "netlink socket creation failed; error: %d %s", errno, |
1456 | strerror(errno)); | ||
1445 | exit(EXIT_FAILURE); | 1457 | exit(EXIT_FAILURE); |
1446 | } | 1458 | } |
1447 | addr.nl_family = AF_NETLINK; | 1459 | addr.nl_family = AF_NETLINK; |
@@ -1452,12 +1464,18 @@ int main(void) | |||
1452 | 1464 | ||
1453 | error = bind(fd, (struct sockaddr *)&addr, sizeof(addr)); | 1465 | error = bind(fd, (struct sockaddr *)&addr, sizeof(addr)); |
1454 | if (error < 0) { | 1466 | if (error < 0) { |
1455 | syslog(LOG_ERR, "bind failed; error:%d", error); | 1467 | syslog(LOG_ERR, "bind failed; error: %d %s", errno, strerror(errno)); |
1456 | close(fd); | 1468 | close(fd); |
1457 | exit(EXIT_FAILURE); | 1469 | exit(EXIT_FAILURE); |
1458 | } | 1470 | } |
1459 | nl_group = CN_KVP_IDX; | 1471 | nl_group = CN_KVP_IDX; |
1460 | setsockopt(fd, SOL_NETLINK, NETLINK_ADD_MEMBERSHIP, &nl_group, sizeof(nl_group)); | 1472 | |
1473 | if (setsockopt(fd, SOL_NETLINK, NETLINK_ADD_MEMBERSHIP, &nl_group, sizeof(nl_group)) < 0) { | ||
1474 | syslog(LOG_ERR, "setsockopt failed; error: %d %s", errno, strerror(errno)); | ||
1475 | close(fd); | ||
1476 | exit(EXIT_FAILURE); | ||
1477 | } | ||
1478 | |||
1461 | /* | 1479 | /* |
1462 | * Register ourselves with the kernel. | 1480 | * Register ourselves with the kernel. |
1463 | */ | 1481 | */ |
@@ -1472,7 +1490,7 @@ int main(void) | |||
1472 | 1490 | ||
1473 | len = netlink_send(fd, message); | 1491 | len = netlink_send(fd, message); |
1474 | if (len < 0) { | 1492 | if (len < 0) { |
1475 | syslog(LOG_ERR, "netlink_send failed; error:%d", len); | 1493 | syslog(LOG_ERR, "netlink_send failed; error: %d %s", errno, strerror(errno)); |
1476 | close(fd); | 1494 | close(fd); |
1477 | exit(EXIT_FAILURE); | 1495 | exit(EXIT_FAILURE); |
1478 | } | 1496 | } |
@@ -1484,7 +1502,16 @@ int main(void) | |||
1484 | socklen_t addr_l = sizeof(addr); | 1502 | socklen_t addr_l = sizeof(addr); |
1485 | pfd.events = POLLIN; | 1503 | pfd.events = POLLIN; |
1486 | pfd.revents = 0; | 1504 | pfd.revents = 0; |
1487 | poll(&pfd, 1, -1); | 1505 | |
1506 | if (poll(&pfd, 1, -1) < 0) { | ||
1507 | syslog(LOG_ERR, "poll failed; error: %d %s", errno, strerror(errno)); | ||
1508 | if (errno == EINVAL) { | ||
1509 | close(fd); | ||
1510 | exit(EXIT_FAILURE); | ||
1511 | } | ||
1512 | else | ||
1513 | continue; | ||
1514 | } | ||
1488 | 1515 | ||
1489 | len = recvfrom(fd, kvp_recv_buffer, sizeof(kvp_recv_buffer), 0, | 1516 | len = recvfrom(fd, kvp_recv_buffer, sizeof(kvp_recv_buffer), 0, |
1490 | addr_p, &addr_l); | 1517 | addr_p, &addr_l); |
@@ -1695,7 +1722,8 @@ kvp_done: | |||
1695 | 1722 | ||
1696 | len = netlink_send(fd, incoming_cn_msg); | 1723 | len = netlink_send(fd, incoming_cn_msg); |
1697 | if (len < 0) { | 1724 | if (len < 0) { |
1698 | syslog(LOG_ERR, "net_link send failed; error:%d", len); | 1725 | syslog(LOG_ERR, "net_link send failed; error: %d %s", errno, |
1726 | strerror(errno)); | ||
1699 | exit(EXIT_FAILURE); | 1727 | exit(EXIT_FAILURE); |
1700 | } | 1728 | } |
1701 | } | 1729 | } |