diff options
author | David Strauss <david@davidstrauss.net> | 2012-06-26 01:00:46 -0700 |
---|---|---|
committer | David Strauss <david@davidstrauss.net> | 2012-06-26 01:00:46 -0700 |
commit | 51189a1b46d11c45548f71ded3acc683f041fa53 (patch) | |
tree | f1bbc8863c9bc7ff116ce4e22440501ec1634e6d /journald.c | |
parent | 83a9513518fe6b2f3009961e00da454d286ec503 (diff) | |
download | python-systemd-51189a1b46d11c45548f71ded3acc683f041fa53.tar.gz |
Allow varags.
Diffstat (limited to 'journald.c')
-rw-r--r-- | journald.c | 27 |
1 files changed, 24 insertions, 3 deletions
@@ -5,16 +5,37 @@ #define journaldpython static PyObject * -journald_send(PyObject *self, PyObject *args) -{ +journald_send(PyObject *self, PyObject *args) { + int argc = PyTuple_Size(args); + struct iovec *iov = NULL; + int i; + + // Allocate sufficient iovector space for the arguments. + iov = malloc(argc * sizeof(struct iovec)); + if (!iov) { + return PyErr_NoMemory(); + } + + // Iterate through the Python arguments and fill the iovector. + for (i = 0; i < argc; ++i) { + PyObject *item = PyTuple_GetItem(args, i); + char * stritem = PyString_AsString(item); + iov[i].iov_base = stritem; + iov[i].iov_len = strlen(stritem); + } + + sd_journal_sendv(iov, argc); + //sd_journal_send("MESSAGE=foobar", "VALUE=%i", 7, NULL); + //const char *command; //int sts; //if (!PyArg_ParseTuple(args, "s", &command)) // return NULL; //sts = system(command); + //return Py_BuildValue("i", sts); - sd_journal_print(1, "Test message: %s.", "arg1", NULL); + //sd_journal_print(1, "Testing message: %s. ANOTHERFIELD=one", "arg1", NULL); Py_INCREF(Py_None); return Py_None; } |