Skip to content

Commit f83dea9

Browse files
committed
Add compatibility with systemd < 205
1 parent c71fbb5 commit f83dea9

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

setup.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys, os
22
from distutils.core import setup, Extension
3-
from subprocess import Popen, PIPE
3+
from subprocess import Popen, PIPE, check_output
44

55
def call(*cmd):
66
cmd = Popen(cmd,
@@ -18,14 +18,20 @@ def pkgconfig(package, **kw):
1818
return status, result
1919
for token in result.split():
2020
kw.setdefault(flag_map.get(token[:2]), []).append(token[2:])
21+
version = check_output(['pkg-config', '--modversion', package],
22+
universal_newlines=True).strip()
23+
pair = (package.replace('-', '_').upper() + '_VERSION', version)
24+
defines = kw.setdefault('define_macros', [])
25+
if pair not in defines:
26+
defines.append(pair)
2127
return status, kw
2228

23-
def lib(*names):
29+
def lib(*names, **kw):
2430
if '--version' in sys.argv:
2531
return {}
2632
results = []
2733
for name in names:
28-
status, result = pkgconfig(name)
34+
status, result = pkgconfig(name, **kw)
2935
if status == 0:
3036
return result
3137
results.append(result)
@@ -34,35 +40,30 @@ def lib(*names):
3440
sys.exit(status)
3541

3642
version = '230'
37-
defines = [('PACKAGE_VERSION', '"{}"'.format(version))]
43+
defines = {'define_macros':[('PACKAGE_VERSION', '"{}"'.format(version))]}
3844

3945
_journal = Extension('systemd/_journal',
40-
define_macros = defines,
4146
sources = ['systemd/_journal.c',
4247
'systemd/pyutil.c'],
43-
**lib('libsystemd', 'libsystemd-journal'))
48+
**lib('libsystemd', 'libsystemd-journal', **defines))
4449
_reader = Extension('systemd/_reader',
45-
define_macros = defines,
4650
sources = ['systemd/_reader.c',
4751
'systemd/pyutil.c',
4852
'systemd/strv.c'],
49-
**lib('libsystemd', 'libsystemd-journal'))
53+
**lib('libsystemd', 'libsystemd-journal', **defines))
5054
_daemon = Extension('systemd/_daemon',
51-
define_macros = defines,
5255
sources = ['systemd/_daemon.c',
5356
'systemd/pyutil.c'],
54-
**lib('libsystemd', 'libsystemd-daemon'))
57+
**lib('libsystemd', 'libsystemd-daemon', **defines))
5558
id128 = Extension('systemd/id128',
56-
define_macros = defines,
5759
sources = ['systemd/id128.c',
5860
'systemd/pyutil.c'],
59-
**lib('libsystemd', 'libsystemd-id128'))
61+
**lib('libsystemd', 'libsystemd-id128', **defines))
6062
login = Extension('systemd/login',
61-
define_macros = defines,
6263
sources = ['systemd/login.c',
6364
'systemd/pyutil.c',
6465
'systemd/strv.c'],
65-
**lib('libsystemd', 'libsystemd-login'))
66+
**lib('libsystemd', 'libsystemd-login', **defines))
6667
setup (name = 'python-systemd',
6768
version = version,
6869
description = 'Native interface to the facilities of systemd',

systemd/_reader.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@
3131
#include "macro.h"
3232
#include "strv.h"
3333

34+
#if defined(LIBSYSTEMD_VERSION) || LIBSYSTEMD_JOURNAL_VERSION > 204
35+
# define HAVE_JOURNAL_OPEN_FILES
36+
#else
37+
# define SD_JOURNAL_SYSTEM 4
38+
# define SD_JOURNAL_CURRENT_USER 8
39+
#endif
40+
3441
typedef struct {
3542
PyObject_HEAD
3643
sd_journal *j;
@@ -170,9 +177,13 @@ static int Reader_init(Reader *self, PyObject *args, PyObject *keywds) {
170177
Py_BEGIN_ALLOW_THREADS
171178
if (path)
172179
r = sd_journal_open_directory(&self->j, path, 0);
173-
else if (files)
180+
else if (files) {
181+
#ifdef HAVE_JOURNAL_OPEN_FILES
174182
r = sd_journal_open_files(&self->j, (const char**) files, 0);
175-
else
183+
#else
184+
r = -ENOSYS;
185+
#endif
186+
} else
176187
r = sd_journal_open(&self->j, flags);
177188
Py_END_ALLOW_THREADS
178189

0 commit comments

Comments
 (0)