From 466a9b7fe1a2eb91d6007c67eeead6484917e64c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 8 May 2013 19:46:49 -0400 Subject: systemd-python: add wrappers for easy functions in sd-login sd_get_uids, sd_get_seats, sd_get_sessions, and sd_get_machine_names. --- systemd/pyutil.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'systemd/pyutil.c') diff --git a/systemd/pyutil.c b/systemd/pyutil.c index 79065a1..9510acd 100644 --- a/systemd/pyutil.c +++ b/systemd/pyutil.c @@ -28,3 +28,19 @@ void cleanup_Py_DECREFp(PyObject **p) { Py_DECREF(*p); } + +PyObject* absolute_timeout(uint64_t t) { + if (t == (uint64_t) -1) + return PyLong_FromLong(-1); + else { + struct timespec ts; + uint64_t n; + int msec; + + clock_gettime(CLOCK_MONOTONIC, &ts); + n = (uint64_t) ts.tv_sec * 1000000 + ts.tv_nsec / 1000; + msec = t > n ? (int) ((t - n + 999) / 1000) : 0; + + return PyLong_FromLong(msec); + } +} -- cgit v1.2.1