mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-26 15:31:35 +00:00
tools: acrn-manager: Replace pdebug with explicit err msg
pdebug just provide information about function name and source code line number. From debug point of view, it is better to give developer more detailed err msg. Tracked-On: #2716 Signed-off-by: Kaige Fu <kaige.fu@intel.com> Acked-by: Yan, Like <like.yan@intel.com>
This commit is contained in:
parent
48774f716f
commit
d5ec844f86
@ -34,7 +34,6 @@ static int check_dir(const char *path)
|
||||
if (S_ISDIR(st.st_mode))
|
||||
return 0;
|
||||
|
||||
pdebug();
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -95,13 +94,13 @@ static struct mngr_client *mngr_client_new(struct mngr_fd *mfd)
|
||||
|
||||
client = calloc(1, sizeof(*client));
|
||||
if (!client) {
|
||||
pdebug();
|
||||
printf("%s: Failed to alloc mem for client\n", __func__);
|
||||
goto alloc_client;
|
||||
}
|
||||
|
||||
client->buf = calloc(1, CLIENT_BUF_LEN);
|
||||
if (!client->buf) {
|
||||
pdebug();
|
||||
printf("%s: Failed to alloc mem for client buf\n", __func__);
|
||||
goto alloc_buf;
|
||||
}
|
||||
|
||||
@ -110,7 +109,7 @@ static struct mngr_client *mngr_client_new(struct mngr_fd *mfd)
|
||||
accept(mfd->fd, (struct sockaddr *)&client->addr,
|
||||
&client->addr_len);
|
||||
if (client->fd < 0) {
|
||||
pdebug();
|
||||
printf("%s: Failed to accept from fd %d, err: %s\n", __func__, mfd->fd, strerror(errno));
|
||||
goto accept_con;
|
||||
}
|
||||
|
||||
@ -190,7 +189,7 @@ static int server_parse_buf(struct mngr_fd *mfd, struct mngr_client *client)
|
||||
|
||||
/* do we out-of-boundary? */
|
||||
if (p + sizeof(struct mngr_msg) > client->len) {
|
||||
pdebug();
|
||||
printf("%s: Out of boundary, client len: %d, p: %lu\n", __func__, client->len, p);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -318,7 +317,7 @@ static int create_new_server(const char *name)
|
||||
unlink(path);
|
||||
mfd->fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (mfd->fd < 0) {
|
||||
pdebug();
|
||||
printf("%s: Failed to call socket, err: %s\n", __func__, strerror(errno));
|
||||
ret = mfd->fd;
|
||||
goto sock_err;
|
||||
}
|
||||
@ -327,7 +326,7 @@ static int create_new_server(const char *name)
|
||||
|
||||
ret = bind(mfd->fd, (struct sockaddr *)&mfd->addr, sizeof(mfd->addr));
|
||||
if (ret < 0) {
|
||||
pdebug();
|
||||
printf("%s: Failed to bind fd %d, err: %s\n", __func__, mfd->fd, strerror(errno));
|
||||
goto bind_err;
|
||||
}
|
||||
listen(mfd->fd, 1);
|
||||
@ -337,7 +336,7 @@ static int create_new_server(const char *name)
|
||||
ret =
|
||||
pthread_create(&mfd->listen_thread, NULL, server_listen_func, mfd);
|
||||
if (ret < 0) {
|
||||
pdebug();
|
||||
printf("%s: Failed to create listen_thread, err: %s\n", __func__, strerror(errno));
|
||||
goto listen_err;
|
||||
}
|
||||
pthread_setname_np(mfd->listen_thread, "mngr_listen");
|
||||
@ -346,7 +345,7 @@ static int create_new_server(const char *name)
|
||||
mfd->polling = 1;
|
||||
ret = pthread_create(&mfd->poll_thread, NULL, server_poll_func, mfd);
|
||||
if (ret < 0) {
|
||||
pdebug();
|
||||
printf("%s: Failed to create poll_thread, err: %s\n", __func__, strerror(errno));
|
||||
goto poll_err;
|
||||
}
|
||||
pthread_setname_np(mfd->poll_thread, "mngr_pull");
|
||||
@ -415,7 +414,7 @@ static int connect_to_server(const char *name)
|
||||
|
||||
dir = opendir("/run/acrn/mngr");
|
||||
if (!dir) {
|
||||
pdebug();
|
||||
printf("%s: Failed to open directory /run/acrn/mngr\n", __func__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -433,7 +432,7 @@ static int connect_to_server(const char *name)
|
||||
}
|
||||
|
||||
if (!s_name) {
|
||||
pdebug();
|
||||
printf("%s: Can't find %s\n", __func__, name);
|
||||
closedir(dir);
|
||||
return -1;
|
||||
}
|
||||
@ -495,7 +494,7 @@ int mngr_open_un(const char *name, int flags)
|
||||
check_dir("/run/acrn/mngr");
|
||||
|
||||
if (!name) {
|
||||
pdebug();
|
||||
printf("%s: No socket name configured\n", __func__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -505,7 +504,7 @@ int mngr_open_un(const char *name, int flags)
|
||||
case MNGR_CLIENT:
|
||||
return connect_to_server(name);
|
||||
default:
|
||||
pdebug();
|
||||
printf("%s: Unknow flag %d\n", __func__, flags);
|
||||
}
|
||||
|
||||
return -1;
|
||||
@ -517,7 +516,7 @@ void mngr_close(int val)
|
||||
|
||||
mfd = desc_to_mfd(val);
|
||||
if (!mfd) {
|
||||
pdebug();
|
||||
printf("%s: No mngr_fd binded to fd %d\n", __func__, val);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -533,7 +532,7 @@ void mngr_close(int val)
|
||||
close_client(mfd);
|
||||
break;
|
||||
default:
|
||||
pdebug();
|
||||
printf("%s: Unknown mfd type %d\n", __func__, mfd->type);
|
||||
}
|
||||
|
||||
}
|
||||
@ -547,13 +546,13 @@ int mngr_add_handler(int server_fd, unsigned id,
|
||||
|
||||
mfd = desc_to_mfd(server_fd);
|
||||
if (!mfd) {
|
||||
pdebug();
|
||||
printf("%s: No mngr_fd binded to fd %d\n", __func__, server_fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
handler = calloc(1, sizeof(*handler));
|
||||
if (!handler) {
|
||||
pdebug();
|
||||
printf("%s: Failed to alloc mem for handler\n", __func__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -6,12 +6,6 @@
|
||||
#ifndef ACRN_MANAGER_H
|
||||
#define ACRN_MANAGER_H
|
||||
|
||||
#ifdef MNGR_DEBUG
|
||||
#define pdebug() fprintf(stderr, "%s %d\n", __FUNCTION__, __LINE__)
|
||||
#else
|
||||
#define pdebug() while(0){}
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#define MNGR_MSG_MAGIC 0x67736d206d6d76 /* that is char[8] "mngr msg", on X86 */
|
||||
|
@ -76,7 +76,7 @@ static int query_state(const char *name)
|
||||
|
||||
ret = send_msg(name, &req, &ack);
|
||||
if (ret) {
|
||||
pdebug();
|
||||
printf("%s: Error to quary %s state, err: %d\n", __func__, name, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -133,13 +133,13 @@ static void _scan_alive_vm(void)
|
||||
|
||||
ret = check_dir(ACRN_DM_SOCK_PATH);
|
||||
if (ret) {
|
||||
pdebug();
|
||||
printf("%s: Failed to check directory %s, err: %d\n", __func__, ACRN_DM_SOCK_PATH, ret);
|
||||
return;
|
||||
}
|
||||
|
||||
dir = opendir(ACRN_DM_SOCK_PATH);
|
||||
if (!dir) {
|
||||
pdebug();
|
||||
printf("%s: Failed to open directory %s\n", __func__, ACRN_DM_SOCK_PATH);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -150,9 +150,9 @@ static void _scan_alive_vm(void)
|
||||
continue;
|
||||
|
||||
if (name[sizeof(name) - 1]) {
|
||||
pdebug();
|
||||
/* truncate name and go a head */
|
||||
name[sizeof(name) - 1] = 0;
|
||||
printf("%s: Truncate name as %s\n", __func__, name);
|
||||
}
|
||||
|
||||
vm = vmmngr_find(name);
|
||||
@ -160,7 +160,7 @@ static void _scan_alive_vm(void)
|
||||
if (!vm) {
|
||||
vm = calloc(1, sizeof(*vm));
|
||||
if (!vm) {
|
||||
pdebug();
|
||||
printf("%s: Failed to alloc mem for %s\n", __func__, name);
|
||||
continue;
|
||||
}
|
||||
memcpy(vm->name, name, sizeof(vm->name) - 1);
|
||||
@ -207,9 +207,9 @@ static inline int _get_vmname_suffix(const char *src,
|
||||
|
||||
strncpy(name, src, p - src);
|
||||
if (p - src >= max_len_name) {
|
||||
pdebug();
|
||||
/* truncate name and go a head */
|
||||
name[max_len_name - 1] = '\0';
|
||||
printf("%s: Truncate name as %s\n", __func__, name);
|
||||
}
|
||||
|
||||
strncpy(suffix, p + 1, max_len_suffix);
|
||||
@ -230,26 +230,25 @@ static void _scan_added_vm(void)
|
||||
|
||||
ret = check_dir(ACRN_CONF_PATH);
|
||||
if (ret) {
|
||||
pdebug();
|
||||
printf("%s: Failed to check directory %s, err: %d\n", __func__, ACRN_CONF_PATH, ret);
|
||||
return;
|
||||
}
|
||||
|
||||
ret = check_dir(ACRN_CONF_PATH_ADD);
|
||||
if (ret) {
|
||||
pdebug();
|
||||
printf("%s: Failed to check directory %s, err: %d\n", __func__, ACRN_CONF_PATH_ADD, ret);
|
||||
return;
|
||||
}
|
||||
|
||||
dir = opendir(ACRN_CONF_PATH_ADD);
|
||||
if (!dir) {
|
||||
pdebug();
|
||||
printf("%s: Failed to open directory %s\n", __func__, ACRN_CONF_PATH_ADD);
|
||||
return;
|
||||
}
|
||||
|
||||
while ((entry = readdir(dir))) {
|
||||
ret = strnlen(entry->d_name, sizeof(entry->d_name));
|
||||
if (ret >= sizeof(name)) {
|
||||
pdebug();
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -265,7 +264,7 @@ static void _scan_added_vm(void)
|
||||
if (!vm) {
|
||||
vm = calloc(1, sizeof(*vm));
|
||||
if (!vm) {
|
||||
pdebug();
|
||||
printf("%s: Failed to alloc mem for %s\n", __func__, name);
|
||||
continue;
|
||||
}
|
||||
memcpy(vm->name, name, sizeof(vm->name) - 1);
|
||||
@ -287,7 +286,7 @@ static void _remove_dead_vm(void)
|
||||
if (vm->update == update_count)
|
||||
continue;
|
||||
LIST_REMOVE(vm, list);
|
||||
pdebug();
|
||||
printf("%s: Removed dead %s\n", __func__, vm->name);
|
||||
free(vm);
|
||||
}
|
||||
};
|
||||
|
@ -56,7 +56,7 @@ int acrnd_add_work(void (*func) (struct work_arg *arg),
|
||||
time_t current;
|
||||
|
||||
if (!func) {
|
||||
pdebug();
|
||||
printf("%s: No worker function configured\n", __func__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -124,14 +124,14 @@ void acrnd_vm_timer_func(struct work_arg *arg)
|
||||
struct vmmngr_struct *vm;
|
||||
|
||||
if (!arg) {
|
||||
pdebug();
|
||||
printf("%s: No work argument configured\n", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
vmmngr_update();
|
||||
vm = vmmngr_find(arg->name);
|
||||
if (!vm) {
|
||||
pdebug();
|
||||
printf("%s: Can't find %s\n", __func__, arg->name);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -143,7 +143,7 @@ void acrnd_vm_timer_func(struct work_arg *arg)
|
||||
resume_vm(arg->name, CBC_WK_RSN_RTC);
|
||||
break;
|
||||
default:
|
||||
pdebug();
|
||||
printf("%s: Unknown vm state %ld\n", __func__, vm->state);
|
||||
}
|
||||
}
|
||||
|
||||
@ -259,7 +259,7 @@ static int active_all_vms(void)
|
||||
ret += resume_vm(vm->name, reason);
|
||||
break;
|
||||
default:
|
||||
pdebug();
|
||||
printf("%s: Unkown vm state %ld\n", __func__, vm->state);
|
||||
}
|
||||
}
|
||||
|
||||
@ -343,7 +343,7 @@ static void handle_timer_req(struct mngr_msg *msg, int client_fd, void *param)
|
||||
vmmngr_update();
|
||||
vm = vmmngr_find(msg->data.acrnd_timer.name);
|
||||
if (!vm) {
|
||||
pdebug();
|
||||
printf("%s: Can't find %s\n", __func__, msg->data.acrnd_timer.name);
|
||||
goto reply_ack;
|
||||
}
|
||||
|
||||
@ -354,7 +354,7 @@ static void handle_timer_req(struct mngr_msg *msg, int client_fd, void *param)
|
||||
}
|
||||
|
||||
if (acrnd_add_work(acrnd_vm_timer_func, &arg, msg->data.acrnd_timer.t)) {
|
||||
pdebug();
|
||||
printf("%s: Failed to add acrnd_vm_timer_func\n", __func__);
|
||||
goto reply_ack;
|
||||
}
|
||||
|
||||
@ -673,12 +673,12 @@ int main(int argc, char *argv[])
|
||||
/* create listening thread */
|
||||
acrnd_fd = mngr_open_un(ACRND_NAME, MNGR_SERVER);
|
||||
if (acrnd_fd < 0) {
|
||||
pdebug();
|
||||
printf("%s: Failed to open %s, err: %s\n", __func__, ACRND_NAME, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (init_vm()) {
|
||||
pdebug();
|
||||
printf("%s: Failed to init_vm\n", __func__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user