summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2015-07-05 14:39:14 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2015-07-05 15:10:30 -0400
commit31baccc855b48adde5173a31037bb1b82c42f7aa (patch)
treef932694ba82c76714400b09d08e7ebea435c1c51
parent022c9b5be4a1edf77bf73566a89ce41397f72147 (diff)
downloadpython-systemd-31baccc855b48adde5173a31037bb1b82c42f7aa.tar.gz
build-sys: update setup.py to build everything
-rw-r--r--Makefile5
-rw-r--r--setup.py42
-rw-r--r--systemd/.gitignore1
-rw-r--r--systemd/_journal.c3
-rw-r--r--systemd/_reader.c11
-rw-r--r--systemd/id128.c2
-rw-r--r--systemd/login.c1
-rw-r--r--systemd/macro.h60
-rw-r--r--systemd/strv.c40
-rw-r--r--systemd/strv.h26
10 files changed, 176 insertions, 15 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..ba2b316
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,5 @@
+SED = sed
+INCLUDE_DIR = /usr/include/
+
+systemd/id128-constants.h: $(INCLUDE_DIR)/systemd/sd-messages.h
+ $(SED) -n -r 's/,//g; s/#define (SD_MESSAGE_[A-Z0-9_]+)\s.*/add_id(m, "\1", \1) JOINER/p' <$< >$@
diff --git a/setup.py b/setup.py
index bd4402f..5ff205e 100644
--- a/setup.py
+++ b/setup.py
@@ -1,13 +1,43 @@
from distutils.core import setup, Extension
-cjournal = Extension('systemd/_journal',
- libraries = ['systemd-journal'],
- sources = ['systemd/_journal.c'])
+version = '221'
+defines = [('PACKAGE_VERSION', '"{}"'.format(version))]
+_journal = Extension('systemd/_journal',
+ define_macros = defines,
+ libraries = ['systemd'],
+ sources = ['systemd/_journal.c',
+ 'systemd/pyutil.c'])
+_reader = Extension('systemd/_reader',
+ define_macros = defines,
+ libraries = ['systemd'],
+ sources = ['systemd/_reader.c',
+ 'systemd/pyutil.c',
+ 'systemd/strv.c'])
+_daemon = Extension('systemd/_daemon',
+ define_macros = defines,
+ libraries = ['systemd'],
+ sources = ['systemd/_daemon.c',
+ 'systemd/pyutil.c'])
+id128 = Extension('systemd/id128',
+ define_macros = defines,
+ libraries = ['systemd'],
+ sources = ['systemd/id128.c',
+ 'systemd/pyutil.c'])
+login = Extension('systemd/login',
+ define_macros = defines,
+ libraries = ['systemd'],
+ sources = ['systemd/login.c',
+ 'systemd/pyutil.c',
+ 'systemd/strv.c'])
setup (name = 'systemd',
- version = '0.1',
+ version = version,
description = 'Native interface to the facilities of systemd',
author_email = 'david@davidstrauss.net',
url = 'https://github.com/systemd/python-systemd',
- py_modules = ['systemd.journal'],
- ext_modules = [cjournal])
+ py_modules = ['systemd.journal', 'systemd.daemon'],
+ ext_modules = [_journal,
+ _reader,
+ _daemon,
+ id128,
+ login])
diff --git a/systemd/.gitignore b/systemd/.gitignore
index 4124b7a..1d295fb 100644
--- a/systemd/.gitignore
+++ b/systemd/.gitignore
@@ -1,2 +1,3 @@
/id128-constants.h
*.py[oc]
+*.so
diff --git a/systemd/_journal.c b/systemd/_journal.c
index 456e4a2..ffa54e1 100644
--- a/systemd/_journal.c
+++ b/systemd/_journal.c
@@ -22,11 +22,12 @@
#include <Python.h>
#include <alloca.h>
-#include "util.h"
#define SD_JOURNAL_SUPPRESS_LOCATION
#include "systemd/sd-journal.h"
+#include "macro.h"
+
PyDoc_STRVAR(journal_sendv__doc__,
"sendv('FIELD=value', 'FIELD=value', ...) -> None\n\n"
"Send an entry to the journal."
diff --git a/systemd/_reader.c b/systemd/_reader.c
index 3a56126..a28081c 100644
--- a/systemd/_reader.c
+++ b/systemd/_reader.c
@@ -24,14 +24,13 @@
#include <datetime.h>
#include <time.h>
#include <stdio.h>
+#include <stdbool.h>
#include "systemd/sd-journal.h"
#include "pyutil.h"
#include "macro.h"
-#include "util.h"
#include "strv.h"
-#include "build.h"
typedef struct {
PyObject_HEAD
@@ -113,8 +112,10 @@ static int strv_converter(PyObject* obj, void *_result) {
goto cleanup;
s2 = strdup(s);
- if (!s2)
- log_oom();
+ if (!s2) {
+ set_error(-ENOMEM, NULL, NULL);
+ goto cleanup;
+ }
(*result)[i] = s2;
}
@@ -343,7 +344,7 @@ static PyObject* Reader_next(Reader *self, PyObject *args) {
else if (skip < -1LL)
r = sd_journal_previous_skip(self->j, -skip);
else
- assert_not_reached("should not be here");
+ assert(!"should be here");
Py_END_ALLOW_THREADS
if (set_error(r, NULL, NULL) < 0)
diff --git a/systemd/id128.c b/systemd/id128.c
index 5ec7309..bc2f6e8 100644
--- a/systemd/id128.c
+++ b/systemd/id128.c
@@ -24,8 +24,6 @@
#include "systemd/sd-messages.h"
#include "pyutil.h"
-#include "log.h"
-#include "util.h"
#include "macro.h"
PyDoc_STRVAR(module__doc__,
diff --git a/systemd/login.c b/systemd/login.c
index e844f5f..18b99cf 100644
--- a/systemd/login.c
+++ b/systemd/login.c
@@ -27,7 +27,6 @@
#include "systemd/sd-login.h"
#include "pyutil.h"
-#include "util.h"
#include "strv.h"
PyDoc_STRVAR(module__doc__,
diff --git a/systemd/macro.h b/systemd/macro.h
new file mode 100644
index 0000000..2af6006
--- /dev/null
+++ b/systemd/macro.h
@@ -0,0 +1,60 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+#pragma once
+
+/***
+ This file is part of systemd.
+
+ Copyright 2010 Lennart Poettering
+
+ 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/>.
+***/
+
+#define DISABLE_WARNING_MISSING_PROTOTYPES \
+ _Pragma("GCC diagnostic push"); \
+ _Pragma("GCC diagnostic ignored \"-Wmissing-prototypes\"")
+
+#define REENABLE_WARNING \
+ _Pragma("GCC diagnostic pop")
+
+#define DEFINE_TRIVIAL_CLEANUP_FUNC(type, func) \
+ static inline void func##p(type *p) { \
+ if (*p) \
+ func(*p); \
+ } \
+ struct __useless_struct_to_allow_trailing_semicolon__
+
+#define new0(t, n) ((t*) calloc((n), sizeof(t)))
+#define alloca0(n) \
+ ({ \
+ char *_new_; \
+ size_t _len_ = n; \
+ _new_ = alloca(_len_); \
+ (void *) memset(_new_, 0, _len_); \
+ })
+
+#define _cleanup_(x) __attribute__((cleanup(x)))
+
+static inline void freep(void *p) {
+ free(*(void**) p);
+}
+
+#define _cleanup_free_ _cleanup_(freep)
+
+#if defined(static_assert)
+# define assert_cc(expr) \
+ static_assert(expr, #expr)
+#else
+# define assert_cc(expr)
+#endif
diff --git a/systemd/strv.c b/systemd/strv.c
new file mode 100644
index 0000000..373346d
--- /dev/null
+++ b/systemd/strv.c
@@ -0,0 +1,40 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+ This file is part of systemd.
+
+ Copyright 2010 Lennart Poettering
+
+ 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 <stdlib.h>
+
+void strv_clear(char **l) {
+ char **k;
+
+ if (!l)
+ return;
+
+ for (k = l; *k; k++)
+ free(*k);
+
+ *l = NULL;
+}
+
+char **strv_free(char **l) {
+ strv_clear(l);
+ free(l);
+ return NULL;
+}
diff --git a/systemd/strv.h b/systemd/strv.h
new file mode 100644
index 0000000..942849a
--- /dev/null
+++ b/systemd/strv.h
@@ -0,0 +1,26 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+ This file is part of systemd.
+
+ Copyright 2010 Lennart Poettering
+
+ 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 "macro.h"
+
+char **strv_free(char **l);
+DEFINE_TRIVIAL_CLEANUP_FUNC(char**, strv_free);
+#define _cleanup_strv_free_ _cleanup_(strv_freep)