chiark / gitweb /
systemd-python: correct data_threshold error return value
[elogind.git] / src / python-systemd / _reader.c
index 5d743eb5628e53e234b75b4af87c52a22fa78eed..d2f738b9c7d0f0a14780050671248a3d5bf6c94e 100644 (file)
@@ -1,21 +1,23 @@
-/*
-_reader - Python module that reads systemd journal similar to journalctl
-Copyright (C) 2012  Steven Hiscocks
-
-This library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Lesser General Public
-License as published by the Free Software Foundation; either
-version 2.1 of the License, or (at your option) any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-Lesser General Public License for more details.
-
-You should have received a copy of the GNU Lesser General Public
-License along with this library; if not, write to the Free Software
-Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
-*/
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+  This file is part of systemd.
+
+  Copyright 2013 Steven Hiscocks, Zbigniew JÄ™drzejewski-Szmek
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published by
+  the Free Software Foundation; either version 2.1 of the License, or
+  (at your option) any later version.
+
+  systemd is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
 #include <systemd/sd-journal.h>
 
 #include <Python.h>
 #include <systemd/sd-journal.h>
 
 #include <Python.h>
@@ -426,34 +428,12 @@ PyDoc_STRVAR(Journal_seek_realtime__doc__,
 static PyObject *
 Journal_seek_realtime(Journal *self, PyObject *args)
 {
 static PyObject *
 Journal_seek_realtime(Journal *self, PyObject *args)
 {
-    PyObject *arg;
-    if (! PyArg_ParseTuple(args, "O", &arg))
+    uint64_t timestamp;
+    if (! PyArg_ParseTuple(args, "K", &timestamp))
         return NULL;
 
         return NULL;
 
-    uint64_t timestamp=-1LL;
-    if (PyDateTime_Check(arg)) {
-        PyObject *temp;
-        char *timestamp_str;
-        temp = PyObject_CallMethod(arg, "strftime", "s", "%s%f");
-#if PY_MAJOR_VERSION >=3
-        PyObject *temp2;
-        temp2 = PyUnicode_AsUTF8String(temp);
-        timestamp_str = PyBytes_AsString(temp2);
-        Py_DECREF(temp2);
-#else
-        timestamp_str = PyString_AsString(temp);
-#endif
-        Py_DECREF(temp);
-        timestamp = strtoull(timestamp_str, NULL, 10);
-    }else if (PyLong_Check(arg)) {
-        timestamp = PyLong_AsUnsignedLongLong(arg);
-#if PY_MAJOR_VERSION <3
-    }else if (PyInt_Check(arg)) {
-        timestamp = PyInt_AsUnsignedLongLongMask(arg);
-#endif
-    }
     if ((int64_t) timestamp < 0LL) {
     if ((int64_t) timestamp < 0LL) {
-        PyErr_SetString(PyExc_ValueError, "Time must be positive integer or datetime instance");
+        PyErr_SetString(PyExc_ValueError, "Time must be positive integer");
         return NULL;
     }
 
         return NULL;
     }
 
@@ -479,30 +459,16 @@ PyDoc_STRVAR(Journal_seek_monotonic__doc__,
 static PyObject *
 Journal_seek_monotonic(Journal *self, PyObject *args)
 {
 static PyObject *
 Journal_seek_monotonic(Journal *self, PyObject *args)
 {
-    PyObject *arg;
+    double timedouble;
     char *bootid=NULL;
     char *bootid=NULL;
-    if (! PyArg_ParseTuple(args, "O|s", &arg, &bootid))
+    if (! PyArg_ParseTuple(args, "d|z", &timedouble, &bootid))
         return NULL;
 
         return NULL;
 
-    uint64_t timestamp=-1LL;
-    if PyDelta_Check(arg) {
-        PyObject *temp;
-        temp = PyObject_CallMethod(arg, "total_seconds", NULL);
-        timestamp = (uint64_t) (PyFloat_AsDouble(temp) * 1E6);
-        Py_DECREF(temp);
-    }else if (PyFloat_Check(arg)) {
-        timestamp = (uint64_t) (PyFloat_AsDouble(arg) * 1E6);
-    }else if (PyLong_Check(arg)) {
-        timestamp = PyLong_AsUnsignedLongLong(arg) * (uint64_t) 1E6;
-#if PY_MAJOR_VERSION <3
-    }else if (PyInt_Check(arg)) {
-        timestamp = PyInt_AsUnsignedLongLongMask(arg) * (uint64_t) 1E6;
-#endif
-
-    }
+    uint64_t timestamp;
+    timestamp = (uint64_t) (timedouble * 1.0E6);
 
     if ((int64_t) timestamp < 0LL) {
 
     if ((int64_t) timestamp < 0LL) {
-        PyErr_SetString(PyExc_ValueError, "Time must be positive number or timedelta instance");
+        PyErr_SetString(PyExc_ValueError, "Time must be positive number");
         return NULL;
     }
 
         return NULL;
     }
 
@@ -722,7 +688,7 @@ Journal_set_data_threshold(Journal *self, PyObject *value, void *closure)
     if (r < 0) {
         errno = -r;
         PyErr_SetFromErrno(PyExc_OSError);
     if (r < 0) {
         errno = -r;
         PyErr_SetFromErrno(PyExc_OSError);
-        return NULL;
+        return -1;
     }
     return 0;
 }
     }
     return 0;
 }