add some checking of opening and read in dom0_init and return -1 if error.
authorvhanquez@kneesa.uk.xensource.com <vhanquez@kneesa.uk.xensource.com>
Tue, 24 Jan 2006 13:14:42 +0000 (13:14 +0000)
committervhanquez@kneesa.uk.xensource.com <vhanquez@kneesa.uk.xensource.com>
Tue, 24 Jan 2006 13:14:42 +0000 (13:14 +0000)
instead of crashing, it now prints a more meaningful error message.

Signed-off-by: Vincent Hanquez <vincent@xensource.com>
tools/xenstore/xenstored_domain.c

index 353ef9b7ac3dc15a8325d419c02bfb05975a2455..cf862e4b8bcabe2dbccad0b1b413e90a63debedc 100644 (file)
@@ -468,28 +468,38 @@ static int dom0_init(void)
         struct domain *dom0; 
         
         fd = open(XENSTORED_PROC_MFN, O_RDONLY); 
+       if (fd == -1)
+               return -1;
         
         rc = read(fd, str, sizeof(str)); 
+       if (rc == -1)
+               goto outfd;
         str[rc] = '\0'; 
         mfn = strtoul(str, NULL, 0); 
         
         close(fd); 
         
         fd = open(XENSTORED_PROC_PORT, O_RDONLY); 
+       if (fd == -1)
+               return -1;
         
         rc = read(fd, str, sizeof(str)); 
+       if (rc == -1)
+               goto outfd;
         str[rc] = '\0'; 
         port = strtoul(str, NULL, 0); 
         
         close(fd); 
         
-        
         dom0 = new_domain(NULL, 0, mfn, port); 
         talloc_steal(dom0->conn, dom0); 
 
         evtchn_notify(dom0->port); 
 
         return 0; 
+outfd:
+       close(fd);
+       return -1;
 }