diff --git a/.dir-locals.el b/.dir-locals.el index 8bccaf0..489230c 100644 --- a/.dir-locals.el +++ b/.dir-locals.el @@ -2,6 +2,17 @@ ; A list of (major-mode . ((var1 . value1) (var2 . value2))) ; Mode can be nil, which gives default values. -((nil . ((indent-tabs-mode . nil) - (c-basic-offset . 4))) -) +; NOTE: If you update this file make sure to update .editorconfig too. + +((c-mode . ((fill-column . 109) + (c-basic-offset . 8) + (eval . (c-set-offset 'substatement-open 0)) + (eval . (c-set-offset 'statement-case-open 0)) + (eval . (c-set-offset 'case-label 0)) + (eval . (c-set-offset 'arglist-intro '++)) + (eval . (c-set-offset 'arglist-close 0)) + (eval . (c-set-offset 'arglist-cont-nonempty '(c-lineup-gcc-asm-reg c-lineup-arglist))))) + (meson-mode . ((meson-indent-basic . 8))) + (nil . ((indent-tabs-mode . nil) + (tab-width . 8) + (fill-column . 79))) ) diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..04eb116 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,3 @@ +[meson.build] +indent_style = space +indent_size = 8 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..95701d0 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +*.[ch] whitespace=tab-in-indent,trailing-space +*.py whitespace=tab-in-indent,trailing-space diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 93f1bb1..4a4e645 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,7 +2,7 @@ # vi: ts=2 sw=2 et: # SPDX-License-Identifier: LGPL-2.1-or-later # -name: Build test +name: Build on: pull_request: push: @@ -14,27 +14,36 @@ permissions: jobs: build: - runs-on: ubuntu-20.04 - concurrency: - group: ${{ github.workflow }}-${{ matrix.python }}-${{ github.ref }} - cancel-in-progress: true strategy: fail-fast: false matrix: + os: ["ubuntu-22.04", "ubuntu-24.04", "ubuntu-26.04"] python: [ - "3.7", - "3.8", "3.9", "3.10", - "3.11.0-rc.1", + "3.11", + "3.12", + "3.13", + "3.14", ] - name: Python ${{ matrix.python }} + exclude: + - os: "ubuntu-22.04" + python: "3.13" + - os: "ubuntu-22.04" + python: "3.14" + - os: "ubuntu-26.04" + python: "3.9" + runs-on: ${{ matrix.os }} + concurrency: + group: ${{ github.workflow }}-${{ matrix.python }}-${{ matrix.os }}-${{ github.ref }} + cancel-in-progress: true + name: Python ${{ matrix.python }} on ${{ matrix.os }} steps: - name: Repository checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Configure Python ${{ matrix.python }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python }} architecture: x64 @@ -43,14 +52,14 @@ jobs: run: | sudo apt -y update sudo apt -y install gcc libsystemd-dev - python -m pip install pytest sphinx + python -m pip install -U --break-system-packages pip build + # Note: The `pip install --group` is available on pip v25+ - name: Build (Python ${{ matrix.python }}) run: | set -x - make -j - make doc SPHINXOPTS="-W -v" - - - name: Test (Python ${{ matrix.python }}) - run: | - make check + python -m build -Cbuild-dir=build + python -m pip install --group docs + python -m pip install . + cd build + python -m sphinx -b html -W -v ../docs html diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..0e799f1 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,54 @@ +--- +# vi: ts=2 sw=2 et: +# SPDX-License-Identifier: LGPL-2.1-or-later +# +name: "CodeQL" + +on: + push: + branches: + - main + pull_request: + branches: + - main + +permissions: + contents: read + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-24.04 + concurrency: + group: ${{ github.workflow }}-${{ matrix.language }}-${{ github.ref }} + cancel-in-progress: true + permissions: + actions: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: ['cpp', 'python'] + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Initialize CodeQL + uses: github/codeql-action/init@v3 + with: + languages: ${{ matrix.language }} + queries: +security-extended,security-and-quality + + - name: Install dependencies + run: | + sudo apt -y update + sudo apt -y install gcc libsystemd-dev + python -m pip install -U --break-system-packages pip build + + - name: Autobuild + uses: github/codeql-action/autobuild@v3 + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v3 diff --git a/.github/workflows/install.yml b/.github/workflows/install.yml index 6a8cc39..055574f 100644 --- a/.github/workflows/install.yml +++ b/.github/workflows/install.yml @@ -2,7 +2,7 @@ # vi: ts=2 sw=2 et: # SPDX-License-Identifier: LGPL-2.1-or-later # -name: Install test +name: Install then test on: pull_request: push: @@ -24,16 +24,14 @@ jobs: container: [ "archlinux:latest", "debian:testing", - "quay.io/centos/centos:stream8", + "quay.io/centos/centos:stream10", "quay.io/fedora/fedora:rawhide", - "ubuntu:focal", + "ubuntu:noble", ] container: image: ${{ matrix.container }} name: ${{ matrix.container }} steps: - - name: Repository checkout - uses: actions/checkout@v2 - name: Install dependencies shell: bash @@ -51,10 +49,14 @@ jobs: case "$DIST_ID" in arch) - pacman --noconfirm -Sy "${DEPS_COMMON[@]}" systemd-libs - python3 -m ensurepip + pacman --noconfirm -Sy -u "${DEPS_COMMON[@]}" systemd-libs python-pip + ;; + centos) + dnf config-manager --set-enabled crb + dnf install -y epel-release + dnf -y install "${DEPS_COMMON[@]}" systemd-devel python3-devel python3-pip ;; - centos|fedora) + fedora) dnf -y install "${DEPS_COMMON[@]}" systemd-devel python3-devel python3-pip ;; ubuntu|debian) @@ -66,16 +68,22 @@ jobs: exit 1 esac - python3 -m pip install pytest sphinx + python3 -m pip install -U --break-system-packages build pytest + + - name: Fix Git config to satisfy Meson + run: git config --global safe.directory "*" + + # Checkout repo after installing Git, or the "checkout" GH Action will download our source as non-Git repo, making Meson fail + # to build Python source dist. + - name: Repository checkout + uses: actions/checkout@v4 - - name: Build & install + - name: Install & test shell: bash run: | set -x - python3 -m pip install -I -v . - # Avoid importing the systemd module from the git repository - cd / + git --version + python3 -m build + python3 -m pip install --break-system-packages . python3 -c 'from systemd import journal; print(journal.__version__)' - # Initialize /etc/machine-id if it's empty to make the tests happy - [[ ! -s /etc/machine-id ]] && systemd-id128 new >/etc/machine-id pytest -v --pyargs systemd diff --git a/.gitignore b/.gitignore index e6610fe..caaa83a 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ sdist develop-eggs .installed.cfg MANIFEST +.venv # Installer logs pip-log.txt @@ -30,3 +31,6 @@ pip-log.txt #Mr Developer .mr.developer.cfg + +# Zed +.zed diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index 49dc944..0000000 --- a/MANIFEST.in +++ /dev/null @@ -1,8 +0,0 @@ -include systemd/*.h -include README.md -include NEWS -include LICENSE.txt -include Makefile -include pytest.ini -graft docs -exclude docs/__pycache__/* diff --git a/Makefile b/Makefile index 02d357f..f107112 100644 --- a/Makefile +++ b/Makefile @@ -1,78 +1,48 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later + PYTHON = python SED = sed ETAGS = etags INCLUDE_DIR := $(shell pkg-config --variable=includedir libsystemd) INCLUDE_FLAGS := $(shell pkg-config --cflags libsystemd) -VERSION := $(shell $(PYTHON) setup.py --version) +VERSION := $(shell meson introspect --projectinfo build | jq -r .version) TESTFLAGS = -v - -define buildscript -import sys, sysconfig, setuptools -sversion = int(setuptools.__version__.split(".")[0]) -end = sys.implementation.cache_tag if sversion >= 61 else "{}.{}".format(*sys.version_info[:2]) -print("build/lib.{}-{}".format(sysconfig.get_platform(), end)) -endef - -builddir := $(shell $(PYTHON) -c '$(buildscript)') +BUILD_DIR = build all: build -.PHONY: update-constants -update-constants: update-constants.py $(INCLUDE_DIR)/systemd/sd-messages.h - $(PYTHON) $+ systemd/id128-defines.h | \ - sort -u | \ - tee systemd/id128-defines.h.tmp | \ - $(SED) -n -r 's/,//g; s/#define (SD_MESSAGE_[A-Z0-9_]+)\s.*/add_id(m, "\1", \1) JOINER/p' | \ - sort -u >systemd/id128-constants.h.tmp - mv systemd/id128-defines.h{.tmp,} - mv systemd/id128-constants.h{.tmp,} - ($(SED) 9q docs/id128.rst.tmp - mv docs/id128.rst{.tmp,} - build: - $(PYTHON) setup.py build_ext $(INCLUDE_FLAGS) - $(PYTHON) setup.py build + $(PYTHON) -m build -Cbuild-dir=$(BUILD_DIR) install: - $(PYTHON) setup.py install --skip-build $(if $(DESTDIR),--root $(DESTDIR)) + $(PYTHON) -m pip install . dist: - $(PYTHON) setup.py sdist + $(PYTHON) -m build --sdist sign: dist/systemd-python-$(VERSION).tar.gz gpg --detach-sign -a dist/systemd-python-$(VERSION).tar.gz clean: - rm -rf build systemd/*.so systemd/*.py[co] *.py[co] systemd/__pycache__ + rm -rf $(BUILD_DIR) systemd/*.so systemd/*.py[co] *.py[co] systemd/__pycache__ distclean: clean rm -rf dist MANIFEST -SPHINXOPTS += -D version=$(VERSION) -D release=$(VERSION) -sphinx-%: build - cd build && \ - PYTHONPATH=../$(builddir) $(PYTHON) -m sphinx -b $* $(SPHINXOPTS) ../docs $* - @echo Output has been generated in build/$* - -doc: sphinx-html - -check: build - (cd $(builddir) && $(PYTHON) -m pytest . ../../docs $(TESTFLAGS)) +check: build install + ($(PYTHON) -m pytest src/systemd/test docs $(TESTFLAGS)) www_target = www.freedesktop.org:/srv/www.freedesktop.org/www/software/systemd/python-systemd doc-sync: - rsync -rlv --delete --omit-dir-times build/html/ $(www_target)/ + rsync -rlv --delete --omit-dir-times $(BUILD_DIR)/html/ $(www_target)/ -upload: dist/systemd-python-$(VERSION).tar.gz dist/systemd-python-$(VERSION).tar.gz.asc - twine-3 upload $+ +upload: dist/systemd_python-$(VERSION).tar.gz + twine upload $+ TAGS: $(shell git ls-files systemd/*.[ch]) $(ETAGS) $+ shell: -# we change the directory because python insists on adding $CWD to path - (cd $(builddir) && $(PYTHON)) + $(PYTHON) .PHONY: build install dist sign upload clean distclean TAGS doc doc-sync shell diff --git a/NEWS b/NEWS index 17e3b82..d40535d 100644 --- a/NEWS +++ b/NEWS @@ -1,26 +1,66 @@ Python wrappers for libsystemd API +CHANGES WITH 236: + + * Building python-systemd has been modernized and the project now uses + pyproject.toml instead of setup.py. Meson has been adopted as the + project's build system. + + Note to packagers: meson-python is now a build dependency of + python-systemd. + + * The running of tests and building documentation has been integrated + with meson. + + Tests can be run as + + meson test -C build + + and the documentation can be built with + + meson compile -C build html + + * Support for Python 2 as well as Python 3.7 and 3.8 has been dropped. + + * Various build warnings have been addressed and a fresh build should + be clean now. + + * All files use SPDX license headers now. + + Contributions from: Eric T. Johnson, Frantisek Sumsal, Guiorgy, + Jelle van der Waa, Jörg Behrmann, Nguyễn Hồng Quân, + Zbigniew Jędrzejewski-Szmek + CHANGES WITH 235: * Adapt the rename of systemd-activate to systemd-socket-activate performed in systemd 230. - * Support for the new sd_listen_fds_with_names added in systemd 227 - is added. + * Support for sd_listen_fds_with_names added in systemd 227. + + * Support for sd_journal_get_cutoff_realtime_usec added in systemd + 186. * Make the Reader PY_SSIZE_T_CLEAN for py3.10 compatibility. * id128: update for systemd-243 compatibility and other fixes. - * C syntax modernization. A minimum of C99 is assumed. + * C syntax modernization. A minimum of C99 is assumed. - * Fix seek_realtime to work with timezone aware date. + * Fix seek_realtime to work with timezone aware date on Python 3. * journal: add namespace support. - * Memory leak fixes. + * Fixes for memory leaks and documentation. + + * Support for Python 2 will be removed after this release. - * Documentation and other fixes. + Contributions from: Alexander Olekhnovich, Andrew Stone, + Architector #4, Chris Mullins, Dan Bungert, Dominik Prien, + Federico Ceratto, Frantisek Sumsal, Glandos, Hendrikto, Khem + Raj, Léonard Gérard, Marcel Waldvogel, Marco Paolini, Samuel + BF, Tamaki Nishino, Tim Orling, Tomasz Meresiński, Zbigniew + Jędrzejewski-Szmek, ytyt-yt CHANGES WITH 234: diff --git a/README.md b/README.md index 8c5c5bf..78b8de1 100644 --- a/README.md +++ b/README.md @@ -34,28 +34,21 @@ On Arch: pacman -Sy python-systemd -To build from source --------------------- +The project is also available on pypi as `systemd-python`: -On CentOS, RHEL, and Fedora with Python 2: +[![PyPI](https://img.shields.io/pypi/v/systemd-python.svg)](https://pypi.org/project/systemd-python/) - dnf install git python-pip gcc python-devel systemd-devel - pip install 'git+https://github.com/systemd/python-systemd.git#egg=systemd-python' +To build from source +-------------------- -On Fedora with Python 3: +On CentOS, RHEL, and Fedora: dnf install git python3-pip gcc python3-devel systemd-devel pip3 install 'git+https://github.com/systemd/python-systemd.git#egg=systemd-python' -On Debian or Ubuntu with Python 2: - - apt install libsystemd-{journal,daemon,login,id128}-dev gcc python-dev pkg-config - -On Debian or Ubuntu with Python 3: - - apt install libsystemd-{journal,daemon,login,id128}-dev gcc python3-dev pkg-config +On Debian or Ubuntu: -The project is also available on pypi as `systemd-python`. + apt install libsystemd-dev gcc python3-dev pkg-config Usage ===== @@ -160,12 +153,11 @@ Notes ----- * Unlike the native C version of journald's `sd_journal_send()`, - printf-style substitution is not supported. Perform any - substitution using Python's f-strings first (or .format() - capabilities or `%` operator). + printf-style substitution is not supported. Perform any substitution + using Python's f-strings first (or `.format()` or the `%` operator). * A `ValueError` is raised if `sd_journald_sendv()` results in an - error. This might happen if there are no arguments or one of them - is invalid. + error. This might happen if there are no arguments or one of them is + invalid. A handler class for the Python logging framework is also provided: @@ -193,9 +185,9 @@ Online documentation can be found at [freedesktop.org](https://www.freedesktop.o To build it locally run: - make sphinx-html + ninja -C build html -Or use any other builder, see `man sphinx-build` for a list. The compiled docs will be e.g. in `docs/html`. +Or use any other builder, see `man sphinx-build` for a list. The compiled docs will be e.g. in `build/html`. Viewing Output ============== @@ -207,7 +199,8 @@ Quick way to view output with all fields as it comes in: Test Builds (for Development) ============================= - python setup.py build_ext -i + python -m build + python -m pip install . python >>> from systemd import journal >>> journal.send("Test") diff --git a/docs/conf.py b/docs/conf.py index 05df507..3329338 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,3 +1,5 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later + # -*- coding: utf-8 -*- # # python-systemd documentation build configuration file, created by @@ -275,6 +277,5 @@ # Allow duplicate toc entries. #epub_tocdup = True - # Example configuration for intersphinx: refer to the Python standard library. -intersphinx_mapping = {'http://docs.python.org/': None} +intersphinx_mapping = {'python': ('https://docs.python.org/3', None)} diff --git a/docs/daemon.rst b/docs/daemon.rst index 0ad11ed..d6065e0 100644 --- a/docs/daemon.rst +++ b/docs/daemon.rst @@ -1,3 +1,5 @@ +.. SPDX-License-Identifier: LGPL-2.1-or-later + `systemd.daemon` module ======================= diff --git a/docs/id128.rst b/docs/id128.rst index cd562d5..99d1e8d 100644 --- a/docs/id128.rst +++ b/docs/id128.rst @@ -1,3 +1,5 @@ +.. SPDX-License-Identifier: LGPL-2.1-or-later + `systemd.id128` module ====================== @@ -8,17 +10,44 @@ .. autogenerated, do not edit! .. autoattribute:: systemd.id128.SD_MESSAGE_BACKTRACE + .. autoattribute:: systemd.id128.SD_MESSAGE_BATTERY_LOW_POWEROFF + .. autoattribute:: systemd.id128.SD_MESSAGE_BATTERY_LOW_WARNING .. autoattribute:: systemd.id128.SD_MESSAGE_BOOTCHART + .. autoattribute:: systemd.id128.SD_MESSAGE_CANT_BREAK_ORDERING_CYCLE .. autoattribute:: systemd.id128.SD_MESSAGE_CONFIG_ERROR .. autoattribute:: systemd.id128.SD_MESSAGE_COREDUMP + .. autoattribute:: systemd.id128.SD_MESSAGE_CORE_CAPABILITY_BOUNDING + .. autoattribute:: systemd.id128.SD_MESSAGE_CORE_CAPABILITY_BOUNDING_USER + .. autoattribute:: systemd.id128.SD_MESSAGE_CORE_DISABLE_PRIVILEGES + .. autoattribute:: systemd.id128.SD_MESSAGE_CORE_FD_SET_FAILED + .. autoattribute:: systemd.id128.SD_MESSAGE_CORE_ISOLATE_TARGET_FAILED + .. autoattribute:: systemd.id128.SD_MESSAGE_CORE_MAINLOOP_FAILED + .. autoattribute:: systemd.id128.SD_MESSAGE_CORE_MANAGER_ALLOCATE + .. autoattribute:: systemd.id128.SD_MESSAGE_CORE_NO_XDGDIR_PATH + .. autoattribute:: systemd.id128.SD_MESSAGE_CORE_PID1_ENVIRONMENT + .. autoattribute:: systemd.id128.SD_MESSAGE_CORE_START_TARGET_FAILED + .. autoattribute:: systemd.id128.SD_MESSAGE_CRASH_COREDUMP_FAILED + .. autoattribute:: systemd.id128.SD_MESSAGE_CRASH_COREDUMP_PID + .. autoattribute:: systemd.id128.SD_MESSAGE_CRASH_EXECLE_FAILED + .. autoattribute:: systemd.id128.SD_MESSAGE_CRASH_EXIT + .. autoattribute:: systemd.id128.SD_MESSAGE_CRASH_FAILED + .. autoattribute:: systemd.id128.SD_MESSAGE_CRASH_FREEZE + .. autoattribute:: systemd.id128.SD_MESSAGE_CRASH_NO_COREDUMP + .. autoattribute:: systemd.id128.SD_MESSAGE_CRASH_NO_FORK + .. autoattribute:: systemd.id128.SD_MESSAGE_CRASH_PROCESS_SIGNAL + .. autoattribute:: systemd.id128.SD_MESSAGE_CRASH_SHELL_FORK_FAILED + .. autoattribute:: systemd.id128.SD_MESSAGE_CRASH_SYSTEMD_SIGNAL + .. autoattribute:: systemd.id128.SD_MESSAGE_CRASH_UNKNOWN_SIGNAL + .. autoattribute:: systemd.id128.SD_MESSAGE_CRASH_WAITPID_FAILED + .. autoattribute:: systemd.id128.SD_MESSAGE_DELETING_JOB_BECAUSE_ORDERING_CYCLE .. autoattribute:: systemd.id128.SD_MESSAGE_DEVICE_PATH_NOT_SUITABLE .. autoattribute:: systemd.id128.SD_MESSAGE_DNSSEC_DOWNGRADE .. autoattribute:: systemd.id128.SD_MESSAGE_DNSSEC_FAILURE .. autoattribute:: systemd.id128.SD_MESSAGE_DNSSEC_TRUST_ANCHOR_REVOKED .. autoattribute:: systemd.id128.SD_MESSAGE_FACTORY_RESET .. autoattribute:: systemd.id128.SD_MESSAGE_FORWARD_SYSLOG_MISSED - .. autoattribute:: systemd.id128.SD_MESSAGE_HIBERNATE_KEY_LONG_PRESS .. autoattribute:: systemd.id128.SD_MESSAGE_HIBERNATE_KEY + .. autoattribute:: systemd.id128.SD_MESSAGE_HIBERNATE_KEY_LONG_PRESS .. autoattribute:: systemd.id128.SD_MESSAGE_INVALID_CONFIGURATION .. autoattribute:: systemd.id128.SD_MESSAGE_JOURNAL_DROPPED .. autoattribute:: systemd.id128.SD_MESSAGE_JOURNAL_MISSED @@ -29,35 +58,56 @@ .. autoattribute:: systemd.id128.SD_MESSAGE_LID_OPENED .. autoattribute:: systemd.id128.SD_MESSAGE_MACHINE_START .. autoattribute:: systemd.id128.SD_MESSAGE_MACHINE_STOP + .. autoattribute:: systemd.id128.SD_MESSAGE_MEMORY_TRIM .. autoattribute:: systemd.id128.SD_MESSAGE_MOUNT_POINT_PATH_NOT_SUITABLE .. autoattribute:: systemd.id128.SD_MESSAGE_NOBODY_USER_UNSUITABLE + .. autoattribute:: systemd.id128.SD_MESSAGE_NON_CANONICAL_MOUNT .. autoattribute:: systemd.id128.SD_MESSAGE_OVERMOUNTING - .. autoattribute:: systemd.id128.SD_MESSAGE_POWER_KEY_LONG_PRESS + .. autoattribute:: systemd.id128.SD_MESSAGE_PORTABLE_ATTACHED + .. autoattribute:: systemd.id128.SD_MESSAGE_PORTABLE_DETACHED .. autoattribute:: systemd.id128.SD_MESSAGE_POWER_KEY - .. autoattribute:: systemd.id128.SD_MESSAGE_REBOOT_KEY_LONG_PRESS + .. autoattribute:: systemd.id128.SD_MESSAGE_POWER_KEY_LONG_PRESS .. autoattribute:: systemd.id128.SD_MESSAGE_REBOOT_KEY + .. autoattribute:: systemd.id128.SD_MESSAGE_REBOOT_KEY_LONG_PRESS .. autoattribute:: systemd.id128.SD_MESSAGE_SEAT_START .. autoattribute:: systemd.id128.SD_MESSAGE_SEAT_STOP + .. autoattribute:: systemd.id128.SD_MESSAGE_SECURE_ATTENTION_KEY_PRESS + .. autoattribute:: systemd.id128.SD_MESSAGE_SELINUX_FAILED .. autoattribute:: systemd.id128.SD_MESSAGE_SESSION_START .. autoattribute:: systemd.id128.SD_MESSAGE_SESSION_STOP .. autoattribute:: systemd.id128.SD_MESSAGE_SHUTDOWN + .. autoattribute:: systemd.id128.SD_MESSAGE_SHUTDOWN_CANCELED + .. autoattribute:: systemd.id128.SD_MESSAGE_SHUTDOWN_ERROR + .. autoattribute:: systemd.id128.SD_MESSAGE_SHUTDOWN_SCHEDULED .. autoattribute:: systemd.id128.SD_MESSAGE_SLEEP_START .. autoattribute:: systemd.id128.SD_MESSAGE_SLEEP_STOP + .. autoattribute:: systemd.id128.SD_MESSAGE_SMACK_FAILED_WRITE .. autoattribute:: systemd.id128.SD_MESSAGE_SPAWN_FAILED + .. autoattribute:: systemd.id128.SD_MESSAGE_SRK_ENROLLMENT_NEEDS_AUTHORIZATION .. autoattribute:: systemd.id128.SD_MESSAGE_STARTUP_FINISHED - .. autoattribute:: systemd.id128.SD_MESSAGE_SUSPEND_KEY_LONG_PRESS .. autoattribute:: systemd.id128.SD_MESSAGE_SUSPEND_KEY - .. autoattribute:: systemd.id128.SD_MESSAGE_SYSTEM_DOCKED + .. autoattribute:: systemd.id128.SD_MESSAGE_SUSPEND_KEY_LONG_PRESS + .. autoattribute:: systemd.id128.SD_MESSAGE_SYSCTL_CHANGED .. autoattribute:: systemd.id128.SD_MESSAGE_SYSTEMD_UDEV_SETTLE_DEPRECATED + .. autoattribute:: systemd.id128.SD_MESSAGE_SYSTEM_ACCOUNT_REQUIRED + .. autoattribute:: systemd.id128.SD_MESSAGE_SYSTEM_DOCKED .. autoattribute:: systemd.id128.SD_MESSAGE_SYSTEM_UNDOCKED + .. autoattribute:: systemd.id128.SD_MESSAGE_SYSV_GENERATOR_DEPRECATED .. autoattribute:: systemd.id128.SD_MESSAGE_TAINTED + .. autoattribute:: systemd.id128.SD_MESSAGE_TIMEZONE_CHANGE + .. autoattribute:: systemd.id128.SD_MESSAGE_TIME_BUMP .. autoattribute:: systemd.id128.SD_MESSAGE_TIME_CHANGE .. autoattribute:: systemd.id128.SD_MESSAGE_TIME_SYNC - .. autoattribute:: systemd.id128.SD_MESSAGE_TIMEZONE_CHANGE + .. autoattribute:: systemd.id128.SD_MESSAGE_TPM2_CLEAR_REQUESTED + .. autoattribute:: systemd.id128.SD_MESSAGE_TPM_NVINDEX_EXHAUSTED + .. autoattribute:: systemd.id128.SD_MESSAGE_TPM_NVPCR_EXTEND + .. autoattribute:: systemd.id128.SD_MESSAGE_TPM_NVPCR_UNSUPPORTED + .. autoattribute:: systemd.id128.SD_MESSAGE_TPM_PCR_EXTEND .. autoattribute:: systemd.id128.SD_MESSAGE_TRUNCATED_CORE .. autoattribute:: systemd.id128.SD_MESSAGE_UNIT_FAILED .. autoattribute:: systemd.id128.SD_MESSAGE_UNIT_FAILURE_RESULT .. autoattribute:: systemd.id128.SD_MESSAGE_UNIT_OOMD_KILL + .. autoattribute:: systemd.id128.SD_MESSAGE_UNIT_ORDERING_CYCLE .. autoattribute:: systemd.id128.SD_MESSAGE_UNIT_OUT_OF_MEMORY .. autoattribute:: systemd.id128.SD_MESSAGE_UNIT_PROCESS_EXIT .. autoattribute:: systemd.id128.SD_MESSAGE_UNIT_RELOADED @@ -72,3 +122,7 @@ .. autoattribute:: systemd.id128.SD_MESSAGE_UNIT_SUCCESS .. autoattribute:: systemd.id128.SD_MESSAGE_UNSAFE_USER_NAME .. autoattribute:: systemd.id128.SD_MESSAGE_USER_STARTUP_FINISHED + .. autoattribute:: systemd.id128.SD_MESSAGE_VALGRIND_HELPER_FORK + .. autoattribute:: systemd.id128.SD_MESSAGE_WATCHDOG_OPENED + .. autoattribute:: systemd.id128.SD_MESSAGE_WATCHDOG_OPEN_FAILED + .. autoattribute:: systemd.id128.SD_MESSAGE_WATCHDOG_PING_FAILED diff --git a/docs/index.rst b/docs/index.rst index 07b478a..396b4cb 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,7 +1,7 @@ -.. python-systemd documentation master file, created by +.. SPDX-License-Identifier: LGPL-2.1-or-later + +.. python-systemd documentation main file, created by sphinx-quickstart on Sat Feb 9 13:49:42 2013. - You can adapt this file completely to your liking, but it should at least - contain the root `toctree` directive. .. _index: diff --git a/docs/journal.rst b/docs/journal.rst index 49c07b1..a5846b7 100644 --- a/docs/journal.rst +++ b/docs/journal.rst @@ -1,3 +1,5 @@ +.. SPDX-License-Identifier: LGPL-2.1-or-later + `systemd.journal` module ======================== diff --git a/docs/login.rst b/docs/login.rst index 23204e0..75e5252 100644 --- a/docs/login.rst +++ b/docs/login.rst @@ -1,3 +1,5 @@ +.. SPDX-License-Identifier: LGPL-2.1-or-later + `systemd.login` module ======================= diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..0181375 --- /dev/null +++ b/meson.build @@ -0,0 +1,62 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later + +project( + 'python-systemd', + 'c', + version: '236', + license: 'LGPL-2.1-or-later', + default_options: ['warning_level=2', 'c_std=c99'], + meson_version: '>= 1.8.0', +) + +# Dependencies +python = import('python').find_installation('python3', pure: false) +python_dep = python.dependency() + +fs = import('fs') + +libsystemd_dep = dependency('libsystemd') + +add_project_arguments( + '-D_GNU_SOURCE=1', + '-DPACKAGE_VERSION="@0@"'.format(meson.project_version()), + '-DLIBSYSTEMD_VERSION=@0@'.format(libsystemd_dep.version()), + '-Wno-unused-parameter', + language : 'c', +) + +update_constants_py = files('update-constants.py') + +subdir('src/systemd') + +test( + 'unit', + find_program(python.full_path()), + args: [ + '-m', 'pytest', + '-v', + python_test_dir, + ], + env: { 'PYTHONPATH': meson.current_build_dir() / 'src' }, +) + +alias_target('update-constants', update_constants) + +# Docs +sphinx_build = find_program('sphinx-build', disabler: true, required: get_option('docs')) +sphinx_args = ['-Dversion=' + meson.project_version(), '-Drelease=' + meson.project_version()] + +input_dir = meson.current_source_dir() / 'docs' +output_dir = meson.current_build_dir() / 'html' +doc_target = custom_target('html', + output: 'html', + input: files('docs/conf.py', + 'docs/daemon.rst', 'docs/id128.rst', + 'docs/journal.rst', 'docs/login.rst', + 'docs/layout.html', 'docs/default.css'), + command: [sphinx_build, '-b', 'html', sphinx_args, input_dir, output_dir], + env: { 'PYTHONPATH': meson.current_build_dir() / 'src' }, + build_by_default: get_option('docs'), + install: get_option('docs'), + install_dir: get_option('datadir') / 'doc' / meson.project_name() +) diff --git a/meson.options b/meson.options new file mode 100644 index 0000000..38dcb92 --- /dev/null +++ b/meson.options @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later + +option('docs', type : 'boolean', value : false) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..2871ebc --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,66 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later + +[project] +name = "systemd-python" +dynamic = ["version"] +description = "Python interface for libsystemd" +readme = "README.md" +license = "LGPL-2.1-or-later" +license-files = [ "LICENSE.txt" ] +authors = [{ email = "david@davidstrauss.net" }] +maintainers = [ + { name = "systemd developers", email = "systemd-devel@lists.freedesktop.org" }, +] +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Developers", + "Operating System :: POSIX :: Linux", + "Programming Language :: C", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", + "Programming Language :: Python :: 3.14", + "Topic :: Software Development :: Libraries :: Python Modules", + "Topic :: System :: Logging", + "Topic :: System :: Systems Administration", +] +keywords = ["systemd", "journal", "logging", "daemon"] +requires-python = ">=3.9" +dependencies = [] + +[project.urls] +Homepage = "https://github.com/systemd/python-systemd" +Repository = "https://github.com/systemd/python-systemd.git" +Issues = "https://github.com/systemd/python-systemd/issues" +Documentation = "https://www.freedesktop.org/software/systemd/python-systemd/" + +[dependency-groups] +test = ["pytest", "pytest-cov"] +docs = ["sphinx"] +build = [ + "meson>=1.8.2", + "twine>=4.0.2", +] + +[build-system] +requires = ["meson-python"] +build-backend = "mesonpy" + +[tool.coverage.run] +source = ["systemd"] +omit = ["systemd/test/*"] + +[tool.coverage.report] +exclude_lines = [ + "pragma: no cover", + "def __repr__", + "raise AssertionError", + "raise NotImplementedError", +] + +[tool.pytest.ini_options] +addopts = "--doctest-modules --doctest-glob=*.rst --ignore=setup.py" +norecursedirs = ".git build" diff --git a/pytest.ini b/pytest.ini deleted file mode 100644 index c5beb19..0000000 --- a/pytest.ini +++ /dev/null @@ -1,3 +0,0 @@ -[pytest] -addopts = --doctest-modules --doctest-glob=*.rst --ignore=setup.py -norecursedirs = .git build diff --git a/setup.py b/setup.py deleted file mode 100644 index fe9c03a..0000000 --- a/setup.py +++ /dev/null @@ -1,103 +0,0 @@ -import sys, os -from setuptools import setup, Extension -from subprocess import Popen, PIPE, check_output - -def call(*cmd): - cmd = Popen(cmd, - stdout=PIPE, stderr=PIPE, - universal_newlines=True) - if cmd.wait() == 0: - return cmd.returncode, cmd.stdout.read() - else: - return cmd.returncode, cmd.stderr.read() - -def pkgconfig(package, **kw): - pkg_version = package.replace('-', '_').upper() + '_VERSION' - flag_map = {'-I': 'include_dirs', '-L': 'library_dirs', '-l': 'libraries'} - pkgconf = os.getenv('PKG_CONFIG', 'pkg-config') - status, result = call(pkgconf, '--libs', '--cflags', package) - if status != 0: - return status, result - for token in result.split(): - kw.setdefault(flag_map.get(token[:2]), []).append(token[2:]) - - # allow version detection to be overridden using environment variables - version = os.getenv(pkg_version) - if not version: - version = check_output([pkgconf, '--modversion', package], - universal_newlines=True).strip() - pair = (pkg_version, version) - defines = kw.setdefault('define_macros', []) - if pair not in defines: - defines.append(pair) - return status, kw - -def lib(*names, **kw): - if '--version' in sys.argv: - return {} - results = [] - for name in names: - status, result = pkgconfig(name, **kw) - if status == 0: - return result - results.append(result) - sys.stderr.write('Cannot find ' + ' or '.join(names) + ':\n\n' - + '\n'.join(results) + '\n') - sys.exit(status) - -version = '235' -defines = {'define_macros':[('PACKAGE_VERSION', '"{}"'.format(version))]} - -_journal = Extension('systemd/_journal', - sources = ['systemd/_journal.c', - 'systemd/pyutil.c'], - extra_compile_args=['-std=c99', '-Werror=implicit-function-declaration'], - **lib('libsystemd', 'libsystemd-journal', **defines)) -_reader = Extension('systemd/_reader', - sources = ['systemd/_reader.c', - 'systemd/pyutil.c', - 'systemd/strv.c'], - extra_compile_args=['-std=c99', '-Werror=implicit-function-declaration'], - **lib('libsystemd', 'libsystemd-journal', **defines)) -_daemon = Extension('systemd/_daemon', - sources = ['systemd/_daemon.c', - 'systemd/pyutil.c', - 'systemd/util.c'], - extra_compile_args=['-std=c99', '-Werror=implicit-function-declaration'], - **lib('libsystemd', 'libsystemd-daemon', **defines)) -id128 = Extension('systemd/id128', - sources = ['systemd/id128.c', - 'systemd/pyutil.c'], - extra_compile_args=['-std=c99', '-Werror=implicit-function-declaration'], - **lib('libsystemd', 'libsystemd-id128', **defines)) -login = Extension('systemd/login', - sources = ['systemd/login.c', - 'systemd/pyutil.c', - 'systemd/strv.c'], - extra_compile_args=['-std=c99', '-Werror=implicit-function-declaration'], - **lib('libsystemd', 'libsystemd-login', **defines)) -setup (name = 'systemd-python', - version = version, - description = 'Python interface for libsystemd', - author_email = 'david@davidstrauss.net', - maintainer = 'systemd developers', - maintainer_email = 'systemd-devel@lists.freedesktop.org', - url = 'https://github.com/systemd/python-systemd', - license = 'LGPLv2+', - classifiers = [ - 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 3', - 'Topic :: Software Development :: Libraries :: Python Modules', - 'Topic :: System :: Logging', - 'License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)', - ], - py_modules = ['systemd.journal', 'systemd.daemon', - 'systemd.test.test_daemon', - 'systemd.test.test_journal', - 'systemd.test.test_login', - 'systemd.test.test_id128'], - ext_modules = [_journal, - _reader, - _daemon, - id128, - login]) diff --git a/src/systemd/.gitattributes b/src/systemd/.gitattributes new file mode 100644 index 0000000..442a3ba --- /dev/null +++ b/src/systemd/.gitattributes @@ -0,0 +1,2 @@ +id128-constants.h generated +id128-defines.h generated diff --git a/systemd/.gitignore b/src/systemd/.gitignore similarity index 100% rename from systemd/.gitignore rename to src/systemd/.gitignore diff --git a/src/systemd/__init__.py b/src/systemd/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/systemd/_daemon.c b/src/systemd/_daemon.c similarity index 74% rename from systemd/_daemon.c rename to src/systemd/_daemon.c index e83da48..d5214e8 100644 --- a/systemd/_daemon.c +++ b/src/systemd/_daemon.c @@ -1,22 +1,4 @@ -/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ - -/*** - - Copyright 2013-2016 Zbigniew Jędrzejewski-Szmek - - python-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. - - python-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 python-systemd; If not, see . -***/ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ #define PY_SSIZE_T_CLEAN #pragma GCC diagnostic push @@ -53,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(); @@ -73,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; @@ -89,20 +72,9 @@ static PyObject* notify(PyObject *self, PyObject *args, PyObject *keywds) { "fds", NULL, }; -#if PY_MAJOR_VERSION >=3 && PY_MINOR_VERSION >= 3 if (!PyArg_ParseTupleAndKeywords(args, keywds, "s|piO:notify", (char**) kwlist, &msg, &unset, &_pid, &fds)) return NULL; -#else - PyObject *obj = NULL; - if (!PyArg_ParseTupleAndKeywords(args, keywds, "s|OiO:notify", - (char**) kwlist, &msg, &obj, &_pid, &fds)) - return NULL; - if (obj) - unset = PyObject_IsTrue(obj); - if (unset < 0) - return NULL; -#endif pid = _pid; if (pid < 0 || pid != _pid) { PyErr_SetString(PyExc_OverflowError, "Bad pid_t"); @@ -171,31 +143,20 @@ 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; static const char* const kwlist[] = {"unset_environment", NULL}; -#if PY_MAJOR_VERSION >=3 && PY_MINOR_VERSION >= 3 if (!PyArg_ParseTupleAndKeywords(args, keywds, "|p:_listen_fds", (char**) kwlist, &unset)) return NULL; -#else - PyObject *obj = NULL; - if (!PyArg_ParseTupleAndKeywords(args, keywds, "|O:_listen_fds", - (char**) kwlist, &obj)) - return NULL; - if (obj) - unset = PyObject_IsTrue(obj); - if (unset < 0) - return NULL; -#endif r = sd_listen_fds(unset); if (set_error(r, NULL, NULL) < 0) return NULL; - return long_FromLong(r); + return PyLong_FromLong(r); } PyDoc_STRVAR(listen_fds_with_names__doc__, @@ -216,27 +177,17 @@ 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; PyObject *tpl, *item; static const char* const kwlist[] = {"unset_environment", NULL}; -#if PY_MAJOR_VERSION >=3 && PY_MINOR_VERSION >= 3 if (!PyArg_ParseTupleAndKeywords(args, keywds, "|p:_listen_fds_with_names", (char**) kwlist, &unset)) return NULL; -#else - PyObject *obj = NULL; - if (!PyArg_ParseTupleAndKeywords(args, keywds, "|O:_listen_fds_with_names", - (char**) kwlist, &obj)) - return NULL; - if (obj != NULL) - unset = PyObject_IsTrue(obj); - if (unset < 0) - return NULL; -#endif #if HAVE_SD_LISTEN_FDS_WITH_NAMES r = sd_listen_fds_with_names(unset, &names); @@ -247,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; @@ -257,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); @@ -279,22 +230,17 @@ 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; -#if PY_MAJOR_VERSION >=3 && PY_MINOR_VERSION >= 1 _cleanup_Py_DECREF_ PyObject *_path = NULL; if (!PyArg_ParseTuple(args, "i|O&:_is_fifo", &fd, Unicode_FSConverter, &_path)) return NULL; if (_path) path = PyBytes_AsString(_path); -#else - if (!PyArg_ParseTuple(args, "i|z:_is_fifo", &fd, &path)) - return NULL; -#endif r = sd_is_fifo(fd, path); if (set_error(r, path, NULL) < 0) @@ -310,22 +256,17 @@ 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; -#if PY_MAJOR_VERSION >=3 && PY_MINOR_VERSION >= 1 _cleanup_Py_DECREF_ PyObject *_path = NULL; if (!PyArg_ParseTuple(args, "i|O&:_is_mq", &fd, Unicode_FSConverter, &_path)) return NULL; if (_path) path = PyBytes_AsString(_path); -#else - if (!PyArg_ParseTuple(args, "i|z:_is_mq", &fd, &path)) - return NULL; -#endif r = sd_is_mq(fd, path); if (set_error(r, path, NULL) < 0) @@ -343,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; @@ -365,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; @@ -398,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; @@ -445,13 +386,12 @@ 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; Py_ssize_t length = 0; -#if PY_MAJOR_VERSION >=3 && PY_MINOR_VERSION >= 1 _cleanup_Py_DECREF_ PyObject *_path = NULL; if (!PyArg_ParseTuple(args, "i|iiO&:_is_socket_unix", &fd, &type, &listening, Unicode_FSConverter, &_path)) @@ -461,11 +401,6 @@ static PyObject* is_socket_unix(PyObject *self, PyObject *args) { if (PyBytes_AsStringAndSize(_path, &path, &length)) return NULL; } -#else - if (!PyArg_ParseTuple(args, "i|iiz#:_is_socket_unix", - &fd, &type, &listening, &path, &length)) - return NULL; -#endif r = sd_is_socket_unix(fd, type, listening, path, length); if (set_error(r, path, NULL) < 0) @@ -475,38 +410,23 @@ 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 */ }; - -#if PY_MAJOR_VERSION < 3 - -DISABLE_WARNING_MISSING_PROTOTYPES; -PyMODINIT_FUNC init_daemon(void) { - PyObject *m; - - m = Py_InitModule3("_daemon", methods, module__doc__); - if (!m) - return; - - PyModule_AddIntConstant(m, "LISTEN_FDS_START", SD_LISTEN_FDS_START); - PyModule_AddStringConstant(m, "__version__", PACKAGE_VERSION); -} REENABLE_WARNING; -#else - static struct PyModuleDef module = { PyModuleDef_HEAD_INIT, .m_name = "_daemon", /* name of module */ @@ -532,5 +452,3 @@ PyMODINIT_FUNC PyInit__daemon(void) { return m; } REENABLE_WARNING; - -#endif diff --git a/systemd/_journal.c b/src/systemd/_journal.c similarity index 61% rename from systemd/_journal.c rename to src/systemd/_journal.c index 4f53dba..185cd79 100644 --- a/systemd/_journal.c +++ b/src/systemd/_journal.c @@ -1,24 +1,4 @@ -/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ - -/*** - - Copyright 2012 David Strauss - - python-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. - - python-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 python-systemd; If not, see . -***/ - -#include +/* SPDX-License-Identifier: LGPL-2.1-or-later */ #include @@ -26,28 +6,26 @@ #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; @@ -69,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; } @@ -78,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; @@ -89,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; @@ -101,34 +79,18 @@ 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 */ }; -#if PY_MAJOR_VERSION < 3 - -DISABLE_WARNING_MISSING_PROTOTYPES; -PyMODINIT_FUNC init_journal(void) { - PyObject *m; - - m = Py_InitModule("_journal", methods); - if (!m) - return; - - PyModule_AddStringConstant(m, "__version__", PACKAGE_VERSION); -} -REENABLE_WARNING; - -#else - static struct PyModuleDef module = { PyModuleDef_HEAD_INIT, .m_name = "_journal", /* name of module */ @@ -152,5 +114,3 @@ PyMODINIT_FUNC PyInit__journal(void) { return m; } REENABLE_WARNING; - -#endif diff --git a/systemd/_reader.c b/src/systemd/_reader.c similarity index 80% rename from systemd/_reader.c rename to src/systemd/_reader.c index 4e8f47f..faeaead 100644 --- a/systemd/_reader.c +++ b/src/systemd/_reader.c @@ -1,41 +1,18 @@ -/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ -/*** - - Copyright 2013 Steven Hiscocks, Zbigniew Jędrzejewski-Szmek - - python-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. - - python-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 python-systemd; If not, see . -***/ - -#define PY_SSIZE_T_CLEAN -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wredundant-decls" -#include -#pragma GCC diagnostic pop - -#include -#include -#include -#include #include - -#include "systemd/sd-journal.h" +#include +#include +#include +#include #include "pyutil.h" #include "macro.h" #include "strv.h" +/* This needs to be below Python.h include for some reason */ +#include + #if defined(LIBSYSTEMD_VERSION) || LIBSYSTEMD_JOURNAL_VERSION > 204 # define HAVE_JOURNAL_OPEN_FILES 1 #else @@ -63,7 +40,7 @@ typedef struct { PyObject_HEAD - sd_journal *j; + sd_journal *journal; } Reader; static PyTypeObject ReaderType; @@ -71,7 +48,6 @@ PyDoc_STRVAR(module__doc__, "Class to reads the systemd journal similar to journalctl."); -#if PY_MAJOR_VERSION >= 3 static PyTypeObject MonotonicType; PyDoc_STRVAR(MonotonicType__doc__, @@ -89,24 +65,19 @@ static PyStructSequence_Desc Monotonic_desc = { MonotonicType_fields, 2, }; -#endif /** * Convert a str or bytes object into a C-string path. * Returns NULL on error. */ static char* str_converter(PyObject *str, PyObject **bytes) { -#if PY_MAJOR_VERSION >=3 && PY_MINOR_VERSION >= 1 - int r; + int r; - r = PyUnicode_FSConverter(str, bytes); - if (r == 0) - return NULL; + r = PyUnicode_FSConverter(str, bytes); + if (r == 0) + return NULL; - return PyBytes_AsString(*bytes); -#else - return PyString_AsString(str); -#endif + return PyBytes_AsString(*bytes); } /** @@ -132,21 +103,20 @@ static int null_converter(PyObject* obj, void *_result) { */ static int strv_converter(PyObject* obj, void *_result) { char ***result = _result; - Py_ssize_t i, len; assert(result); if (!PySequence_Check(obj)) return 0; - len = PySequence_Length(obj); + Py_ssize_t len = PySequence_Length(obj); *result = new0(char*, len + 1); if (!*result) { set_error(-ENOMEM, NULL, NULL); return 0; } - for (i = 0; i < len; i++) { + for (Py_ssize_t i = 0; i < len; i++) { PyObject *item; _cleanup_Py_DECREF_ PyObject *bytes = NULL; char *s; @@ -175,7 +145,7 @@ static int strv_converter(PyObject* obj, void *_result) { } static int long_as_fd(PyObject *obj, int *fd) { - long num = long_AsLong(obj); + long num = PyLong_AsLong(obj); if (PyErr_Occurred()) return -1; @@ -192,23 +162,21 @@ static int long_as_fd(PyObject *obj, int *fd) { * Convert a Python sequence object into an int array. */ static int intlist_converter(PyObject* obj, int **_result, size_t *_len) { - _cleanup_free_ int *result = NULL; - Py_ssize_t i, len; - assert(_result); assert(_len); if (!PySequence_Check(obj)) return 0; - len = PySequence_Length(obj); - result = new0(int, len); + Py_ssize_t len = PySequence_Length(obj); + _cleanup_free_ int *result = new0(int, len); + if (!result) { set_error(-ENOMEM, NULL, NULL); return 0; } - for (i = 0; i < len; i++) { + for (Py_ssize_t i = 0; i < len; i++) { PyObject *item; int fd; @@ -226,7 +194,7 @@ static int intlist_converter(PyObject* obj, int **_result, size_t *_len) { } static void Reader_dealloc(Reader* self) { - sd_journal_close(self->j); + sd_journal_close(self->journal); Py_TYPE(self)->tp_free((PyObject*)self); } @@ -270,7 +238,7 @@ static int Reader_init(Reader *self, PyObject *args, PyObject *keywds) { } if (_path) { - if (long_Check(_path)) { + if (PyLong_Check(_path)) { int fd; if (long_as_fd(_path, &fd) < 0) @@ -278,7 +246,7 @@ static int Reader_init(Reader *self, PyObject *args, PyObject *keywds) { #if HAVE_JOURNAL_OPEN_DIRECTORY_FD Py_BEGIN_ALLOW_THREADS - r = sd_journal_open_directory_fd(&self->j, (int) fd, flags); + r = sd_journal_open_directory_fd(&self->journal, (int) fd, flags); Py_END_ALLOW_THREADS #else r = -ENOSYS; @@ -292,7 +260,7 @@ static int Reader_init(Reader *self, PyObject *args, PyObject *keywds) { return -1; Py_BEGIN_ALLOW_THREADS - r = sd_journal_open_directory(&self->j, path, flags); + r = sd_journal_open_directory(&self->journal, path, flags); Py_END_ALLOW_THREADS } } else if (_files) { @@ -307,7 +275,7 @@ static int Reader_init(Reader *self, PyObject *args, PyObject *keywds) { #if HAVE_JOURNAL_OPEN_FILES Py_BEGIN_ALLOW_THREADS - r = sd_journal_open_files(&self->j, (const char**) files, flags); + r = sd_journal_open_files(&self->journal, (const char**) files, flags); Py_END_ALLOW_THREADS #else r = -ENOSYS; @@ -321,7 +289,7 @@ static int Reader_init(Reader *self, PyObject *args, PyObject *keywds) { #if HAVE_JOURNAL_OPEN_DIRECTORY_FD Py_BEGIN_ALLOW_THREADS - r = sd_journal_open_files_fd(&self->j, fds, n_fds, flags); + r = sd_journal_open_files_fd(&self->journal, fds, n_fds, flags); Py_END_ALLOW_THREADS #else r = -ENOSYS; @@ -336,14 +304,14 @@ static int Reader_init(Reader *self, PyObject *args, PyObject *keywds) { return -1; Py_BEGIN_ALLOW_THREADS - r = sd_journal_open_namespace(&self->j, namespace, flags); + r = sd_journal_open_namespace(&self->journal, namespace, flags); Py_END_ALLOW_THREADS #else r = -ENOSYS; #endif } else { Py_BEGIN_ALLOW_THREADS - r = sd_journal_open(&self->j, flags); + r = sd_journal_open(&self->journal, flags); Py_END_ALLOW_THREADS } @@ -361,11 +329,14 @@ PyDoc_STRVAR(Reader_fileno__doc__, static PyObject* Reader_fileno(Reader *self, PyObject *args) { int fd; - fd = sd_journal_get_fd(self->j); + assert(self); + assert(!args); + + fd = sd_journal_get_fd(self->journal); set_error(fd, NULL, NULL); if (fd < 0) return NULL; - return long_FromLong(fd); + return PyLong_FromLong(fd); } PyDoc_STRVAR(Reader_reliable_fd__doc__, @@ -376,7 +347,10 @@ PyDoc_STRVAR(Reader_reliable_fd__doc__, static PyObject* Reader_reliable_fd(Reader *self, PyObject *args) { int r; - r = sd_journal_reliable_fd(self->j); + assert(self); + assert(!args); + + r = sd_journal_reliable_fd(self->journal); if (set_error(r, NULL, NULL) < 0) return NULL; return PyBool_FromLong(r); @@ -390,10 +364,13 @@ PyDoc_STRVAR(Reader_get_events__doc__, static PyObject* Reader_get_events(Reader *self, PyObject *args) { int r; - r = sd_journal_get_events(self->j); + assert(self); + assert(!args); + + r = sd_journal_get_events(self->journal); if (set_error(r, NULL, NULL) < 0) return NULL; - return long_FromLong(r); + return PyLong_FromLong(r); } PyDoc_STRVAR(Reader_get_timeout__doc__, @@ -408,7 +385,10 @@ static PyObject* Reader_get_timeout(Reader *self, PyObject *args) { int r; uint64_t t; - r = sd_journal_get_timeout(self->j, &t); + assert(self); + assert(!args); + + r = sd_journal_get_timeout(self->journal, &t); if (set_error(r, NULL, NULL) < 0) return NULL; @@ -428,7 +408,10 @@ static PyObject* Reader_get_timeout_ms(Reader *self, PyObject *args) { int r; uint64_t t; - r = sd_journal_get_timeout(self->j, &t); + assert(self); + assert(!args); + + r = sd_journal_get_timeout(self->journal, &t); if (set_error(r, NULL, NULL) < 0) return NULL; @@ -444,8 +427,8 @@ static PyObject* Reader_close(Reader *self, PyObject *args) { assert(self); assert(!args); - sd_journal_close(self->j); - self->j = NULL; + sd_journal_close(self->journal); + self->journal = NULL; Py_RETURN_NONE; } @@ -462,7 +445,10 @@ static PyObject* Reader_get_usage(Reader *self, PyObject *args) { int r; uint64_t bytes; - r = sd_journal_get_usage(self->j, &bytes); + assert(self); + assert(!args); + + r = sd_journal_get_usage(self->journal, &bytes); if (set_error(r, NULL, NULL) < 0) return NULL; @@ -486,7 +472,9 @@ PyDoc_STRVAR(Reader___exit____doc__, "__exit__(type, value, traceback) -> None\n\n" "Part of the context manager protocol.\n" "Closes the journal.\n"); -static PyObject* Reader___exit__(Reader *self, PyObject *args) { +static PyObject* Reader___exit__(Reader *self, PyObject *args _unused_) { + assert(self); + return Reader_close(self, NULL); } @@ -496,26 +484,28 @@ PyDoc_STRVAR(Reader_next__doc__, "the `skip`\\-th log entry.\n" "Returns False if at end of file, True otherwise."); static PyObject* Reader_next(Reader *self, PyObject *args) { - int64_t skip = 1LL; + int64_t skip = 1; int r = -EUCLEAN; + assert(self); + if (!PyArg_ParseTuple(args, "|L:next", &skip)) return NULL; - if (skip == 0LL) { + if (skip == 0) { PyErr_SetString(PyExc_ValueError, "skip must be nonzero"); return NULL; } Py_BEGIN_ALLOW_THREADS - if (skip == 1LL) - r = sd_journal_next(self->j); - else if (skip == -1LL) - r = sd_journal_previous(self->j); - else if (skip > 1LL) - r = sd_journal_next_skip(self->j, skip); - else if (skip < -1LL) - r = sd_journal_previous_skip(self->j, -skip); + if (skip == 1) + r = sd_journal_next(self->journal); + else if (skip == -1) + r = sd_journal_previous(self->journal); + else if (skip > 1) + r = sd_journal_next_skip(self->journal, skip); + else if (skip < -1) + r = sd_journal_previous_skip(self->journal, -skip); else assert(!"should be here"); Py_END_ALLOW_THREADS @@ -552,7 +542,7 @@ static int extract(const char* msg, size_t msg_len, } if (key) { - k = unicode_FromStringAndSize(msg, delim_ptr - (const char*) msg); + k = PyUnicode_FromStringAndSize(msg, delim_ptr - (const char*) msg); if (!k) return -1; } @@ -591,7 +581,7 @@ static PyObject* Reader_get(Reader *self, PyObject *args) { if (!PyArg_ParseTuple(args, "s:get", &field)) return NULL; - r = sd_journal_get_data(self->j, field, &msg, &msg_len); + r = sd_journal_get_data(self->journal, field, &msg, &msg_len); if (r == -ENOENT) { PyErr_SetString(PyExc_KeyError, field); return NULL; @@ -614,11 +604,14 @@ static PyObject* Reader_get_all(Reader *self, PyObject *args) { size_t msg_len; int r; + assert(self); + assert(!args); + dict = PyDict_New(); if (!dict) return NULL; - SD_JOURNAL_FOREACH_DATA(self->j, msg, msg_len) { + SD_JOURNAL_FOREACH_DATA(self->journal, msg, msg_len) { _cleanup_Py_DECREF_ PyObject *key = NULL, *value = NULL; r = extract(msg, msg_len, &key, &value); @@ -676,7 +669,7 @@ static PyObject* Reader_get_realtime(Reader *self, PyObject *args) { assert(self); assert(!args); - r = sd_journal_get_realtime_usec(self->j, ×tamp); + r = sd_journal_get_realtime_usec(self->journal, ×tamp); if (set_error(r, NULL, NULL) < 0) return NULL; @@ -699,18 +692,14 @@ static PyObject* Reader_get_monotonic(Reader *self, PyObject *args) { assert(self); assert(!args); - r = sd_journal_get_monotonic_usec(self->j, ×tamp, &id); + r = sd_journal_get_monotonic_usec(self->journal, ×tamp, &id); if (set_error(r, NULL, NULL) < 0) return NULL; assert_cc(sizeof(unsigned long long) == sizeof(timestamp)); monotonic = PyLong_FromUnsignedLongLong(timestamp); bootid = PyBytes_FromStringAndSize((const char*) &id.bytes, sizeof(id.bytes)); -#if PY_MAJOR_VERSION >= 3 tuple = PyStructSequence_New(&MonotonicType); -#else - tuple = PyTuple_New(2); -#endif if (!monotonic || !bootid || !tuple) { Py_XDECREF(monotonic); Py_XDECREF(bootid); @@ -718,13 +707,8 @@ static PyObject* Reader_get_monotonic(Reader *self, PyObject *args) { return NULL; } -#if PY_MAJOR_VERSION >= 3 PyStructSequence_SET_ITEM(tuple, 0, monotonic); PyStructSequence_SET_ITEM(tuple, 1, bootid); -#else - PyTuple_SET_ITEM(tuple, 0, monotonic); - PyTuple_SET_ITEM(tuple, 1, bootid); -#endif return tuple; } @@ -735,10 +719,11 @@ PyDoc_STRVAR(Reader_add_match__doc__, "fields are combined with logical AND, and matches of the same field\n" "are automatically combined with logical OR.\n" "Match is a string of the form \"FIELD=value\"."); -static PyObject* Reader_add_match(Reader *self, PyObject *args, PyObject *keywds) { +static PyObject* Reader_add_match(Reader *self, PyObject *args) { char *match; Py_ssize_t match_len; int r; + if (!PyArg_ParseTuple(args, "s#:add_match", &match, &match_len)) return NULL; @@ -747,7 +732,7 @@ static PyObject* Reader_add_match(Reader *self, PyObject *args, PyObject *keywds return NULL; } - r = sd_journal_add_match(self->j, match, (int) match_len); + r = sd_journal_add_match(self->journal, match, (int) match_len); if (set_error(r, NULL, "Invalid match") < 0) return NULL; @@ -762,7 +747,11 @@ PyDoc_STRVAR(Reader_add_disjunction__doc__, "See :manpage:`sd_journal_add_disjunction(3)` for explanation."); static PyObject* Reader_add_disjunction(Reader *self, PyObject *args) { int r; - r = sd_journal_add_disjunction(self->j); + + assert(self); + assert(!args); + + r = sd_journal_add_disjunction(self->journal); if (set_error(r, NULL, NULL) < 0) return NULL; Py_RETURN_NONE; @@ -776,7 +765,11 @@ PyDoc_STRVAR(Reader_add_conjunction__doc__, "See :manpage:`sd_journal_add_disjunction(3)` for explanation."); static PyObject* Reader_add_conjunction(Reader *self, PyObject *args) { int r; - r = sd_journal_add_conjunction(self->j); + + assert(self); + assert(!args); + + r = sd_journal_add_conjunction(self->journal); if (set_error(r, NULL, NULL) < 0) return NULL; Py_RETURN_NONE; @@ -786,7 +779,10 @@ PyDoc_STRVAR(Reader_flush_matches__doc__, "flush_matches() -> None\n\n" "Clear all current match filters."); static PyObject* Reader_flush_matches(Reader *self, PyObject *args) { - sd_journal_flush_matches(self->j); + assert(self); + assert(!args); + + sd_journal_flush_matches(self->journal); Py_RETURN_NONE; } @@ -797,8 +793,12 @@ PyDoc_STRVAR(Reader_seek_head__doc__, "See :manpage:`sd_journal_seek_head(3)`."); static PyObject* Reader_seek_head(Reader *self, PyObject *args) { int r; + + assert(self); + assert(!args); + Py_BEGIN_ALLOW_THREADS - r = sd_journal_seek_head(self->j); + r = sd_journal_seek_head(self->journal); Py_END_ALLOW_THREADS if (set_error(r, NULL, NULL) < 0) @@ -815,8 +815,11 @@ PyDoc_STRVAR(Reader_seek_tail__doc__, static PyObject* Reader_seek_tail(Reader *self, PyObject *args) { int r; + assert(self); + assert(!args); + Py_BEGIN_ALLOW_THREADS - r = sd_journal_seek_tail(self->j); + r = sd_journal_seek_tail(self->journal); Py_END_ALLOW_THREADS if (set_error(r, NULL, NULL) < 0) @@ -832,11 +835,13 @@ static PyObject* Reader_seek_realtime(Reader *self, PyObject *args) { uint64_t timestamp; int r; + assert(self); + if (!PyArg_ParseTuple(args, "K:seek_realtime", ×tamp)) return NULL; Py_BEGIN_ALLOW_THREADS - r = sd_journal_seek_realtime_usec(self->j, timestamp); + r = sd_journal_seek_realtime_usec(self->journal, timestamp); Py_END_ALLOW_THREADS if (set_error(r, NULL, NULL) < 0) @@ -857,6 +862,8 @@ static PyObject* Reader_seek_monotonic(Reader *self, PyObject *args) { sd_id128_t id; int r; + assert(self); + if (!PyArg_ParseTuple(args, "K|z:seek_monotonic", ×tamp, &bootid)) return NULL; @@ -874,7 +881,7 @@ static PyObject* Reader_seek_monotonic(Reader *self, PyObject *args) { } Py_BEGIN_ALLOW_THREADS - r = sd_journal_seek_monotonic_usec(self->j, id, timestamp); + r = sd_journal_seek_monotonic_usec(self->journal, id, timestamp); Py_END_ALLOW_THREADS if (set_error(r, NULL, NULL) < 0) @@ -896,7 +903,7 @@ static PyObject* Reader_get_start(Reader *self, PyObject *args) { assert(self); assert(!args); - r = sd_journal_get_cutoff_realtime_usec(self->j, &start, NULL); + r = sd_journal_get_cutoff_realtime_usec(self->journal, &start, NULL); if (set_error(r, NULL, NULL) < 0) return NULL; @@ -917,7 +924,7 @@ static PyObject* Reader_get_end(Reader *self, PyObject *args) { assert(self); assert(!args); - r = sd_journal_get_cutoff_realtime_usec(self->j, NULL, &end); + r = sd_journal_get_cutoff_realtime_usec(self->journal, NULL, &end); if (set_error(r, NULL, NULL) < 0) return NULL; @@ -940,12 +947,12 @@ static PyObject* Reader_process(Reader *self, PyObject *args) { assert(!args); Py_BEGIN_ALLOW_THREADS - r = sd_journal_process(self->j); + r = sd_journal_process(self->journal); Py_END_ALLOW_THREADS if (set_error(r, NULL, NULL) < 0) return NULL; - return long_FromLong(r); + return PyLong_FromLong(r); } PyDoc_STRVAR(Reader_wait__doc__, @@ -966,13 +973,13 @@ static PyObject* Reader_wait(Reader *self, PyObject *args) { return NULL; Py_BEGIN_ALLOW_THREADS - r = sd_journal_wait(self->j, timeout); + r = sd_journal_wait(self->journal, timeout); Py_END_ALLOW_THREADS if (set_error(r, NULL, NULL) < 0) return NULL; - return long_FromLong(r); + return PyLong_FromLong(r); } PyDoc_STRVAR(Reader_seek_cursor__doc__, @@ -986,7 +993,7 @@ static PyObject* Reader_seek_cursor(Reader *self, PyObject *args) { return NULL; Py_BEGIN_ALLOW_THREADS - r = sd_journal_seek_cursor(self->j, cursor); + r = sd_journal_seek_cursor(self->journal, cursor); Py_END_ALLOW_THREADS if (set_error(r, NULL, "Invalid cursor") < 0) @@ -1006,11 +1013,11 @@ static PyObject* Reader_get_cursor(Reader *self, PyObject *args) { assert(self); assert(!args); - r = sd_journal_get_cursor(self->j, &cursor); + r = sd_journal_get_cursor(self->journal, &cursor); if (set_error(r, NULL, NULL) < 0) return NULL; - return unicode_FromString(cursor); + return PyUnicode_FromString(cursor); } PyDoc_STRVAR(Reader_test_cursor__doc__, @@ -1027,7 +1034,7 @@ static PyObject* Reader_test_cursor(Reader *self, PyObject *args) { if (!PyArg_ParseTuple(args, "s:test_cursor", &cursor)) return NULL; - r = sd_journal_test_cursor(self->j, cursor); + r = sd_journal_test_cursor(self->journal, cursor); if (set_error(r, NULL, NULL) < 0) return NULL; @@ -1051,7 +1058,7 @@ static PyObject* Reader_query_unique(Reader *self, PyObject *args) { return NULL; Py_BEGIN_ALLOW_THREADS - r = sd_journal_query_unique(self->j, query); + r = sd_journal_query_unique(self->journal, query); Py_END_ALLOW_THREADS if (set_error(r, NULL, "Invalid field name") < 0) @@ -1061,11 +1068,11 @@ static PyObject* Reader_query_unique(Reader *self, PyObject *args) { if (!value_set) return NULL; - key = unicode_FromString(query); + key = PyUnicode_FromString(query); if (!key) return NULL; - SD_JOURNAL_FOREACH_UNIQUE(self->j, uniq, uniq_len) { + SD_JOURNAL_FOREACH_UNIQUE(self->journal, uniq, uniq_len) { const char *delim_ptr; _cleanup_Py_DECREF_ PyObject *value = NULL; @@ -1094,6 +1101,9 @@ PyDoc_STRVAR(Reader_enumerate_fields__doc__, "Return a set of field names appearing in the journal.\n" "See sd_journal_enumerate_fields(3)."); static PyObject* Reader_enumerate_fields(Reader *self, PyObject *args) { + assert(self); + assert(!args); + #if HAVE_ENUMERATE_FIELDS _cleanup_Py_DECREF_ PyObject *_value_set = NULL; PyObject *value_set; @@ -1103,13 +1113,13 @@ static PyObject* Reader_enumerate_fields(Reader *self, PyObject *args) { if (!value_set) return NULL; - sd_journal_restart_fields(self->j); + sd_journal_restart_fields(self->journal); while (true) { const char *field; _cleanup_Py_DECREF_ PyObject *value = NULL; - r = sd_journal_enumerate_fields(self->j, &field); + r = sd_journal_enumerate_fields(self->journal, &field); if (r == 0) break; if (set_error(r, NULL, "Field enumeration failed") < 0) @@ -1136,12 +1146,15 @@ PyDoc_STRVAR(Reader_has_runtime_files__doc__, "Returns true if runtime journal files have been found.\n\n" "See :manpage:`sd_journal_test_cursor(3)`."); static PyObject* Reader_has_runtime_files(Reader *self, PyObject *args) { + assert(self); + assert(!args); + #if HAVE_ENUMERATE_FIELDS int r; assert(self); - r = sd_journal_has_runtime_files(self->j); + r = sd_journal_has_runtime_files(self->journal); if (set_error(r, NULL, NULL) < 0) return NULL; @@ -1157,12 +1170,15 @@ PyDoc_STRVAR(Reader_has_persistent_files__doc__, "Returns true if persistent journal files have been found.\n\n" "See :manpage:`sd_journal_test_cursor(3)`."); static PyObject* Reader_has_persistent_files(Reader *self, PyObject *args) { + assert(self); + assert(!args); + #if HAVE_ENUMERATE_FIELDS int r; assert(self); - r = sd_journal_has_persistent_files(self->j); + r = sd_journal_has_persistent_files(self->journal); if (set_error(r, NULL, NULL) < 0) return NULL; @@ -1188,14 +1204,14 @@ static PyObject* Reader_get_catalog(Reader *self, PyObject *args) { assert(!args); Py_BEGIN_ALLOW_THREADS - r = sd_journal_get_catalog(self->j, &msg); + r = sd_journal_get_catalog(self->journal, &msg); Py_END_ALLOW_THREADS if (r == -ENOENT) { const void* mid; size_t mid_len; - r = sd_journal_get_data(self->j, "MESSAGE_ID", &mid, &mid_len); + r = sd_journal_get_data(self->journal, "MESSAGE_ID", &mid, &mid_len); if (r == 0) { const size_t l = sizeof("MESSAGE_ID"); assert(mid_len > l); @@ -1211,14 +1227,14 @@ static PyObject* Reader_get_catalog(Reader *self, PyObject *args) { if (set_error(r, NULL, NULL) < 0) return NULL; - return unicode_FromString(msg); + return PyUnicode_FromString(msg); } PyDoc_STRVAR(get_catalog__doc__, "get_catalog(id128) -> str\n\n" "Retrieve a message catalog entry for the given id.\n" "Wraps :manpage:`sd_journal_get_catalog_for_message_id(3)`."); -static PyObject* get_catalog(PyObject *self, PyObject *args) { +static PyObject* get_catalog(PyObject *self _unused_, PyObject *args) { int r; char *id_ = NULL; sd_id128_t id; @@ -1240,7 +1256,7 @@ static PyObject* get_catalog(PyObject *self, PyObject *args) { if (set_error(r, NULL, NULL) < 0) return NULL; - return unicode_FromString(msg); + return PyUnicode_FromString(msg); } PyDoc_STRVAR(data_threshold__doc__, @@ -1248,38 +1264,44 @@ PyDoc_STRVAR(data_threshold__doc__, "Fields longer than this will be truncated to the threshold size.\n" "Defaults to 64Kb."); -static PyObject* Reader_get_data_threshold(Reader *self, void *closure) { +static PyObject* Reader_get_data_threshold(Reader *self, void *closure _unused_) { size_t cvalue; int r; - r = sd_journal_get_data_threshold(self->j, &cvalue); + assert(self); + + r = sd_journal_get_data_threshold(self->journal, &cvalue); if (set_error(r, NULL, NULL) < 0) return NULL; - return long_FromSize_t(cvalue); + return PyLong_FromSize_t(cvalue); } -static int Reader_set_data_threshold(Reader *self, PyObject *value, void *closure) { +static int Reader_set_data_threshold(Reader *self, PyObject *value, void *closure _unused_) { int r; + assert(self); + if (!value) { PyErr_SetString(PyExc_AttributeError, "Cannot delete data threshold"); return -1; } - if (!long_Check(value)){ + if (!PyLong_Check(value)){ PyErr_SetString(PyExc_TypeError, "Data threshold must be an int"); return -1; } - r = sd_journal_set_data_threshold(self->j, (size_t) long_AsLong(value)); + r = sd_journal_set_data_threshold(self->journal, (size_t) PyLong_AsLong(value)); return set_error(r, NULL, NULL); } PyDoc_STRVAR(closed__doc__, "True iff journal is closed"); -static PyObject* Reader_get_closed(Reader *self, void *closure) { - return PyBool_FromLong(!self->j); +static PyObject* Reader_get_closed(Reader *self, void *closure _unused_) { + assert(self); + + return PyBool_FromLong(!self->journal); } static PyGetSetDef Reader_getsetters[] = { @@ -1297,41 +1319,41 @@ static PyGetSetDef Reader_getsetters[] = { }; static PyMethodDef Reader_methods[] = { - {"fileno", (PyCFunction) Reader_fileno, METH_NOARGS, Reader_fileno__doc__}, - {"reliable_fd", (PyCFunction) Reader_reliable_fd, METH_NOARGS, Reader_reliable_fd__doc__}, - {"get_events", (PyCFunction) Reader_get_events, METH_NOARGS, Reader_get_events__doc__}, - {"get_timeout", (PyCFunction) Reader_get_timeout, METH_NOARGS, Reader_get_timeout__doc__}, - {"get_timeout_ms", (PyCFunction) Reader_get_timeout_ms, METH_NOARGS, Reader_get_timeout_ms__doc__}, - {"close", (PyCFunction) Reader_close, METH_NOARGS, Reader_close__doc__}, - {"get_usage", (PyCFunction) Reader_get_usage, METH_NOARGS, Reader_get_usage__doc__}, - {"__enter__", (PyCFunction) Reader___enter__, METH_NOARGS, Reader___enter____doc__}, - {"__exit__", (PyCFunction) Reader___exit__, METH_VARARGS, Reader___exit____doc__}, - {"_next", (PyCFunction) Reader_next, METH_VARARGS, Reader_next__doc__}, - {"_previous", (PyCFunction) Reader_previous, METH_VARARGS, Reader_previous__doc__}, - {"_get", (PyCFunction) Reader_get, METH_VARARGS, Reader_get__doc__}, - {"_get_all", (PyCFunction) Reader_get_all, METH_NOARGS, Reader_get_all__doc__}, - {"_get_realtime", (PyCFunction) Reader_get_realtime, METH_NOARGS, Reader_get_realtime__doc__}, - {"_get_monotonic", (PyCFunction) Reader_get_monotonic, METH_NOARGS, Reader_get_monotonic__doc__}, - {"add_match", (PyCFunction) Reader_add_match, METH_VARARGS|METH_KEYWORDS, Reader_add_match__doc__}, - {"add_disjunction", (PyCFunction) Reader_add_disjunction, METH_NOARGS, Reader_add_disjunction__doc__}, - {"add_conjunction", (PyCFunction) Reader_add_conjunction, METH_NOARGS, Reader_add_conjunction__doc__}, - {"flush_matches", (PyCFunction) Reader_flush_matches, METH_NOARGS, Reader_flush_matches__doc__}, - {"seek_head", (PyCFunction) Reader_seek_head, METH_NOARGS, Reader_seek_head__doc__}, - {"seek_tail", (PyCFunction) Reader_seek_tail, METH_NOARGS, Reader_seek_tail__doc__}, - {"seek_realtime", (PyCFunction) Reader_seek_realtime, METH_VARARGS, Reader_seek_realtime__doc__}, - {"seek_monotonic", (PyCFunction) Reader_seek_monotonic, METH_VARARGS, Reader_seek_monotonic__doc__}, - {"_get_start", (PyCFunction) Reader_get_start, METH_NOARGS, Reader_get_start__doc__}, - {"_get_end", (PyCFunction) Reader_get_end, METH_NOARGS, Reader_get_end__doc__}, - {"process", (PyCFunction) Reader_process, METH_NOARGS, Reader_process__doc__}, - {"wait", (PyCFunction) Reader_wait, METH_VARARGS, Reader_wait__doc__}, - {"seek_cursor", (PyCFunction) Reader_seek_cursor, METH_VARARGS, Reader_seek_cursor__doc__}, - {"_get_cursor", (PyCFunction) Reader_get_cursor, METH_NOARGS, Reader_get_cursor__doc__}, - {"test_cursor", (PyCFunction) Reader_test_cursor, METH_VARARGS, Reader_test_cursor__doc__}, - {"query_unique", (PyCFunction) Reader_query_unique, METH_VARARGS, Reader_query_unique__doc__}, - {"enumerate_fields", (PyCFunction) Reader_enumerate_fields, METH_NOARGS, Reader_enumerate_fields__doc__}, - {"has_runtime_files", (PyCFunction) Reader_has_runtime_files, METH_NOARGS, Reader_has_runtime_files__doc__}, - {"has_persistent_files", (PyCFunction) Reader_has_persistent_files, METH_NOARGS, Reader_has_persistent_files__doc__}, - {"get_catalog", (PyCFunction) Reader_get_catalog, METH_NOARGS, Reader_get_catalog__doc__}, + { "fileno", (PyCFunction) Reader_fileno, METH_NOARGS, Reader_fileno__doc__ }, + { "reliable_fd", (PyCFunction) Reader_reliable_fd, METH_NOARGS, Reader_reliable_fd__doc__ }, + { "get_events", (PyCFunction) Reader_get_events, METH_NOARGS, Reader_get_events__doc__ }, + { "get_timeout", (PyCFunction) Reader_get_timeout, METH_NOARGS, Reader_get_timeout__doc__ }, + { "get_timeout_ms", (PyCFunction) Reader_get_timeout_ms, METH_NOARGS, Reader_get_timeout_ms__doc__ }, + { "close", (PyCFunction) Reader_close, METH_NOARGS, Reader_close__doc__ }, + { "get_usage", (PyCFunction) Reader_get_usage, METH_NOARGS, Reader_get_usage__doc__ }, + { "__enter__", (PyCFunction) Reader___enter__, METH_NOARGS, Reader___enter____doc__ }, + { "__exit__", (PyCFunction) Reader___exit__, METH_VARARGS, Reader___exit____doc__ }, + { "_next", (PyCFunction) Reader_next, METH_VARARGS, Reader_next__doc__ }, + { "_previous", (PyCFunction) Reader_previous, METH_VARARGS, Reader_previous__doc__ }, + { "_get", (PyCFunction) Reader_get, METH_VARARGS, Reader_get__doc__ }, + { "_get_all", (PyCFunction) Reader_get_all, METH_NOARGS, Reader_get_all__doc__ }, + { "_get_realtime", (PyCFunction) Reader_get_realtime, METH_NOARGS, Reader_get_realtime__doc__ }, + { "_get_monotonic", (PyCFunction) Reader_get_monotonic, METH_NOARGS, Reader_get_monotonic__doc__ }, + { "add_match", (PyCFunction) Reader_add_match, METH_VARARGS, Reader_add_match__doc__ }, + { "add_disjunction", (PyCFunction) Reader_add_disjunction, METH_NOARGS, Reader_add_disjunction__doc__ }, + { "add_conjunction", (PyCFunction) Reader_add_conjunction, METH_NOARGS, Reader_add_conjunction__doc__ }, + { "flush_matches", (PyCFunction) Reader_flush_matches, METH_NOARGS, Reader_flush_matches__doc__ }, + { "seek_head", (PyCFunction) Reader_seek_head, METH_NOARGS, Reader_seek_head__doc__ }, + { "seek_tail", (PyCFunction) Reader_seek_tail, METH_NOARGS, Reader_seek_tail__doc__ }, + { "seek_realtime", (PyCFunction) Reader_seek_realtime, METH_VARARGS, Reader_seek_realtime__doc__ }, + { "seek_monotonic", (PyCFunction) Reader_seek_monotonic, METH_VARARGS, Reader_seek_monotonic__doc__ }, + { "_get_start", (PyCFunction) Reader_get_start, METH_NOARGS, Reader_get_start__doc__ }, + { "_get_end", (PyCFunction) Reader_get_end, METH_NOARGS, Reader_get_end__doc__ }, + { "process", (PyCFunction) Reader_process, METH_NOARGS, Reader_process__doc__ }, + { "wait", (PyCFunction) Reader_wait, METH_VARARGS, Reader_wait__doc__ }, + { "seek_cursor", (PyCFunction) Reader_seek_cursor, METH_VARARGS, Reader_seek_cursor__doc__ }, + { "_get_cursor", (PyCFunction) Reader_get_cursor, METH_NOARGS, Reader_get_cursor__doc__ }, + { "test_cursor", (PyCFunction) Reader_test_cursor, METH_VARARGS, Reader_test_cursor__doc__ }, + { "query_unique", (PyCFunction) Reader_query_unique, METH_VARARGS, Reader_query_unique__doc__ }, + { "enumerate_fields", (PyCFunction) Reader_enumerate_fields, METH_NOARGS, Reader_enumerate_fields__doc__ }, + { "has_runtime_files", (PyCFunction) Reader_has_runtime_files, METH_NOARGS, Reader_has_runtime_files__doc__ }, + { "has_persistent_files", (PyCFunction) Reader_has_persistent_files, METH_NOARGS, Reader_has_persistent_files__doc__ }, + { "get_catalog", (PyCFunction) Reader_get_catalog, METH_NOARGS, Reader_get_catalog__doc__ }, {} /* Sentinel */ }; @@ -1349,11 +1371,10 @@ static PyTypeObject ReaderType = { }; static PyMethodDef methods[] = { - { "_get_catalog", get_catalog, METH_VARARGS, get_catalog__doc__}, + { "_get_catalog", get_catalog, METH_VARARGS, get_catalog__doc__ }, {} /* Sentinel */ }; -#if PY_MAJOR_VERSION >= 3 static PyModuleDef module = { PyModuleDef_HEAD_INIT, .m_name = "_reader", @@ -1361,33 +1382,20 @@ static PyModuleDef module = { .m_size = -1, .m_methods = methods, }; -#endif - -#if PY_MAJOR_VERSION >= 3 static bool initialized = false; -#endif DISABLE_WARNING_MISSING_PROTOTYPES; PyMODINIT_FUNC -#if PY_MAJOR_VERSION >= 3 PyInit__reader(void) -#else -init_reader(void) -#endif { PyObject* m; PyDateTime_IMPORT; if (PyType_Ready(&ReaderType) < 0) -#if PY_MAJOR_VERSION >= 3 return NULL; -#else - return; -#endif -#if PY_MAJOR_VERSION >= 3 m = PyModule_Create(&module); if (!m) return NULL; @@ -1396,20 +1404,11 @@ init_reader(void) PyStructSequence_InitType(&MonotonicType, &Monotonic_desc); initialized = true; } -#else - m = Py_InitModule3("_reader", methods, module__doc__); - if (!m) - return; -#endif Py_INCREF(&ReaderType); -#if PY_MAJOR_VERSION >= 3 Py_INCREF(&MonotonicType); -#endif if (PyModule_AddObject(m, "_Reader", (PyObject *) &ReaderType) || -#if PY_MAJOR_VERSION >= 3 PyModule_AddObject(m, "Monotonic", (PyObject*) &MonotonicType) || -#endif PyModule_AddIntConstant(m, "NOP", SD_JOURNAL_NOP) || PyModule_AddIntConstant(m, "APPEND", SD_JOURNAL_APPEND) || PyModule_AddIntConstant(m, "INVALIDATE", SD_JOURNAL_INVALIDATE) || @@ -1420,15 +1419,11 @@ init_reader(void) PyModule_AddIntConstant(m, "CURRENT_USER", SD_JOURNAL_CURRENT_USER) || PyModule_AddIntConstant(m, "OS_ROOT", SD_JOURNAL_OS_ROOT) || PyModule_AddStringConstant(m, "__version__", PACKAGE_VERSION)) { -#if PY_MAJOR_VERSION >= 3 Py_DECREF(m); return NULL; -#endif } -#if PY_MAJOR_VERSION >= 3 return m; -#endif } REENABLE_WARNING; diff --git a/systemd/daemon.py b/src/systemd/daemon.py similarity index 98% rename from systemd/daemon.py rename to src/systemd/daemon.py index 168e55d..178680c 100644 --- a/systemd/daemon.py +++ b/src/systemd/daemon.py @@ -1,3 +1,5 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later + from socket import AF_UNSPEC as _AF_UNSPEC from ._daemon import (__version__, diff --git a/systemd/id128-constants.h b/src/systemd/id128-constants.h similarity index 52% rename from systemd/id128-constants.h rename to src/systemd/id128-constants.h index a1d215c..fe8aaaa 100644 --- a/systemd/id128-constants.h +++ b/src/systemd/id128-constants.h @@ -1,15 +1,42 @@ add_id(m, "SD_MESSAGE_BACKTRACE", SD_MESSAGE_BACKTRACE) JOINER +add_id(m, "SD_MESSAGE_BATTERY_LOW_POWEROFF", SD_MESSAGE_BATTERY_LOW_POWEROFF) JOINER +add_id(m, "SD_MESSAGE_BATTERY_LOW_WARNING", SD_MESSAGE_BATTERY_LOW_WARNING) JOINER add_id(m, "SD_MESSAGE_BOOTCHART", SD_MESSAGE_BOOTCHART) JOINER +add_id(m, "SD_MESSAGE_CANT_BREAK_ORDERING_CYCLE", SD_MESSAGE_CANT_BREAK_ORDERING_CYCLE) JOINER add_id(m, "SD_MESSAGE_CONFIG_ERROR", SD_MESSAGE_CONFIG_ERROR) JOINER add_id(m, "SD_MESSAGE_COREDUMP", SD_MESSAGE_COREDUMP) JOINER +add_id(m, "SD_MESSAGE_CORE_CAPABILITY_BOUNDING", SD_MESSAGE_CORE_CAPABILITY_BOUNDING) JOINER +add_id(m, "SD_MESSAGE_CORE_CAPABILITY_BOUNDING_USER", SD_MESSAGE_CORE_CAPABILITY_BOUNDING_USER) JOINER +add_id(m, "SD_MESSAGE_CORE_DISABLE_PRIVILEGES", SD_MESSAGE_CORE_DISABLE_PRIVILEGES) JOINER +add_id(m, "SD_MESSAGE_CORE_FD_SET_FAILED", SD_MESSAGE_CORE_FD_SET_FAILED) JOINER +add_id(m, "SD_MESSAGE_CORE_ISOLATE_TARGET_FAILED", SD_MESSAGE_CORE_ISOLATE_TARGET_FAILED) JOINER +add_id(m, "SD_MESSAGE_CORE_MAINLOOP_FAILED", SD_MESSAGE_CORE_MAINLOOP_FAILED) JOINER +add_id(m, "SD_MESSAGE_CORE_MANAGER_ALLOCATE", SD_MESSAGE_CORE_MANAGER_ALLOCATE) JOINER +add_id(m, "SD_MESSAGE_CORE_NO_XDGDIR_PATH", SD_MESSAGE_CORE_NO_XDGDIR_PATH) JOINER +add_id(m, "SD_MESSAGE_CORE_PID1_ENVIRONMENT", SD_MESSAGE_CORE_PID1_ENVIRONMENT) JOINER +add_id(m, "SD_MESSAGE_CORE_START_TARGET_FAILED", SD_MESSAGE_CORE_START_TARGET_FAILED) JOINER +add_id(m, "SD_MESSAGE_CRASH_COREDUMP_FAILED", SD_MESSAGE_CRASH_COREDUMP_FAILED) JOINER +add_id(m, "SD_MESSAGE_CRASH_COREDUMP_PID", SD_MESSAGE_CRASH_COREDUMP_PID) JOINER +add_id(m, "SD_MESSAGE_CRASH_EXECLE_FAILED", SD_MESSAGE_CRASH_EXECLE_FAILED) JOINER +add_id(m, "SD_MESSAGE_CRASH_EXIT", SD_MESSAGE_CRASH_EXIT) JOINER +add_id(m, "SD_MESSAGE_CRASH_FAILED", SD_MESSAGE_CRASH_FAILED) JOINER +add_id(m, "SD_MESSAGE_CRASH_FREEZE", SD_MESSAGE_CRASH_FREEZE) JOINER +add_id(m, "SD_MESSAGE_CRASH_NO_COREDUMP", SD_MESSAGE_CRASH_NO_COREDUMP) JOINER +add_id(m, "SD_MESSAGE_CRASH_NO_FORK", SD_MESSAGE_CRASH_NO_FORK) JOINER +add_id(m, "SD_MESSAGE_CRASH_PROCESS_SIGNAL", SD_MESSAGE_CRASH_PROCESS_SIGNAL) JOINER +add_id(m, "SD_MESSAGE_CRASH_SHELL_FORK_FAILED", SD_MESSAGE_CRASH_SHELL_FORK_FAILED) JOINER +add_id(m, "SD_MESSAGE_CRASH_SYSTEMD_SIGNAL", SD_MESSAGE_CRASH_SYSTEMD_SIGNAL) JOINER +add_id(m, "SD_MESSAGE_CRASH_UNKNOWN_SIGNAL", SD_MESSAGE_CRASH_UNKNOWN_SIGNAL) JOINER +add_id(m, "SD_MESSAGE_CRASH_WAITPID_FAILED", SD_MESSAGE_CRASH_WAITPID_FAILED) JOINER +add_id(m, "SD_MESSAGE_DELETING_JOB_BECAUSE_ORDERING_CYCLE", SD_MESSAGE_DELETING_JOB_BECAUSE_ORDERING_CYCLE) JOINER add_id(m, "SD_MESSAGE_DEVICE_PATH_NOT_SUITABLE", SD_MESSAGE_DEVICE_PATH_NOT_SUITABLE) JOINER add_id(m, "SD_MESSAGE_DNSSEC_DOWNGRADE", SD_MESSAGE_DNSSEC_DOWNGRADE) JOINER add_id(m, "SD_MESSAGE_DNSSEC_FAILURE", SD_MESSAGE_DNSSEC_FAILURE) JOINER add_id(m, "SD_MESSAGE_DNSSEC_TRUST_ANCHOR_REVOKED", SD_MESSAGE_DNSSEC_TRUST_ANCHOR_REVOKED) JOINER add_id(m, "SD_MESSAGE_FACTORY_RESET", SD_MESSAGE_FACTORY_RESET) JOINER add_id(m, "SD_MESSAGE_FORWARD_SYSLOG_MISSED", SD_MESSAGE_FORWARD_SYSLOG_MISSED) JOINER -add_id(m, "SD_MESSAGE_HIBERNATE_KEY_LONG_PRESS", SD_MESSAGE_HIBERNATE_KEY_LONG_PRESS) JOINER add_id(m, "SD_MESSAGE_HIBERNATE_KEY", SD_MESSAGE_HIBERNATE_KEY) JOINER +add_id(m, "SD_MESSAGE_HIBERNATE_KEY_LONG_PRESS", SD_MESSAGE_HIBERNATE_KEY_LONG_PRESS) JOINER add_id(m, "SD_MESSAGE_INVALID_CONFIGURATION", SD_MESSAGE_INVALID_CONFIGURATION) JOINER add_id(m, "SD_MESSAGE_JOURNAL_DROPPED", SD_MESSAGE_JOURNAL_DROPPED) JOINER add_id(m, "SD_MESSAGE_JOURNAL_MISSED", SD_MESSAGE_JOURNAL_MISSED) JOINER @@ -20,35 +47,56 @@ add_id(m, "SD_MESSAGE_LID_CLOSED", SD_MESSAGE_LID_CLOSED) JOINER add_id(m, "SD_MESSAGE_LID_OPENED", SD_MESSAGE_LID_OPENED) JOINER add_id(m, "SD_MESSAGE_MACHINE_START", SD_MESSAGE_MACHINE_START) JOINER add_id(m, "SD_MESSAGE_MACHINE_STOP", SD_MESSAGE_MACHINE_STOP) JOINER +add_id(m, "SD_MESSAGE_MEMORY_TRIM", SD_MESSAGE_MEMORY_TRIM) JOINER add_id(m, "SD_MESSAGE_MOUNT_POINT_PATH_NOT_SUITABLE", SD_MESSAGE_MOUNT_POINT_PATH_NOT_SUITABLE) JOINER add_id(m, "SD_MESSAGE_NOBODY_USER_UNSUITABLE", SD_MESSAGE_NOBODY_USER_UNSUITABLE) JOINER +add_id(m, "SD_MESSAGE_NON_CANONICAL_MOUNT", SD_MESSAGE_NON_CANONICAL_MOUNT) JOINER add_id(m, "SD_MESSAGE_OVERMOUNTING", SD_MESSAGE_OVERMOUNTING) JOINER -add_id(m, "SD_MESSAGE_POWER_KEY_LONG_PRESS", SD_MESSAGE_POWER_KEY_LONG_PRESS) JOINER +add_id(m, "SD_MESSAGE_PORTABLE_ATTACHED", SD_MESSAGE_PORTABLE_ATTACHED) JOINER +add_id(m, "SD_MESSAGE_PORTABLE_DETACHED", SD_MESSAGE_PORTABLE_DETACHED) JOINER add_id(m, "SD_MESSAGE_POWER_KEY", SD_MESSAGE_POWER_KEY) JOINER -add_id(m, "SD_MESSAGE_REBOOT_KEY_LONG_PRESS", SD_MESSAGE_REBOOT_KEY_LONG_PRESS) JOINER +add_id(m, "SD_MESSAGE_POWER_KEY_LONG_PRESS", SD_MESSAGE_POWER_KEY_LONG_PRESS) JOINER add_id(m, "SD_MESSAGE_REBOOT_KEY", SD_MESSAGE_REBOOT_KEY) JOINER +add_id(m, "SD_MESSAGE_REBOOT_KEY_LONG_PRESS", SD_MESSAGE_REBOOT_KEY_LONG_PRESS) JOINER add_id(m, "SD_MESSAGE_SEAT_START", SD_MESSAGE_SEAT_START) JOINER add_id(m, "SD_MESSAGE_SEAT_STOP", SD_MESSAGE_SEAT_STOP) JOINER +add_id(m, "SD_MESSAGE_SECURE_ATTENTION_KEY_PRESS", SD_MESSAGE_SECURE_ATTENTION_KEY_PRESS) JOINER +add_id(m, "SD_MESSAGE_SELINUX_FAILED", SD_MESSAGE_SELINUX_FAILED) JOINER add_id(m, "SD_MESSAGE_SESSION_START", SD_MESSAGE_SESSION_START) JOINER add_id(m, "SD_MESSAGE_SESSION_STOP", SD_MESSAGE_SESSION_STOP) JOINER add_id(m, "SD_MESSAGE_SHUTDOWN", SD_MESSAGE_SHUTDOWN) JOINER +add_id(m, "SD_MESSAGE_SHUTDOWN_CANCELED", SD_MESSAGE_SHUTDOWN_CANCELED) JOINER +add_id(m, "SD_MESSAGE_SHUTDOWN_ERROR", SD_MESSAGE_SHUTDOWN_ERROR) JOINER +add_id(m, "SD_MESSAGE_SHUTDOWN_SCHEDULED", SD_MESSAGE_SHUTDOWN_SCHEDULED) JOINER add_id(m, "SD_MESSAGE_SLEEP_START", SD_MESSAGE_SLEEP_START) JOINER add_id(m, "SD_MESSAGE_SLEEP_STOP", SD_MESSAGE_SLEEP_STOP) JOINER +add_id(m, "SD_MESSAGE_SMACK_FAILED_WRITE", SD_MESSAGE_SMACK_FAILED_WRITE) JOINER add_id(m, "SD_MESSAGE_SPAWN_FAILED", SD_MESSAGE_SPAWN_FAILED) JOINER +add_id(m, "SD_MESSAGE_SRK_ENROLLMENT_NEEDS_AUTHORIZATION", SD_MESSAGE_SRK_ENROLLMENT_NEEDS_AUTHORIZATION) JOINER add_id(m, "SD_MESSAGE_STARTUP_FINISHED", SD_MESSAGE_STARTUP_FINISHED) JOINER -add_id(m, "SD_MESSAGE_SUSPEND_KEY_LONG_PRESS", SD_MESSAGE_SUSPEND_KEY_LONG_PRESS) JOINER add_id(m, "SD_MESSAGE_SUSPEND_KEY", SD_MESSAGE_SUSPEND_KEY) JOINER -add_id(m, "SD_MESSAGE_SYSTEM_DOCKED", SD_MESSAGE_SYSTEM_DOCKED) JOINER +add_id(m, "SD_MESSAGE_SUSPEND_KEY_LONG_PRESS", SD_MESSAGE_SUSPEND_KEY_LONG_PRESS) JOINER +add_id(m, "SD_MESSAGE_SYSCTL_CHANGED", SD_MESSAGE_SYSCTL_CHANGED) JOINER add_id(m, "SD_MESSAGE_SYSTEMD_UDEV_SETTLE_DEPRECATED", SD_MESSAGE_SYSTEMD_UDEV_SETTLE_DEPRECATED) JOINER +add_id(m, "SD_MESSAGE_SYSTEM_ACCOUNT_REQUIRED", SD_MESSAGE_SYSTEM_ACCOUNT_REQUIRED) JOINER +add_id(m, "SD_MESSAGE_SYSTEM_DOCKED", SD_MESSAGE_SYSTEM_DOCKED) JOINER add_id(m, "SD_MESSAGE_SYSTEM_UNDOCKED", SD_MESSAGE_SYSTEM_UNDOCKED) JOINER +add_id(m, "SD_MESSAGE_SYSV_GENERATOR_DEPRECATED", SD_MESSAGE_SYSV_GENERATOR_DEPRECATED) JOINER add_id(m, "SD_MESSAGE_TAINTED", SD_MESSAGE_TAINTED) JOINER +add_id(m, "SD_MESSAGE_TIMEZONE_CHANGE", SD_MESSAGE_TIMEZONE_CHANGE) JOINER +add_id(m, "SD_MESSAGE_TIME_BUMP", SD_MESSAGE_TIME_BUMP) JOINER add_id(m, "SD_MESSAGE_TIME_CHANGE", SD_MESSAGE_TIME_CHANGE) JOINER add_id(m, "SD_MESSAGE_TIME_SYNC", SD_MESSAGE_TIME_SYNC) JOINER -add_id(m, "SD_MESSAGE_TIMEZONE_CHANGE", SD_MESSAGE_TIMEZONE_CHANGE) JOINER +add_id(m, "SD_MESSAGE_TPM2_CLEAR_REQUESTED", SD_MESSAGE_TPM2_CLEAR_REQUESTED) JOINER +add_id(m, "SD_MESSAGE_TPM_NVINDEX_EXHAUSTED", SD_MESSAGE_TPM_NVINDEX_EXHAUSTED) JOINER +add_id(m, "SD_MESSAGE_TPM_NVPCR_EXTEND", SD_MESSAGE_TPM_NVPCR_EXTEND) JOINER +add_id(m, "SD_MESSAGE_TPM_NVPCR_UNSUPPORTED", SD_MESSAGE_TPM_NVPCR_UNSUPPORTED) JOINER +add_id(m, "SD_MESSAGE_TPM_PCR_EXTEND", SD_MESSAGE_TPM_PCR_EXTEND) JOINER add_id(m, "SD_MESSAGE_TRUNCATED_CORE", SD_MESSAGE_TRUNCATED_CORE) JOINER add_id(m, "SD_MESSAGE_UNIT_FAILED", SD_MESSAGE_UNIT_FAILED) JOINER add_id(m, "SD_MESSAGE_UNIT_FAILURE_RESULT", SD_MESSAGE_UNIT_FAILURE_RESULT) JOINER add_id(m, "SD_MESSAGE_UNIT_OOMD_KILL", SD_MESSAGE_UNIT_OOMD_KILL) JOINER +add_id(m, "SD_MESSAGE_UNIT_ORDERING_CYCLE", SD_MESSAGE_UNIT_ORDERING_CYCLE) JOINER add_id(m, "SD_MESSAGE_UNIT_OUT_OF_MEMORY", SD_MESSAGE_UNIT_OUT_OF_MEMORY) JOINER add_id(m, "SD_MESSAGE_UNIT_PROCESS_EXIT", SD_MESSAGE_UNIT_PROCESS_EXIT) JOINER add_id(m, "SD_MESSAGE_UNIT_RELOADED", SD_MESSAGE_UNIT_RELOADED) JOINER @@ -63,3 +111,7 @@ add_id(m, "SD_MESSAGE_UNIT_STOPPING", SD_MESSAGE_UNIT_STOPPING) JOINER add_id(m, "SD_MESSAGE_UNIT_SUCCESS", SD_MESSAGE_UNIT_SUCCESS) JOINER add_id(m, "SD_MESSAGE_UNSAFE_USER_NAME", SD_MESSAGE_UNSAFE_USER_NAME) JOINER add_id(m, "SD_MESSAGE_USER_STARTUP_FINISHED", SD_MESSAGE_USER_STARTUP_FINISHED) JOINER +add_id(m, "SD_MESSAGE_VALGRIND_HELPER_FORK", SD_MESSAGE_VALGRIND_HELPER_FORK) JOINER +add_id(m, "SD_MESSAGE_WATCHDOG_OPENED", SD_MESSAGE_WATCHDOG_OPENED) JOINER +add_id(m, "SD_MESSAGE_WATCHDOG_OPEN_FAILED", SD_MESSAGE_WATCHDOG_OPEN_FAILED) JOINER +add_id(m, "SD_MESSAGE_WATCHDOG_PING_FAILED", SD_MESSAGE_WATCHDOG_PING_FAILED) JOINER diff --git a/systemd/id128-defines.h b/src/systemd/id128-defines.h similarity index 54% rename from systemd/id128-defines.h rename to src/systemd/id128-defines.h index 178de83..4492b14 100644 --- a/systemd/id128-defines.h +++ b/src/systemd/id128-defines.h @@ -1,15 +1,42 @@ #define SD_MESSAGE_BACKTRACE SD_ID128_MAKE(1f,4e,0a,44,a8,86,49,93,9a,ae,a3,4f,c6,da,8c,95) +#define SD_MESSAGE_BATTERY_LOW_POWEROFF SD_ID128_MAKE(26,74,37,d3,3f,dd,41,09,9a,d7,62,21,cc,24,a3,35) +#define SD_MESSAGE_BATTERY_LOW_WARNING SD_ID128_MAKE(e6,f4,56,bd,92,00,4d,95,80,16,0b,22,07,55,51,86) #define SD_MESSAGE_BOOTCHART SD_ID128_MAKE(9f,26,aa,56,2c,f4,40,c2,b1,6c,77,3d,04,79,b5,18) +#define SD_MESSAGE_CANT_BREAK_ORDERING_CYCLE SD_ID128_MAKE(b3,11,2d,da,d1,90,45,53,8c,76,68,5b,a5,91,8a,80) #define SD_MESSAGE_CONFIG_ERROR SD_ID128_MAKE(c7,72,d2,4e,9a,88,4c,be,b9,ea,12,62,5c,30,6c,01) #define SD_MESSAGE_COREDUMP SD_ID128_MAKE(fc,2e,22,bc,6e,e6,47,b6,b9,07,29,ab,34,a2,50,b1) +#define SD_MESSAGE_CORE_CAPABILITY_BOUNDING SD_ID128_MAKE(42,69,5b,50,0d,f0,48,29,8b,ee,37,15,9c,aa,9f,2e) +#define SD_MESSAGE_CORE_CAPABILITY_BOUNDING_USER SD_ID128_MAKE(ed,15,8c,2d,f8,88,4f,a5,84,ee,ad,2d,90,2c,10,32) +#define SD_MESSAGE_CORE_DISABLE_PRIVILEGES SD_ID128_MAKE(bf,c2,43,07,24,ab,44,49,97,35,b4,f9,4c,ca,92,95) +#define SD_MESSAGE_CORE_FD_SET_FAILED SD_ID128_MAKE(5e,d8,36,f1,76,6f,4a,8a,9f,c5,da,45,aa,e2,3b,29) +#define SD_MESSAGE_CORE_ISOLATE_TARGET_FAILED SD_ID128_MAKE(68,9b,4f,cc,97,b4,48,6e,a5,da,92,db,69,c9,e3,14) +#define SD_MESSAGE_CORE_MAINLOOP_FAILED SD_ID128_MAKE(79,e0,5b,67,bc,45,45,d1,92,2f,e4,71,07,ee,60,c5) +#define SD_MESSAGE_CORE_MANAGER_ALLOCATE SD_ID128_MAKE(0e,54,47,09,84,ac,41,96,89,74,3d,95,7a,11,9e,2e) +#define SD_MESSAGE_CORE_NO_XDGDIR_PATH SD_ID128_MAKE(db,b1,36,b1,0e,f4,45,7b,a4,7a,79,5d,62,f1,08,c9) +#define SD_MESSAGE_CORE_PID1_ENVIRONMENT SD_ID128_MAKE(6a,40,fb,fb,d2,ba,4b,8d,b0,2f,b4,0c,9c,d0,90,d7) +#define SD_MESSAGE_CORE_START_TARGET_FAILED SD_ID128_MAKE(59,28,8a,f5,23,be,43,a2,8d,49,4e,41,e2,6e,45,10) +#define SD_MESSAGE_CRASH_COREDUMP_FAILED SD_ID128_MAKE(56,b1,cd,96,f2,42,46,c5,b6,07,66,6f,da,95,23,56) +#define SD_MESSAGE_CRASH_COREDUMP_PID SD_ID128_MAKE(4a,c7,56,6d,4d,75,48,f4,98,1f,62,9a,28,f0,f8,29) +#define SD_MESSAGE_CRASH_EXECLE_FAILED SD_ID128_MAKE(87,27,29,b4,7d,be,47,3e,b7,68,cc,ec,d4,77,be,da) +#define SD_MESSAGE_CRASH_EXIT SD_ID128_MAKE(d9,ec,5e,95,e4,b6,46,aa,ae,a2,fd,05,21,4e,db,da) +#define SD_MESSAGE_CRASH_FAILED SD_ID128_MAKE(3e,d0,16,3e,86,8a,44,17,ab,8b,9e,21,04,07,a9,6c) +#define SD_MESSAGE_CRASH_FREEZE SD_ID128_MAKE(64,5c,73,55,37,63,4a,e0,a3,2b,15,a7,c6,cb,a7,d4) +#define SD_MESSAGE_CRASH_NO_COREDUMP SD_ID128_MAKE(5a,dd,b3,a0,6a,73,4d,33,96,b7,94,bf,98,fb,2d,01) +#define SD_MESSAGE_CRASH_NO_FORK SD_ID128_MAKE(5c,9e,98,de,4a,b9,4c,6a,9d,04,d0,ad,79,3b,d9,03) +#define SD_MESSAGE_CRASH_PROCESS_SIGNAL SD_ID128_MAKE(3a,73,a9,8b,af,5b,4b,19,99,29,e3,22,6c,0b,e7,83) +#define SD_MESSAGE_CRASH_SHELL_FORK_FAILED SD_ID128_MAKE(38,e8,b1,e0,39,ad,46,92,91,b1,8b,44,c5,53,a5,b7) +#define SD_MESSAGE_CRASH_SYSTEMD_SIGNAL SD_ID128_MAKE(83,f8,4b,35,ee,26,4f,74,a3,89,6a,97,17,af,34,cb) +#define SD_MESSAGE_CRASH_UNKNOWN_SIGNAL SD_ID128_MAKE(5e,6f,1f,5e,4d,b6,4a,0e,ae,e3,36,82,49,d2,0b,94) +#define SD_MESSAGE_CRASH_WAITPID_FAILED SD_ID128_MAKE(2e,d1,8d,4f,78,ca,47,f0,a9,bc,25,27,1c,26,ad,b4) +#define SD_MESSAGE_DELETING_JOB_BECAUSE_ORDERING_CYCLE SD_ID128_MAKE(50,84,36,75,42,f7,47,2d,bc,6a,94,12,5d,5d,eb,ce) #define SD_MESSAGE_DEVICE_PATH_NOT_SUITABLE SD_ID128_MAKE(01,01,90,13,8f,49,4e,29,a0,ef,66,69,74,95,31,aa) #define SD_MESSAGE_DNSSEC_DOWNGRADE SD_ID128_MAKE(36,db,2d,fa,5a,90,45,e1,bd,4a,f5,f9,3e,1c,f0,57) #define SD_MESSAGE_DNSSEC_FAILURE SD_ID128_MAKE(16,75,d7,f1,72,17,40,98,b1,10,8b,f8,c7,dc,8f,5d) #define SD_MESSAGE_DNSSEC_TRUST_ANCHOR_REVOKED SD_ID128_MAKE(4d,44,08,cf,d0,d1,44,85,91,84,d1,e6,5d,7c,8a,65) #define SD_MESSAGE_FACTORY_RESET SD_ID128_MAKE(c1,4a,af,76,ec,28,4a,5f,a1,f1,05,f8,8d,fb,06,1c) #define SD_MESSAGE_FORWARD_SYSLOG_MISSED SD_ID128_MAKE(00,27,22,9c,a0,64,41,81,a7,6c,4e,92,45,8a,fa,2e) -#define SD_MESSAGE_HIBERNATE_KEY_LONG_PRESS SD_ID128_MAKE(16,78,36,df,6f,7f,42,8e,98,14,72,27,b2,dc,89,45) #define SD_MESSAGE_HIBERNATE_KEY SD_ID128_MAKE(b7,2e,a4,a2,88,15,45,a0,b5,0e,20,0e,55,b9,b0,73) +#define SD_MESSAGE_HIBERNATE_KEY_LONG_PRESS SD_ID128_MAKE(16,78,36,df,6f,7f,42,8e,98,14,72,27,b2,dc,89,45) #define SD_MESSAGE_INVALID_CONFIGURATION SD_ID128_MAKE(c7,72,d2,4e,9a,88,4c,be,b9,ea,12,62,5c,30,6c,01) #define SD_MESSAGE_JOURNAL_DROPPED SD_ID128_MAKE(a5,96,d6,fe,7b,fa,49,94,82,8e,72,30,9e,95,d6,1e) #define SD_MESSAGE_JOURNAL_MISSED SD_ID128_MAKE(e9,bf,28,e6,e8,34,48,1b,b6,f4,8f,54,8a,d1,36,06) @@ -20,35 +47,56 @@ #define SD_MESSAGE_LID_OPENED SD_ID128_MAKE(b7,2e,a4,a2,88,15,45,a0,b5,0e,20,0e,55,b9,b0,6f) #define SD_MESSAGE_MACHINE_START SD_ID128_MAKE(24,d8,d4,45,25,73,40,24,96,06,83,81,a6,31,2d,f2) #define SD_MESSAGE_MACHINE_STOP SD_ID128_MAKE(58,43,2b,d3,ba,ce,47,7c,b5,14,b5,63,81,b8,a7,58) +#define SD_MESSAGE_MEMORY_TRIM SD_ID128_MAKE(f9,b0,be,46,5a,d5,40,d0,85,0a,d3,21,72,d5,7c,21) #define SD_MESSAGE_MOUNT_POINT_PATH_NOT_SUITABLE SD_ID128_MAKE(1b,3b,b9,40,37,f0,4b,bf,81,02,8e,13,5a,12,d2,93) #define SD_MESSAGE_NOBODY_USER_UNSUITABLE SD_ID128_MAKE(b4,80,32,5f,9c,39,4a,7b,80,2c,23,1e,51,a2,75,2c) +#define SD_MESSAGE_NON_CANONICAL_MOUNT SD_ID128_MAKE(1e,da,bb,4e,da,2a,49,c1,9b,c0,20,6f,24,b4,38,89) #define SD_MESSAGE_OVERMOUNTING SD_ID128_MAKE(1d,ee,03,69,c7,fc,47,36,b7,09,9b,38,ec,b4,6e,e7) -#define SD_MESSAGE_POWER_KEY_LONG_PRESS SD_ID128_MAKE(3e,01,17,10,1e,b2,43,c1,b9,a5,0d,b3,49,4a,b1,0b) +#define SD_MESSAGE_PORTABLE_ATTACHED SD_ID128_MAKE(18,7c,62,eb,1e,7f,46,3b,b5,30,39,4f,52,cb,09,0f) +#define SD_MESSAGE_PORTABLE_DETACHED SD_ID128_MAKE(76,c5,c7,54,d6,28,49,0d,8e,cb,a4,c9,d0,42,11,2b) #define SD_MESSAGE_POWER_KEY SD_ID128_MAKE(b7,2e,a4,a2,88,15,45,a0,b5,0e,20,0e,55,b9,b0,71) -#define SD_MESSAGE_REBOOT_KEY_LONG_PRESS SD_ID128_MAKE(f1,c5,9a,58,c9,d9,43,66,89,65,c3,37,ca,ec,59,75) +#define SD_MESSAGE_POWER_KEY_LONG_PRESS SD_ID128_MAKE(3e,01,17,10,1e,b2,43,c1,b9,a5,0d,b3,49,4a,b1,0b) #define SD_MESSAGE_REBOOT_KEY SD_ID128_MAKE(9f,a9,d2,c0,12,13,4e,c3,85,45,1f,fe,31,6f,97,d0) +#define SD_MESSAGE_REBOOT_KEY_LONG_PRESS SD_ID128_MAKE(f1,c5,9a,58,c9,d9,43,66,89,65,c3,37,ca,ec,59,75) #define SD_MESSAGE_SEAT_START SD_ID128_MAKE(fc,be,fc,5d,a2,3d,42,80,93,f9,7c,82,a9,29,0f,7b) #define SD_MESSAGE_SEAT_STOP SD_ID128_MAKE(e7,85,2b,fe,46,78,4e,d0,ac,cd,e0,4b,c8,64,c2,d5) +#define SD_MESSAGE_SECURE_ATTENTION_KEY_PRESS SD_ID128_MAKE(b2,bc,ba,f5,ed,f9,48,e0,93,ce,50,bb,ea,0e,81,ec) +#define SD_MESSAGE_SELINUX_FAILED SD_ID128_MAKE(65,8a,67,ad,c1,c9,40,b3,b3,31,6e,7e,86,28,83,4a) #define SD_MESSAGE_SESSION_START SD_ID128_MAKE(8d,45,62,0c,1a,43,48,db,b1,74,10,da,57,c6,0c,66) #define SD_MESSAGE_SESSION_STOP SD_ID128_MAKE(33,54,93,94,24,b4,45,6d,98,02,ca,83,33,ed,42,4a) #define SD_MESSAGE_SHUTDOWN SD_ID128_MAKE(98,26,88,66,d1,d5,4a,49,9c,4e,98,92,1d,93,bc,40) +#define SD_MESSAGE_SHUTDOWN_CANCELED SD_ID128_MAKE(24,9f,6f,b9,e6,e2,42,8c,96,f3,f0,87,56,81,ff,a3) +#define SD_MESSAGE_SHUTDOWN_ERROR SD_ID128_MAKE(af,55,a6,f7,5b,54,44,31,b7,26,49,f3,6f,f6,d6,2c) +#define SD_MESSAGE_SHUTDOWN_SCHEDULED SD_ID128_MAKE(9e,70,66,27,9d,c8,40,3d,a7,9c,e4,b1,a6,90,64,b2) #define SD_MESSAGE_SLEEP_START SD_ID128_MAKE(6b,bd,95,ee,97,79,41,e4,97,c4,8b,e2,7c,25,41,28) #define SD_MESSAGE_SLEEP_STOP SD_ID128_MAKE(88,11,e6,df,2a,8e,40,f5,8a,94,ce,a2,6f,8e,bf,14) +#define SD_MESSAGE_SMACK_FAILED_WRITE SD_ID128_MAKE(d6,7f,a9,f8,47,aa,4b,04,8a,2a,e3,35,35,33,1a,db) #define SD_MESSAGE_SPAWN_FAILED SD_ID128_MAKE(64,12,57,65,1c,1b,4e,c9,a8,62,4d,7a,40,a9,e1,e7) +#define SD_MESSAGE_SRK_ENROLLMENT_NEEDS_AUTHORIZATION SD_ID128_MAKE(ad,70,89,f9,28,ac,4f,7e,a0,0c,07,45,7d,47,ba,8a) #define SD_MESSAGE_STARTUP_FINISHED SD_ID128_MAKE(b0,7a,24,9c,d0,24,41,4a,82,dd,00,cd,18,13,78,ff) -#define SD_MESSAGE_SUSPEND_KEY_LONG_PRESS SD_ID128_MAKE(bf,da,f6,d3,12,ab,40,07,bc,1f,e4,0a,15,df,78,e8) #define SD_MESSAGE_SUSPEND_KEY SD_ID128_MAKE(b7,2e,a4,a2,88,15,45,a0,b5,0e,20,0e,55,b9,b0,72) -#define SD_MESSAGE_SYSTEM_DOCKED SD_ID128_MAKE(f5,f4,16,b8,62,07,4b,28,92,7a,48,c3,ba,7d,51,ff) +#define SD_MESSAGE_SUSPEND_KEY_LONG_PRESS SD_ID128_MAKE(bf,da,f6,d3,12,ab,40,07,bc,1f,e4,0a,15,df,78,e8) +#define SD_MESSAGE_SYSCTL_CHANGED SD_ID128_MAKE(9c,f5,6b,8b,af,95,46,cf,94,78,78,3a,8d,e4,21,13) #define SD_MESSAGE_SYSTEMD_UDEV_SETTLE_DEPRECATED SD_ID128_MAKE(1c,04,54,c1,bd,22,41,e0,ac,6f,ef,b4,bc,63,14,33) +#define SD_MESSAGE_SYSTEM_ACCOUNT_REQUIRED SD_ID128_MAKE(34,05,20,5d,36,8e,49,fe,b5,ab,39,25,fe,e1,38,74) +#define SD_MESSAGE_SYSTEM_DOCKED SD_ID128_MAKE(f5,f4,16,b8,62,07,4b,28,92,7a,48,c3,ba,7d,51,ff) #define SD_MESSAGE_SYSTEM_UNDOCKED SD_ID128_MAKE(51,e1,71,bd,58,52,48,56,81,10,14,4c,51,7c,ca,53) +#define SD_MESSAGE_SYSV_GENERATOR_DEPRECATED SD_ID128_MAKE(a8,fa,8d,ac,db,1d,44,3e,95,03,b8,be,36,7a,6a,db) #define SD_MESSAGE_TAINTED SD_ID128_MAKE(50,87,6a,9d,b0,0f,4c,40,bd,e1,a2,ad,38,1c,3a,1b) +#define SD_MESSAGE_TIMEZONE_CHANGE SD_ID128_MAKE(45,f8,2f,4a,ef,7a,4b,bf,94,2c,e8,61,d1,f2,09,90) +#define SD_MESSAGE_TIME_BUMP SD_ID128_MAKE(7d,b7,3c,8a,f0,d9,4e,eb,82,2a,e0,43,23,fe,6a,b6) #define SD_MESSAGE_TIME_CHANGE SD_ID128_MAKE(c7,a7,87,07,9b,35,4e,aa,a9,e7,7b,37,18,93,cd,27) #define SD_MESSAGE_TIME_SYNC SD_ID128_MAKE(7c,8a,41,f3,7b,76,49,41,a0,e1,78,0b,1b,e2,f0,37) -#define SD_MESSAGE_TIMEZONE_CHANGE SD_ID128_MAKE(45,f8,2f,4a,ef,7a,4b,bf,94,2c,e8,61,d1,f2,09,90) +#define SD_MESSAGE_TPM2_CLEAR_REQUESTED SD_ID128_MAKE(43,81,88,86,1e,0b,42,7a,9d,63,8a,90,48,7a,0c,a6) +#define SD_MESSAGE_TPM_NVINDEX_EXHAUSTED SD_ID128_MAKE(ab,98,4e,a0,08,96,4f,b8,8d,6e,38,9f,b5,13,fb,94) +#define SD_MESSAGE_TPM_NVPCR_EXTEND SD_ID128_MAKE(4c,2e,46,d2,66,a7,47,c6,ac,14,60,aa,54,48,4f,a7) +#define SD_MESSAGE_TPM_NVPCR_UNSUPPORTED SD_ID128_MAKE(8f,07,a5,b8,14,ca,47,62,b8,9f,cc,30,82,e4,8a,ed) +#define SD_MESSAGE_TPM_PCR_EXTEND SD_ID128_MAKE(3f,7d,5e,f3,e5,4f,43,02,b4,f0,b1,43,bb,27,0c,ab) #define SD_MESSAGE_TRUNCATED_CORE SD_ID128_MAKE(5a,ad,d8,e9,54,dc,4b,1a,8c,95,4d,63,fd,9e,11,37) #define SD_MESSAGE_UNIT_FAILED SD_ID128_MAKE(be,02,cf,68,55,d2,42,8b,a4,0d,f7,e9,d0,22,f0,3d) #define SD_MESSAGE_UNIT_FAILURE_RESULT SD_ID128_MAKE(d9,b3,73,ed,55,a6,4f,eb,82,42,e0,2d,be,79,a4,9c) #define SD_MESSAGE_UNIT_OOMD_KILL SD_ID128_MAKE(d9,89,61,1b,15,e4,4c,9d,bf,31,e3,c8,12,56,e4,ed) +#define SD_MESSAGE_UNIT_ORDERING_CYCLE SD_ID128_MAKE(f2,7a,3f,94,40,6a,47,83,b9,46,a9,bc,84,9e,94,52) #define SD_MESSAGE_UNIT_OUT_OF_MEMORY SD_ID128_MAKE(fe,6f,aa,94,e7,77,46,63,a0,da,52,71,78,91,d8,ef) #define SD_MESSAGE_UNIT_PROCESS_EXIT SD_ID128_MAKE(98,e3,22,20,3f,7a,4e,d2,90,d0,9f,e0,3c,09,fe,15) #define SD_MESSAGE_UNIT_RELOADED SD_ID128_MAKE(7b,05,eb,c6,68,38,42,22,ba,a8,88,11,79,cf,da,54) @@ -63,3 +111,7 @@ #define SD_MESSAGE_UNIT_SUCCESS SD_ID128_MAKE(7a,d2,d1,89,f7,e9,4e,70,a3,8c,78,13,54,91,24,48) #define SD_MESSAGE_UNSAFE_USER_NAME SD_ID128_MAKE(b6,1f,da,c6,12,e9,4b,91,82,28,5b,99,88,43,06,1f) #define SD_MESSAGE_USER_STARTUP_FINISHED SD_ID128_MAKE(ee,d0,0a,68,ff,d8,4e,31,88,21,05,fd,97,3a,bd,d1) +#define SD_MESSAGE_VALGRIND_HELPER_FORK SD_ID128_MAKE(d1,8e,03,39,ef,b2,4a,06,8d,9c,10,60,22,10,48,c2) +#define SD_MESSAGE_WATCHDOG_OPENED SD_ID128_MAKE(21,66,8d,bd,3d,7a,4a,32,a2,67,6d,53,da,da,b0,22) +#define SD_MESSAGE_WATCHDOG_OPEN_FAILED SD_ID128_MAKE(37,5a,c1,51,ef,9d,4d,e3,90,68,b3,ef,bf,ed,0c,ee) +#define SD_MESSAGE_WATCHDOG_PING_FAILED SD_ID128_MAKE(87,39,78,9e,ca,06,43,25,af,15,a8,ed,0e,cf,c5,56) diff --git a/systemd/id128.c b/src/systemd/id128.c similarity index 72% rename from systemd/id128.c rename to src/systemd/id128.c index 891c658..8d128f6 100644 --- a/systemd/id128.c +++ b/src/systemd/id128.c @@ -1,24 +1,4 @@ -/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ - -/*** - - Copyright 2013 Zbigniew Jędrzejewski-Szmek - - python-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. - - python-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 python-systemd; If not, see . -***/ - -#include +/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* Our include is first, so that our defines are replaced by the ones * from the system header. If the system header has the same definitions @@ -30,8 +10,8 @@ #include "id128-defines.h" #include -#include "pyutil.h" #include "macro.h" +#include "pyutil.h" #define HAVE_SD_ID128_GET_MACHINE_APP_SPECIFIC (LIBSYSTEMD_VERSION >= 240) @@ -87,27 +67,27 @@ static PyObject* make_uuid(sd_id128_t id) { return PyObject_Call(UUID, args, kwargs); } -#define helper(name) \ - static PyObject *name(PyObject *self, PyObject *args) { \ - sd_id128_t id; \ - int r; \ - \ - assert(!args); \ - \ - r = sd_id128_##name(&id); \ - if (r < 0) { \ - errno = -r; \ - return PyErr_SetFromErrno(PyExc_IOError); \ - } \ - \ - return make_uuid(id); \ +#define helper(name) \ + static PyObject *name(PyObject *self _unused_, PyObject *args) { \ + sd_id128_t id; \ + int r; \ + \ + assert(!args); \ + \ + r = sd_id128_##name(&id); \ + if (r < 0) { \ + errno = -r; \ + return PyErr_SetFromErrno(PyExc_OSError); \ + } \ + \ + return make_uuid(id); \ } helper(randomize) helper(get_machine) helper(get_boot) -static PyObject *get_machine_app_specific(PyObject *self, PyObject *args) { +static PyObject *get_machine_app_specific(PyObject *self _unused_, PyObject *args) { _cleanup_Py_DECREF_ PyObject *uuid_bytes = NULL; uuid_bytes = PyObject_GetAttrString(args, "bytes"); @@ -132,7 +112,7 @@ static PyObject *get_machine_app_specific(PyObject *self, PyObject *args) { PyBuffer_Release(&buffer); if (r < 0) { errno = -r; - return PyErr_SetFromErrno(PyExc_IOError); + return PyErr_SetFromErrno(PyExc_OSError); } return make_uuid(app_id); @@ -144,10 +124,10 @@ static PyObject *get_machine_app_specific(PyObject *self, PyObject *args) { } static PyMethodDef methods[] = { - { "randomize", randomize, METH_NOARGS, randomize__doc__}, - { "get_machine", get_machine, METH_NOARGS, get_machine__doc__}, - { "get_machine_app_specific", get_machine_app_specific, METH_O, get_machine_app_specific__doc__}, - { "get_boot", get_boot, METH_NOARGS, get_boot__doc__}, + { "randomize", randomize, METH_NOARGS, randomize__doc__ }, + { "get_machine", get_machine, METH_NOARGS, get_machine__doc__ }, + { "get_machine_app_specific", get_machine_app_specific, METH_O, get_machine_app_specific__doc__ }, + { "get_boot", get_boot, METH_NOARGS, get_boot__doc__ }, {} /* Sentinel */ }; @@ -161,26 +141,6 @@ static int add_id(PyObject *module, const char* name, sd_id128_t id) { return PyModule_AddObject(module, name, obj); } -#if PY_MAJOR_VERSION < 3 - -DISABLE_WARNING_MISSING_PROTOTYPES; -PyMODINIT_FUNC initid128(void) { - PyObject *m; - - m = Py_InitModule3("id128", methods, module__doc__); - if (!m) - return; - - /* a series of lines like 'add_id() ;' follow */ -#define JOINER ; -#include "id128-constants.h" -#undef JOINER - PyModule_AddStringConstant(m, "__version__", PACKAGE_VERSION); -} -REENABLE_WARNING; - -#else - static struct PyModuleDef module = { PyModuleDef_HEAD_INIT, .m_name = "id128", /* name of module */ @@ -209,5 +169,3 @@ PyMODINIT_FUNC PyInit_id128(void) { return m; } REENABLE_WARNING; - -#endif diff --git a/systemd/journal.py b/src/systemd/journal.py similarity index 93% rename from systemd/journal.py rename to src/systemd/journal.py index b1f2fef..da3404a 100644 --- a/systemd/journal.py +++ b/src/systemd/journal.py @@ -1,24 +1,4 @@ -# -*- Mode: python; coding:utf-8; indent-tabs-mode: nil -*- */ -# -# -# Copyright 2012 David Strauss -# Copyright 2012 Zbigniew Jędrzejewski-Szmek -# Copyright 2012 Marti Raudsepp -# -# python-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. -# -# python-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 python-systemd; If not, see . - -from __future__ import division +# SPDX-License-Identifier: LGPL-2.1-or-later import sys as _sys import datetime as _datetime @@ -34,14 +14,9 @@ LOCAL_ONLY, RUNTIME_ONLY, SYSTEM, SYSTEM_ONLY, CURRENT_USER, OS_ROOT, - _get_catalog) + _get_catalog, Monotonic) from . import id128 as _id128 -if _sys.version_info >= (3,): - from ._reader import Monotonic -else: - Monotonic = tuple - def _convert_monotonic(m): return Monotonic((_datetime.timedelta(microseconds=m[0]), @@ -51,7 +26,10 @@ def _convert_monotonic(m): def _convert_source_monotonic(s): return _datetime.timedelta(microseconds=int(s)) -_LOCAL_TIMEZONE = _datetime.datetime.now().astimezone().tzinfo +try: + _LOCAL_TIMEZONE = _datetime.datetime.now().astimezone().tzinfo +except TypeError: + _LOCAL_TIMEZONE = None def _convert_realtime(t): return _datetime.datetime.fromtimestamp(t / 1000000, _LOCAL_TIMEZONE) @@ -63,11 +41,10 @@ def _convert_timestamp(s): def _convert_trivial(x): return x -if _sys.version_info >= (3,): - def _convert_uuid(s): - return _uuid.UUID(s.decode()) -else: - _convert_uuid = _uuid.UUID + +def _convert_uuid(s): + return _uuid.UUID(s.decode()) + DEFAULT_CONVERTERS = { 'MESSAGE_ID': _convert_uuid, @@ -219,9 +196,6 @@ def __next__(self): else: raise StopIteration() - if _sys.version_info < (3,): - next = __next__ - def add_match(self, *args, **kwargs): """Add one or more matches to the filter journal log entries. @@ -313,7 +287,7 @@ def seek_realtime(self, realtime): >>> j.seek_realtime(yesterday) """ if isinstance(realtime, _datetime.datetime): - realtime = int(float(realtime.astimezone().strftime("%s.%f")) * 1000000) + realtime = int(realtime.astimezone().timestamp() * 1000000) elif not isinstance(realtime, int): realtime = int(realtime * 1000000) return super(Reader, self).seek_realtime(realtime) @@ -480,7 +454,6 @@ def stream(identifier=None, priority=LOG_INFO, level_prefix=False): This interface can be used conveniently with the print function: - >>> from __future__ import print_function >>> stream = journal.stream() # doctest: +SKIP >>> print('message...', file=stream) # doctest: +SKIP diff --git a/systemd/login.c b/src/systemd/login.c similarity index 73% rename from systemd/login.c rename to src/systemd/login.c index b029229..4bc2aab 100644 --- a/systemd/login.c +++ b/src/systemd/login.c @@ -1,30 +1,7 @@ -/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ -/*** +#include - Copyright 2013 Zbigniew Jędrzejewski-Szmek - - python-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. - - python-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 python-systemd; If not, see . -***/ - -#define PY_SSIZE_T_CLEAN -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wredundant-decls" -#include -#pragma GCC diagnostic pop - -#include "systemd/sd-login.h" #include "pyutil.h" #include "strv.h" @@ -33,25 +10,24 @@ PyDoc_STRVAR(module__doc__, ); #define helper(name) \ -static PyObject* name(PyObject *self, PyObject *args) { \ +static PyObject* name(PyObject *self _unused_, PyObject *args) { \ _cleanup_strv_free_ char **list = NULL; \ int r; \ - PyObject *ans; \ \ assert(!args); \ \ r = sd_get_##name(&list); \ if (r < 0) { \ errno = -r; \ - return PyErr_SetFromErrno(PyExc_IOError); \ + return PyErr_SetFromErrno(PyExc_OSError); \ } \ \ - ans = PyList_New(r); \ + PyObject *ans = PyList_New(r); \ if (!ans) \ return NULL; \ \ for (r--; r >= 0; r--) { \ - PyObject *s = unicode_FromString(list[r]); \ + PyObject *s = PyUnicode_FromString(list[r]); \ if (!s) { \ Py_DECREF(ans); \ return NULL; \ @@ -68,25 +44,24 @@ helper(sessions) helper(machine_names) #undef helper -static PyObject* uids(PyObject *self, PyObject *args) { +static PyObject* uids(PyObject *self _unused_, PyObject *args) { _cleanup_free_ uid_t *list = NULL; int r; - PyObject *ans; assert(!args); r = sd_get_uids(&list); if (r < 0) { errno = -r; - return PyErr_SetFromErrno(PyExc_IOError); + return PyErr_SetFromErrno(PyExc_OSError); } - ans = PyList_New(r); + PyObject *ans = PyList_New(r); if (!ans) return NULL; for (r--; r >= 0; r--) { - PyObject *s = long_FromLong(list[r]); + PyObject *s = PyLong_FromLong(list[r]); if (!s) { Py_DECREF(ans); return NULL; @@ -124,10 +99,10 @@ PyDoc_STRVAR(uids__doc__, ); static PyMethodDef methods[] = { - { "seats", seats, METH_NOARGS, seats__doc__}, - { "sessions", sessions, METH_NOARGS, sessions__doc__}, - { "machine_names", machine_names, METH_NOARGS, machine_names__doc__}, - { "uids", uids, METH_NOARGS, uids__doc__}, + { "seats", seats, METH_NOARGS, seats__doc__ }, + { "sessions", sessions, METH_NOARGS, sessions__doc__ }, + { "machine_names", machine_names, METH_NOARGS, machine_names__doc__ }, + { "uids", uids, METH_NOARGS, uids__doc__ }, {} /* Sentinel */ }; @@ -139,7 +114,7 @@ typedef struct { static PyTypeObject MonitorType; static void Monitor_dealloc(Monitor* self) { - sd_login_monitor_unref(self->monitor); + self->monitor = sd_login_monitor_unref(self->monitor); Py_TYPE(self)->tp_free((PyObject*)self); } @@ -171,11 +146,14 @@ PyDoc_STRVAR(Monitor_fileno__doc__, "Get a file descriptor to poll for events.\n" "This method wraps sd_login_monitor_get_fd(3)."); static PyObject* Monitor_fileno(Monitor *self, PyObject *args) { + assert(self); + assert(!args); + int fd = sd_login_monitor_get_fd(self->monitor); set_error(fd, NULL, NULL); if (fd < 0) return NULL; - return long_FromLong(fd); + return PyLong_FromLong(fd); } @@ -185,11 +163,16 @@ PyDoc_STRVAR(Monitor_get_events__doc__, "by .fileno().\n\n" "See :manpage:`sd_login_monitor_get_events(3)` for further discussion."); static PyObject* Monitor_get_events(Monitor *self, PyObject *args) { - int r = sd_login_monitor_get_events(self->monitor); + int r; + + assert(self); + assert(!args); + + r = sd_login_monitor_get_events(self->monitor); set_error(r, NULL, NULL); if (r < 0) return NULL; - return long_FromLong(r); + return PyLong_FromLong(r); } @@ -205,6 +188,9 @@ static PyObject* Monitor_get_timeout(Monitor *self, PyObject *args) { int r; uint64_t t; + assert(self); + assert(!args); + r = sd_login_monitor_get_timeout(self->monitor, &t); set_error(r, NULL, NULL); if (r < 0) @@ -227,6 +213,9 @@ static PyObject* Monitor_get_timeout_ms(Monitor *self, PyObject *args) { int r; uint64_t t; + assert(self); + assert(!args); + r = sd_login_monitor_get_timeout(self->monitor, &t); set_error(r, NULL, NULL); if (r < 0) @@ -245,8 +234,7 @@ static PyObject* Monitor_close(Monitor *self, PyObject *args) { assert(self); assert(!args); - sd_login_monitor_unref(self->monitor); - self->monitor = NULL; + self->monitor = sd_login_monitor_unref(self->monitor); Py_RETURN_NONE; } @@ -285,19 +273,22 @@ PyDoc_STRVAR(Monitor___exit____doc__, "Part of the context manager protocol.\n" "Closes the monitor..\n"); static PyObject* Monitor___exit__(Monitor *self, PyObject *args) { + assert(self); + assert(!args); + return Monitor_close(self, args); } static PyMethodDef Monitor_methods[] = { - {"fileno", (PyCFunction) Monitor_fileno, METH_NOARGS, Monitor_fileno__doc__}, - {"get_events", (PyCFunction) Monitor_get_events, METH_NOARGS, Monitor_get_events__doc__}, - {"get_timeout", (PyCFunction) Monitor_get_timeout, METH_NOARGS, Monitor_get_timeout__doc__}, - {"get_timeout_ms", (PyCFunction) Monitor_get_timeout_ms, METH_NOARGS, Monitor_get_timeout_ms__doc__}, - {"close", (PyCFunction) Monitor_close, METH_NOARGS, Monitor_close__doc__}, - {"flush", (PyCFunction) Monitor_flush, METH_NOARGS, Monitor_flush__doc__}, - {"__enter__", (PyCFunction) Monitor___enter__, METH_NOARGS, Monitor___enter____doc__}, - {"__exit__", (PyCFunction) Monitor___exit__, METH_VARARGS, Monitor___exit____doc__}, + { "fileno", (PyCFunction) Monitor_fileno, METH_NOARGS, Monitor_fileno__doc__ }, + { "get_events", (PyCFunction) Monitor_get_events, METH_NOARGS, Monitor_get_events__doc__ }, + { "get_timeout", (PyCFunction) Monitor_get_timeout, METH_NOARGS, Monitor_get_timeout__doc__ }, + { "get_timeout_ms", (PyCFunction) Monitor_get_timeout_ms, METH_NOARGS, Monitor_get_timeout_ms__doc__ }, + { "close", (PyCFunction) Monitor_close, METH_NOARGS, Monitor_close__doc__ }, + { "flush", (PyCFunction) Monitor_flush, METH_NOARGS, Monitor_flush__doc__ }, + { "__enter__", (PyCFunction) Monitor___enter__, METH_NOARGS, Monitor___enter____doc__ }, + { "__exit__", (PyCFunction) Monitor___exit__, METH_VARARGS, Monitor___exit____doc__ }, {} /* Sentinel */ }; @@ -313,34 +304,13 @@ static PyTypeObject MonitorType = { .tp_new = PyType_GenericNew, }; -#if PY_MAJOR_VERSION < 3 - -DISABLE_WARNING_MISSING_PROTOTYPES; -PyMODINIT_FUNC initlogin(void) { - PyObject *m; - - if (PyType_Ready(&MonitorType) < 0) - return; - - m = Py_InitModule3("login", methods, module__doc__); - if (!m) - return; - - PyModule_AddStringConstant(m, "__version__", PACKAGE_VERSION); - - Py_INCREF(&MonitorType); - PyModule_AddObject(m, "Monitor", (PyObject *) &MonitorType); -} -REENABLE_WARNING; - -#else - static struct PyModuleDef module = { PyModuleDef_HEAD_INIT, - "login", /* name of module */ - module__doc__, /* module documentation, may be NULL */ - -1, /* size of per-interpreter state of the module */ - methods + .m_name = "login", /* name of module */ + .m_doc = module__doc__, /* module documentation, may be NULL */ + .m_size = -1, /* size of per-interpreter state of the module */ + .m_methods = methods, + .m_slots = NULL, }; DISABLE_WARNING_MISSING_PROTOTYPES; @@ -369,5 +339,3 @@ PyMODINIT_FUNC PyInit_login(void) { return m; } REENABLE_WARNING; - -#endif diff --git a/systemd/macro.h b/src/systemd/macro.h similarity index 65% rename from systemd/macro.h rename to src/systemd/macro.h index 1b0db1d..d6e3197 100644 --- a/systemd/macro.h +++ b/src/systemd/macro.h @@ -1,29 +1,17 @@ -/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -/*** - - Copyright 2010 Lennart Poettering - - python-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. - - python-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 python-systemd; If not, see . -***/ +#include #define DISABLE_WARNING_MISSING_PROTOTYPES \ _Pragma("GCC diagnostic push"); \ _Pragma("GCC diagnostic ignored \"-Wmissing-prototypes\"") +#define DISABLE_WARNING_CAST_FUNCTION_TYPE \ + _Pragma("GCC diagnostic push"); \ + _Pragma("GCC diagnostic ignored \"-Wcast-function-type\"") + #define REENABLE_WARNING \ _Pragma("GCC diagnostic pop") @@ -43,6 +31,7 @@ (void *) memset(_new_, 0, _len_); \ }) +#define _unused_ __attribute__((__unused__)) #define _cleanup_(x) __attribute__((cleanup(x))) static inline void freep(void *p) { diff --git a/src/systemd/meson.build b/src/systemd/meson.build new file mode 100644 index 0000000..842be36 --- /dev/null +++ b/src/systemd/meson.build @@ -0,0 +1,81 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later + +# Build _journal extension module +python.extension_module( + '_journal', + ['_journal.c', 'pyutil.c'], + dependencies: [libsystemd_dep], + install: true, + subdir: 'systemd', +) + +# Build _reader extension module +python.extension_module( + '_reader', + ['_reader.c', 'pyutil.c', 'strv.c'], + dependencies: [libsystemd_dep], + install: true, + subdir: 'systemd', +) + +# Build _daemon extension module +python.extension_module( + '_daemon', + ['_daemon.c', 'pyutil.c', 'util.c'], + dependencies: [libsystemd_dep], + install: true, + subdir: 'systemd', +) + +# Build id128 extension module +python.extension_module( + 'id128', + ['id128.c', 'pyutil.c'], + dependencies: [libsystemd_dep], + install: true, + subdir: 'systemd', +) + +# Build login extension module +python.extension_module( + 'login', + ['login.c', 'pyutil.c', 'strv.c'], + dependencies: [libsystemd_dep], + install: true, + subdir: 'systemd', +) + +# Install Python modules +py_files = files( + '__init__.py', + 'journal.py', + 'daemon.py', +) + +python.install_sources(py_files, subdir: 'systemd') +foreach file: py_files + fs.copyfile(file) +endforeach + +# Test code +python_test_dir = meson.current_source_dir() / 'test' +python.install_sources( + 'test/test_daemon.py', + 'test/test_journal.py', + 'test/test_login.py', + 'test/test_id128.py', + subdir: 'systemd/test', +) + +# The 'update-constants' target +include_dir = libsystemd_dep.get_variable(pkgconfig: 'includedir') + +update_constants = custom_target( + output: 'update-constants', + command: [ + update_constants_py, + meson.current_source_dir() / 'id128-constants.h', + meson.project_source_root() / 'docs/id128.rst', + meson.current_source_dir() / 'id128-defines.h', + include_dir / 'systemd/sd-messages.h', + ]) diff --git a/systemd/pyutil.c b/src/systemd/pyutil.c similarity index 64% rename from systemd/pyutil.c rename to src/systemd/pyutil.c index cd91ec3..df2f2e9 100644 --- a/systemd/pyutil.c +++ b/src/systemd/pyutil.c @@ -1,24 +1,5 @@ -/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ -/*** - - Copyright 2013 Zbigniew Jędrzejewski-Szmek - - python-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. - - python-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 python-systemd; If not, see . -***/ - -#include #include "pyutil.h" void cleanup_Py_DECREFp(PyObject **p) { @@ -58,7 +39,6 @@ int set_error(int r, const char* path, const char* invalid_message) { return -1; } -#if PY_MAJOR_VERSION >=3 && PY_MINOR_VERSION >= 1 int Unicode_FSConverter(PyObject* obj, void *_result) { PyObject **result = _result; @@ -76,4 +56,3 @@ int Unicode_FSConverter(PyObject* obj, void *_result) { return PyUnicode_FSConverter(obj, result); } -#endif diff --git a/src/systemd/pyutil.h b/src/systemd/pyutil.h new file mode 100644 index 0000000..36ff6c0 --- /dev/null +++ b/src/systemd/pyutil.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ + +#pragma once + +#define PY_SSIZE_T_CLEAN +/* Work around bug in Python.h: + * it tries to redefine defines already defined by /usr/include/features.h, + * without calling #undef first, causing a warning to be emitted. + * (https://github.com/python/cpython/issues/61322). */ +#undef _POSIX_C_SOURCE +#undef _XOPEN_SOURCE +# include +#undef _POSIX_C_SOURCE +#undef _XOPEN_SOURCE +#define _XOPEN_SOURCE 800 +#define _POSIX_C_SOURCE 202405L + +void cleanup_Py_DECREFp(PyObject **p); +PyObject* absolute_timeout(uint64_t t); +int set_error(int r, const char* path, const char* invalid_message); + +int Unicode_FSConverter(PyObject* obj, void *_result); + +#define _cleanup_Py_DECREF_ _cleanup_(cleanup_Py_DECREFp) diff --git a/src/systemd/strv.c b/src/systemd/strv.c new file mode 100644 index 0000000..f3d9c53 --- /dev/null +++ b/src/systemd/strv.c @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ + +#include + +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/src/systemd/strv.h b/src/systemd/strv.h new file mode 100644 index 0000000..4cf0d8f --- /dev/null +++ b/src/systemd/strv.h @@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ + +#include "macro.h" + +char **strv_free(char **l); +DEFINE_TRIVIAL_CLEANUP_FUNC(char**, strv_free); +#define _cleanup_strv_free_ _cleanup_(strv_freep) diff --git a/systemd/test/test_daemon.py b/src/systemd/test/test_daemon.py similarity index 96% rename from systemd/test/test_daemon.py rename to src/systemd/test/test_daemon.py index ac782f9..7355153 100644 --- a/systemd/test/test_daemon.py +++ b/src/systemd/test/test_daemon.py @@ -1,3 +1,5 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later + import sys import os import posix @@ -306,24 +308,20 @@ def test_notify_no_socket(): assert notify('FDSTORE=1', pid=os.getpid()) is False assert notify('FDSTORE=1', pid=os.getpid(), fds=(1,)) is False -if sys.version_info >= (3,): - connection_error = ConnectionRefusedError -else: - connection_error = OSError def test_notify_bad_socket(): os.environ['NOTIFY_SOCKET'] = '/dev/null' - with pytest.raises(connection_error): + with pytest.raises(ConnectionRefusedError): notify('READY=1') - with pytest.raises(connection_error): + with pytest.raises(ConnectionRefusedError): with skip_enosys(): notify('FDSTORE=1', fds=[]) - with pytest.raises(connection_error): + with pytest.raises(ConnectionRefusedError): notify('FDSTORE=1', fds=[1, 2]) - with pytest.raises(connection_error): + with pytest.raises(ConnectionRefusedError): notify('FDSTORE=1', pid=os.getpid()) - with pytest.raises(connection_error): + with pytest.raises(ConnectionRefusedError): notify('FDSTORE=1', pid=os.getpid(), fds=(1,)) def test_notify_with_socket(tmpdir): @@ -333,9 +331,7 @@ def test_notify_with_socket(tmpdir): sock.bind(path) except socket.error as e: pytest.xfail('failed to bind socket (%s)' % e) - # SO_PASSCRED is not defined in python2.7 - SO_PASSCRED = getattr(socket, 'SO_PASSCRED', 16) - sock.setsockopt(socket.SOL_SOCKET, SO_PASSCRED, 1) + sock.setsockopt(socket.SOL_SOCKET, socket.SO_PASSCRED, 1) os.environ['NOTIFY_SOCKET'] = path assert notify('READY=1') diff --git a/systemd/test/test_id128.py b/src/systemd/test/test_id128.py similarity index 72% rename from systemd/test/test_id128.py rename to src/systemd/test/test_id128.py index 146ec73..ece098b 100644 --- a/systemd/test/test_id128.py +++ b/src/systemd/test/test_id128.py @@ -1,3 +1,5 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later + import contextlib import errno import uuid @@ -6,11 +8,11 @@ from systemd import id128 @contextlib.contextmanager -def skip_oserror(code): +def skip_oserror(*errnos): try: yield - except (OSError, IOError) as e: - if e.errno == code: + except OSError as e: + if e.errno in errnos: pytest.skip() raise @@ -21,7 +23,9 @@ def test_randomize(): assert u1 != u2 def test_get_machine(): - u1 = id128.get_machine() + with skip_oserror(errno.ENOENT, errno.ENOSYS, errno.ENOMEDIUM): + u1 = id128.get_machine() + u2 = id128.get_machine() assert u1 == u2 @@ -29,7 +33,7 @@ def test_get_machine_app_specific(): a1 = uuid.uuid1() a2 = uuid.uuid1() - with skip_oserror(errno.ENOSYS): + with skip_oserror(errno.ENOENT, errno.ENOSYS, 123): u1 = id128.get_machine_app_specific(a1) u2 = id128.get_machine_app_specific(a2) diff --git a/systemd/test/test_journal.py b/src/systemd/test/test_journal.py similarity index 95% rename from systemd/test/test_journal.py rename to src/systemd/test/test_journal.py index e6761ca..709fb0b 100644 --- a/systemd/test/test_journal.py +++ b/src/systemd/test/test_journal.py @@ -1,4 +1,5 @@ -from __future__ import print_function +# SPDX-License-Identifier: LGPL-2.1-or-later + import contextlib import datetime import errno @@ -6,7 +7,8 @@ import os import time import uuid -import traceback as _traceback +import sys +import traceback from systemd import journal, id128 from systemd.journal import _make_line @@ -30,7 +32,7 @@ def send(self, MESSAGE, MESSAGE_ID=None, args.append('MESSAGE_ID=' + id) if CODE_LINE is CODE_FILE is CODE_FUNC is None: - CODE_FILE, CODE_LINE, CODE_FUNC = _traceback.extract_stack(limit=2)[0][:3] + CODE_FILE, CODE_LINE, CODE_FUNC = traceback.extract_stack(limit=2)[0][:3] if CODE_FILE is not None: args.append('CODE_FILE=' + CODE_FILE) if CODE_LINE is not None: @@ -45,7 +47,7 @@ def send(self, MESSAGE, MESSAGE_ID=None, def skip_oserror(code): try: yield - except (OSError, IOError) as e: + except OSError as e: if e.errno == code: pytest.skip() raise @@ -232,7 +234,11 @@ def test_reader_this_boot(tmpdir): def test_reader_this_machine(tmpdir): j = journal.Reader(path=tmpdir.strpath) with j: - j.this_machine() + try: + j.this_machine() + except OSError: + pass + j.this_machine(TEST_MID) j.this_machine(TEST_MID.hex) @@ -294,13 +300,16 @@ def test_reader_convert_timestamps(tmpdir): j = journal.Reader(path=tmpdir.strpath) val = j._convert_field('_SOURCE_REALTIME_TIMESTAMP', 1641651559324187) - assert val.tzinfo is not None + if sys.version_info >= (3,): + assert val.tzinfo is not None val = j._convert_field('__REALTIME_TIMESTAMP', 1641651559324187) - assert val.tzinfo is not None + if sys.version_info >= (3,): + assert val.tzinfo is not None val = j._convert_field('COREDUMP_TIMESTAMP', 1641651559324187) - assert val.tzinfo is not None + if sys.version_info >= (3,): + assert val.tzinfo is not None def test_seek_realtime(tmpdir): j = journal.Reader(path=tmpdir.strpath) diff --git a/systemd/test/test_login.py b/src/systemd/test/test_login.py similarity index 93% rename from systemd/test/test_login.py rename to src/systemd/test/test_login.py index afb5f45..5e51b02 100644 --- a/systemd/test/test_login.py +++ b/src/systemd/test/test_login.py @@ -1,4 +1,5 @@ -from __future__ import print_function +# SPDX-License-Identifier: LGPL-2.1-or-later + import select import contextlib import errno @@ -11,7 +12,7 @@ def skip_oserror(code): try: yield - except (OSError, IOError) as e: + except OSError as e: if e.errno == code: pytest.skip() raise diff --git a/systemd/util.c b/src/systemd/util.c similarity index 83% rename from systemd/util.c rename to src/systemd/util.c index a8ca299..0db9e27 100644 --- a/systemd/util.c +++ b/src/systemd/util.c @@ -1,21 +1,4 @@ -/*** - 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 . -***/ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* stuff imported from systemd without any changes */ @@ -111,19 +94,16 @@ static int assign_address(const char *s, int parse_sockaddr(const char *s, union sockaddr_union *addr, unsigned *addr_len) { - - char *e, *n; - unsigned u; int r; if (*s == '[') { /* IPv6 in [x:.....:z]:p notation */ - e = strchr(s+1, ']'); + const char *e = strchr(s + 1, ']'); if (!e) return -EINVAL; - n = strndupa(s+1, e-s-1); + char *n = strndupa(s+1, e-s-1); errno = 0; if (inet_pton(AF_INET6, n, &addr->in6.sin6_addr) <= 0) @@ -133,8 +113,9 @@ int parse_sockaddr(const char *s, if (*e) { if (*e != ':') return -EINVAL; - e++; + + unsigned u; r = safe_atou(e, &u); if (r < 0) return r; @@ -149,19 +130,21 @@ int parse_sockaddr(const char *s, *addr_len = sizeof(struct sockaddr_in6); } else { - e = strchr(s, ':'); + const char *e = strchr(s, ':'); if (e) { - r = safe_atou(e+1, &u); + unsigned u; + r = safe_atou(e + 1, &u); if (r < 0) return r; if (u <= 0 || u > 0xFFFF) return -EINVAL; - n = strndupa(s, e-s); + char *n = strndupa(s, e-s); return assign_address(n, u, addr, addr_len); } else { + unsigned u; r = safe_atou(s, &u); if (r < 0) return assign_address(s, 0, addr, addr_len); diff --git a/src/systemd/util.h b/src/systemd/util.h new file mode 100644 index 0000000..1438f85 --- /dev/null +++ b/src/systemd/util.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ + +#pragma once + +#include +#include + +union sockaddr_union { + struct sockaddr sa; + struct sockaddr_in in; + struct sockaddr_in6 in6; +}; + +int safe_atou(const char *s, unsigned *ret_u); +int parse_sockaddr(const char *s, + union sockaddr_union *addr, unsigned *addr_len); diff --git a/systemd/__init__.py b/systemd/__init__.py deleted file mode 100644 index 3b5dbe1..0000000 --- a/systemd/__init__.py +++ /dev/null @@ -1,17 +0,0 @@ -# -*- Mode: python; indent-tabs-mode: nil -*- */ -# -# -# Copyright 2012 David Strauss -# -# python-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. -# -# python-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 python-systemd; If not, see . diff --git a/systemd/pyutil.h b/systemd/pyutil.h deleted file mode 100644 index f840e87..0000000 --- a/systemd/pyutil.h +++ /dev/null @@ -1,53 +0,0 @@ -/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ - -#pragma once - -/*** - - Copyright 2013 Zbigniew Jędrzejewski-Szmek - - python-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. - - python-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 python-systemd; If not, see . -***/ - -#ifndef Py_TYPE -/* avoid duplication warnings from errors in Python 2.7 headers */ -# include -#endif - -void cleanup_Py_DECREFp(PyObject **p); -PyObject* absolute_timeout(uint64_t t); -int set_error(int r, const char* path, const char* invalid_message); - -#if PY_MAJOR_VERSION >=3 && PY_MINOR_VERSION >= 1 -int Unicode_FSConverter(PyObject* obj, void *_result); -#endif - -#define _cleanup_Py_DECREF_ _cleanup_(cleanup_Py_DECREFp) - -#if PY_MAJOR_VERSION >=3 -# define unicode_FromStringAndSize PyUnicode_FromStringAndSize -# define unicode_FromString PyUnicode_FromString -# define long_FromLong PyLong_FromLong -# define long_FromSize_t PyLong_FromSize_t -# define long_Check PyLong_Check -# define long_AsLong PyLong_AsLong -#else -/* Python 3 type naming convention is used */ -# define unicode_FromStringAndSize PyString_FromStringAndSize -# define unicode_FromString PyString_FromString -# define long_FromLong PyInt_FromLong -# define long_FromSize_t PyInt_FromSize_t -# define long_Check PyInt_Check -# define long_AsLong PyInt_AsLong -#endif diff --git a/systemd/strv.c b/systemd/strv.c deleted file mode 100644 index 0ba62a3..0000000 --- a/systemd/strv.c +++ /dev/null @@ -1,39 +0,0 @@ -/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ - -/*** - - Copyright 2010 Lennart Poettering - - python-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. - - python-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 python-systemd; If not, see . -***/ - -#include - -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 deleted file mode 100644 index 3ce5505..0000000 --- a/systemd/strv.h +++ /dev/null @@ -1,25 +0,0 @@ -/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ - -/*** - - Copyright 2010 Lennart Poettering - - python-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. - - python-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 python-systemd; If not, see . -***/ - -#include "macro.h" - -char **strv_free(char **l); -DEFINE_TRIVIAL_CLEANUP_FUNC(char**, strv_free); -#define _cleanup_strv_free_ _cleanup_(strv_freep) diff --git a/systemd/util.h b/systemd/util.h deleted file mode 100644 index 337920c..0000000 --- a/systemd/util.h +++ /dev/null @@ -1,33 +0,0 @@ -#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 . -***/ - -#include -#include - -union sockaddr_union { - struct sockaddr sa; - struct sockaddr_in in; - struct sockaddr_in6 in6; -}; - -int safe_atou(const char *s, unsigned *ret_u); -int parse_sockaddr(const char *s, - union sockaddr_union *addr, unsigned *addr_len); diff --git a/update-constants.py b/update-constants.py old mode 100644 new mode 100755 index 2dcacda..aff1725 --- a/update-constants.py +++ b/update-constants.py @@ -1,9 +1,51 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: LGPL-2.1-or-later + import sys -for file in sys.argv[1:]: +def defines(file): lines = iter(open(file).read().splitlines()) for line in lines: if line.startswith('#define SD_MESSAGE') and '_STR ' not in line: if line.endswith('\\'): line = line[:-1] + next(lines) - print(' '.join(line.split())) + _, name, value = line.split() + assert 'SD_' in name + assert 'SD_ID128_MAKE' in value + yield name, value + + +def process(includefile, docfile, *headers): + # Collects all messages from all headers and saves the sorted list back to + # headers[0]. Writes includefile (C) and docfile (rst). + + # Collect all messages into a single sorted, deduplicated list + defs = sum((list(defines(file)) for file in headers), start=[]) + defs = sorted(set(defs)) + + with open(includefile, 'wt') as out: + print(f'Writing {out.name}…') + for name, value in defs: + print(f'add_id(m, "{name}", {name}) JOINER', file=out) + + with open(headers[0], 'wt') as out: + print(f'Writing {out.name}…') + for name, value in defs: + print(f'#define {name} {value}', file=out) + + old = open(docfile).read().splitlines() + + with open(docfile, 'wt') as out: + print(f'Writing {out.name}…') + for line in old: + print(line, file=out) + if 'autogenerated' in line: + break + for name, value in defs: + print(f' .. autoattribute:: systemd.id128.{name}', file=out) + +if __name__ == '__main__': + includefile = sys.argv[1] + docfile = sys.argv[2] + headers = sys.argv[3:] + process(includefile, docfile, *headers)