From: Yang Bai <hamo.by@gmail.com>
To: penberg@kernel.org
Cc: kvm@vger.kernel.org, Yang Bai <hamo.by@gmail.com>
Subject: [PATCH 3/4] kvm tool: if kvm_ipc__start failed, return negative
Date: Fri, 10 Feb 2012 17:55:35 +0800 [thread overview]
Message-ID: <1328867736-4394-3-git-send-email-hamo.by@gmail.com> (raw)
In-Reply-To: <1328867736-4394-1-git-send-email-hamo.by@gmail.com>
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 <hamo.by@gmail.com>
---
tools/kvm/kvm-ipc.c | 38 ++++++++++++++++++++++++++++++++------
tools/kvm/kvm.c | 7 ++++++-
2 files changed, 38 insertions(+), 7 deletions(-)
diff --git a/tools/kvm/kvm-ipc.c b/tools/kvm/kvm-ipc.c
index 6a0bd21..257c806c 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 192d70e..f02d5df 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;
--
1.7.8.3
next prev parent reply other threads:[~2012-02-10 9:57 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-10 9:55 [PATCH 1/4] kvm tool: Stop init if check_extensions failed Yang Bai
2012-02-10 9:55 ` [PATCH 2/4] kvm tool: unite the error handle in kvm__init Yang Bai
2012-02-10 9:55 ` Yang Bai [this message]
2012-02-10 9:55 ` [PATCH 4/4] kvm tool: ensure kvm_ipc__register_handler success Yang Bai
2012-02-10 11:38 ` [PATCH 1/4] kvm tool: Stop init if check_extensions failed Pekka Enberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1328867736-4394-3-git-send-email-hamo.by@gmail.com \
--to=hamo.by@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=penberg@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox