diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2013-05-09 18:10:30 -0400 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2013-05-09 18:13:33 -0400 |
commit | 7ecec4705c0cacb1446af0eb7a4aee66c00d058f (patch) | |
tree | 9761c582b900067bca3e69c6f22f18e77fa70385 /src/python-systemd/pyutil.c | |
parent | b3af9646f8ac23e73fe1d7af3b69e35b1547b13e (diff) |
systemd-python: wrap sd_login_monitor
Diffstat (limited to 'src/python-systemd/pyutil.c')
-rw-r--r-- | src/python-systemd/pyutil.c | 14 |
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; +} |