]> xenbits.xensource.com Git - libvirt.git/commitdiff
xenDaemonDomainSetAutostart: avoid appearance of impropriety
authorJim Meyering <meyering@redhat.com>
Wed, 17 Feb 2010 21:14:25 +0000 (22:14 +0100)
committerJim Meyering <meyering@redhat.com>
Fri, 19 Feb 2010 10:52:04 +0000 (11:52 +0100)
* src/xen/xend_internal.c (xenDaemonDomainSetAutostart): Rewrite to
avoid dereferencing the result of sexpr_lookup.  While in this
particular case, it was guaranteed never to be NULL, due to the
preceding "if sexpr_node(...)" guard, it's cleaner to skip the
sexpr_node call altogether, and also saves a lookup.

src/xen/xend_internal.c

index 88923c84248a0c553d3063cbe86666e3c4629cef..1f8b1065b45d99bb8c3ae00824cb8e25146bdddd 100644 (file)
@@ -4383,7 +4383,6 @@ xenDaemonDomainSetAutostart(virDomainPtr domain,
                             int autostart)
 {
     struct sexpr *root, *autonode;
-    const char *autostr;
     char buf[4096];
     int ret = -1;
     xenUnifiedPrivatePtr priv;
@@ -4408,16 +4407,17 @@ xenDaemonDomainSetAutostart(virDomainPtr domain,
         return (-1);
     }
 
-    autostr = sexpr_node(root, "domain/on_xend_start");
-    if (autostr) {
-        if (!STREQ(autostr, "ignore") && !STREQ(autostr, "start")) {
+    autonode = sexpr_lookup(root, "domain/on_xend_start");
+    if (autonode) {
+        const char *val = (autonode->u.s.car->kind == SEXPR_VALUE
+                           ? autonode->u.s.car->u.value : NULL);
+        if (!STREQ(val, "ignore") && !STREQ(val, "start")) {
             virXendError(domain->conn, VIR_ERR_INTERNAL_ERROR,
                          "%s", _("unexpected value from on_xend_start"));
             goto error;
         }
 
         // Change the autostart value in place, then define the new sexpr
-        autonode = sexpr_lookup(root, "domain/on_xend_start");
         VIR_FREE(autonode->u.s.car->u.value);
         autonode->u.s.car->u.value = (autostart ? strdup("start")
                                                 : strdup("ignore"));