summaryrefslogtreecommitdiff
path: root/src/python-systemd/pyutil.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-05-09 18:10:30 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-05-09 18:13:33 -0400
commit7ecec4705c0cacb1446af0eb7a4aee66c00d058f (patch)
tree9761c582b900067bca3e69c6f22f18e77fa70385 /src/python-systemd/pyutil.c
parentb3af9646f8ac23e73fe1d7af3b69e35b1547b13e (diff)
systemd-python: wrap sd_login_monitor
Diffstat (limited to 'src/python-systemd/pyutil.c')
-rw-r--r--src/python-systemd/pyutil.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/python-systemd/pyutil.c b/src/python-systemd/pyutil.c
index 9510acdddb..2f047e643a 100644
--- a/src/python-systemd/pyutil.c
+++ b/src/python-systemd/pyutil.c
@@ -44,3 +44,17 @@ PyObject* absolute_timeout(uint64_t t) {
return PyLong_FromLong(msec);
}
}
+
+int set_error(int r, const char* path, const char* invalid_message) {
+ if (r >= 0)
+ return r;
+ if (r == -EINVAL && invalid_message)
+ PyErr_SetString(PyExc_ValueError, invalid_message);
+ else if (r == -ENOMEM)
+ PyErr_SetString(PyExc_MemoryError, "Not enough memory");
+ else {
+ errno = -r;
+ PyErr_SetFromErrnoWithFilename(PyExc_OSError, path);
+ }
+ return -1;
+}