WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] Fix race between xspy_read_watch and xspy_watch, by plac

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] Fix race between xspy_read_watch and xspy_watch, by placing the watch in the
From: Xen patchbot -unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Tue, 15 Nov 2005 21:16:17 +0000
Delivery-date: Tue, 15 Nov 2005 21:18:07 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User emellor@xxxxxxxxxxxxxxxxxxxxxx
# Node ID a064c5804eae2893bd19597116c31c41f1a25d41
# Parent  bb0e5f7f94fd186868b68379aeb81938a1967d25
Fix race between xspy_read_watch and xspy_watch, by placing the watch in the
xshandle's list of watches *before* registering the watch with Xend.

Closes bug #392.

Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx>

diff -r bb0e5f7f94fd -r a064c5804eae tools/python/xen/lowlevel/xs/xs.c
--- a/tools/python/xen/lowlevel/xs/xs.c Tue Nov 15 15:24:31 2005
+++ b/tools/python/xen/lowlevel/xs/xs.c Tue Nov 15 16:22:04 2005
@@ -16,7 +16,7 @@
  *
  * Copyright (C) 2005 Mike Wray Hewlett-Packard
  * Copyright (C) 2005 Christian Limpach <Christian.Limpach@xxxxxxxxxxxx>
- *
+ * Copyright (C) 2005 XenSource Ltd.
  */
 
 #include <Python.h>
@@ -453,25 +453,20 @@
 
     XsHandle *xsh = (XsHandle *)self;
     struct xs_handle *xh = xshandle(self);
-    PyObject *val = NULL;
     int xsval = 0;
 
     if (!xh)
-        goto exit;
+        return NULL;
     if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec, 
                                      &path, &token))
-        goto exit;
+        return NULL;
+
+    /* Note that we have to store the watch token in the xs->watches list
+       before registering the watch with xs_watch, otherwise this function
+       races with xs_read_watch.
+    */
+
     Py_INCREF(token);
-    sprintf(token_str, "%li", (unsigned long)token);
-    Py_BEGIN_ALLOW_THREADS
-    xsval = xs_watch(xh, path, token_str);
-    Py_END_ALLOW_THREADS
-    if (!xsval) {
-        PyErr_SetFromErrno(PyExc_RuntimeError);
-        Py_DECREF(token);
-        goto exit;
-    }
-
     for (i = 0; i < PyList_Size(xsh->watches); i++) {
         if (PyList_GetItem(xsh->watches, i) == Py_None) {
             PyList_SetItem(xsh->watches, i, token);
@@ -480,10 +475,26 @@
     }
     if (i == PyList_Size(xsh->watches))
         PyList_Append(xsh->watches, token);
+
+    sprintf(token_str, "%li", (unsigned long)token);
+    Py_BEGIN_ALLOW_THREADS
+    xsval = xs_watch(xh, path, token_str);
+    Py_END_ALLOW_THREADS
+    if (!xsval) {
+        for (i = 0; i < PyList_Size(xsh->watches); i++) {
+            if (PyList_GetItem(xsh->watches, i) == token) {
+                Py_INCREF(Py_None);
+                PyList_SetItem(xsh->watches, i,  Py_None);
+                break;
+            }
+        }
+
+        PyErr_SetFromErrno(PyExc_RuntimeError);
+        return NULL;
+    }
+
     Py_INCREF(Py_None);
-    val = Py_None;
- exit:
-    return val;
+    return Py_None;
 }
 
 #define xspy_read_watch_doc "\n"                               \
@@ -944,3 +955,11 @@
 
     module = Py_InitModule(PYPKG, xs_methods);
 }
+
+
+/*
+ * Local variables:
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
+ * End:
+ */

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] Fix race between xspy_read_watch and xspy_watch, by placing the watch in the, Xen patchbot -unstable <=