"running under systemd."
);
-static PyObject* set_error(int r, const char* invalid_message) {
- assert (r < 0);
-
- 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_SetFromErrno(PyExc_OSError);
- }
-
- return NULL;
-}
-
#if PY_MAJOR_VERSION >=3 && PY_MINOR_VERSION >= 1
static int Unicode_FSConverter(PyObject* obj, void *_result) {
assert(args == NULL);
r = sd_booted();
- if (r < 0)
- return set_error(r, NULL);
+ if (set_error(r, NULL, NULL))
+ return NULL;
return PyBool_FromLong(r);
}
#endif
r = sd_listen_fds(unset);
- if (r < 0)
- return set_error(r, NULL);
+ if (set_error(r, NULL, NULL))
+ return NULL;
return long_FromLong(r);
}
#endif
r = sd_is_fifo(fd, path);
- if (r < 0)
- return set_error(r, NULL);
+ if (set_error(r, path, NULL))
+ return NULL;
return PyBool_FromLong(r);
}
#endif
r = sd_is_mq(fd, path);
- if (r < 0)
- return set_error(r, NULL);
+ if (set_error(r, path, NULL))
+ return NULL;
return PyBool_FromLong(r);
}
return NULL;
r = sd_is_socket(fd, family, type, listening);
- if (r < 0)
- return set_error(r, NULL);
+ if (set_error(r, NULL, NULL))
+ return NULL;
return PyBool_FromLong(r);
}
&fd, &family, &type, &listening, &port))
return NULL;
- if (port < 0 || port > INT16_MAX)
- return set_error(-EINVAL, "port must fit into uint16_t");
+ if (port < 0 || port > INT16_MAX) {
+ set_error(-EINVAL, NULL, "port must fit into uint16_t");
+ return NULL;
+ }
r = sd_is_socket_inet(fd, family, type, listening, (uint16_t) port);
- if (r < 0)
- return set_error(r, NULL);
+ if (set_error(r, NULL, NULL))
+ return NULL;
return PyBool_FromLong(r);
}
Py_ssize_t length = 0;
#if PY_MAJOR_VERSION >=3 && PY_MINOR_VERSION >= 1
- PyObject _cleanup_Py_DECREF_ *_path = NULL;
+ _cleanup_Py_DECREF_ PyObject *_path = NULL;
if (!PyArg_ParseTuple(args, "i|iiO&:_is_socket_unix",
&fd, &type, &listening, Unicode_FSConverter, &_path))
return NULL;
#endif
r = sd_is_socket_unix(fd, type, listening, path, length);
- if (r < 0)
- return set_error(r, NULL);
+ if (set_error(r, path, NULL))
+ return NULL;
return PyBool_FromLong(r);
}
return;
PyModule_AddIntConstant(m, "LISTEN_FDS_START", SD_LISTEN_FDS_START);
+ PyModule_AddStringConstant(m, "__version__", PACKAGE_VERSION);
}
#else
if (m == NULL)
return NULL;
- if (PyModule_AddIntConstant(m, "LISTEN_FDS_START", SD_LISTEN_FDS_START)) {
+ if (PyModule_AddIntConstant(m, "LISTEN_FDS_START", SD_LISTEN_FDS_START) ||
+ PyModule_AddStringConstant(m, "__version__", PACKAGE_VERSION)) {
Py_DECREF(m);
return NULL;
}