Skip to content

Commit 570a1de

Browse files
committed
Add elogind support and use pkg-config to get libsystemd version
1 parent 06cb91b commit 570a1de

File tree

4 files changed

+30
-31
lines changed

4 files changed

+30
-31
lines changed

.github/workflows/ubuntu_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
run: |
3737
sudo apt update
3838
sudo apt install python3-setuptools python3-dev libsystemd-dev \
39-
systemd dbus python3 gcc
39+
systemd dbus python3 gcc pkg-config
4040
- name: Build extension
4141
env:
4242
PYTHON_SDBUS_USE_LIMITED_API: "1"

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Features:
99
* Asyncio and blocking calls.
1010
* Type hints. (`mypy --strict` compatible)
1111
* No Python 2 legacy.
12-
* Based on fast sd-bus from systemd.
12+
* Based on fast sd-bus from systemd. (also supports elogind)
1313
* Unified client/server interface classes. Write interface once!
1414
* Dbus methods can have keyword and default arguments.
1515

@@ -50,9 +50,10 @@ platforms.
5050
* Python 3.8 or higher.
5151
* Python headers. (`python3-dev` package on ubuntu)
5252
* GCC.
53-
* libsystemd. (comes with systemd)
53+
* libsystemd or libelogind
5454
* libsystemd headers. (`libsystemd-dev` package on ubuntu)
5555
* Python setuptools.
56+
* pkg-config
5657

5758
Systemd version should be higher than 246.
5859

setup.py

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from __future__ import annotations
2121

2222
from os import environ
23-
from subprocess import DEVNULL, PIPE, CalledProcessError
23+
from subprocess import DEVNULL, PIPE
2424
from subprocess import run as subprocess_run
2525
from typing import List, Optional, Tuple
2626

@@ -30,49 +30,47 @@
3030
c_macros: List[Tuple[str, Optional[str]]] = []
3131

3232

33-
def get_libsystemd_version() -> Tuple[int, int, int]:
33+
def get_libsystemd_version() -> int:
3434
process = subprocess_run(
35-
args=('ldconfig', '-f', '/dev/null', '-C', '/dev/null',
36-
'-v', '-N', '-X'),
35+
args=('pkg-config', '--modversion', 'libsystemd'),
3736
stderr=DEVNULL,
3837
stdout=PIPE,
38+
check=True,
3939
)
4040

41-
try:
42-
process.check_returncode()
43-
except CalledProcessError:
44-
return 0, 0, 0
45-
4641
result_str = process.stdout.decode('utf-8')
4742

48-
for line in result_str.splitlines():
49-
if 'libsystemd.so' in line:
50-
version_str = line.split('libsystemd.so')[-1]
51-
semver_strs = version_str.split('.')
52-
return (
53-
int(semver_strs[1]),
54-
int(semver_strs[2]),
55-
int(semver_strs[3]),
56-
)
57-
58-
return 0, 0, 0
43+
return int(result_str)
5944

6045

6146
if not environ.get('PYTHON_SDBUS_USE_IGNORE_SYSTEMD_VERSION'):
62-
LIBSYSTEMD_MAJOR, LIBSYSTEMD_MINOR, LIBSYTEMD_PATCH \
63-
= get_libsystemd_version()
47+
systemd_version = get_libsystemd_version()
6448

65-
if LIBSYSTEMD_MAJOR <= 0 and LIBSYSTEMD_MINOR < 29:
49+
if systemd_version < 246:
6650
c_macros.append(('LIBSYSTEMD_NO_VALIDATION_FUNCS', None))
6751

68-
if LIBSYSTEMD_MAJOR <= 0 and LIBSYSTEMD_MINOR < 31:
52+
if systemd_version < 248:
6953
c_macros.append(('LIBSYSTEMD_NO_OPEN_USER_MACHINE', None))
7054

71-
link_arguments: List[str] = ['-lsystemd']
55+
56+
def get_link_arguments() -> List[str]:
57+
process = subprocess_run(
58+
args=('pkg-config', '--libs-only-l', 'libsystemd'),
59+
stderr=DEVNULL,
60+
stdout=PIPE,
61+
check=True,
62+
)
63+
64+
result_str = process.stdout.decode('utf-8')
65+
66+
return result_str.rstrip(' \n').split(' ')
67+
68+
69+
link_arguments: List[str] = get_link_arguments()
7270

7371
if environ.get('PYTHON_SDBUS_USE_STATIC_LINK'):
7472
# Link statically against libsystemd and libcap
75-
link_arguments = ['-Wl,-Bstatic', '-lsystemd', '-lcap',
73+
link_arguments = ['-Wl,-Bstatic', *link_arguments, '-lcap',
7674
'-Wl,-Bdynamic', '-lrt', '-lpthread']
7775

7876
link_arguments.append('-flto')

src/sdbus/sd_bus_internals_funcs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static SdBusObject* sd_bus_py_open_user_machine(PyObject* Py_UNUSED(self), PyObj
6565
CALL_SD_BUS_AND_CHECK(sd_bus_open_user_machine(&(new_sd_bus->sd_bus_ref), remote_host_char_ptr));
6666
return new_sd_bus;
6767
#else
68-
PyErr_SetString(PyExc_NotImplementedError, "libsystemd<0.31.0 does not opening machine user bus");
68+
PyErr_SetString(PyExc_NotImplementedError, "libsystemd < 248 does not support opening machine user bus");
6969
return NULL;
7070
#endif
7171
}
@@ -86,7 +86,7 @@ static PyObject* encode_object_path(PyObject* Py_UNUSED(self), PyObject* args) {
8686
CALL_PYTHON_BOOL_CHECK(PyArg_ParseTuple(args, "ss", &prefix_char_ptr, &external_char_ptr, NULL));
8787
#endif
8888
#ifdef LIBSYSTEMD_NO_VALIDATION_FUNCS
89-
PyErr_SetString(PyExc_NotImplementedError, "libsystemd<0.29.0 does not support validation functions");
89+
PyErr_SetString(PyExc_NotImplementedError, "libsystemd < 246 does not support validation functions");
9090
return NULL;
9191
#else
9292

0 commit comments

Comments
 (0)