Commit 12e50c30 authored by Tomas Hozza's avatar Tomas Hozza Committed by Greg Kroah-Hartman
Browse files

tools: hv: Improve error logging in KVP daemon.



Use errno and strerror() when logging errors to provide
more information.

Signed-off-by: default avatarTomas Hozza <thozza@redhat.com>
Signed-off-by: default avatarK. Y. Srinivasan <kys@microsoft.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 0e496b8e
Loading
Loading
Loading
Loading
+18 −11
Original line number Diff line number Diff line
@@ -127,7 +127,8 @@ static void kvp_acquire_lock(int pool)
	fl.l_pid = getpid();

	if (fcntl(kvp_file_info[pool].fd, F_SETLKW, &fl) == -1) {
		syslog(LOG_ERR, "Failed to acquire the lock pool: %d", pool);
		syslog(LOG_ERR, "Failed to acquire the lock pool: %d; error: %d %s", pool,
				errno, strerror(errno));
		exit(EXIT_FAILURE);
	}
}
@@ -138,8 +139,8 @@ static void kvp_release_lock(int pool)
	fl.l_pid = getpid();

	if (fcntl(kvp_file_info[pool].fd, F_SETLK, &fl) == -1) {
		perror("fcntl");
		syslog(LOG_ERR, "Failed to release the lock pool: %d", pool);
		syslog(LOG_ERR, "Failed to release the lock pool: %d; error: %d %s", pool,
				errno, strerror(errno));
		exit(EXIT_FAILURE);
	}
}
@@ -157,8 +158,9 @@ static void kvp_update_file(int pool)

	filep = fopen(kvp_file_info[pool].fname, "we");
	if (!filep) {
		syslog(LOG_ERR, "Failed to open file, pool: %d; error: %d %s", pool,
				errno, strerror(errno));
		kvp_release_lock(pool);
		syslog(LOG_ERR, "Failed to open file, pool: %d", pool);
		exit(EXIT_FAILURE);
	}

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

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

	if (access(KVP_CONFIG_LOC, F_OK)) {
		if (mkdir(KVP_CONFIG_LOC, 0755 /* rwxr-xr-x */)) {
			syslog(LOG_ERR, " Failed to create %s", KVP_CONFIG_LOC);
			syslog(LOG_ERR, "Failed to create '%s'; error: %d %s", KVP_CONFIG_LOC,
					errno, strerror(errno));
			exit(EXIT_FAILURE);
		}
	}
@@ -1280,7 +1284,8 @@ static int kvp_set_ip_info(char *if_name, struct hv_kvp_ipaddr_value *new_val)
	file = fopen(if_file, "w");

	if (file == NULL) {
		syslog(LOG_ERR, "Failed to open config file");
		syslog(LOG_ERR, "Failed to open config file; error: %d %s",
				errno, strerror(errno));
		return HV_E_FAIL;
	}

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

	fd = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_CONNECTOR);
	if (fd < 0) {
		syslog(LOG_ERR, "netlink socket creation failed; error:%d", fd);
		syslog(LOG_ERR, "netlink socket creation failed; error: %d %s", errno,
				strerror(errno));
		exit(EXIT_FAILURE);
	}
	addr.nl_family = AF_NETLINK;
@@ -1458,7 +1464,7 @@ int main(void)

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

	len = netlink_send(fd, message);
	if (len < 0) {
		syslog(LOG_ERR, "netlink_send failed; error:%d", len);
		syslog(LOG_ERR, "netlink_send failed; error: %d %s", errno, strerror(errno));
		close(fd);
		exit(EXIT_FAILURE);
	}
@@ -1716,7 +1722,8 @@ kvp_done:

		len = netlink_send(fd, incoming_cn_msg);
		if (len < 0) {
			syslog(LOG_ERR, "net_link send failed; error:%d", len);
			syslog(LOG_ERR, "net_link send failed; error: %d %s", errno,
					strerror(errno));
			exit(EXIT_FAILURE);
		}
	}