Skip to content

Commit 12e50c3

Browse files
thozzagregkh
authored andcommitted
tools: hv: Improve error logging in KVP daemon.
Use errno and strerror() when logging errors to provide more information. Signed-off-by: Tomas Hozza <thozza@redhat.com> Signed-off-by: K. Y. Srinivasan <kys@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 0e496b8 commit 12e50c3

1 file changed

Lines changed: 18 additions & 11 deletions

File tree

‎tools/hv/hv_kvp_daemon.c‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ static void kvp_acquire_lock(int pool)
127127
fl.l_pid = getpid();
128128

129129
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));
131132
exit(EXIT_FAILURE);
132133
}
133134
}
@@ -138,8 +139,8 @@ static void kvp_release_lock(int pool)
138139
fl.l_pid = getpid();
139140

140141
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", pool);
142+
syslog(LOG_ERR, "Failed to release the lock pool: %d; error: %d %s", pool,
143+
errno, strerror(errno));
143144
exit(EXIT_FAILURE);
144145
}
145146
}
@@ -157,8 +158,9 @@ static void kvp_update_file(int pool)
157158

158159
filep = fopen(kvp_file_info[pool].fname, "we");
159160
if (!filep) {
161+
syslog(LOG_ERR, "Failed to open file, pool: %d; error: %d %s", pool,
162+
errno, strerror(errno));
160163
kvp_release_lock(pool);
161-
syslog(LOG_ERR, "Failed to open file, pool: %d", pool);
162164
exit(EXIT_FAILURE);
163165
}
164166

@@ -188,8 +190,9 @@ static void kvp_update_mem_state(int pool)
188190

189191
filep = fopen(kvp_file_info[pool].fname, "re");
190192
if (!filep) {
193+
syslog(LOG_ERR, "Failed to open file, pool: %d; error: %d %s", pool,
194+
errno, strerror(errno));
191195
kvp_release_lock(pool);
192-
syslog(LOG_ERR, "Failed to open file, pool: %d", pool);
193196
exit(EXIT_FAILURE);
194197
}
195198
for (;;) {
@@ -240,7 +243,8 @@ static int kvp_file_init(void)
240243

241244
if (access(KVP_CONFIG_LOC, F_OK)) {
242245
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));
244248
exit(EXIT_FAILURE);
245249
}
246250
}
@@ -1280,7 +1284,8 @@ static int kvp_set_ip_info(char *if_name, struct hv_kvp_ipaddr_value *new_val)
12801284
file = fopen(if_file, "w");
12811285

12821286
if (file == NULL) {
1283-
syslog(LOG_ERR, "Failed to open config file");
1287+
syslog(LOG_ERR, "Failed to open config file; error: %d %s",
1288+
errno, strerror(errno));
12841289
return HV_E_FAIL;
12851290
}
12861291

@@ -1447,7 +1452,8 @@ int main(void)
14471452

14481453
fd = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_CONNECTOR);
14491454
if (fd < 0) {
1450-
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));
14511457
exit(EXIT_FAILURE);
14521458
}
14531459
addr.nl_family = AF_NETLINK;
@@ -1458,7 +1464,7 @@ int main(void)
14581464

14591465
error = bind(fd, (struct sockaddr *)&addr, sizeof(addr));
14601466
if (error < 0) {
1461-
syslog(LOG_ERR, "bind failed; error:%d", error);
1467+
syslog(LOG_ERR, "bind failed; error: %d %s", errno, strerror(errno));
14621468
close(fd);
14631469
exit(EXIT_FAILURE);
14641470
}
@@ -1484,7 +1490,7 @@ int main(void)
14841490

14851491
len = netlink_send(fd, message);
14861492
if (len < 0) {
1487-
syslog(LOG_ERR, "netlink_send failed; error:%d", len);
1493+
syslog(LOG_ERR, "netlink_send failed; error: %d %s", errno, strerror(errno));
14881494
close(fd);
14891495
exit(EXIT_FAILURE);
14901496
}
@@ -1716,7 +1722,8 @@ int main(void)
17161722

17171723
len = netlink_send(fd, incoming_cn_msg);
17181724
if (len < 0) {
1719-
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));
17201727
exit(EXIT_FAILURE);
17211728
}
17221729
}

0 commit comments

Comments
 (0)