From: Yang Bai Date: Fri, 10 Feb 2012 09:55:35 +0000 (+0800) Subject: kvm tools: if kvm_ipc__start failed, return negative X-Git-Tag: next-20120402~5^2~12 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=62964f64be8d75170e691f48db820ba98a93dbe2;p=karo-tx-linux.git kvm tools: if kvm_ipc__start failed, return negative If kvm_ipc__start failed, it returns a negative and by checking this return value, we can ensure that it succeeds. Signed-off-by: Yang Bai Signed-off-by: Pekka Enberg --- diff --git a/tools/kvm/kvm-ipc.c b/tools/kvm/kvm-ipc.c index 6a0bd215a817..257c806cf191 100644 --- a/tools/kvm/kvm-ipc.c +++ b/tools/kvm/kvm-ipc.c @@ -166,27 +166,53 @@ static void *kvm_ipc__thread(void *param) int kvm_ipc__start(int sock) { + int ret; struct epoll_event ev = {0}; server_fd = sock; epoll_fd = epoll_create(KVM_IPC_MAX_MSGS); + if (epoll_fd < 0) { + ret = epoll_fd; + goto err; + } ev.events = EPOLLIN | EPOLLET; ev.data.fd = sock; - if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, sock, &ev) < 0) - die("Failed starting IPC thread"); + if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, sock, &ev) < 0) { + pr_err("Failed starting IPC thread"); + ret = -EFAULT; + goto err_epoll; + } stop_fd = eventfd(0, 0); + if (stop_fd < 0) { + ret = stop_fd; + goto err_epoll; + } + ev.events = EPOLLIN | EPOLLET; ev.data.fd = stop_fd; - if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, stop_fd, &ev) < 0) - die("Failed adding stop event to epoll"); + if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, stop_fd, &ev) < 0) { + pr_err("Failed adding stop event to epoll"); + ret = -EFAULT; + goto err_stop; + } - if (pthread_create(&thread, NULL, kvm_ipc__thread, NULL) != 0) - die("Failed starting IPC thread"); + if (pthread_create(&thread, NULL, kvm_ipc__thread, NULL) != 0) { + pr_err("Failed starting IPC thread"); + ret = -EFAULT; + goto err_stop; + } return 0; + +err_stop: + close(stop_fd); +err_epoll: + close(epoll_fd); +err: + return ret; } int kvm_ipc__stop(void) diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c index 192d70eddf84..f02d5dffedc8 100644 --- a/tools/kvm/kvm.c +++ b/tools/kvm/kvm.c @@ -390,7 +390,12 @@ struct kvm *kvm__init(const char *kvm_dev, const char *hugetlbfs_path, u64 ram_s kvm__arch_init(kvm, hugetlbfs_path, ram_size); - kvm_ipc__start(kvm__create_socket(kvm)); + ret = kvm_ipc__start(kvm__create_socket(kvm)); + if (ret < 0) { + pr_err("Starting ipc failed."); + goto err_vm_fd; + } + kvm_ipc__register_handler(KVM_IPC_PID, kvm__pid); return kvm;