From b54707abf4cfe9204ed68b92166cad9e3d2e59ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sun, 16 Jun 2019 16:03:43 +0200 Subject: id128: conditionalize get_machine_app_specific on libsystemd version --- systemd/id128.c | 20 ++++++++++++++------ 1 file 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 - #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[] = { -- cgit v1.2.1