Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ python_dep = python.dependency()

libsystemd_dep = dependency('libsystemd')

common_c_args = [
add_project_arguments(
'-D_GNU_SOURCE=1',
'-DPACKAGE_VERSION="@0@"'.format(meson.project_version()),
'-DLIBSYSTEMD_VERSION=@0@'.format(libsystemd_dep.version()),
]
language : 'c',
)

subdir('src/systemd')
50 changes: 27 additions & 23 deletions src/systemd/_daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ PyDoc_STRVAR(booted__doc__,
"Wraps sd_booted(3)."
);

static PyObject* booted(PyObject *self, PyObject *args) {
static PyObject* booted(PyObject *self _unused_, PyObject *args) {
int r;

assert(!args);

r = sd_booted();
Expand All @@ -55,7 +56,7 @@ PyDoc_STRVAR(notify__doc__,
"Send a message to the init system about a status change.\n"
"Wraps sd_notify(3).");

static PyObject* notify(PyObject *self, PyObject *args, PyObject *keywds) {
static PyObject* notify(PyObject *self _unused_, PyObject *args, PyObject *keywds) {
int r;
const char* msg;
int unset = false, n_fds;
Expand Down Expand Up @@ -142,7 +143,7 @@ PyDoc_STRVAR(listen_fds__doc__,
"Wraps sd_listen_fds(3)."
);

static PyObject* listen_fds(PyObject *self, PyObject *args, PyObject *keywds) {
static PyObject* listen_fds(PyObject *self _unused_, PyObject *args, PyObject *keywds) {
int r;
int unset = true;

Expand All @@ -155,7 +156,7 @@ static PyObject* listen_fds(PyObject *self, PyObject *args, PyObject *keywds) {
if (set_error(r, NULL, NULL) < 0)
return NULL;

return long_FromLong(r);
return PyLong_FromLong(r);
}

PyDoc_STRVAR(listen_fds_with_names__doc__,
Expand All @@ -176,7 +177,8 @@ static void free_names(char **names) {
free(*n);
free(names);
}
static PyObject* listen_fds_with_names(PyObject *self, PyObject *args, PyObject *keywds) {

static PyObject* listen_fds_with_names(PyObject *self _unused_, PyObject *args, PyObject *keywds) {
int r;
int unset = false;
char **names = NULL;
Expand All @@ -196,7 +198,7 @@ static PyObject* listen_fds_with_names(PyObject *self, PyObject *args, PyObject
if (tpl == NULL)
return NULL;

item = long_FromLong(r);
item = PyLong_FromLong(r);
if (item == NULL) {
Py_DECREF(tpl);
return NULL;
Expand All @@ -206,7 +208,7 @@ static PyObject* listen_fds_with_names(PyObject *self, PyObject *args, PyObject
return NULL;
}
for (int i = 0; i < r && names[i] != NULL; i++) {
item = unicode_FromString(names[i]);
item = PyUnicode_FromString(names[i]);
if (PyTuple_SetItem(tpl, 1+i, item) < 0) {
Py_DECREF(tpl);
free_names(names);
Expand All @@ -228,7 +230,7 @@ PyDoc_STRVAR(is_fifo__doc__,
);


static PyObject* is_fifo(PyObject *self, PyObject *args) {
static PyObject* is_fifo(PyObject *self _unused_, PyObject *args) {
int r;
int fd;
const char *path = NULL;
Expand All @@ -254,7 +256,7 @@ PyDoc_STRVAR(is_mq__doc__,
"Wraps sd_is_mq(3)."
);

static PyObject* is_mq(PyObject *self, PyObject *args) {
static PyObject* is_mq(PyObject *self _unused_, PyObject *args) {
int r;
int fd;
const char *path = NULL;
Expand Down Expand Up @@ -282,7 +284,7 @@ PyDoc_STRVAR(is_socket__doc__,
"Constants for `family` are defined in the socket module."
);

static PyObject* is_socket(PyObject *self, PyObject *args) {
static PyObject* is_socket(PyObject *self _unused_, PyObject *args) {
int r;
int fd, family = AF_UNSPEC, type = 0, listening = -1;

Expand All @@ -304,7 +306,7 @@ PyDoc_STRVAR(is_socket_inet__doc__,
"Constants for `family` are defined in the socket module."
);

static PyObject* is_socket_inet(PyObject *self, PyObject *args) {
static PyObject* is_socket_inet(PyObject *self _unused_, PyObject *args) {
int r;
int fd, family = AF_UNSPEC, type = 0, listening = -1, port = 0;

Expand Down Expand Up @@ -337,7 +339,7 @@ PyDoc_STRVAR(is_socket_sockaddr__doc__,
#endif
);

static PyObject* is_socket_sockaddr(PyObject *self, PyObject *args) {
static PyObject* is_socket_sockaddr(PyObject *self _unused_, PyObject *args) {
int r;
int fd, type = 0, flowinfo = 0, listening = -1;
const char *address;
Expand Down Expand Up @@ -384,7 +386,7 @@ PyDoc_STRVAR(is_socket_unix__doc__,
"Wraps sd_is_socket_unix(3)."
);

static PyObject* is_socket_unix(PyObject *self, PyObject *args) {
static PyObject* is_socket_unix(PyObject *self _unused_, PyObject *args) {
int r;
int fd, type = 0, listening = -1;
char* path = NULL;
Expand All @@ -408,20 +410,22 @@ static PyObject* is_socket_unix(PyObject *self, PyObject *args) {
}


DISABLE_WARNING_CAST_FUNCTION_TYPE;
static PyMethodDef methods[] = {
{ "booted", booted, METH_NOARGS, booted__doc__},
{ "notify", (PyCFunction) notify, METH_VARARGS | METH_KEYWORDS, notify__doc__},
{ "_listen_fds", (PyCFunction) listen_fds, METH_VARARGS | METH_KEYWORDS, listen_fds__doc__},
{ "booted", booted, METH_NOARGS, booted__doc__ },
{ "notify", (PyCFunction) notify, METH_VARARGS | METH_KEYWORDS, notify__doc__ },
{ "_listen_fds", (PyCFunction) listen_fds, METH_VARARGS | METH_KEYWORDS, listen_fds__doc__ },
{ "_listen_fds_with_names", (PyCFunction) listen_fds_with_names,
METH_VARARGS | METH_KEYWORDS, listen_fds_with_names__doc__},
{ "_is_fifo", is_fifo, METH_VARARGS, is_fifo__doc__},
{ "_is_mq", is_mq, METH_VARARGS, is_mq__doc__},
{ "_is_socket", is_socket, METH_VARARGS, is_socket__doc__},
{ "_is_socket_inet", is_socket_inet, METH_VARARGS, is_socket_inet__doc__},
{ "_is_socket_sockaddr", is_socket_sockaddr, METH_VARARGS, is_socket_sockaddr__doc__},
{ "_is_socket_unix", is_socket_unix, METH_VARARGS, is_socket_unix__doc__},
METH_VARARGS | METH_KEYWORDS, listen_fds_with_names__doc__ },
{ "_is_fifo", is_fifo, METH_VARARGS, is_fifo__doc__ },
{ "_is_mq", is_mq, METH_VARARGS, is_mq__doc__ },
{ "_is_socket", is_socket, METH_VARARGS, is_socket__doc__ },
{ "_is_socket_inet", is_socket_inet, METH_VARARGS, is_socket_inet__doc__ },
{ "_is_socket_sockaddr", is_socket_sockaddr, METH_VARARGS, is_socket_sockaddr__doc__ },
{ "_is_socket_unix", is_socket_unix, METH_VARARGS, is_socket_unix__doc__ },
{} /* Sentinel */
};
REENABLE_WARNING;

static struct PyModuleDef module = {
PyModuleDef_HEAD_INIT,
Expand Down
28 changes: 12 additions & 16 deletions src/systemd/_journal.c
Original file line number Diff line number Diff line change
@@ -1,35 +1,31 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */

#include <Python.h>

#include <alloca.h>

#define SD_JOURNAL_SUPPRESS_LOCATION
#include "systemd/sd-journal.h"

#include "macro.h"
#include "pyutil.h"

PyDoc_STRVAR(journal_sendv__doc__,
"sendv('FIELD=value', 'FIELD=value', ...) -> None\n\n"
"Send an entry to the journal."
);

static PyObject *journal_sendv(PyObject *self, PyObject *args) {
struct iovec *iov = NULL;
int argc;
int i, r;
static PyObject* journal_sendv(PyObject *self _unused_, PyObject *args) {
PyObject *ret = NULL;
PyObject **encoded;
int r;

/* Allocate an array for the argument strings */
argc = PyTuple_Size(args);
encoded = alloca0(argc * sizeof(PyObject*));
int argc = PyTuple_Size(args);
PyObject **encoded = alloca0(argc * sizeof(PyObject*));

/* Allocate sufficient iovector space for the arguments. */
iov = alloca(argc * sizeof(struct iovec));
struct iovec *iov = alloca(argc * sizeof(struct iovec));

/* Iterate through the Python arguments and fill the iovector. */
for (i = 0; i < argc; ++i) {
for (int i = 0; i < argc; ++i) {
PyObject *item = PyTuple_GetItem(args, i);
char *stritem;
Py_ssize_t length;
Expand All @@ -51,7 +47,7 @@ static PyObject *journal_sendv(PyObject *self, PyObject *args) {
r = sd_journal_sendv(iov, argc);
if (r < 0) {
errno = -r;
PyErr_SetFromErrno(PyExc_IOError);
PyErr_SetFromErrno(PyExc_OSError);
goto out;
}

Expand All @@ -60,7 +56,7 @@ static PyObject *journal_sendv(PyObject *self, PyObject *args) {
ret = Py_None;

out:
for (i = 0; i < argc; ++i)
for (int i = 0; i < argc; i++)
Py_XDECREF(encoded[i]);

return ret;
Expand All @@ -71,7 +67,7 @@ PyDoc_STRVAR(journal_stream_fd__doc__,
"Open a stream to journal by calling sd_journal_stream_fd(3)."
);

static PyObject* journal_stream_fd(PyObject *self, PyObject *args) {
static PyObject* journal_stream_fd(PyObject *self _unused_, PyObject *args) {
const char* identifier;
int priority, level_prefix;
int fd;
Expand All @@ -83,14 +79,14 @@ static PyObject* journal_stream_fd(PyObject *self, PyObject *args) {
fd = sd_journal_stream_fd(identifier, priority, level_prefix);
if (fd < 0) {
errno = -fd;
return PyErr_SetFromErrno(PyExc_IOError);
return PyErr_SetFromErrno(PyExc_OSError);
}

return PyLong_FromLong(fd);
}

static PyMethodDef methods[] = {
{ "sendv", journal_sendv, METH_VARARGS, journal_sendv__doc__ },
{ "sendv", journal_sendv, METH_VARARGS, journal_sendv__doc__ },
{ "stream_fd", journal_stream_fd, METH_VARARGS, journal_stream_fd__doc__ },
{} /* Sentinel */
};
Expand Down
Loading