# HG changeset patch
# User cl349@xxxxxxxxxxxxxxxxxxxx
# Node ID 4856f000d35d6be0bfb6f5c822e91e9ef7fc885e
# Parent cdfa7dd00c44eaa68b56656d236df5a60df17cf7
Make error reporting consistent.
Also note addition of Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS
which slipped in in previous merge changeset: allow other threads
to run during communication with xenstored.
Signed-off-by: Christian Limpach <Christian.Limpach@xxxxxxxxxxxx>
diff -r cdfa7dd00c44 -r 4856f000d35d tools/python/xen/lowlevel/xs/xs.c
--- a/tools/python/xen/lowlevel/xs/xs.c Fri Sep 9 10:20:25 2005
+++ b/tools/python/xen/lowlevel/xs/xs.c Fri Sep 9 13:08:25 2005
@@ -89,7 +89,7 @@
PyObject *val = NULL;
if (!xh)
- goto exit;
+ goto exit;
if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec,
&path))
goto exit;
@@ -97,13 +97,13 @@
xsval = xs_read(xh, path, &xsval_n);
Py_END_ALLOW_THREADS
if (!xsval) {
- val = pyvalue_int(0);
+ PyErr_SetFromErrno(PyExc_RuntimeError);
goto exit;
}
val = PyString_FromStringAndSize(xsval, xsval_n);
exit:
if (xsval)
- free(xsval);
+ free(xsval);
return val;
}
@@ -114,7 +114,7 @@
" create [int] : create flag, default 0.\n" \
" excl [int] : exclusive flag, default 0.\n" \
"\n" \
- "Returns: [int] 0 on success.\n" \
+ "Returns None on success.\n" \
"Raises RuntimeError on error.\n" \
"\n"
@@ -134,18 +134,23 @@
int xsval = 0;
if (!xh)
- goto exit;
+ goto exit;
if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec,
&path, &data, &data_n, &create, &excl))
goto exit;
if (create)
- flags |= O_CREAT;
+ flags |= O_CREAT;
if (excl)
- flags |= O_EXCL;
+ flags |= O_EXCL;
Py_BEGIN_ALLOW_THREADS
xsval = xs_write(xh, path, data, data_n, flags);
Py_END_ALLOW_THREADS
- val = pyvalue_int(xsval);
+ if (!xsval) {
+ PyErr_SetFromErrno(PyExc_RuntimeError);
+ goto exit;
+ }
+ Py_INCREF(Py_None);
+ val = Py_None;
exit:
return val;
}
@@ -171,14 +176,14 @@
int i;
if (!xh)
- goto exit;
+ goto exit;
if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec, &path))
goto exit;
Py_BEGIN_ALLOW_THREADS
xsval = xs_directory(xh, path, &xsval_n);
Py_END_ALLOW_THREADS
if (!xsval) {
- val = pyvalue_int(0);
+ PyErr_SetFromErrno(PyExc_RuntimeError);
goto exit;
}
val = PyList_New(xsval_n);
@@ -192,7 +197,7 @@
"Make a directory.\n" \
" path [string]: path to directory to create.\n" \
"\n" \
- "Returns: [int] 0 on success.\n" \
+ "Returns None on success.\n" \
"Raises RuntimeError on error.\n" \
"\n"
@@ -207,13 +212,18 @@
int xsval = 0;
if (!xh)
- goto exit;
+ goto exit;
if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec, &path))
goto exit;
Py_BEGIN_ALLOW_THREADS
xsval = xs_mkdir(xh, path);
Py_END_ALLOW_THREADS
- val = pyvalue_int(xsval);
+ if (!xsval) {
+ PyErr_SetFromErrno(PyExc_RuntimeError);
+ goto exit;
+ }
+ Py_INCREF(Py_None);
+ val = Py_None;
exit:
return val;
}
@@ -222,7 +232,7 @@
"Remove a path.\n" \
" path [string] : path to remove\n" \
"\n" \
- "Returns: [int] 0 on success.\n" \
+ "Returns None on success.\n" \
"Raises RuntimeError on error.\n" \
"\n"
@@ -237,13 +247,18 @@
int xsval = 0;
if (!xh)
- goto exit;
+ goto exit;
if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec, &path))
goto exit;
Py_BEGIN_ALLOW_THREADS
xsval = xs_rm(xh, path);
Py_END_ALLOW_THREADS
- val = pyvalue_int(xsval);
+ if (!xsval) {
+ PyErr_SetFromErrno(PyExc_RuntimeError);
+ goto exit;
+ }
+ Py_INCREF(Py_None);
+ val = Py_None;
exit:
return val;
}
@@ -257,7 +272,7 @@
"\n"
static PyObject *xspy_get_permissions(PyObject *self, PyObject *args,
- PyObject *kwds)
+ PyObject *kwds)
{
static char *kwd_spec[] = { "path", NULL };
static char *arg_spec = "s|";
@@ -270,7 +285,7 @@
int i;
if (!xh)
- goto exit;
+ goto exit;
if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec, &path))
goto exit;
Py_BEGIN_ALLOW_THREADS
@@ -297,12 +312,12 @@
" path [string] : xenstore path.\n" \
" perms : permissions.\n" \
"\n" \
- "Returns: [int] 0 on success.\n" \
+ "Returns None on success.\n" \
"Raises RuntimeError on error.\n" \
"\n"
static PyObject *xspy_set_permissions(PyObject *self, PyObject *args,
- PyObject *kwds)
+ PyObject *kwds)
{
static char *kwd_spec[] = { "path", "perms", NULL };
static char *arg_spec = "sO";
@@ -335,7 +350,7 @@
}
tuple0 = PyTuple_New(0);
if (!tuple0)
- goto exit;
+ goto exit;
for (i = 0; i < xsperms_n; i++) {
/* Domain the permissions apply to. */
int dom = 0;
@@ -343,22 +358,27 @@
int p_read = 0, p_write = 0;
PyObject *p = PyList_GetItem(perms, i);
if (!PyArg_ParseTupleAndKeywords(tuple0, p, perm_spec, perm_names,
- &dom, &p_read, &p_write))
+ &dom, &p_read, &p_write))
goto exit;
xsperms[i].id = dom;
if (p_read)
- xsperms[i].perms |= XS_PERM_READ;
+ xsperms[i].perms |= XS_PERM_READ;
if (p_write)
- xsperms[i].perms |= XS_PERM_WRITE;
+ xsperms[i].perms |= XS_PERM_WRITE;
}
Py_BEGIN_ALLOW_THREADS
xsval = xs_set_permissions(xh, path, xsperms, xsperms_n);
Py_END_ALLOW_THREADS
- val = pyvalue_int(xsval);
+ if (!xsval) {
+ PyErr_SetFromErrno(PyExc_RuntimeError);
+ goto exit;
+ }
+ Py_INCREF(Py_None);
+ val = Py_None;
exit:
Py_XDECREF(tuple0);
if (xsperms)
- free(xsperms);
+ free(xsperms);
return val;
}
@@ -389,7 +409,7 @@
int xsval = 0;
if (!xh)
- goto exit;
+ goto exit;
if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec,
&path, &token))
goto exit;
@@ -399,19 +419,19 @@
xsval = xs_watch(xh, path, token_str);
Py_END_ALLOW_THREADS
if (!xsval) {
- val = PyErr_SetFromErrno(PyExc_RuntimeError);
- Py_DECREF(token);
- goto exit;
+ 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);
- break;
- }
+ if (PyList_GetItem(xsh->watches, i) == Py_None) {
+ PyList_SetItem(xsh->watches, i, token);
+ break;
+ }
}
if (i == PyList_Size(xsh->watches))
- PyList_Append(xsh->watches, token);
+ PyList_Append(xsh->watches, token);
Py_INCREF(Py_None);
val = Py_None;
exit:
@@ -429,7 +449,7 @@
"\n"
static PyObject *xspy_read_watch(PyObject *self, PyObject *args,
- PyObject *kwds)
+ PyObject *kwds)
{
static char *kwd_spec[] = { NULL };
static char *arg_spec = "";
@@ -442,33 +462,33 @@
int i;
if (!xh)
- goto exit;
+ goto exit;
if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec))
goto exit;
Py_BEGIN_ALLOW_THREADS
xsval = xs_read_watch(xh);
Py_END_ALLOW_THREADS
if (!xsval) {
- val = PyErr_SetFromErrno(PyExc_RuntimeError);
- goto exit;
+ PyErr_SetFromErrno(PyExc_RuntimeError);
+ goto exit;
}
if (sscanf(xsval[1], "%li", (unsigned long *)&token) != 1) {
- PyErr_SetString(PyExc_RuntimeError, "invalid token");
- goto exit;
+ PyErr_SetString(PyExc_RuntimeError, "invalid token");
+ goto exit;
}
for (i = 0; i < PyList_Size(xsh->watches); i++) {
- if (token == PyList_GetItem(xsh->watches, i))
- break;
+ if (token == PyList_GetItem(xsh->watches, i))
+ break;
}
if (i == PyList_Size(xsh->watches)) {
- PyErr_SetString(PyExc_RuntimeError, "invalid token");
- goto exit;
+ PyErr_SetString(PyExc_RuntimeError, "invalid token");
+ goto exit;
}
/* Create tuple (path, token). */
val = Py_BuildValue("(sO)", xsval[0], token);
exit:
if (xsval)
- free(xsval);
+ free(xsval);
return val;
}
@@ -481,7 +501,7 @@
"\n"
static PyObject *xspy_acknowledge_watch(PyObject *self, PyObject *args,
- PyObject *kwds)
+ PyObject *kwds)
{
static char *kwd_spec[] = { "token", NULL };
static char *arg_spec = "O";
@@ -493,7 +513,7 @@
int xsval = 0;
if (!xh)
- goto exit;
+ goto exit;
if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec, &token))
goto exit;
sprintf(token_str, "%li", (unsigned long)token);
@@ -501,8 +521,8 @@
xsval = xs_acknowledge_watch(xh, token_str);
Py_END_ALLOW_THREADS
if (!xsval) {
- val = PyErr_SetFromErrno(PyExc_RuntimeError);
- goto exit;
+ PyErr_SetFromErrno(PyExc_RuntimeError);
+ goto exit;
}
Py_INCREF(Py_None);
val = Py_None;
@@ -534,26 +554,26 @@
int xsval = 0;
if (!xh)
- goto exit;
+ goto exit;
if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec, &path,
- &token))
+ &token))
goto exit;
sprintf(token_str, "%li", (unsigned long)token);
Py_BEGIN_ALLOW_THREADS
xsval = xs_unwatch(xh, path, token_str);
Py_END_ALLOW_THREADS
if (!xsval)
- val = PyErr_SetFromErrno(PyExc_RuntimeError);
+ PyErr_SetFromErrno(PyExc_RuntimeError);
else {
- Py_INCREF(Py_None);
- val = Py_None;
+ Py_INCREF(Py_None);
+ val = Py_None;
}
for (i = 0; i < PyList_Size(xsh->watches); i++) {
- if (token == PyList_GetItem(xsh->watches, i)) {
- Py_INCREF(Py_None);
- PyList_SetItem(xsh->watches, i, Py_None);
- break;
- }
+ if (token == PyList_GetItem(xsh->watches, i)) {
+ Py_INCREF(Py_None);
+ PyList_SetItem(xsh->watches, i, Py_None);
+ break;
+ }
}
exit:
return val;
@@ -564,12 +584,12 @@
"Only one transaction can be active at a time.\n" \
" path [string]: xenstore path.\n" \
"\n" \
- "Returns: [int] 0 on success.\n" \
+ "Returns None on success.\n" \
"Raises RuntimeError on error.\n" \
"\n"
static PyObject *xspy_transaction_start(PyObject *self, PyObject *args,
- PyObject *kwds)
+ PyObject *kwds)
{
static char *kwd_spec[] = { "path", NULL };
static char *arg_spec = "s|";
@@ -580,13 +600,18 @@
int xsval = 0;
if (!xh)
- goto exit;
+ goto exit;
if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec, &path))
goto exit;
Py_BEGIN_ALLOW_THREADS
xsval = xs_transaction_start(xh, path);
Py_END_ALLOW_THREADS
- val = pyvalue_int(xsval);
+ if (!xsval) {
+ PyErr_SetFromErrno(PyExc_RuntimeError);
+ goto exit;
+ }
+ Py_INCREF(Py_None);
+ val = Py_None;
exit:
return val;
}
@@ -596,12 +621,12 @@
"Attempts to commit the transaction unless abort is true.\n" \
" abort [int]: abort flag (default 0).\n" \
"\n" \
- "Returns: [int] 0 on success.\n" \
+ "Returns None on success.\n" \
"Raises RuntimeError on error.\n" \
"\n"
static PyObject *xspy_transaction_end(PyObject *self, PyObject *args,
- PyObject *kwds)
+ PyObject *kwds)
{
static char *kwd_spec[] = { "abort", NULL };
static char *arg_spec = "|i";
@@ -612,13 +637,18 @@
int xsval = 0;
if (!xh)
- goto exit;
+ goto exit;
if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec, &abort))
goto exit;
Py_BEGIN_ALLOW_THREADS
xsval = xs_transaction_end(xh, abort);
Py_END_ALLOW_THREADS
- val = pyvalue_int(xsval);
+ if (!xsval) {
+ PyErr_SetFromErrno(PyExc_RuntimeError);
+ goto exit;
+ }
+ Py_INCREF(Py_None);
+ val = Py_None;
exit:
return val;
}
@@ -630,12 +660,12 @@
" port [int] : port the domain is using for xenstore\n" \
" path [string]: path to the domain's data in xenstore\n" \
"\n" \
- "Returns: [int] 0 on success.\n" \
+ "Returns None on success.\n" \
"Raises RuntimeError on error.\n" \
"\n"
static PyObject *xspy_introduce_domain(PyObject *self, PyObject *args,
- PyObject *kwds)
+ PyObject *kwds)
{
static char *kwd_spec[] = { "dom", "page", "port", "path", NULL };
static char *arg_spec = "iiis|";
@@ -649,14 +679,19 @@
int xsval = 0;
if (!xh)
- goto exit;
+ goto exit;
if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec,
&dom, &page, &port, &path))
goto exit;
Py_BEGIN_ALLOW_THREADS
xsval = xs_introduce_domain(xh, dom, page, port, path);
Py_END_ALLOW_THREADS
- val = pyvalue_int(xsval);
+ if (!xsval) {
+ PyErr_SetFromErrno(PyExc_RuntimeError);
+ goto exit;
+ }
+ Py_INCREF(Py_None);
+ val = Py_None;
exit:
return val;
}
@@ -666,12 +701,12 @@
"Unless this is done the domain will not be released.\n" \
" dom [int]: domain id\n" \
"\n" \
- "Returns: [int] 0 on success.\n" \
+ "Returns None on success.\n" \
"Raises RuntimeError on error.\n" \
"\n"
static PyObject *xspy_release_domain(PyObject *self, PyObject *args,
- PyObject *kwds)
+ PyObject *kwds)
{
static char *kwd_spec[] = { "dom", NULL };
static char *arg_spec = "i|";
@@ -682,14 +717,19 @@
int xsval = 0;
if (!xh)
- goto exit;
+ goto exit;
if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec,
&dom))
goto exit;
Py_BEGIN_ALLOW_THREADS
xsval = xs_release_domain(xh, dom);
Py_END_ALLOW_THREADS
- val = pyvalue_int(xsval);
+ if (!xsval) {
+ PyErr_SetFromErrno(PyExc_RuntimeError);
+ goto exit;
+ }
+ Py_INCREF(Py_None);
+ val = Py_None;
exit:
return val;
}
@@ -697,7 +737,7 @@
#define xspy_close_doc "\n" \
"Close the connection to xenstore.\n" \
"\n" \
- "Returns: [int] 0 on success.\n" \
+ "Returns None on success.\n" \
"Raises RuntimeError on error.\n" \
"\n"
@@ -710,20 +750,20 @@
XsHandle *xsh = (XsHandle *)self;
struct xs_handle *xh = xshandle(self);
PyObject *val = NULL;
- int xsval = 1;
-
- if (!xh)
- goto exit;
+
+ if (!xh)
+ goto exit;
if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec))
goto exit;
for (i = 0; i < PyList_Size(xsh->watches); i++) {
- /* TODO: xs_unwatch watches */
- Py_INCREF(Py_None);
- PyList_SetItem(xsh->watches, i, Py_None);
+ /* TODO: xs_unwatch watches */
+ Py_INCREF(Py_None);
+ PyList_SetItem(xsh->watches, i, Py_None);
}
xs_daemon_close(xh);
xsh->xh = NULL;
- val = pyvalue_int(xsval);
+ Py_INCREF(Py_None);
+ val = Py_None;
exit:
return val;
}
@@ -731,7 +771,7 @@
#define xspy_shutdown_doc "\n" \
"Shutdown the xenstore daemon.\n" \
"\n" \
- "Returns: [int] 0 on success.\n" \
+ "Returns None on success.\n" \
"Raises RuntimeError on error.\n" \
"\n"
@@ -745,13 +785,18 @@
int xsval = 0;
if (!xh)
- goto exit;
+ goto exit;
if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec))
goto exit;
Py_BEGIN_ALLOW_THREADS
xsval = xs_shutdown(xh);
Py_END_ALLOW_THREADS
- val = pyvalue_int(xsval);
+ if (!xsval) {
+ PyErr_SetFromErrno(PyExc_RuntimeError);
+ goto exit;
+ }
+ Py_INCREF(Py_None);
+ val = Py_None;
exit:
return val;
}
@@ -852,17 +897,18 @@
if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec,
&readonly))
- return NULL;
+ return NULL;
xsh = PyObject_New(XsHandle, &xshandle_type);
if (!xsh)
- return NULL;
+ return NULL;
xsh->watches = PyList_New(0);
if (!xsh->watches)
- goto exit;
+ goto exit;
xsh->xh = (readonly ? xs_daemon_open_readonly() : xs_daemon_open());
if (!xsh->xh) {
- Py_DECREF(xsh->watches);
+ Py_DECREF(xsh->watches);
+ PyErr_SetFromErrno(PyExc_RuntimeError);
goto exit;
}
val = (PyObject *)xsh;
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|