chiark / gitweb /
systemd-python: some python3 and bug fixes
[elogind.git] / src / python-systemd / _reader.c
index f047ab9e6d95b81a362f2a7610d5618950d23724..ae3d77cfe9ef2fdc678d010ebd1e903dffd11f0f 100644 (file)
@@ -383,7 +383,7 @@ Journal_seek(Journal *self, PyObject *args, PyObject *keywds)
                                       &offset, &whence))
         return NULL;
 
-    PyObject *arg;
+    PyObject *result=NULL;
     if (whence == SEEK_SET){
         int r;
         Py_BEGIN_ALLOW_THREADS
@@ -394,10 +394,10 @@ Journal_seek(Journal *self, PyObject *args, PyObject *keywds)
             return NULL;
         }
         if (offset > 0LL) {
-            Py_DECREF(PyObject_CallMethod((PyObject *)self, "get_next", "L", offset));
+            result = PyObject_CallMethod((PyObject *)self, "get_next", "L", offset);
         }
     }else if (whence == SEEK_CUR){
-        Py_DECREF(PyObject_CallMethod((PyObject *)self, "get_next", "L", offset));
+        result = PyObject_CallMethod((PyObject *)self, "get_next", "L", offset);
     }else if (whence == SEEK_END){
         int r;
         Py_BEGIN_ALLOW_THREADS
@@ -407,14 +407,19 @@ Journal_seek(Journal *self, PyObject *args, PyObject *keywds)
             PyErr_SetString(PyExc_RuntimeError, "Error seeking to tail");
             return NULL;
         }
-        Py_DECREF(PyObject_CallMethod((PyObject *)self, "get_next", "L", -1LL));
         if (offset < 0LL) {
-            Py_DECREF(PyObject_CallMethod((PyObject *)self, "get_next", "L", offset));
+            result = PyObject_CallMethod((PyObject *)self, "get_next", "L", offset);
+        }else{
+            result = PyObject_CallMethod((PyObject *)self, "get_next", "L", -1LL);
         }
     }else{
         PyErr_SetString(PyExc_ValueError, "Invalid value for whence");
-        return NULL;
     }
+
+    if (result)
+        Py_DECREF(result);
+    if (PyErr_Occurred())
+        return NULL;
     Py_RETURN_NONE;
 }
 
@@ -607,7 +612,7 @@ Journal_iter(PyObject *self)
 static PyObject *
 Journal_iternext(PyObject *self)
 {
-    PyObject *dict, *arg;
+    PyObject *dict;
     Py_ssize_t dict_size;
 
     dict = PyObject_CallMethod(self, "get_next", "");
@@ -671,100 +676,6 @@ Journal_query_unique(Journal *self, PyObject *args)
 }
 #endif //def SD_JOURNAL_FOREACH_UNIQUE
 
-PyDoc_STRVAR(Journal_log_level__doc__,
-"log_level(level) -> None\n\n"
-"Sets maximum log level by setting matches for PRIORITY.");
-static PyObject *
-Journal_log_level(Journal *self, PyObject *args)
-{
-    int level;
-    if (! PyArg_ParseTuple(args, "i", &level))
-        return NULL;
-
-    if (level < 0 || level > 7) {
-        PyErr_SetString(PyExc_ValueError, "Log level should be 0 <= level <= 7");
-        return NULL;
-    }
-    int i;
-    char level_str[2];
-    PyObject *arg, *keywds;
-    for(i = 0; i <= level; i++) {
-        sprintf(level_str, "%i", i);
-        arg = PyTuple_New(0);
-        keywds = Py_BuildValue("{s:s}", "PRIORITY", level_str);
-        Journal_add_match(self, arg, keywds);
-        Py_DECREF(arg);
-        Py_DECREF(keywds);
-        if (PyErr_Occurred())
-            return NULL;
-    }
-    Py_RETURN_NONE;
-}
-
-PyDoc_STRVAR(Journal_this_boot__doc__,
-"this_boot() -> None\n\n"
-"Sets match filter for the current _BOOT_ID.");
-static PyObject *
-Journal_this_boot(Journal *self, PyObject *args)
-{
-    sd_id128_t sd_id;
-    int r;
-    r = sd_id128_get_boot(&sd_id);
-    if (r == -EIO) {
-        PyErr_SetString(PyExc_IOError, "Error getting current boot ID");
-        return NULL;
-    } else if (r < 0) {
-        PyErr_SetString(PyExc_RuntimeError, "Error getting current boot ID");
-        return NULL;
-    }
-
-    char bootid[33];
-    sd_id128_to_string(sd_id, bootid);
-
-    PyObject *arg, *keywds;
-    arg = PyTuple_New(0);
-    keywds = Py_BuildValue("{s:s}", "_BOOT_ID", bootid);
-    Journal_add_match(self, arg, keywds);
-    Py_DECREF(arg);
-    Py_DECREF(keywds);
-    if (PyErr_Occurred())
-        return NULL;
-
-    Py_RETURN_NONE;
-}
-
-PyDoc_STRVAR(Journal_this_machine__doc__,
-"this_machine() -> None\n\n"
-"Sets match filter for the current _MACHINE_ID.");
-static PyObject *
-Journal_this_machine(Journal *self, PyObject *args)
-{
-    sd_id128_t sd_id;
-    int r;
-    r = sd_id128_get_machine(&sd_id);
-    if (r == -EIO) {
-        PyErr_SetString(PyExc_IOError, "Error getting current boot ID");
-        return NULL;
-    } else if (r < 0) {
-        PyErr_SetString(PyExc_RuntimeError, "Error getting current boot ID");
-        return NULL;
-    }
-
-    char machineid[33];
-    sd_id128_to_string(sd_id, machineid);
-
-    PyObject *arg, *keywds;
-    arg = PyTuple_New(0);
-    keywds = Py_BuildValue("{s:s}", "_MACHINE_ID", machineid);
-    Journal_add_match(self, arg, keywds);
-    Py_DECREF(arg);
-    Py_DECREF(keywds);
-    if (PyErr_Occurred())
-        return NULL;
-
-    Py_RETURN_NONE;
-}
-
 static PyObject *
 Journal_get_data_threshold(Journal *self, void *closure)
 {
@@ -848,12 +759,6 @@ static PyMethodDef Journal_methods[] = {
     {"query_unique", (PyCFunction)Journal_query_unique, METH_VARARGS,
     Journal_query_unique__doc__},
 #endif
-    {"log_level", (PyCFunction)Journal_log_level, METH_VARARGS,
-    Journal_log_level__doc__},
-    {"this_boot", (PyCFunction)Journal_this_boot, METH_NOARGS,
-    Journal_this_boot__doc__},
-    {"this_machine", (PyCFunction)Journal_this_machine, METH_NOARGS,
-    Journal_this_machine__doc__},
     {NULL}  /* Sentinel */
 };