On Tue, Apr 28, 2009 at 11:31:56AM -0400, Cole Robinson wrote:
By checking the pid every retry period, we can quickly determine if
the process crashed at startup, rather than make the user wait for
the entire timeout (3 seconds).
ACK, this looks good.
---
src/qemu_driver.c | 33 ++++++++++++++++++++++-----------
1 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/src/qemu_driver.c b/src/qemu_driver.c
index 2f17f6c..04df8ae 100644
--- a/src/qemu_driver.c
+++ b/src/qemu_driver.c
@@ -744,29 +744,40 @@ qemudReadLogOutput(virConnectPtr conn,
int timeout)
{
int retries = timeout*10;
+ int got = 0;
buf[0] = '\0';
while (retries) {
ssize_t ret;
- size_t got = 0;
+ int isdead = 0;
- while((ret = read(fd, buf+got, buflen-got-1)) > 0) {
- got += ret;
- buf[got] = '\0';
- if ((buflen-got-1) == 0) {
- qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("Out of space while reading %s log
output"), what);
- return -1;
- }
- }
+ if (kill(vm->pid, 0) == -1 && errno == ESRCH)
+ isdead = 1;
- if (ret < 0 && errno != EINTR) {
+ ret = saferead(fd, buf+got, buflen-got-1);
+ if (ret < 0) {
virReportSystemError(conn, errno,
_("Failure while reading %s log output"),
what);
return -1;
}
+ got += ret;
+ buf[got] = '\0';
+ if (got == buflen-1) {
+ qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ _("Out of space while reading %s log output"),
+ what);
+ return -1;
+ }
+
+ if (isdead) {
+ qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ _("Process exited while reading %s log output"),
+ what);
+ return -1;
+ }
+
ret = func(conn, vm, buf, fd);
if (ret <= 0)
return ret;
--
Daniel
--
|: Red Hat, Engineering, London -o-
http://people.redhat.com/berrange/ :|
|:
http://libvirt.org -o-
http://virt-manager.org -o-
http://ovirt.org :|
|:
http://autobuild.org -o-
http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|