summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-06-16 16:03:43 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-06-16 16:27:11 +0200
commitb54707abf4cfe9204ed68b92166cad9e3d2e59ba (patch)
tree167632419babe233378ffe8a034f5e4a23962d42
parent56d6fc58c930e4eeb5b5b7f713e94361451fdef2 (diff)
downloadpython-systemd-b54707abf4cfe9204ed68b92166cad9e3d2e59ba.tar.gz
id128: conditionalize get_machine_app_specific on libsystemd version
-rw-r--r--systemd/id128.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/systemd/id128.c b/systemd/id128.c
index 1f525be..891c658 100644
--- a/systemd/id128.c
+++ b/systemd/id128.c
@@ -30,10 +30,11 @@
#include "id128-defines.h"
#include <systemd/sd-messages.h>
-
#include "pyutil.h"
#include "macro.h"
+#define HAVE_SD_ID128_GET_MACHINE_APP_SPECIFIC (LIBSYSTEMD_VERSION >= 240)
+
PyDoc_STRVAR(module__doc__,
"Python interface to the libsystemd-id128 library.\n\n"
"Provides SD_MESSAGE_* constants and functions to query and generate\n"
@@ -107,15 +108,17 @@ helper(get_machine)
helper(get_boot)
static PyObject *get_machine_app_specific(PyObject *self, PyObject *args) {
- sd_id128_t machine_id;
- Py_buffer buffer;
_cleanup_Py_DECREF_ PyObject *uuid_bytes = NULL;
- int r;
uuid_bytes = PyObject_GetAttrString(args, "bytes");
if (!uuid_bytes)
return NULL;
+#if HAVE_SD_ID128_GET_MACHINE_APP_SPECIFIC
+ Py_buffer buffer;
+ sd_id128_t app_id;
+ int r;
+
r = PyObject_GetBuffer(uuid_bytes, &buffer, 0);
if (r == -1)
return NULL;
@@ -125,14 +128,19 @@ static PyObject *get_machine_app_specific(PyObject *self, PyObject *args) {
return NULL;
}
- r = sd_id128_get_machine_app_specific(*(sd_id128_t*)buffer.buf, &machine_id);
+ r = sd_id128_get_machine_app_specific(*(sd_id128_t*)buffer.buf, &app_id);
PyBuffer_Release(&buffer);
if (r < 0) {
errno = -r;
return PyErr_SetFromErrno(PyExc_IOError);
}
- return make_uuid(machine_id);
+ return make_uuid(app_id);
+
+#else
+ set_error(-ENOSYS, NULL, "Compiled without support for sd_id128_get_machine_app_specific");
+ return NULL;
+#endif
}
static PyMethodDef methods[] = {