"See man:sd_journal_get_fd(3).");
static PyObject* Reader_fileno(Reader *self, PyObject *args)
{
- int r;
- r = sd_journal_get_fd(self->j);
- set_error(r, NULL, NULL);
- if (r < 0)
+ int fd;
+ fd = sd_journal_get_fd(self->j);
+ set_error(fd, NULL, NULL);
+ if (fd < 0)
return NULL;
- return long_FromLong(r);
+ return long_FromLong(fd);
}
}
+PyDoc_STRVAR(Reader_get_usage__doc__,
+ "get_usage() -> int\n\n"
+ "Returns the total disk space currently used by journal"
+ "files (in bytes). If `SD_JOURNAL_LOCAL_ONLY` was"
+ "passed when opening the journal this value will only reflect"
+ "the size of journal files of the local host, otherwise"
+ "of all hosts.\n\n"
+ "This method invokes sd_journal_get_usage().\n"
+ "See man:sd_journal_get_usage(3).");
+static PyObject* Reader_get_usage(Reader *self, PyObject *args)
+{
+ int r;
+ uint64_t bytes;
+
+ r = sd_journal_get_usage(self->j, &bytes);
+ if (set_error(r, NULL, NULL))
+ return NULL;
+
+ assert_cc(sizeof(unsigned long long) == sizeof(bytes));
+ return PyLong_FromUnsignedLongLong(bytes);
+}
+
+
PyDoc_STRVAR(Reader___enter____doc__,
"__enter__() -> self\n\n"
"Part of the context manager protocol.\n"
PyDoc_STRVAR(Reader_seek_realtime__doc__,
"seek_realtime(realtime) -> None\n\n"
"Seek to nearest matching journal entry to `realtime`. Argument\n"
- "`realtime` can must be an integer unix timestamp.");
+ "`realtime` in specified in seconds.");
static PyObject* Reader_seek_realtime(Reader *self, PyObject *args)
{
- double timedouble;
uint64_t timestamp;
int r;
- if (!PyArg_ParseTuple(args, "d:_Reader.seek_realtime", &timedouble))
- return NULL;
-
- timestamp = (uint64_t) (timedouble * 1.0E6);
- if ((int64_t) timestamp < 0LL) {
- PyErr_SetString(PyExc_ValueError, "Time must be a positive integer");
+ if (!PyArg_ParseTuple(args, "K:seek_realtime", ×tamp))
return NULL;
- }
Py_BEGIN_ALLOW_THREADS
r = sd_journal_seek_realtime_usec(self->j, timestamp);
PyDoc_STRVAR(Reader_seek_monotonic__doc__,
"seek_monotonic(monotonic[, bootid]) -> None\n\n"
"Seek to nearest matching journal entry to `monotonic`. Argument\n"
- "`monotonic` is an timestamp from boot in seconds.\n"
+ "`monotonic` is an timestamp from boot in microseconds.\n"
"Argument `bootid` is a string representing which boot the\n"
"monotonic time is reference to. Defaults to current bootid.");
static PyObject* Reader_seek_monotonic(Reader *self, PyObject *args)
{
- double timedouble;
char *bootid = NULL;
uint64_t timestamp;
sd_id128_t id;
int r;
- if (!PyArg_ParseTuple(args, "d|z:_Reader.seek_monotonic", &timedouble, &bootid))
+ if (!PyArg_ParseTuple(args, "K|z:seek_monotonic", ×tamp, &bootid))
return NULL;
- timestamp = (uint64_t) (timedouble * 1.0E6);
-
- if ((int64_t) timestamp < 0LL) {
- PyErr_SetString(PyExc_ValueError, "Time must be positive number");
- return NULL;
- }
-
if (bootid) {
r = sd_id128_from_string(bootid, &id);
if (set_error(r, NULL, "Invalid bootid"))
Py_END_ALLOW_THREADS
if (set_error(r, NULL, NULL))
return NULL;
+
Py_RETURN_NONE;
}
PyDoc_STRVAR(Reader_wait__doc__,
"wait([timeout]) -> state change (integer)\n\n"
"Wait for a change in the journal. Argument `timeout` specifies\n"
- "the maximum number of seconds to wait before returning\n"
- "regardless of wheter the journal has changed. If `timeout` is not given\n"
- "or is 0, then block forever.\n"
+ "the maximum number of microseconds to wait before returning\n"
+ "regardless of wheter the journal has changed. If `timeout` is -1,\n"
+ "then block forever.\n\n"
"Will return constants: NOP if no change; APPEND if new\n"
"entries have been added to the end of the journal; and\n"
"INVALIDATE if journal files have been added or removed.");
-static PyObject* Reader_wait(Reader *self, PyObject *args, PyObject *keywds)
+static PyObject* Reader_wait(Reader *self, PyObject *args)
{
int r;
- int64_t timeout = 0LL;
+ int64_t timeout;
- if (!PyArg_ParseTuple(args, "|L:_Reader.wait", &timeout))
+ if (!PyArg_ParseTuple(args, "|L:wait", &timeout))
return NULL;
Py_BEGIN_ALLOW_THREADS
- r = sd_journal_wait(self->j,
- timeout == 0 ? (uint64_t) -1 : timeout * 1E6);
+ r = sd_journal_wait(self->j, timeout);
Py_END_ALLOW_THREADS
if (set_error(r, NULL, NULL) < 0)
return NULL;
{"fileno", (PyCFunction) Reader_fileno, METH_NOARGS, Reader_fileno__doc__},
{"reliable_fd", (PyCFunction) Reader_reliable_fd, METH_NOARGS, Reader_reliable_fd__doc__},
{"close", (PyCFunction) Reader_close, METH_NOARGS, Reader_close__doc__},
+ {"get_usage", (PyCFunction) Reader_get_usage, METH_NOARGS, Reader_get_usage__doc__},
{"__enter__", (PyCFunction) Reader___enter__, METH_NOARGS, Reader___enter____doc__},
{"__exit__", (PyCFunction) Reader___exit__, METH_VARARGS, Reader___exit____doc__},
- {"close", (PyCFunction) Reader_close, METH_NOARGS, Reader_close__doc__},
{"get_next", (PyCFunction) Reader_get_next, METH_VARARGS, Reader_get_next__doc__},
{"get_previous", (PyCFunction) Reader_get_previous, METH_VARARGS, Reader_get_previous__doc__},
{"add_match", (PyCFunction) Reader_add_match, METH_VARARGS|METH_KEYWORDS, Reader_add_match__doc__},