diff options
54 files changed, 1335 insertions, 4209 deletions
diff --git a/Makefile-man.am b/Makefile-man.am index 74a1f4cb43..218a299e91 100644 --- a/Makefile-man.am +++ b/Makefile-man.am @@ -24,6 +24,7 @@ MANPAGES += \ man/machine-id.5 \ man/machine-info.5 \ man/os-release.5 \ + man/sd-bus-errors.3 \ man/sd-daemon.3 \ man/sd-id128.3 \ man/sd-journal.3 \ @@ -32,6 +33,7 @@ MANPAGES += \ man/sd_bus_creds_new_from_pid.3 \ man/sd_bus_default.3 \ man/sd_bus_error.3 \ + man/sd_bus_error_add_map.3 \ man/sd_bus_message_append.3 \ man/sd_bus_message_append_array.3 \ man/sd_bus_message_append_basic.3 \ @@ -161,6 +163,40 @@ MANPAGES += \ man/udevadm.8 MANPAGES_ALIAS += \ man/SD_ALERT.3 \ + man/SD_BUS_ERROR_ACCESS_DENIED.3 \ + man/SD_BUS_ERROR_ADDRESS_IN_USE.3 \ + man/SD_BUS_ERROR_AUTH_FAILED.3 \ + man/SD_BUS_ERROR_BAD_ADDRESS.3 \ + man/SD_BUS_ERROR_DISCONNECTED.3 \ + man/SD_BUS_ERROR_END.3 \ + man/SD_BUS_ERROR_FAILED.3 \ + man/SD_BUS_ERROR_FILE_EXISTS.3 \ + man/SD_BUS_ERROR_FILE_NOT_FOUND.3 \ + man/SD_BUS_ERROR_INCONSISTENT_MESSAGE.3 \ + man/SD_BUS_ERROR_INTERACTIVE_AUTHORIZATION_REQUIRED.3 \ + man/SD_BUS_ERROR_INVALID_ARGS.3 \ + man/SD_BUS_ERROR_INVALID_SIGNATURE.3 \ + man/SD_BUS_ERROR_IO_ERROR.3 \ + man/SD_BUS_ERROR_LIMITS_EXCEEDED.3 \ + man/SD_BUS_ERROR_MAKE_CONST.3 \ + man/SD_BUS_ERROR_MAP.3 \ + man/SD_BUS_ERROR_MATCH_RULE_INVALID.3 \ + man/SD_BUS_ERROR_MATCH_RULE_NOT_FOUND.3 \ + man/SD_BUS_ERROR_NAME_HAS_NO_OWNER.3 \ + man/SD_BUS_ERROR_NOT_SUPPORTED.3 \ + man/SD_BUS_ERROR_NO_MEMORY.3 \ + man/SD_BUS_ERROR_NO_NETWORK.3 \ + man/SD_BUS_ERROR_NO_REPLY.3 \ + man/SD_BUS_ERROR_NO_SERVER.3 \ + man/SD_BUS_ERROR_NULL.3 \ + man/SD_BUS_ERROR_PROPERTY_READ_ONLY.3 \ + man/SD_BUS_ERROR_SERVICE_UNKNOWN.3 \ + man/SD_BUS_ERROR_TIMEOUT.3 \ + man/SD_BUS_ERROR_UNIX_PROCESS_ID_UNKNOWN.3 \ + man/SD_BUS_ERROR_UNKNOWN_INTERFACE.3 \ + man/SD_BUS_ERROR_UNKNOWN_METHOD.3 \ + man/SD_BUS_ERROR_UNKNOWN_OBJECT.3 \ + man/SD_BUS_ERROR_UNKNOWN_PROPERTY.3 \ man/SD_CRIT.3 \ man/SD_DEBUG.3 \ man/SD_EMERG.3 \ @@ -191,6 +227,7 @@ MANPAGES_ALIAS += \ man/reboot.8 \ man/sd_bus_creds_get_audit_login_uid.3 \ man/sd_bus_creds_get_audit_session_id.3 \ + man/sd_bus_creds_get_augmented_mask.3 \ man/sd_bus_creds_get_cgroup.3 \ man/sd_bus_creds_get_cmdline.3 \ man/sd_bus_creds_get_comm.3 \ @@ -216,6 +253,7 @@ MANPAGES_ALIAS += \ man/sd_bus_creds_get_uid.3 \ man/sd_bus_creds_get_unique_name.3 \ man/sd_bus_creds_get_unit.3 \ + man/sd_bus_creds_get_user_slice.3 \ man/sd_bus_creds_get_user_unit.3 \ man/sd_bus_creds_get_well_known_names.3 \ man/sd_bus_creds_has_bounding_cap.3 \ @@ -231,10 +269,13 @@ MANPAGES_ALIAS += \ man/sd_bus_error_get_errno.3 \ man/sd_bus_error_has_name.3 \ man/sd_bus_error_is_set.3 \ + man/sd_bus_error_map.3 \ man/sd_bus_error_set.3 \ man/sd_bus_error_set_const.3 \ man/sd_bus_error_set_errno.3 \ man/sd_bus_error_set_errnof.3 \ + man/sd_bus_error_set_errnofv.3 \ + man/sd_bus_error_setf.3 \ man/sd_bus_message_append_array_iovec.3 \ man/sd_bus_message_append_array_memfd.3 \ man/sd_bus_message_append_array_space.3 \ @@ -244,7 +285,7 @@ MANPAGES_ALIAS += \ man/sd_bus_message_get_reply_cookie.3 \ man/sd_bus_message_get_seqnum.3 \ man/sd_bus_negotiate_creds.3 \ - man/sd_bus_negotiate_timestamps.3 \ + man/sd_bus_negotiate_timestamp.3 \ man/sd_bus_open.3 \ man/sd_bus_open_system.3 \ man/sd_bus_open_system_machine.3 \ @@ -408,6 +449,40 @@ MANPAGES_ALIAS += \ man/udev_unref.3 \ man/user.conf.d.5 man/SD_ALERT.3: man/sd-daemon.3 +man/SD_BUS_ERROR_ACCESS_DENIED.3: man/sd-bus-errors.3 +man/SD_BUS_ERROR_ADDRESS_IN_USE.3: man/sd-bus-errors.3 +man/SD_BUS_ERROR_AUTH_FAILED.3: man/sd-bus-errors.3 +man/SD_BUS_ERROR_BAD_ADDRESS.3: man/sd-bus-errors.3 +man/SD_BUS_ERROR_DISCONNECTED.3: man/sd-bus-errors.3 +man/SD_BUS_ERROR_END.3: man/sd_bus_error_add_map.3 +man/SD_BUS_ERROR_FAILED.3: man/sd-bus-errors.3 +man/SD_BUS_ERROR_FILE_EXISTS.3: man/sd-bus-errors.3 +man/SD_BUS_ERROR_FILE_NOT_FOUND.3: man/sd-bus-errors.3 +man/SD_BUS_ERROR_INCONSISTENT_MESSAGE.3: man/sd-bus-errors.3 +man/SD_BUS_ERROR_INTERACTIVE_AUTHORIZATION_REQUIRED.3: man/sd-bus-errors.3 +man/SD_BUS_ERROR_INVALID_ARGS.3: man/sd-bus-errors.3 +man/SD_BUS_ERROR_INVALID_SIGNATURE.3: man/sd-bus-errors.3 +man/SD_BUS_ERROR_IO_ERROR.3: man/sd-bus-errors.3 +man/SD_BUS_ERROR_LIMITS_EXCEEDED.3: man/sd-bus-errors.3 +man/SD_BUS_ERROR_MAKE_CONST.3: man/sd_bus_error.3 +man/SD_BUS_ERROR_MAP.3: man/sd_bus_error_add_map.3 +man/SD_BUS_ERROR_MATCH_RULE_INVALID.3: man/sd-bus-errors.3 +man/SD_BUS_ERROR_MATCH_RULE_NOT_FOUND.3: man/sd-bus-errors.3 +man/SD_BUS_ERROR_NAME_HAS_NO_OWNER.3: man/sd-bus-errors.3 +man/SD_BUS_ERROR_NOT_SUPPORTED.3: man/sd-bus-errors.3 +man/SD_BUS_ERROR_NO_MEMORY.3: man/sd-bus-errors.3 +man/SD_BUS_ERROR_NO_NETWORK.3: man/sd-bus-errors.3 +man/SD_BUS_ERROR_NO_REPLY.3: man/sd-bus-errors.3 +man/SD_BUS_ERROR_NO_SERVER.3: man/sd-bus-errors.3 +man/SD_BUS_ERROR_NULL.3: man/sd_bus_error.3 +man/SD_BUS_ERROR_PROPERTY_READ_ONLY.3: man/sd-bus-errors.3 +man/SD_BUS_ERROR_SERVICE_UNKNOWN.3: man/sd-bus-errors.3 +man/SD_BUS_ERROR_TIMEOUT.3: man/sd-bus-errors.3 +man/SD_BUS_ERROR_UNIX_PROCESS_ID_UNKNOWN.3: man/sd-bus-errors.3 +man/SD_BUS_ERROR_UNKNOWN_INTERFACE.3: man/sd-bus-errors.3 +man/SD_BUS_ERROR_UNKNOWN_METHOD.3: man/sd-bus-errors.3 +man/SD_BUS_ERROR_UNKNOWN_OBJECT.3: man/sd-bus-errors.3 +man/SD_BUS_ERROR_UNKNOWN_PROPERTY.3: man/sd-bus-errors.3 man/SD_CRIT.3: man/sd-daemon.3 man/SD_DEBUG.3: man/sd-daemon.3 man/SD_EMERG.3: man/sd-daemon.3 @@ -438,6 +513,7 @@ man/poweroff.8: man/halt.8 man/reboot.8: man/halt.8 man/sd_bus_creds_get_audit_login_uid.3: man/sd_bus_creds_get_pid.3 man/sd_bus_creds_get_audit_session_id.3: man/sd_bus_creds_get_pid.3 +man/sd_bus_creds_get_augmented_mask.3: man/sd_bus_creds_new_from_pid.3 man/sd_bus_creds_get_cgroup.3: man/sd_bus_creds_get_pid.3 man/sd_bus_creds_get_cmdline.3: man/sd_bus_creds_get_pid.3 man/sd_bus_creds_get_comm.3: man/sd_bus_creds_get_pid.3 @@ -463,6 +539,7 @@ man/sd_bus_creds_get_tty.3: man/sd_bus_creds_get_pid.3 man/sd_bus_creds_get_uid.3: man/sd_bus_creds_get_pid.3 man/sd_bus_creds_get_unique_name.3: man/sd_bus_creds_get_pid.3 man/sd_bus_creds_get_unit.3: man/sd_bus_creds_get_pid.3 +man/sd_bus_creds_get_user_slice.3: man/sd_bus_creds_get_pid.3 man/sd_bus_creds_get_user_unit.3: man/sd_bus_creds_get_pid.3 man/sd_bus_creds_get_well_known_names.3: man/sd_bus_creds_get_pid.3 man/sd_bus_creds_has_bounding_cap.3: man/sd_bus_creds_get_pid.3 @@ -478,10 +555,13 @@ man/sd_bus_error_free.3: man/sd_bus_error.3 man/sd_bus_error_get_errno.3: man/sd_bus_error.3 man/sd_bus_error_has_name.3: man/sd_bus_error.3 man/sd_bus_error_is_set.3: man/sd_bus_error.3 +man/sd_bus_error_map.3: man/sd_bus_error_add_map.3 man/sd_bus_error_set.3: man/sd_bus_error.3 man/sd_bus_error_set_const.3: man/sd_bus_error.3 man/sd_bus_error_set_errno.3: man/sd_bus_error.3 man/sd_bus_error_set_errnof.3: man/sd_bus_error.3 +man/sd_bus_error_set_errnofv.3: man/sd_bus_error.3 +man/sd_bus_error_setf.3: man/sd_bus_error.3 man/sd_bus_message_append_array_iovec.3: man/sd_bus_message_append_array.3 man/sd_bus_message_append_array_memfd.3: man/sd_bus_message_append_array.3 man/sd_bus_message_append_array_space.3: man/sd_bus_message_append_array.3 @@ -491,7 +571,7 @@ man/sd_bus_message_get_realtime_usec.3: man/sd_bus_message_get_monotonic_usec.3 man/sd_bus_message_get_reply_cookie.3: man/sd_bus_message_get_cookie.3 man/sd_bus_message_get_seqnum.3: man/sd_bus_message_get_monotonic_usec.3 man/sd_bus_negotiate_creds.3: man/sd_bus_negotiate_fds.3 -man/sd_bus_negotiate_timestamps.3: man/sd_bus_negotiate_fds.3 +man/sd_bus_negotiate_timestamp.3: man/sd_bus_negotiate_fds.3 man/sd_bus_open.3: man/sd_bus_default.3 man/sd_bus_open_system.3: man/sd_bus_default.3 man/sd_bus_open_system_machine.3: man/sd_bus_default.3 @@ -657,6 +737,108 @@ man/user.conf.d.5: man/systemd-system.conf.5 man/SD_ALERT.html: man/sd-daemon.html $(html-alias) +man/SD_BUS_ERROR_ACCESS_DENIED.html: man/sd-bus-errors.html + $(html-alias) + +man/SD_BUS_ERROR_ADDRESS_IN_USE.html: man/sd-bus-errors.html + $(html-alias) + +man/SD_BUS_ERROR_AUTH_FAILED.html: man/sd-bus-errors.html + $(html-alias) + +man/SD_BUS_ERROR_BAD_ADDRESS.html: man/sd-bus-errors.html + $(html-alias) + +man/SD_BUS_ERROR_DISCONNECTED.html: man/sd-bus-errors.html + $(html-alias) + +man/SD_BUS_ERROR_END.html: man/sd_bus_error_add_map.html + $(html-alias) + +man/SD_BUS_ERROR_FAILED.html: man/sd-bus-errors.html + $(html-alias) + +man/SD_BUS_ERROR_FILE_EXISTS.html: man/sd-bus-errors.html + $(html-alias) + +man/SD_BUS_ERROR_FILE_NOT_FOUND.html: man/sd-bus-errors.html + $(html-alias) + +man/SD_BUS_ERROR_INCONSISTENT_MESSAGE.html: man/sd-bus-errors.html + $(html-alias) + +man/SD_BUS_ERROR_INTERACTIVE_AUTHORIZATION_REQUIRED.html: man/sd-bus-errors.html + $(html-alias) + +man/SD_BUS_ERROR_INVALID_ARGS.html: man/sd-bus-errors.html + $(html-alias) + +man/SD_BUS_ERROR_INVALID_SIGNATURE.html: man/sd-bus-errors.html + $(html-alias) + +man/SD_BUS_ERROR_IO_ERROR.html: man/sd-bus-errors.html + $(html-alias) + +man/SD_BUS_ERROR_LIMITS_EXCEEDED.html: man/sd-bus-errors.html + $(html-alias) + +man/SD_BUS_ERROR_MAKE_CONST.html: man/sd_bus_error.html + $(html-alias) + +man/SD_BUS_ERROR_MAP.html: man/sd_bus_error_add_map.html + $(html-alias) + +man/SD_BUS_ERROR_MATCH_RULE_INVALID.html: man/sd-bus-errors.html + $(html-alias) + +man/SD_BUS_ERROR_MATCH_RULE_NOT_FOUND.html: man/sd-bus-errors.html + $(html-alias) + +man/SD_BUS_ERROR_NAME_HAS_NO_OWNER.html: man/sd-bus-errors.html + $(html-alias) + +man/SD_BUS_ERROR_NOT_SUPPORTED.html: man/sd-bus-errors.html + $(html-alias) + +man/SD_BUS_ERROR_NO_MEMORY.html: man/sd-bus-errors.html + $(html-alias) + +man/SD_BUS_ERROR_NO_NETWORK.html: man/sd-bus-errors.html + $(html-alias) + +man/SD_BUS_ERROR_NO_REPLY.html: man/sd-bus-errors.html + $(html-alias) + +man/SD_BUS_ERROR_NO_SERVER.html: man/sd-bus-errors.html + $(html-alias) + +man/SD_BUS_ERROR_NULL.html: man/sd_bus_error.html + $(html-alias) + +man/SD_BUS_ERROR_PROPERTY_READ_ONLY.html: man/sd-bus-errors.html + $(html-alias) + +man/SD_BUS_ERROR_SERVICE_UNKNOWN.html: man/sd-bus-errors.html + $(html-alias) + +man/SD_BUS_ERROR_TIMEOUT.html: man/sd-bus-errors.html + $(html-alias) + +man/SD_BUS_ERROR_UNIX_PROCESS_ID_UNKNOWN.html: man/sd-bus-errors.html + $(html-alias) + +man/SD_BUS_ERROR_UNKNOWN_INTERFACE.html: man/sd-bus-errors.html + $(html-alias) + +man/SD_BUS_ERROR_UNKNOWN_METHOD.html: man/sd-bus-errors.html + $(html-alias) + +man/SD_BUS_ERROR_UNKNOWN_OBJECT.html: man/sd-bus-errors.html + $(html-alias) + +man/SD_BUS_ERROR_UNKNOWN_PROPERTY.html: man/sd-bus-errors.html + $(html-alias) + man/SD_CRIT.html: man/sd-daemon.html $(html-alias) @@ -747,6 +929,9 @@ man/sd_bus_creds_get_audit_login_uid.html: man/sd_bus_creds_get_pid.html man/sd_bus_creds_get_audit_session_id.html: man/sd_bus_creds_get_pid.html $(html-alias) +man/sd_bus_creds_get_augmented_mask.html: man/sd_bus_creds_new_from_pid.html + $(html-alias) + man/sd_bus_creds_get_cgroup.html: man/sd_bus_creds_get_pid.html $(html-alias) @@ -822,6 +1007,9 @@ man/sd_bus_creds_get_unique_name.html: man/sd_bus_creds_get_pid.html man/sd_bus_creds_get_unit.html: man/sd_bus_creds_get_pid.html $(html-alias) +man/sd_bus_creds_get_user_slice.html: man/sd_bus_creds_get_pid.html + $(html-alias) + man/sd_bus_creds_get_user_unit.html: man/sd_bus_creds_get_pid.html $(html-alias) @@ -867,6 +1055,9 @@ man/sd_bus_error_has_name.html: man/sd_bus_error.html man/sd_bus_error_is_set.html: man/sd_bus_error.html $(html-alias) +man/sd_bus_error_map.html: man/sd_bus_error_add_map.html + $(html-alias) + man/sd_bus_error_set.html: man/sd_bus_error.html $(html-alias) @@ -879,6 +1070,12 @@ man/sd_bus_error_set_errno.html: man/sd_bus_error.html man/sd_bus_error_set_errnof.html: man/sd_bus_error.html $(html-alias) +man/sd_bus_error_set_errnofv.html: man/sd_bus_error.html + $(html-alias) + +man/sd_bus_error_setf.html: man/sd_bus_error.html + $(html-alias) + man/sd_bus_message_append_array_iovec.html: man/sd_bus_message_append_array.html $(html-alias) @@ -906,7 +1103,7 @@ man/sd_bus_message_get_seqnum.html: man/sd_bus_message_get_monotonic_usec.html man/sd_bus_negotiate_creds.html: man/sd_bus_negotiate_fds.html $(html-alias) -man/sd_bus_negotiate_timestamps.html: man/sd_bus_negotiate_fds.html +man/sd_bus_negotiate_timestamp.html: man/sd_bus_negotiate_fds.html $(html-alias) man/sd_bus_open.html: man/sd_bus_default.html @@ -1740,11 +1937,13 @@ MANPAGES_ALIAS += \ man/sd_peer_get_session.3 \ man/sd_peer_get_slice.3 \ man/sd_peer_get_unit.3 \ + man/sd_peer_get_user_slice.3 \ man/sd_peer_get_user_unit.3 \ man/sd_pid_get_machine_name.3 \ man/sd_pid_get_owner_uid.3 \ man/sd_pid_get_slice.3 \ man/sd_pid_get_unit.3 \ + man/sd_pid_get_user_slice.3 \ man/sd_pid_get_user_unit.3 \ man/sd_seat_can_graphical.3 \ man/sd_seat_can_multi_session.3 \ @@ -1782,11 +1981,13 @@ man/sd_peer_get_owner_uid.3: man/sd_pid_get_session.3 man/sd_peer_get_session.3: man/sd_pid_get_session.3 man/sd_peer_get_slice.3: man/sd_pid_get_session.3 man/sd_peer_get_unit.3: man/sd_pid_get_session.3 +man/sd_peer_get_user_slice.3: man/sd_pid_get_session.3 man/sd_peer_get_user_unit.3: man/sd_pid_get_session.3 man/sd_pid_get_machine_name.3: man/sd_pid_get_session.3 man/sd_pid_get_owner_uid.3: man/sd_pid_get_session.3 man/sd_pid_get_slice.3: man/sd_pid_get_session.3 man/sd_pid_get_unit.3: man/sd_pid_get_session.3 +man/sd_pid_get_user_slice.3: man/sd_pid_get_session.3 man/sd_pid_get_user_unit.3: man/sd_pid_get_session.3 man/sd_seat_can_graphical.3: man/sd_seat_get_active.3 man/sd_seat_can_multi_session.3: man/sd_seat_get_active.3 @@ -1852,6 +2053,9 @@ man/sd_peer_get_slice.html: man/sd_pid_get_session.html man/sd_peer_get_unit.html: man/sd_pid_get_session.html $(html-alias) +man/sd_peer_get_user_slice.html: man/sd_pid_get_session.html + $(html-alias) + man/sd_peer_get_user_unit.html: man/sd_pid_get_session.html $(html-alias) @@ -1867,6 +2071,9 @@ man/sd_pid_get_slice.html: man/sd_pid_get_session.html man/sd_pid_get_unit.html: man/sd_pid_get_session.html $(html-alias) +man/sd_pid_get_user_slice.html: man/sd_pid_get_session.html + $(html-alias) + man/sd_pid_get_user_unit.html: man/sd_pid_get_session.html $(html-alias) @@ -2015,6 +2222,7 @@ EXTRA_DIST += \ man/pam_systemd.xml \ man/resolved.conf.xml \ man/runlevel.xml \ + man/sd-bus-errors.xml \ man/sd-daemon.xml \ man/sd-id128.xml \ man/sd-journal.xml \ @@ -2024,6 +2232,7 @@ EXTRA_DIST += \ man/sd_bus_creds_new_from_pid.xml \ man/sd_bus_default.xml \ man/sd_bus_error.xml \ + man/sd_bus_error_add_map.xml \ man/sd_bus_message_append.xml \ man/sd_bus_message_append_array.xml \ man/sd_bus_message_append_basic.xml \ diff --git a/Makefile.am b/Makefile.am index 19a3706b18..df27088477 100644 --- a/Makefile.am +++ b/Makefile.am @@ -647,7 +647,9 @@ dist_doc_DATA = \ DISTRO_PORTING \ src/libsystemd/sd-bus/PORTING-DBUS1 \ src/libsystemd/sd-bus/DIFFERENCES \ - src/libsystemd/sd-bus/GVARIANT-SERIALIZATION \ + src/libsystemd/sd-bus/GVARIANT-SERIALIZATION + +EXTRA_DIST += \ autogen.sh \ .dir-locals.el \ .vimrc \ @@ -5621,164 +5623,6 @@ EXTRA_DIST += \ test/loopy.service.d/compat.conf # ------------------------------------------------------------------------------ -if HAVE_PYTHON_DEVEL -pkgpyexec_LTLIBRARIES = \ - _journal.la \ - id128.la \ - _daemon.la \ - _reader.la \ - login.la - -_journal_la_SOURCES = \ - src/python-systemd/_journal.c - -_journal_la_CFLAGS = \ - $(AM_CFLAGS) \ - -fvisibility=default \ - $(PYTHON_DEVEL_CFLAGS) - -_journal_la_LDFLAGS = \ - $(AM_LDFLAGS) \ - -shared \ - -module \ - -avoid-version - -_journal_la_LIBADD = \ - $(PYTHON_DEVEL_LIBS) \ - libsystemd.la - -id128_la_SOURCES = \ - src/python-systemd/id128.c \ - src/python-systemd/pyutil.c \ - src/python-systemd/pyutil.h - -nodist_id128_la_SOURCES = \ - src/python-systemd/id128-constants.h - -id128_la_CFLAGS = \ - $(AM_CFLAGS) \ - -fvisibility=default \ - $(PYTHON_DEVEL_CFLAGS) \ - -I$(top_builddir)/src/python-systemd - -id128_la_LDFLAGS = \ - $(AM_LDFLAGS) \ - -shared \ - -module \ - -avoid-version - -id128_la_LIBADD = \ - $(PYTHON_DEVEL_LIBS) \ - libshared.la \ - libsystemd.la - -_daemon_la_SOURCES = \ - src/python-systemd/_daemon.c \ - src/python-systemd/pyutil.c \ - src/python-systemd/pyutil.h - -_daemon_la_CFLAGS = \ - $(AM_CFLAGS) \ - -fvisibility=default \ - $(PYTHON_DEVEL_CFLAGS) \ - -I$(top_builddir)/src/python-systemd - -_daemon_la_LDFLAGS = \ - $(AM_LDFLAGS) \ - -shared \ - -module \ - -avoid-version - -_daemon_la_LIBADD = \ - $(PYTHON_DEVEL_LIBS) \ - libshared.la \ - libsystemd.la - -_reader_la_SOURCES = \ - src/python-systemd/_reader.c \ - src/python-systemd/pyutil.c \ - src/python-systemd/pyutil.h - -_reader_la_CFLAGS = \ - $(AM_CFLAGS) \ - -fvisibility=default \ - $(PYTHON_DEVEL_CFLAGS) - -_reader_la_LDFLAGS = \ - $(AM_LDFLAGS) \ - -shared \ - -module \ - -avoid-version - -_reader_la_LIBADD = \ - $(PYTHON_DEVEL_LIBS) \ - libshared.la \ - libsystemd.la - -login_la_SOURCES = \ - src/python-systemd/login.c \ - src/python-systemd/pyutil.c \ - src/python-systemd/pyutil.h - -login_la_CFLAGS = \ - $(AM_CFLAGS) \ - -fvisibility=default \ - $(PYTHON_DEVEL_CFLAGS) - -login_la_LDFLAGS = \ - $(AM_LDFLAGS) \ - -shared \ - -module \ - -avoid-version - -login_la_LIBADD = \ - $(PYTHON_DEVEL_LIBS) \ - libshared.la \ - libsystemd.la - -dist_pkgpyexec_PYTHON = \ - src/python-systemd/journal.py \ - src/python-systemd/daemon.py \ - src/python-systemd/__init__.py - -src/python-systemd/id128-constants.h: src/systemd/sd-messages.h - $(AM_V_at)$(MKDIR_P) $(dir $@) - $(AM_V_GEN)$(SED) -n -r 's/,//g; s/#define (SD_MESSAGE_[A-Z0-9_]+)\s.*/add_id(m, "\1", \1) JOINER/p' <$< >$@ - -BUILT_SOURCES += \ - $(nodist_id128_la_SOURCES) - -SPHINXOPTS = -D version=$(VERSION) -D release=$(VERSION) -sphinx-%: - $(AM_V_at)test -n "$(SPHINX_BUILD)" || { echo " *** sphinx-build is not available"; exit 1; } - $(AM_V_GEN)PYTHONPATH=$(DESTDIR)$(pyexecdir) LD_LIBRARY_PATH=$(DESTDIR)$(libdir) $(SPHINX_BUILD) -b $* $(SPHINXOPTS) $(top_srcdir)/src/python-systemd/docs $(top_builddir)/docs/html/python-systemd/ - $(AM_V_at)echo Output has been generated in $(abs_top_builddir)/docs/html/python-systemd/ - -python-shell: - $(AM_V_at)echo "Starting python with $(DESTDIR)$(pyexecdir)" - $(AM_V_at)PYTHONPATH=$(DESTDIR)$(pyexecdir) LD_LIBRARY_PATH=$(DESTDIR)$(libdir) $(PYTHON) - -destdir-sphinx: all - dir="$$(mktemp -d /tmp/systemd-install.XXXXXX)" && \ - $(MAKE) DESTDIR="$$dir" install && \ - $(MAKE) DESTDIR="$$dir" sphinx-html && \ - rm -rf "$$dir" - -endif - -CLEAN_LOCAL_HOOKS += clean-sphinx - -.PHONY: python-shell destdir-sphinx clean-sphinx clean-python - -clean-sphinx: - -rm -rf docs/html/python-systemd/ - -# Remove Python stuff, e.g. to force rebuilding for a different Python version. -clean-python: - -rm -rf src/python-systemd/.libs src/python-systemd/*.l[ao] - -rm -f _daemon.la id128.la _journal.la login.la _reader.la - -# ------------------------------------------------------------------------------ if ENABLE_COMPAT_LIBS libsystemd-%.c: src/compat-libs/libsystemd-%.sym $(AM_V_at)$(MKDIR_P) $(dir $@) @@ -5950,7 +5794,6 @@ substitutions = \ '|RC_LOCAL_SCRIPT_PATH_START=$(RC_LOCAL_SCRIPT_PATH_START)|' \ '|RC_LOCAL_SCRIPT_PATH_STOP=$(RC_LOCAL_SCRIPT_PATH_STOP)|' \ '|PYTHON=$(PYTHON)|' \ - '|PYTHON_BINARY=$(PYTHON_BINARY)|' \ '|NTP_SERVERS=$(NTP_SERVERS)|' \ '|DNS_SERVERS=$(DNS_SERVERS)|' \ '|systemuidmax=$(SYSTEM_UID_MAX)|' \ @@ -6251,11 +6094,6 @@ DISTCHECK_CONFIGURE_FLAGS += \ --with-sysvrcnd-path= endif -if HAVE_PYTHON -DISTCHECK_CONFIGURE_FLAGS += \ - --with-python -endif - if ENABLE_SPLIT_USR DISTCHECK_CONFIGURE_FLAGS += \ --enable-split-usr @@ -6312,7 +6150,6 @@ www_target = www.freedesktop.org:/srv/www.freedesktop.org/www/software/systemd .PHONY: doc-sync doc-sync: all destdir-sphinx rsync -rlv --delete-excluded --include="*.html" --exclude="*" --omit-dir-times man/ $(www_target)/man/ - rsync -rlv --delete --omit-dir-times docs/html/python-systemd/ $(www_target)/python-systemd/ .PHONY: gardel gardel: upload @@ -19,6 +19,14 @@ CHANGES WITH 222: which enables IPv6 privacy extensions (RFC 4941, "Privacy Extensions for Stateless Address") on selected networks. + * For the sake of fewer build-time dependencies and less code in the + main repository, the python bindings are about to be removed in the + next release. A new repository has been created which accommodates + the code from now on, and we kindly ask distributions to create a + separate package for this. The removal will take place in v223. + + https://github.com/systemd/python-systemd + Contributions from: Abdo Roig-Maranges, Andrew Eikum, Bastien Nocera, Cédric Delmas, Christian Hesse, Christos Trochalakis, Daniel Mack, daurnimator, David Herrmann, Dimitri John Ledkov, Eric Biggers, Eric @@ -27,10 +35,10 @@ CHANGES WITH 222: (heftig), Jan Engelhardt, Jay Strict, Kay Sievers, Lennart Poettering, Markus Knetschke, Martin Pitt, Michael Biebl, Michael Marineau, Michal Sekletar, Miguel Bernal Marin, Peter Hutterer, Richard Maw, rinrinne, - Susant Sahani, Tom Gundersen, Torstein Husebø, Vedran Miletić, WaLyong - Cho, Zbigniew Jędrzejewski-Szmek + Susant Sahani, Thomas Hindoe Paaboel Andersen, Tom Gundersen, Torstein + Husebø, Vedran Miletić, WaLyong Cho, Zbigniew Jędrzejewski-Szmek - -- Berlin, 2015-07-06 + -- Berlin, 2015-07-07 CHANGES WITH 221: diff --git a/configure.ac b/configure.ac index 88b52c45fe..6804e03d07 100644 --- a/configure.ac +++ b/configure.ac @@ -20,7 +20,7 @@ AC_PREREQ([2.64]) AC_INIT([systemd], - [221], + [222], [http://github.com/systemd/systemd/issues], [systemd], [http://www.freedesktop.org/wiki/Software/systemd]) @@ -238,7 +238,7 @@ AC_CHECK_SIZEOF(rlim_t,,[ ]) # ------------------------------------------------------------------------------ -# we use python to build the man page index, and for systemd-python +# we use python to build the man page index have_python=no AC_ARG_WITH([python], [AS_HELP_STRING([--without-python], [Disable building the man page index and systemd-python (default: test)])]) @@ -260,30 +260,7 @@ AS_IF([test "$have_python" != "yes"], [ AS_IF([test "$with_python" != "no"], [AC_MSG_WARN([*** python support not found, some documentation cannot be built])]) ]) - AM_CONDITIONAL([HAVE_PYTHON], [test "x$have_python" = "xyes"]) -AS_IF([test "x$PYTHON_BINARY" = "x"], - [AS_IF([test "x$have_python" = "xyes"], - [PYTHON_BINARY="$(which "$PYTHON")"], - [PYTHON_BINARY=/usr/bin/python])]) -AC_ARG_VAR(PYTHON_BINARY, [Python binary used to launch installed scripts]) - -AS_IF([test "x$have_python" != "xyes" -a "x$enable_python_devel" = "xyes"], - [AC_MSG_ERROR([*** python-devel support requires --with-python])]) - -have_python_devel=no -AC_ARG_ENABLE(python_devel, AS_HELP_STRING([--disable-python-devel], [Do not build python modules])) -AS_IF([test "x$have_python" = "xyes" -a "x$enable_python_devel" != "xno"], [ - PKG_CHECK_MODULES([PYTHON_DEVEL], [python-${PYTHON_VERSION}], - [have_python_devel=yes], - [PKG_CHECK_MODULES([PYTHON_DEVEL], [python], - [have_python_devel=yes], - [have_python_devel=no])]) - AS_IF([test "x$have_python_devel" = xno -a "x$enable_python_devel" = xyes], - [AC_MSG_ERROR([*** python-devel support requested but libraries not found])]) - AC_PATH_PROGS(SPHINX_BUILD, sphinx-build-${PYTHON_VERSION} sphinx-build) -]) -AM_CONDITIONAL([HAVE_PYTHON_DEVEL], [test "$have_python_devel" = "yes"]) # ------------------------------------------------------------------------------ @@ -1566,7 +1543,6 @@ AC_MSG_RESULT([ terminal: ${have_terminal} kdbus: ${have_kdbus} Python: ${have_python} - Python Headers: ${have_python_devel} man pages: ${have_manpages} test coverage: ${have_coverage} Split /usr: ${enable_split_usr} @@ -1587,7 +1563,6 @@ AC_MSG_RESULT([ SysV init scripts: ${SYSTEM_SYSVINIT_PATH} SysV rc?.d directories: ${SYSTEM_SYSVRCND_PATH} Build Python: ${PYTHON} - Installation Python: ${PYTHON_BINARY} sphinx binary: ${SPHINX_BUILD} PAM modules dir: ${with_pamlibdir} PAM configuration dir: ${with_pamconfdir} @@ -1608,6 +1583,4 @@ AC_MSG_RESULT([ CFLAGS: ${OUR_CFLAGS} ${CFLAGS} CPPFLAGS: ${OUR_CPPFLAGS} ${CPPFLAGS} LDFLAGS: ${OUR_LDFLAGS} ${LDFLAGS} - PYTHON_CFLAGS: ${PYTHON_DEVEL_CFLAGS} - PYTHON_LIBS: ${PYTHON_DEVEL_LIBS} ]) diff --git a/hwdb/20-bluetooth-vendor-product.hwdb b/hwdb/20-bluetooth-vendor-product.hwdb index b737e6b308..dccced77da 100644 --- a/hwdb/20-bluetooth-vendor-product.hwdb +++ b/hwdb/20-bluetooth-vendor-product.hwdb @@ -1706,3 +1706,69 @@ bluetooth:v0235* bluetooth:v0236* ID_VENDOR_FROM_DATABASE=Pitpatpet Ltd + +bluetooth:v0237* + ID_VENDOR_FROM_DATABASE=MSHeli s.r.l. + +bluetooth:v0238* + ID_VENDOR_FROM_DATABASE=Trakm8 Ltd + +bluetooth:v0239* + ID_VENDOR_FROM_DATABASE=JIN CO, Ltd + +bluetooth:v023A* + ID_VENDOR_FROM_DATABASE=Alatech Technology + +bluetooth:v023B* + ID_VENDOR_FROM_DATABASE=Beijing CarePulse Electronic Technology Co, Ltd + +bluetooth:v023C* + ID_VENDOR_FROM_DATABASE=Awarepoint + +bluetooth:v023D* + ID_VENDOR_FROM_DATABASE=ViCentra B.V. + +bluetooth:v023E* + ID_VENDOR_FROM_DATABASE=Raven Industries + +bluetooth:v023F* + ID_VENDOR_FROM_DATABASE=WaveWare Technologies + +bluetooth:v0240* + ID_VENDOR_FROM_DATABASE=Argenox Technologies + +bluetooth:v0241* + ID_VENDOR_FROM_DATABASE=Bragi GmbH + +bluetooth:v0242* + ID_VENDOR_FROM_DATABASE=16Lab Inc + +bluetooth:v0243* + ID_VENDOR_FROM_DATABASE=Masimo Corp + +bluetooth:v0244* + ID_VENDOR_FROM_DATABASE=Iotera Inc. + +bluetooth:v0245* + ID_VENDOR_FROM_DATABASE=Endress+Hauser + +bluetooth:v0246* + ID_VENDOR_FROM_DATABASE=ACKme Networks, Inc. + +bluetooth:v0247* + ID_VENDOR_FROM_DATABASE=FiftyThree Inc. + +bluetooth:v0248* + ID_VENDOR_FROM_DATABASE=Parker Hannifin Corp + +bluetooth:v0249* + ID_VENDOR_FROM_DATABASE=Transcranial Ltd + +bluetooth:v024A* + ID_VENDOR_FROM_DATABASE=Uwatec AG + +bluetooth:v024B* + ID_VENDOR_FROM_DATABASE=Orlan LLC + +bluetooth:v024C* + ID_VENDOR_FROM_DATABASE=Blue Clover Devices diff --git a/man/custom-html.xsl b/man/custom-html.xsl index b298c216b1..2df12411c7 100644 --- a/man/custom-html.xsl +++ b/man/custom-html.xsl @@ -225,12 +225,6 @@ <xsl:text>systemd.directives.html</xsl:text> </xsl:attribute> <xsl:text>Directives </xsl:text> - </a>· - <a> - <xsl:attribute name="href"> - <xsl:text>../python-systemd/index.html</xsl:text> - </xsl:attribute> - <xsl:text>Python </xsl:text> </a> <span style="float:right"> diff --git a/man/sd-bus-errors.xml b/man/sd-bus-errors.xml new file mode 100644 index 0000000000..d6bbd7fbb2 --- /dev/null +++ b/man/sd-bus-errors.xml @@ -0,0 +1,309 @@ +<?xml version='1.0'?> <!--*- Mode: nxml; nxml-child-indent: 2; indent-tabs-mode: nil -*--> +<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" +"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> + +<!-- + This file is part of systemd. + + Copyright 2015 Lennart Poettering + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see <http://www.gnu.org/licenses/>. +--> + +<refentry id="sd-bus-errors"> + + <refentryinfo> + <title>sd-bus-errors</title> + <productname>systemd</productname> + + <authorgroup> + <author> + <contrib>Developer</contrib> + <firstname>Lennart</firstname> + <surname>Poettering</surname> + <email>lennart@poettering.net</email> + </author> + </authorgroup> + </refentryinfo> + + <refmeta> + <refentrytitle>sd-bus-errors</refentrytitle> + <manvolnum>3</manvolnum> + </refmeta> + + <refnamediv> + <refname>sd-bus-errors</refname> + <refname>SD_BUS_ERROR_FAILED</refname> + <refname>SD_BUS_ERROR_NO_MEMORY</refname> + <refname>SD_BUS_ERROR_SERVICE_UNKNOWN</refname> + <refname>SD_BUS_ERROR_NAME_HAS_NO_OWNER</refname> + <refname>SD_BUS_ERROR_NO_REPLY</refname> + <refname>SD_BUS_ERROR_IO_ERROR</refname> + <refname>SD_BUS_ERROR_BAD_ADDRESS</refname> + <refname>SD_BUS_ERROR_NOT_SUPPORTED</refname> + <refname>SD_BUS_ERROR_LIMITS_EXCEEDED</refname> + <refname>SD_BUS_ERROR_ACCESS_DENIED</refname> + <refname>SD_BUS_ERROR_AUTH_FAILED</refname> + <refname>SD_BUS_ERROR_NO_SERVER</refname> + <refname>SD_BUS_ERROR_TIMEOUT</refname> + <refname>SD_BUS_ERROR_NO_NETWORK</refname> + <refname>SD_BUS_ERROR_ADDRESS_IN_USE</refname> + <refname>SD_BUS_ERROR_DISCONNECTED</refname> + <refname>SD_BUS_ERROR_INVALID_ARGS</refname> + <refname>SD_BUS_ERROR_FILE_NOT_FOUND</refname> + <refname>SD_BUS_ERROR_FILE_EXISTS</refname> + <refname>SD_BUS_ERROR_UNKNOWN_METHOD</refname> + <refname>SD_BUS_ERROR_UNKNOWN_OBJECT</refname> + <refname>SD_BUS_ERROR_UNKNOWN_INTERFACE</refname> + <refname>SD_BUS_ERROR_UNKNOWN_PROPERTY</refname> + <refname>SD_BUS_ERROR_PROPERTY_READ_ONLY</refname> + <refname>SD_BUS_ERROR_UNIX_PROCESS_ID_UNKNOWN</refname> + <refname>SD_BUS_ERROR_INVALID_SIGNATURE</refname> + <refname>SD_BUS_ERROR_INCONSISTENT_MESSAGE</refname> + <refname>SD_BUS_ERROR_MATCH_RULE_NOT_FOUND</refname> + <refname>SD_BUS_ERROR_MATCH_RULE_INVALID</refname> + <refname>SD_BUS_ERROR_INTERACTIVE_AUTHORIZATION_REQUIRED</refname> + + <refpurpose>Standard D-Bus error names</refpurpose> + </refnamediv> + + <refsynopsisdiv> + <funcsynopsis> + <funcsynopsisinfo>#include <systemd/sd-bus.h></funcsynopsisinfo> + +<funcsynopsisinfo>#define SD_BUS_ERROR_FAILED "org.freedesktop.DBus.Error.Failed" +#define SD_BUS_ERROR_NO_MEMORY "org.freedesktop.DBus.Error.NoMemory" +#define SD_BUS_ERROR_SERVICE_UNKNOWN "org.freedesktop.DBus.Error.ServiceUnknown" +#define SD_BUS_ERROR_NAME_HAS_NO_OWNER "org.freedesktop.DBus.Error.NameHasNoOwner" +#define SD_BUS_ERROR_NO_REPLY "org.freedesktop.DBus.Error.NoReply" +#define SD_BUS_ERROR_IO_ERROR "org.freedesktop.DBus.Error.IOError" +#define SD_BUS_ERROR_BAD_ADDRESS "org.freedesktop.DBus.Error.BadAddress" +#define SD_BUS_ERROR_NOT_SUPPORTED "org.freedesktop.DBus.Error.NotSupported" +#define SD_BUS_ERROR_LIMITS_EXCEEDED "org.freedesktop.DBus.Error.LimitsExceeded" +#define SD_BUS_ERROR_ACCESS_DENIED "org.freedesktop.DBus.Error.AccessDenied" +#define SD_BUS_ERROR_AUTH_FAILED "org.freedesktop.DBus.Error.AuthFailed" +#define SD_BUS_ERROR_NO_SERVER "org.freedesktop.DBus.Error.NoServer" +#define SD_BUS_ERROR_TIMEOUT "org.freedesktop.DBus.Error.Timeout" +#define SD_BUS_ERROR_NO_NETWORK "org.freedesktop.DBus.Error.NoNetwork" +#define SD_BUS_ERROR_ADDRESS_IN_USE "org.freedesktop.DBus.Error.AddressInUse" +#define SD_BUS_ERROR_DISCONNECTED "org.freedesktop.DBus.Error.Disconnected" +#define SD_BUS_ERROR_INVALID_ARGS "org.freedesktop.DBus.Error.InvalidArgs" +#define SD_BUS_ERROR_FILE_NOT_FOUND "org.freedesktop.DBus.Error.FileNotFound" +#define SD_BUS_ERROR_FILE_EXISTS "org.freedesktop.DBus.Error.FileExists" +#define SD_BUS_ERROR_UNKNOWN_METHOD "org.freedesktop.DBus.Error.UnknownMethod" +#define SD_BUS_ERROR_UNKNOWN_OBJECT "org.freedesktop.DBus.Error.UnknownObject" +#define SD_BUS_ERROR_UNKNOWN_INTERFACE "org.freedesktop.DBus.Error.UnknownInterface" +#define SD_BUS_ERROR_UNKNOWN_PROPERTY "org.freedesktop.DBus.Error.UnknownProperty" +#define SD_BUS_ERROR_PROPERTY_READ_ONLY "org.freedesktop.DBus.Error.PropertyReadOnly" +#define SD_BUS_ERROR_UNIX_PROCESS_ID_UNKNOWN "org.freedesktop.DBus.Error.UnixProcessIdUnknown" +#define SD_BUS_ERROR_INVALID_SIGNATURE "org.freedesktop.DBus.Error.InvalidSignature" +#define SD_BUS_ERROR_INCONSISTENT_MESSAGE "org.freedesktop.DBus.Error.InconsistentMessage" +#define SD_BUS_ERROR_MATCH_RULE_NOT_FOUND "org.freedesktop.DBus.Error.MatchRuleNotFound" +#define SD_BUS_ERROR_MATCH_RULE_INVALID "org.freedesktop.DBus.Error.MatchRuleInvalid" +#define SD_BUS_ERROR_INTERACTIVE_AUTHORIZATION_REQUIRED \ + "org.freedesktop.DBus.Error.InteractiveAuthorizationRequired"</funcsynopsisinfo> + + </funcsynopsis> + </refsynopsisdiv> + + <refsect1> + <title>Description</title> + + <para>In addition to the error names user programs define, D-Bus + knows a number of generic, standardized error names, that are + listed below.</para> + + <para>In addition to this list, in sd-bus the special error + namespace <literal>System.Error.</literal> is used to map + arbitrary Linux system errors (as defined by <citerefentry + project='man-pages'><refentrytitle>errno</refentrytitle><manvolnum>3</manvolnum></citerefentry>) + to D-Bus errors and back. For example, the error + <constant>EUCLEAN</constant> is mapped to + <literal>System.Error.EUCLEAN</literal> and back.</para> + + <variablelist> + + <varlistentry> + <term><varname>SD_BUS_ERROR_FAILED</varname></term> + <listitem><para>A generic error indication. See the error + message for further details. This error name should be + avoided, in favour of a more expressive error + name.</para></listitem> + </varlistentry> + + <varlistentry> + <term><varname>SD_BUS_ERROR_NO_MEMORY</varname></term> + <listitem><para>A memory allocation failed, and the requested + operation could not be completed.</para></listitem> + </varlistentry> + + <varlistentry> + <term><varname>SD_BUS_ERROR_SERVICE_UNKNOWN</varname></term> + <listitem><para>The contacted bus service is unknown and + cannot be activated.</para></listitem> + </varlistentry> + + <varlistentry> + <term><varname>SD_BUS_ERROR_NAME_HAS_NO_OWNER</varname></term> + <listitem><para>The specified bus service name currently has + no owner.</para></listitem> + </varlistentry> + <varlistentry> + <term><varname>SD_BUS_ERROR_NO_REPLY</varname></term> + <listitem><para>A message did not receive a reply. This error + is usually generated after a timeout.</para></listitem> + </varlistentry> + <varlistentry> + <term><varname>SD_BUS_ERROR_IO_ERROR</varname></term> + <listitem><para>Generic input/output error, for example when + accessing a socket or other IO context.</para></listitem> + </varlistentry> + <varlistentry> + <term><varname>SD_BUS_ERROR_BAD_ADDRESS</varname></term> + <listitem><para>The specified D-Bus bus address string is + malformed.</para></listitem> + </varlistentry> + <varlistentry> + <term><varname>SD_BUS_ERROR_NOT_SUPPORTED</varname></term> + <listitem><para>The requested operation is not supported on + the local system.</para></listitem> + </varlistentry> + <varlistentry> + <term><varname>SD_BUS_ERROR_LIMITS_EXCEEDED</varname></term> + <listitem><para>Some limited resource has been + exhausted.</para></listitem> + </varlistentry> + <varlistentry> + <term><varname>SD_BUS_ERROR_ACCESS_DENIED</varname></term> + <listitem><para>Access to a resource has bee denied, due to security restrictions.</para></listitem> + </varlistentry> + <varlistentry> + <term><varname>SD_BUS_ERROR_AUTH_FAILED</varname></term> + <listitem><para>Authentication did not complete successfully.</para></listitem> + </varlistentry> + <varlistentry> + <term><varname>SD_BUS_ERROR_NO_SERVER</varname></term> + <listitem><para>Unable to connect to the specified server.</para></listitem> + </varlistentry> + <varlistentry> + <term><varname>SD_BUS_ERROR_TIMEOUT</varname></term> + <listitem><para>An operation timed out. Note that method calls + which timeout generate a + <varname>SD_BUS_ERROR_NO_REPLY</varname>.</para></listitem> + </varlistentry> + <varlistentry> + <term><varname>SD_BUS_ERROR_NO_NETWORK</varname></term> + <listitem><para>No network available to execute requested network operation on.</para></listitem> + </varlistentry> + <varlistentry> + <term><varname>SD_BUS_ERROR_ADDRESS_IN_USE</varname></term> + <listitem><para>The specified network address is already being listened on.</para></listitem> + </varlistentry> + <varlistentry> + <term><varname>SD_BUS_ERROR_DISCONNECTED</varname></term> + <listitem><para>The connection has been terminated.</para></listitem> + </varlistentry> + <varlistentry> + <term><varname>SD_BUS_ERROR_INVALID_ARGS</varname></term> + <listitem><para>One or more invalid arguments have been passed.</para></listitem> + </varlistentry> + <varlistentry> + <term><varname>SD_BUS_ERROR_FILE_NOT_FOUND</varname></term> + <listitem><para>The requested file could not be found.</para></listitem> + </varlistentry> + <varlistentry> + <term><varname>SD_BUS_ERROR_FILE_EXISTS</varname></term> + <listitem><para>The requested file exists already.</para></listitem> + </varlistentry> + <varlistentry> + <term><varname>SD_BUS_ERROR_UNKNOWN_METHOD</varname></term> + <listitem><para>The requested method does not exist in the selected interface.</para></listitem> + </varlistentry> + <varlistentry> + <term><varname>SD_BUS_ERROR_UNKNOWN_OBJECT</varname></term> + <listitem><para>The requested object does not exist in the selected service.</para></listitem> + </varlistentry> + <varlistentry> + <term><varname>SD_BUS_ERROR_UNKNOWN_INTERFACE</varname></term> + <listitem><para>The requested interface does not exist on the selected object.</para></listitem> + </varlistentry> + <varlistentry> + <term><varname>SD_BUS_ERROR_UNKNOWN_PROPERTY</varname></term> + <listitem><para>The requested property does not exist in the selected interface.</para></listitem> + </varlistentry> + <varlistentry> + <term><varname>SD_BUS_ERROR_PROPERTY_READ_ONLY</varname></term> + <listitem><para>A write operation was requested on a read-only property.</para></listitem> + </varlistentry> + <varlistentry> + <term><varname>SD_BUS_ERROR_UNIX_PROCESS_ID_UNKNOWN</varname></term> + <listitem><para>The requested PID is not known.</para></listitem> + </varlistentry> + <varlistentry> + <term><varname>SD_BUS_ERROR_INVALID_SIGNATURE</varname></term> + <listitem><para>The specified message signature is not + valid.</para> + </listitem> + </varlistentry> + <varlistentry> + <term><varname>SD_BUS_ERROR_INCONSISTENT_MESSAGE</varname></term> + <listitem><para>The passed message does not validate + correctly.</para></listitem> + </varlistentry> + <varlistentry> + <term><varname>SD_BUS_ERROR_MATCH_RULE_NOT_FOUND</varname></term> + <listitem><para>The specified match rule does not exist.</para></listitem> + </varlistentry> + <varlistentry> + <term><varname>SD_BUS_ERROR_MATCH_RULE_INVALID</varname></term> + <listitem><para>The specified match rule is invalid.</para></listitem> + </varlistentry> + <varlistentry> + <term><varname>SD_BUS_ERROR_INTERACTIVE_AUTHORIZATION_REQUIRED</varname></term> + <listitem><para>Access to the requested operation is not + permitted, however, it might be available after interactive + authentication. This is usually returned by method calls + supporting a framework for additional interactive + authorization, when interactive authorization was not enabled + with the + <citerefentry><refentrytitle>sd_bus_message_set_allow_interactive_authorization</refentrytitle><manvolnum>3</manvolnum></citerefentry> + for the method call message.</para></listitem> + </varlistentry> + </variablelist> + </refsect1> + + <refsect1> + <title>Notes</title> + + <para>The various error definitions described here are available + as a shared library, which can be compiled and linked to with the + <constant>libsystemd</constant> <citerefentry + project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry> + file.</para> + </refsect1> + + <refsect1> + <title>See Also</title> + + <para> + <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, + <citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>, + <citerefentry><refentrytitle>sd_bus_error</refentrytitle><manvolnum>3</manvolnum></citerefentry>, + <citerefentry><refentrytitle>sd_bus_message_set_allow_interactive_authorization</refentrytitle><manvolnum>3</manvolnum></citerefentry>, + <citerefentry project='man-pages'><refentrytitle>errno</refentrytitle><manvolnum>3</manvolnum></citerefentry>, + <citerefentry project='die-net'><refentrytitle>strerror</refentrytitle><manvolnum>3</manvolnum></citerefentry> + </para> + </refsect1> + +</refentry> diff --git a/man/sd_bus_creds_get_pid.xml b/man/sd_bus_creds_get_pid.xml index 13f885cd5d..4162fab065 100644 --- a/man/sd_bus_creds_get_pid.xml +++ b/man/sd_bus_creds_get_pid.xml @@ -61,8 +61,9 @@ <refname>sd_bus_creds_get_cmdline</refname> <refname>sd_bus_creds_get_cgroup</refname> <refname>sd_bus_creds_get_unit</refname> - <refname>sd_bus_creds_get_user_unit</refname> <refname>sd_bus_creds_get_slice</refname> + <refname>sd_bus_creds_get_user_unit</refname> + <refname>sd_bus_creds_get_user_slice</refname> <refname>sd_bus_creds_get_session</refname> <refname>sd_bus_creds_get_owner_uid</refname> <refname>sd_bus_creds_has_effective_cap</refname> @@ -193,13 +194,19 @@ </funcprototype> <funcprototype> + <funcdef>int <function>sd_bus_creds_get_slice</function></funcdef> + <paramdef>sd_bus_creds *<parameter>c</parameter></paramdef> + <paramdef>const char **<parameter>slice</parameter></paramdef> + </funcprototype> + + <funcprototype> <funcdef>int <function>sd_bus_creds_get_user_unit</function></funcdef> <paramdef>sd_bus_creds *<parameter>c</parameter></paramdef> <paramdef>const char **<parameter>unit</parameter></paramdef> </funcprototype> <funcprototype> - <funcdef>int <function>sd_bus_creds_get_slice</function></funcdef> + <funcdef>int <function>sd_bus_creds_get_user_slice</function></funcdef> <paramdef>sd_bus_creds *<parameter>c</parameter></paramdef> <paramdef>const char **<parameter>slice</parameter></paramdef> </funcprototype> @@ -288,9 +295,9 @@ <refsect1> <title>Description</title> - <para>These functions return information from an - <parameter>sd_bus_creds</parameter> credential object. Credential - objects may be created with + <para>These functions return credential information from an + <parameter>sd_bus_creds</parameter> object. Credential objects may + be created with <citerefentry><refentrytitle>sd_bus_creds_new_from_pid</refentrytitle><manvolnum>3</manvolnum></citerefentry>, in which case they describe the credentials of the process identified by the specified PID, with @@ -301,7 +308,13 @@ in which case they describe the credentials of the creator of a bus, or with <citerefentry><refentrytitle>sd_bus_message_get_creds</refentrytitle><manvolnum>3</manvolnum></citerefentry>, - in which case they describe the credentials of the sender of the message.</para> + in which case they describe the credentials of the sender of the + message.</para> + + <para>Not all credential fields are part of every + <literal>sd_bus_creds</literal> object. Use + <citerefentry><refentrytitle>sd_bus_creds_get_mask</refentrytitle><manvolnum>3</manvolnum></citerefentry> + to determine the mask of fields available.</para> <para><function>sd_bus_creds_get_pid()</function> will retrieve the PID (process identifier). Similar, @@ -374,19 +387,22 @@ <para><function>sd_bus_creds_get_slice()</function> will retrieve the systemd slice (a unit in the system instance of systemd) that the process is part of. See - <citerefentry><refentrytitle>systemd.slice</refentrytitle><manvolnum>5</manvolnum></citerefentry>. + <citerefentry><refentrytitle>systemd.slice</refentrytitle><manvolnum>5</manvolnum></citerefentry>. Similar, + <function>sd_bus_creds_get_user_slice()</function> retrieves the + systemd slice of the process, in the user instance of systemd. </para> <para><function>sd_bus_creds_get_session()</function> will - retrieve the logind session that the process is part of. See + retrieve the identifier of the login session that the process is + part of. See <citerefentry><refentrytitle>systemd-logind.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>. For processes that are not part of a session returns -ENXIO. </para> <para><function>sd_bus_creds_get_owner_uid()</function> will retrieve the numeric UID (user identifier) of the user who owns - the session that the process is part of. See - <citerefentry><refentrytitle>systemd.slice</refentrytitle><manvolnum>5</manvolnum></citerefentry> + the login session that the process is part of. See + <citerefentry><refentrytitle>systemd-logind.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>. For processes that are not part of a session returns -ENXIO. </para> @@ -395,7 +411,7 @@ <parameter>capability</parameter> was set in the effective capabilities mask. A positive return value means that is was set, zero means that it was not set, and a negative return - value signifies an error. See + value indicates an error. See <citerefentry project='man-pages'><refentrytitle>capabilities</refentrytitle><manvolnum>7</manvolnum></citerefentry> and <varname>Capabilities=</varname> and <varname>CapabilityBoundingSet=</varname> settings in @@ -427,8 +443,8 @@ processes that are not part of an audit session.</para> <para><function>sd_bus_creds_get_tty()</function> will retrieve - the controlling TTY. Returns -ENXIO for processes that have no - controlling TTY.</para> + the controlling TTY, without the prefixing "/dev/". Returns -ENXIO + for processes that have no controlling TTY.</para> <para><function>sd_bus_creds_get_unique_name()</function> will retrieve the D-Bus unique name. See <ulink @@ -489,8 +505,9 @@ <listitem><para>Given field is not specified for the described process or peer. This will be returned by <function>sd_bus_get_unit()</function>, - <function>sd_bus_get_user_unit()</function>, <function>sd_bus_get_slice()</function>, + <function>sd_bus_get_user_unit()</function>, + <function>sd_bus_get_user_slice()</function>, <function>sd_bus_get_session()</function>, and <function>sd_bus_get_owner_uid()</function> if the process is not part of a systemd system unit, systemd user unit, systemd @@ -526,10 +543,11 @@ <refsect1> <title>Notes</title> - <para><function>sd_bus_open_user()</function> and other functions - described here are available as a shared library, which can be - compiled and linked to with the - <constant>libsystemd</constant> <citerefentry project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry> + <para><function>sd_bus_creds_get_pid()</function> and the other + functions described here are available as a shared library, which + can be compiled and linked to with the + <constant>libsystemd</constant> <citerefentry + project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry> file.</para> </refsect1> @@ -539,8 +557,9 @@ <para> <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, <citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>, - <citerefentry><refentrytitle>fork</refentrytitle><manvolnum>2</manvolnum></citerefentry>, - <citerefentry><refentrytitle>execve</refentrytitle><manvolnum>2</manvolnum></citerefentry>, + <citerefentry><refentrytitle>sd_bus_creds_new_from_pid</refentrytitle><manvolnum>2</manvolnum></citerefentry>, + <citerefentry project='man-pages'><refentrytitle>fork</refentrytitle><manvolnum>2</manvolnum></citerefentry>, + <citerefentry project='man-pages'><refentrytitle>execve</refentrytitle><manvolnum>2</manvolnum></citerefentry>, <citerefentry project='man-pages'><refentrytitle>credentials</refentrytitle><manvolnum>7</manvolnum></citerefentry>, <citerefentry project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>, <citerefentry project='man-pages'><refentrytitle>proc</refentrytitle><manvolnum>5</manvolnum></citerefentry>, diff --git a/man/sd_bus_creds_new_from_pid.xml b/man/sd_bus_creds_new_from_pid.xml index 8c054a5905..a78d3f5717 100644 --- a/man/sd_bus_creds_new_from_pid.xml +++ b/man/sd_bus_creds_new_from_pid.xml @@ -45,6 +45,7 @@ <refnamediv> <refname>sd_bus_creds_new_from_pid</refname> <refname>sd_bus_creds_get_mask</refname> + <refname>sd_bus_creds_get_augmented_mask</refname> <refname>sd_bus_creds_ref</refname> <refname>sd_bus_creds_unref</refname> @@ -68,6 +69,11 @@ </funcprototype> <funcprototype> + <funcdef>uint64_t <function>sd_bus_creds_get_augmented_mask</function></funcdef> + <paramdef>const sd_bus_creds *<parameter>c</parameter></paramdef> + </funcprototype> + + <funcprototype> <funcdef>sd_bus_creds *<function>sd_bus_creds_ref</function></funcdef> <paramdef>sd_bus_creds *<parameter>c</parameter></paramdef> </funcprototype> @@ -80,17 +86,26 @@ <para> <constant>SD_BUS_CREDS_PID</constant>, + <constant>SD_BUS_CREDS_PPID</constant>, <constant>SD_BUS_CREDS_TID</constant>, <constant>SD_BUS_CREDS_UID</constant>, + <constant>SD_BUS_CREDS_EUID</constant>, + <constant>SD_BUS_CREDS_SUID</constant>, + <constant>SD_BUS_CREDS_FSUID</constant>, <constant>SD_BUS_CREDS_GID</constant>, + <constant>SD_BUS_CREDS_EGID</constant>, + <constant>SD_BUS_CREDS_SGID</constant>, + <constant>SD_BUS_CREDS_FSGID</constant>, + <constant>SD_BUS_CREDS_SUPPLEMENTARY_GIDS</constant>, <constant>SD_BUS_CREDS_COMM</constant>, <constant>SD_BUS_CREDS_TID_COMM</constant>, <constant>SD_BUS_CREDS_EXE</constant>, <constant>SD_BUS_CREDS_CMDLINE</constant>, <constant>SD_BUS_CREDS_CGROUP</constant>, <constant>SD_BUS_CREDS_UNIT</constant>, - <constant>SD_BUS_CREDS_USER_UNIT</constant>, <constant>SD_BUS_CREDS_SLICE</constant>, + <constant>SD_BUS_CREDS_USER_UNIT</constant>, + <constant>SD_BUS_CREDS_USER_SLICE</constant>, <constant>SD_BUS_CREDS_SESSION</constant>, <constant>SD_BUS_CREDS_OWNER_UID</constant>, <constant>SD_BUS_CREDS_EFFECTIVE_CAPS</constant>, @@ -100,8 +115,11 @@ <constant>SD_BUS_CREDS_SELINUX_CONTEXT</constant>, <constant>SD_BUS_CREDS_AUDIT_SESSION_ID</constant>, <constant>SD_BUS_CREDS_AUDIT_LOGIN_UID</constant>, + <constant>SD_BUS_CREDS_TTY</constant>, <constant>SD_BUS_CREDS_UNIQUE_NAME</constant>, <constant>SD_BUS_CREDS_WELL_KNOWN_NAMES</constant>, + <constant>SD_BUS_CREDS_DESCRIPTION</constant>, + <constant>SD_BUS_CREDS_AUGMENT</constant>, <constant>_SD_BUS_CREDS_ALL</constant> </para> </refsynopsisdiv> @@ -109,25 +127,39 @@ <refsect1> <title>Description</title> - <para><function>sd_bus_creds_new_from_pid()</function> creates a new - credentials object and fills it with information about the process - <parameter>pid</parameter>. This pointer to this object will - be stored in <parameter>ret</parameter> pointer.</para> + <para><function>sd_bus_creds_new_from_pid()</function> creates a + new credentials object and fills it with information about the + process <parameter>pid</parameter>. The pointer to this object + will be stored in <parameter>ret</parameter> pointer. Note that + credential objects may also be created and retrieved via + <citerefentry><refentrytitle>sd_bus_get_name_creds</refentrytitle><manvolnum>3</manvolnum></citerefentry>, + <citerefentry><refentrytitle>sd_bus_get_owner_creds</refentrytitle><manvolnum>3</manvolnum></citerefentry> + and + <citerefentry><refentrytitle>sd_bus_message_get_creds</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para> <para>The information that will be stored is determined by <parameter>creds_mask</parameter>. It may contain a subset of ORed constants <constant>SD_BUS_CREDS_PID</constant>, + <constant>SD_BUS_CREDS_PPID</constant>, <constant>SD_BUS_CREDS_TID</constant>, <constant>SD_BUS_CREDS_UID</constant>, + <constant>SD_BUS_CREDS_EUID</constant>, + <constant>SD_BUS_CREDS_SUID</constant>, + <constant>SD_BUS_CREDS_FSUID</constant>, <constant>SD_BUS_CREDS_GID</constant>, + <constant>SD_BUS_CREDS_EGID</constant>, + <constant>SD_BUS_CREDS_SGID</constant>, + <constant>SD_BUS_CREDS_FSGID</constant>, + <constant>SD_BUS_CREDS_SUPPLEMENTARY_GIDS</constant>, <constant>SD_BUS_CREDS_COMM</constant>, <constant>SD_BUS_CREDS_TID_COMM</constant>, <constant>SD_BUS_CREDS_EXE</constant>, <constant>SD_BUS_CREDS_CMDLINE</constant>, <constant>SD_BUS_CREDS_CGROUP</constant>, <constant>SD_BUS_CREDS_UNIT</constant>, - <constant>SD_BUS_CREDS_USER_UNIT</constant>, <constant>SD_BUS_CREDS_SLICE</constant>, + <constant>SD_BUS_CREDS_USER_UNIT</constant>, + <constant>SD_BUS_CREDS_USER_SLICE</constant>, <constant>SD_BUS_CREDS_SESSION</constant>, <constant>SD_BUS_CREDS_OWNER_UID</constant>, <constant>SD_BUS_CREDS_EFFECTIVE_CAPS</constant>, @@ -137,34 +169,71 @@ <constant>SD_BUS_CREDS_SELINUX_CONTEXT</constant>, <constant>SD_BUS_CREDS_AUDIT_SESSION_ID</constant>, <constant>SD_BUS_CREDS_AUDIT_LOGIN_UID</constant>, + <constant>SD_BUS_CREDS_TTY</constant>, <constant>SD_BUS_CREDS_UNIQUE_NAME</constant>, <constant>SD_BUS_CREDS_WELL_KNOWN_NAMES</constant>, - or <constant>_SD_BUS_CREDS_ALL</constant> to indicate - all known fields.</para> + <constant>SD_BUS_CREDS_DESCRIPTION</constant>. Use the special + value <constant>_SD_BUS_CREDS_ALL</constant> to request all + supported fields. The <constant>SD_BUS_CREDS_AUGMENT</constant> + may not be ORed into the mask for invocations of + <function>sd_bus_creds_new_from_pid()</function>.</para> <para>Fields can be retrieved from the credentials object using <citerefentry><refentrytitle>sd_bus_creds_get_pid</refentrytitle><manvolnum>3</manvolnum></citerefentry> and other functions which correspond directly to the constants listed above.</para> - <para>A mask of fields which were actually successfully set - (acquired from <filename>/proc</filename>, etc.) can be retrieved - with <function>sd_bus_creds_get_mask()</function>. If the - credentials object was created with + <para>A mask of fields which were actually successfully retrieved + can be retrieved with + <function>sd_bus_creds_get_mask()</function>. If the credentials + object was created with <function>sd_bus_creds_new_from_pid()</function>, this will be a subset of fields requested in <parameter>creds_mask</parameter>. </para> - <para><function>sd_bus_creds_ref</function> creates a new + <para>Similar to <function>sd_bus_creds_get_mask()</function> the + function <function>sd_bus_creds_get_augmented_mask()</function> + returns a bitmask of field constants. The mask indicates which + credential fields have been retrieved in a non-atomic fashion. For + credential objects created via + <function>sd_bus_creds_new_from_pid()</function> this mask will be + identical to the mask returned by + <function>sd_bus_creds_get_mask()</function>. However, for + credential objects retrieved via + <function>sd_bus_get_name_creds()</function> this mask will be set + for the credential fields that could not be determined atomically + at peer connection time, and which were later added by reading + augmenting credential data from + <filename>/proc</filename>. Similar, for credential objects + retrieved via <function>sd_bus_get_owner_creds()</function> the + mask is set for the fields that could not be determined atomically + at bus creation time, but have been augmented. Similar, for + credential objects retrieved via + <function>sd_bus_message_get_creds()</function> the mask is set + for the fields that could not be determined atomically at message + send time, but have been augmented. The mask returned by + <function>sd_bus_creds_get_augmented_mask()</function> is always a + subset of (or identical to) the mask returned by + <function>sd_bus_creds_get_mask()</function> for the same + object. The latter call hence returns all credential fields + available in the credential object, the former then marks the + subset of those that have been augmented. Note that augmented + fields are unsuitable for authorization decisions as they may be + retrieved at different times, thus being subject to races. Hence + augmented fields should be used exclusively for informational + purposes. + </para> + + <para><function>sd_bus_creds_ref()</function> creates a new reference to the credentials object <parameter>c</parameter>. This object will not be destroyed until - <function>sd_bus_creds_unref</function> has been called as many + <function>sd_bus_creds_unref()</function> has been called as many times plus once more. Once the reference count has dropped to zero, <parameter>c</parameter> cannot be used anymore, so further calls to <function>sd_bus_creds_ref(c)</function> or <function>sd_bus_creds_unref(c)</function> are illegal.</para> - <para><function>sd_bus_creds_unref</function> destroys a reference + <para><function>sd_bus_creds_unref()</function> destroys a reference to <parameter>c</parameter>.</para> </refsect1> @@ -178,10 +247,15 @@ <para><function>sd_bus_creds_get_mask()</function> returns the mask of successfully acquired fields.</para> - <para><function>sd_bus_creds_ref</function> always returns the + <para><function>sd_bus_creds_get_augmented_mask()</function> + returns the mask of fields that have been augmented from data in + <filename>/proc</filename>, and are thus not suitable for + authorization decisions.</para> + + <para><function>sd_bus_creds_ref()</function> always returns the argument.</para> - <para><function>sd_bus_creds_unref</function> always returns + <para><function>sd_bus_creds_unref()</function> always returns <constant>NULL</constant>.</para> </refsect1> @@ -222,16 +296,23 @@ <listitem><para>Memory allocation failed.</para></listitem> </varlistentry> + + <varlistentry> + <term><constant>-EOPNOTSUPP</constant></term> + + <listitem><para>One of the requested fields is unknown to the local system.</para></listitem> + </varlistentry> </variablelist> </refsect1> <refsect1> <title>Notes</title> - <para><function>sd_bus_creds_new_from_pid()</function> is - available as a shared library, which can be compiled and linked to - with the - <constant>libsystemd</constant> <citerefentry project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry> + <para><function>sd_bus_creds_new_from_pid()</function> and the + other calls described here are available as a shared library, + which can be compiled and linked to with the + <constant>libsystemd</constant> <citerefentry + project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry> file.</para> </refsect1> @@ -241,31 +322,10 @@ <para> <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, <citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>, - <citerefentry><refentrytitle>sd_bus_creds_ref</refentrytitle><manvolnum>3</manvolnum></citerefentry>, - <citerefentry><refentrytitle>sd_bus_creds_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>, <citerefentry><refentrytitle>sd_bus_creds_get_pid</refentrytitle><manvolnum>3</manvolnum></citerefentry>, - <citerefentry><refentrytitle>sd_bus_creds_get_tid</refentrytitle><manvolnum>3</manvolnum></citerefentry>, - <citerefentry><refentrytitle>sd_bus_creds_get_uid</refentrytitle><manvolnum>3</manvolnum></citerefentry>, - <citerefentry><refentrytitle>sd_bus_creds_get_gid</refentrytitle><manvolnum>3</manvolnum></citerefentry>, - <citerefentry><refentrytitle>sd_bus_creds_get_comm</refentrytitle><manvolnum>3</manvolnum></citerefentry>, - <citerefentry><refentrytitle>sd_bus_creds_get_tid_comm</refentrytitle><manvolnum>3</manvolnum></citerefentry>, - <citerefentry><refentrytitle>sd_bus_creds_get_exe</refentrytitle><manvolnum>3</manvolnum></citerefentry>, - <citerefentry><refentrytitle>sd_bus_creds_get_cmdline</refentrytitle><manvolnum>3</manvolnum></citerefentry>, - <citerefentry><refentrytitle>sd_bus_creds_get_cgroup</refentrytitle><manvolnum>3</manvolnum></citerefentry>, - <citerefentry><refentrytitle>sd_bus_creds_get_unit</refentrytitle><manvolnum>3</manvolnum></citerefentry>, - <citerefentry><refentrytitle>sd_bus_creds_get_user_unit</refentrytitle><manvolnum>3</manvolnum></citerefentry>, - <citerefentry><refentrytitle>sd_bus_creds_get_slice</refentrytitle><manvolnum>3</manvolnum></citerefentry>, - <citerefentry><refentrytitle>sd_bus_creds_get_session</refentrytitle><manvolnum>3</manvolnum></citerefentry>, - <citerefentry><refentrytitle>sd_bus_creds_get_owner_uid</refentrytitle><manvolnum>3</manvolnum></citerefentry>, - <citerefentry><refentrytitle>sd_bus_creds_has_effective_cap</refentrytitle><manvolnum>3</manvolnum></citerefentry>, - <citerefentry><refentrytitle>sd_bus_creds_has_permitted_cap</refentrytitle><manvolnum>3</manvolnum></citerefentry>, - <citerefentry><refentrytitle>sd_bus_creds_has_inheritable_cap</refentrytitle><manvolnum>3</manvolnum></citerefentry>, - <citerefentry><refentrytitle>sd_bus_creds_has_bounding_cap</refentrytitle><manvolnum>3</manvolnum></citerefentry>, - <citerefentry><refentrytitle>sd_bus_creds_get_selinux_context</refentrytitle><manvolnum>3</manvolnum></citerefentry>, - <citerefentry><refentrytitle>sd_bus_creds_get_audit_session_id</refentrytitle><manvolnum>3</manvolnum></citerefentry>, - <citerefentry><refentrytitle>sd_bus_creds_get_audit_login_uid</refentrytitle><manvolnum>3</manvolnum></citerefentry>, - <citerefentry><refentrytitle>sd_bus_creds_get_unique_name</refentrytitle><manvolnum>3</manvolnum></citerefentry>, - <citerefentry><refentrytitle>sd_bus_creds_get_well_known_names</refentrytitle><manvolnum>3</manvolnum></citerefentry> + <citerefentry><refentrytitle>sd_bus_get_name_creds</refentrytitle><manvolnum>3</manvolnum></citerefentry>, + <citerefentry><refentrytitle>sd_bus_get_owner_creds</refentrytitle><manvolnum>3</manvolnum></citerefentry>, + <citerefentry><refentrytitle>sd_bus_message_get_creds</refentrytitle><manvolnum>3</manvolnum></citerefentry> </para> </refsect1> diff --git a/man/sd_bus_error.xml b/man/sd_bus_error.xml index b8cb339cec..6dc4541eb1 100644 --- a/man/sd_bus_error.xml +++ b/man/sd_bus_error.xml @@ -44,11 +44,15 @@ <refnamediv> <refname>sd_bus_error</refname> + <refname>SD_BUS_ERROR_MAKE_CONST</refname> + <refname>SD_BUS_ERROR_NULL</refname> <refname>sd_bus_error_free</refname> <refname>sd_bus_error_set</refname> + <refname>sd_bus_error_setf</refname> <refname>sd_bus_error_set_const</refname> <refname>sd_bus_error_set_errno</refname> <refname>sd_bus_error_set_errnof</refname> + <refname>sd_bus_error_set_errnofv</refname> <refname>sd_bus_error_get_errno</refname> <refname>sd_bus_error_copy</refname> <refname>sd_bus_error_is_set</refname> @@ -75,7 +79,7 @@ </para> <funcprototype> - <funcdef>int <function>sd_bus_error_free</function></funcdef> + <funcdef>void <function>sd_bus_error_free</function></funcdef> <paramdef>sd_bus_error *<parameter>e</parameter></paramdef> </funcprototype> @@ -116,6 +120,14 @@ </funcprototype> <funcprototype> + <funcdef>int <function>sd_bus_error_set_errnofv</function></funcdef> + <paramdef>sd_bus_error *<parameter>e</parameter></paramdef> + <paramdef>int <parameter>error</parameter></paramdef> + <paramdef>const char *<parameter>format</parameter></paramdef> + <paramdef>va_list ap</paramdef> + </funcprototype> + + <funcprototype> <funcdef>int <function>sd_bus_error_get_errno</function></funcdef> <paramdef>const sd_bus_error *<parameter>e</parameter></paramdef> </funcprototype> @@ -138,234 +150,194 @@ </funcprototype> </funcsynopsis> - <para> - <constant>SD_BUS_ERROR_FAILED</constant> - </para> - <para> - <constant>SD_BUS_ERROR_NO_MEMORY</constant> - </para> - <para> - <constant>SD_BUS_ERROR_SERVICE_UNKNOWN</constant> - </para> - <para> - <constant>SD_BUS_ERROR_NAME_HAS_NO_OWNER</constant> - </para> - <para> - <constant>SD_BUS_ERROR_NO_REPLY</constant> - </para> - <para> - <constant>SD_BUS_ERROR_IO_ERROR</constant> - </para> - <para> - <constant>SD_BUS_ERROR_BAD_ADDRESS</constant> - </para> - <para> - <constant>SD_BUS_ERROR_NOT_SUPPORTED</constant> - </para> - <para> - <constant>SD_BUS_ERROR_LIMITS_EXCEEDED</constant> - </para> - <para> - <constant>SD_BUS_ERROR_ACCESS_DENIED</constant> - </para> - <para> - <constant>SD_BUS_ERROR_AUTH_FAILED</constant> - </para> - <para> - <constant>SD_BUS_ERROR_NO_SERVER</constant> - </para> - <para> - <constant>SD_BUS_ERROR_TIMEOUT</constant> - </para> - <para> - <constant>SD_BUS_ERROR_NO_NETWORK</constant> - </para> - <para> - <constant>SD_BUS_ERROR_ADDRESS_IN_USE</constant> - </para> - <para> - <constant>SD_BUS_ERROR_DISCONNECTED</constant> - </para> - <para> - <constant>SD_BUS_ERROR_INVALID_ARGS</constant> - </para> - <para> - <constant>SD_BUS_ERROR_FILE_NOT_FOUND</constant> - </para> - <para> - <constant>SD_BUS_ERROR_FILE_EXISTS</constant> - </para> - <para> - <constant>SD_BUS_ERROR_UNKNOWN_METHOD</constant> - </para> - <para> - <constant>SD_BUS_ERROR_UNKNOWN_OBJECT</constant> - </para> - <para> - <constant>SD_BUS_ERROR_UNKNOWN_INTERFACE</constant> - </para> - <para> - <constant>SD_BUS_ERROR_UNKNOWN_PROPERTY</constant> - </para> - <para> - <constant>SD_BUS_ERROR_PROPERTY_READ_ONLY</constant> - </para> - <para> - <constant>SD_BUS_ERROR_UNIX_PROCESS_ID_UNKNOWN</constant> - </para> - <para> - <constant>SD_BUS_ERROR_INVALID_SIGNATURE</constant> - </para> - <para> - <constant>SD_BUS_ERROR_INCONSISTENT_MESSAGE</constant> - </para> - <para> - <constant>SD_BUS_ERROR_MATCH_RULE_NOT_FOUND</constant> - </para> - <para> - <constant>SD_BUS_ERROR_MATCH_RULE_INVALID</constant> - </para> - </refsynopsisdiv> <refsect1> <title>Description</title> <para>The <structname>sd_bus_error</structname> structure carries - information for a <filename>sd-bus</filename> error. The - functions described below can be used to set and query fields in - this structure. The <structfield>name</structfield> field contains a - short identifier of an error. It should follow the rules for error - names described in the D-Bus specification, subsection <ulink + information about a D-Bus error condition. The functions described + below may be used to set and query fields in this structure. The + <structfield>name</structfield> field contains a short identifier + of an error. It should follow the rules for error names described + in the D-Bus specification, subsection <ulink url="http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names">Valid - Names</ulink>. The <structfield>message</structfield> is a human - readable string describing the details. When no longer necessary, - resources held by this structure should be destroyed with - <function>sd_bus_error_free</function>.</para> - - <para><function>sd_bus_error_set</function> will return an - errno-like negative value returned based on parameter - <parameter>name</parameter> (see - <citerefentry project='man-pages'><refentrytitle>errno</refentrytitle><manvolnum>3</manvolnum></citerefentry>). - Various well-known D-Bus errors are converted to specific values, - and the remaining ones to <constant>-ENXIO</constant>. Well-known - D-Bus error names are available as constants - <constant>SD_BUS_ERROR_FAILED</constant>, etc., listed above. If + Names</ulink>. A number of common, standardized error names are + described in + <citerefentry><refentrytitle>sd-bus-errors</refentrytitle><manvolnum>3</manvolnum></citerefentry>, + but additional domain-specific errors may be defined by + applications. The <structfield>message</structfield> field usually + contains a human readable string describing the details, but might + be NULL. An unset <structname>sd_bus_error</structname> structure + should have both fields initialized to NULL. Set an error + structure to <constant>SD_BUS_ERROR_NULL</constant> in order to + reset both fields to NULL. When no longer necessary, resources + held by the <structname>sd_bus_error</structname>structure should + be destroyed with <function>sd_bus_error_free()</function>.</para> + + <para><function>sd_bus_error_set()</function> sets an error + structure to the specified name and message strings. The strings + will be copied into internal, newly allocated memory. It is + essential to free the error structure again when it is not + required anymore (see above). The function will return an + <varname>errno</varname>-like negative value (see <citerefentry + project='man-pages'><refentrytitle>errno</refentrytitle><manvolnum>3</manvolnum></citerefentry>) + determined from the specified error name. Various well-known + D-Bus errors are converted to well-known <varname>errno</varname> + counterparts, and the other ones to <constant>-EIO</constant>. See + <citerefentry><refentrytitle>sd-bus-errors</refentrytitle><manvolnum>3</manvolnum></citerefentry> + for a list of well-known error names. Additional error mappings + may be defined with + <citerefentry><refentrytitle>sd_bus_error_add_map</refentrytitle><manvolnum>3</manvolnum></citerefentry>. If + <parameter>e</parameter> is NULL no error structure is initialized + but the error is still converted into an + <varname>errno</varname>-style error. If <parameter>name</parameter> is <constant>NULL</constant>, it is assumed that no error occurred, and 0 is returned. This means that this function may be conveniently used in a - <function>return</function> statement.</para> - - <para>If <parameter>e</parameter> is not - <constant>NULL</constant>, <structfield>name</structfield> and - <structfield>message</structfield> in the - <structname>sd_bus_error</structname> structure - <parameter>e</parameter> points at will be filled in. As described above, - <parameter>name</parameter> may be <constant>NULL</constant>, - which is treated as no error. Parameter - <parameter>message</parameter> may also be - <constant>NULL</constant>, in which case no message is specified. - <function>sd_bus_error_set</function> will make internal copies of - specified strings.</para> - - <para><function>sd_bus_error_setf</function> is similar to - <function>sd_bus_error_set</function>, but takes a - <citerefentry project='man-pages'><refentrytitle>printf</refentrytitle><manvolnum>3</manvolnum></citerefentry> - format string and corresponding arguments to generate - <structname>message</structname>.</para> - - <para><function>sd_bus_error_set_const</function> is similar to - <function>sd_bus_error_set</function>, but string parameters are - not copied internally, and must remain valid for the lifetime of - <parameter>e</parameter>.</para> - - <para><function>sd_bus_error_set_errno</function> will set - <structfield>name</structfield> based on an errno-like value. - <citerefentry project='die-net'><refentrytitle>strerror</refentrytitle><manvolnum>3</manvolnum></citerefentry> + <function>return</function> statement. If + <parameter>message</parameter> is NULL no message is set. This + call can fail if no memory may be allocated for the name and + message strings, in which case an + <constant>SD_BUS_ERROR_NO_MEMORY</constant> error might be set + instead and -ENOMEM returned. Do not use this call on error + structures that are already initialized. If you intend to reuse an + error structure free the old data stored in it with + <function>sd_bus_error_free()</function> first.</para> + + <para><function>sd_bus_error_setf()</function> is similar to + <function>sd_bus_error_set()</function>, but takes a <citerefentry + project='man-pages'><refentrytitle>printf</refentrytitle><manvolnum>3</manvolnum></citerefentry> + format string and corresponding arguments to generate the + <structfield>message</structfield> field.</para> + + <para><function>sd_bus_error_set_const()</function> is similar to + <function>sd_bus_error_set()</function>, but the string parameters + are not copied internally, and must hence remain constant and + valid for the lifetime of <parameter>e</parameter>. Use this call + to avoid memory allocations when setting error structures. Since + this call does not allocate memory it will not fail with an + out-of-memory condition, as + <function>sd_bus_error_set()</function> can, as described + above. Alternatively, the + <constant>SD_BUS_ERROR_MAKE_CONST()</constant> macro may be used + to generate a literal, constant bus error structure + on-the-fly.</para> + + <para><function>sd_bus_error_set_errno()</function> will set + <structfield>name</structfield> from an + <varname>errno</varname>-like value that is converted to a D-Bus + error. <citerefentry + project='die-net'><refentrytitle>strerror_r</refentrytitle><manvolnum>3</manvolnum></citerefentry> will be used to set <structfield>message</structfield>. Well-known D-Bus error names will be used for <structfield>name</structfield> - if available, otherwise a name in the - <literal>System.Error</literal> namespace will be generated. - </para> - - <para><function>sd_bus_error_set_errnof</function> is similar to - <function>sd_bus_error_set_errno</function>, but in addition to - <parameter>name</parameter>, takes a - <citerefentry project='man-pages'><refentrytitle>printf</refentrytitle><manvolnum>3</manvolnum></citerefentry> - format and corresponding arguments. - <structfield>name</structfield> will be generated from + if applicable, otherwise a name in the + <literal>System.Error.</literal> namespace will be generated. The + sign of the specified error number is ignored. The absolute value + is used implicitly. The call always returns a negative value, for + convenient usage in <function>return</function> statements. This + call might fail due to lack of memory, in which case an + <constant>SD_BUS_ERROR_NO_MEMORY</constant> error is set instead, + and -ENOMEM returned.</para> + + <para><function>sd_bus_error_set_errnof()</function> is similar to + <function>sd_bus_error_set_errno()</function>, but in addition to + <parameter>error</parameter>, takes a <citerefentry + project='man-pages'><refentrytitle>printf</refentrytitle><manvolnum>3</manvolnum></citerefentry> + format string and corresponding arguments. The + <structfield>message</structfield> field will be generated from <parameter>format</parameter> and the arguments.</para> - <para><function>sd_bus_error_get_errno</function> will convert - <structname>e->name</structname> to an errno-like value using the - same rules as <function>sd_bus_error_set</function>. If + <para><function>sd_bus_error_set_errnofv()</function> is similar to + <function>sd_bus_error_set_errnof()</function> but takes the + format string parameters as <citerefentry + project='man-pages'><refentrytitle>va_arg</refentrytitle><manvolnum>3</manvolnum></citerefentry> + parameter list.</para> + + <para><function>sd_bus_error_get_errno()</function> converts the + <structfield>name</structfield> field of an error structure to an + <varname>errno</varname>-like (positive) value using the same + rules as <function>sd_bus_error_set()</function>. If <parameter>e</parameter> is <constant>NULL</constant>, 0 will be returned.</para> - <para><function>sd_bus_error_copy</function> will initialize + <para><function>sd_bus_error_copy()</function> will initialize <parameter>dst</parameter> using the values in <parameter>e</parameter>. If the strings in <parameter>e</parameter> were set using - <function>sd_bus_set_error_const</function>, they will be shared. - Otherwise, they will be copied.</para> + <function>sd_bus_set_error_const()</function>, they will be shared. + Otherwise, they will be copied. Returns a converted + <varname>errno</varname>-like, negative error code.</para> - <para><function>sd_bus_error_is_set</function> will return - <constant>true</constant> if <parameter>e</parameter> is + <para><function>sd_bus_error_is_set()</function> will return a + non-zero value if <parameter>e</parameter> is non-<constant>NULL</constant> and an error has been set, <constant>false</constant> otherwise.</para> - <para><function>sd_bus_error_has_name</function> will return true - if <parameter>e</parameter> is non-<constant>NULL</constant> and - an error with the same <parameter>name</parameter> has been set, + <para><function>sd_bus_error_has_name()</function> will return a + non-zero value if <parameter>e</parameter> is + non-<constant>NULL</constant> and an error with the same + <parameter>name</parameter> has been set, <constant>false</constant> otherwise.</para> - <para><function>sd_bus_error_free</function> will destroy resources - held by <parameter>e</parameter>. The parameter itself will not - be deallocated, and must be - <citerefentry project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>d - by the caller if necessary.</para> + <para><function>sd_bus_error_free()</function> will destroy + resources held by <parameter>e</parameter>. The parameter itself + will not be deallocated, and must be <citerefentry + project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>d + by the caller if necessary. The function may also be called safely + on unset errors (error structures with both fields set to NULL), + in which case it performs no operation. This call will reset the + error structure after freeing the data, so that all fields are set + to NULL. The structure may be reused afterwards.</para> </refsect1> <refsect1> <title>Return Value</title> - <para>Functions <function>sd_bus_error_set</function>, - <function>sd_bus_error_setf</function>, - <function>sd_bus_error_set_const</function>, when successful, + <para>The functions <function>sd_bus_error_set()</function>, + <function>sd_bus_error_setf()</function>, + <function>sd_bus_error_set_const()</function>, when successful, return the negative errno value corresponding to the <parameter>name</parameter> parameter. Functions - <function>sd_bus_error_set_errno</function> and - <function>sd_bus_error_set_errnof</function>, when successful, - return the value of the <parameter>errno</parameter> parameter. If - an error occurs, one of the negative error values listed below - will be returned.</para> - - <para><function>sd_bus_error_get_errno</function> returns + <function>sd_bus_error_set_errno()</function>, + <function>sd_bus_error_set_errnof()</function> and + <function>sd_bus_error_set_errnofv()</function>, when successful, + return the negative value of the <parameter>error</parameter> + parameter. If an error occurs, one of the negative error values + listed below will be returned.</para> + + <para><function>sd_bus_error_get_errno()</function> returns <constant>false</constant> when <parameter>e</parameter> is <constant>NULL</constant>, and a positive errno value mapped from <parameter>e->name</parameter> otherwise.</para> - <para><function>sd_bus_error_copy</function> returns 0 or a - positive integer on success, and one of the negative error values - listed below otherwise.</para> + <para><function>sd_bus_error_copy()</function> returns 0 or a + positive integer on success, and a negative error value converted + from the error name otherwise.</para> - <para><function>sd_bus_error_is_set</function> returns - <constant>true</constant> when <parameter>e</parameter> and - <parameter>e->name</parameter> are non-<constant>NULL</constant>, - <constant>false</constant> otherwise.</para> + <para><function>sd_bus_error_is_set()</function> returns a + non-zero value when <parameter>e</parameter> and the + <structfield>name</structfield> field are + non-<constant>NULL</constant>, zero otherwise.</para> - <para><function>sd_bus_error_has_name</function> returns - <constant>true</constant> when <parameter>e</parameter> is - non-<constant>NULL</constant> and <parameter>e->name</parameter> - is equal to <parameter>name</parameter>, - <constant>false</constant> otherwise.</para> + <para><function>sd_bus_error_has_name()</function> returns a + non-zero value when <parameter>e</parameter> is + non-<constant>NULL</constant> and the + <structfield>name</structfield> field is equal to + <parameter>name</parameter>, zero otherwise.</para> </refsect1> <refsect1> <title>Reference ownership</title> <para><structname>sd_bus_error</structname> is not reference counted. Users should destroy resources held by it by calling - <function>sd_bus_error_free</function>.</para> + <function>sd_bus_error_free()</function>. Usually error structures + are allocated on the stack or passed in as function parameters, + but they may also be allocated dynamically, in which case it is + the duty of the caller to <citerefentry + project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry> + the memory held by the structure itself after freeing its contents + with <function>sd_bus_error_free()</function>.</para> </refsect1> <refsect1> @@ -407,8 +379,10 @@ <para> <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, <citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>, + <citerefentry><refentrytitle>sd-bus-errors</refentrytitle><manvolnum>3</manvolnum></citerefentry>, + <citerefentry><refentrytitle>sd_bus_error_add_map</refentrytitle><manvolnum>3</manvolnum></citerefentry>, <citerefentry project='man-pages'><refentrytitle>errno</refentrytitle><manvolnum>3</manvolnum></citerefentry>, - <citerefentry project='die-net'><refentrytitle>strerror</refentrytitle><manvolnum>3</manvolnum></citerefentry> + <citerefentry project='die-net'><refentrytitle>strerror_r</refentrytitle><manvolnum>3</manvolnum></citerefentry> </para> </refsect1> diff --git a/man/sd_bus_error_add_map.xml b/man/sd_bus_error_add_map.xml new file mode 100644 index 0000000000..3fca63be4a --- /dev/null +++ b/man/sd_bus_error_add_map.xml @@ -0,0 +1,173 @@ +<?xml version='1.0'?> <!--*- Mode: nxml; nxml-child-indent: 2; indent-tabs-mode: nil -*--> +<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" +"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> + +<!-- + This file is part of systemd. + + Copyright 2015 Lennart Poettering + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see <http://www.gnu.org/licenses/>. +--> + +<refentry id="sd_bus_error_add_map"> + + <refentryinfo> + <title>sd_bus_error_add_map</title> + <productname>systemd</productname> + + <authorgroup> + <author> + <contrib>Developer</contrib> + <firstname>Lennart</firstname> + <surname>Poettering</surname> + <email>lennart@poettering.net</email> + </author> + </authorgroup> + </refentryinfo> + + <refmeta> + <refentrytitle>sd_bus_error_add_map</refentrytitle> + <manvolnum>3</manvolnum> + </refmeta> + + <refnamediv> + <refname>sd_bus_error_add_map</refname> + <refname>sd_bus_error_map</refname> + <refname>SD_BUS_ERROR_MAP</refname> + <refname>SD_BUS_ERROR_END</refname> + + <refpurpose>Additional sd-dbus error mappings</refpurpose> + </refnamediv> + + <refsynopsisdiv> + <funcsynopsis> + <funcsynopsisinfo>#include <systemd/sd-bus.h></funcsynopsisinfo> + + <funcsynopsisinfo>typedef struct { + const char *name; + int code; + ... +} sd_bus_error_map;</funcsynopsisinfo> + + </funcsynopsis> + + <para> + <constant>SD_BUS_ERROR_MAP(<replaceable>name</replaceable>, <replaceable>code</replaceable>)</constant> + </para> + <para> + <constant>SD_BUS_ERROR_MAP_END</constant> + </para> + + <funcprototype> + <funcdef>int <function>sd_bus_error_add_map</function></funcdef> + <paramdef>const sd_bus_map *<parameter>map</parameter></paramdef> + </funcprototype> + + </refsynopsisdiv> + + <refsect1> + <title>Description</title> + + <para>The <function>sd_bus_error_add_map()</function> call may be + used to register additional mappings for converting D-Bus errors + to Linux <varname>errno</varname>-style errors. The mappings + defined with this call are consulted by calls such as + <citerefentry><refentrytitle>sd_bus_error_set</refentrytitle><manvolnum>3</manvolnum></citerefentry> + or + <citerefentry><refentrytitle>sd_bus_error_get_errno</refentrytitle><manvolnum>3</manvolnum></citerefentry>. By + default a number of generic, standardized mappings are known, as + documented in + <citerefentry><refentrytitle>sd-bus-errors</refentrytitle><manvolnum>3</manvolnum></citerefentry>. Use + this call to add further, application-specific mappings.</para> + + <para>The function takes a pointer to an array of + <structname>sd_bus_error_map</structname> structures. A reference + to the specified array is added to the lookup tables for error + mappings. Note that the structure is not copied, it is hence + essential that the array stays available and constant during the + entire remaining runtime of the process.</para> + + <para>The mapping array should be put together with a series of + <constant>SD_BUS_ERROR_MAP()</constant> macro invocations, that + take a literal name string and a (positive) + <varname>errno</varname>-style error number. The last entry of the + array should be an invocation of the + <constant>SD_BUS_ERROR_MAP_END</constant> macro. The array should not be + put together without use of these two macros.</para> + + <para>Note that the call is idempotent: it is safe to invoke it + multiple times with the parameter, which will only add the passed + mapping array once.</para> + + <para>Note that the memory allocated by this call is not intended + to be freed during the lifetime of the process. It should not be + freed explicitly.</para> + </refsect1> + + <refsect1> + <title>Return Value</title> + + <para><function>sd_bus_error_add_map()</function> returns a + positive value when the new array was added to the lookup + tables. It returns zero when the same array was already added + before. On error, a negative <varname>errno</varname>-style error + code is returned. See below for known error codes.</para> + </refsect1> + + <refsect1> + <title>Errors</title> + + <para>Returned errors may indicate the following problems:</para> + + <variablelist> + + <varlistentry> + <term><constant>-EINVAL</constant></term> + + <listitem><para>The specified mapping array is invalid.</para></listitem> + </varlistentry> + + <varlistentry> + <term><constant>-ENOMEM</constant></term> + + <listitem><para>Memory allocation failed.</para></listitem> + </varlistentry> + </variablelist> + </refsect1> + + <refsect1> + <title>Notes</title> + + <para>The various error definitions described here are available + as a shared library, which can be compiled and linked to with the + <constant>libsystemd</constant> <citerefentry + project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry> + file.</para> + </refsect1> + + <refsect1> + <title>See Also</title> + + <para> + <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, + <citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>, + <citerefentry><refentrytitle>sd_bus_error</refentrytitle><manvolnum>3</manvolnum></citerefentry>, + <citerefentry><refentrytitle>sd-bus-errors</refentrytitle><manvolnum>3</manvolnum></citerefentry>, + <citerefentry project='man-pages'><refentrytitle>errno</refentrytitle><manvolnum>3</manvolnum></citerefentry>, + <citerefentry project='die-net'><refentrytitle>strerror_r</refentrytitle><manvolnum>3</manvolnum></citerefentry> + </para> + </refsect1> + +</refentry> diff --git a/man/sd_bus_message_append.xml b/man/sd_bus_message_append.xml index 7a4bfa4bc4..0ee849dca7 100644 --- a/man/sd_bus_message_append.xml +++ b/man/sd_bus_message_append.xml @@ -46,7 +46,8 @@ <refnamediv> <refname>sd_bus_message_append</refname> - <refpurpose>Attach parts of message based on a format string</refpurpose> + <refpurpose>Attach fields to a D-Bus message based on a type + string</refpurpose> </refnamediv> <refsynopsisdiv> @@ -65,17 +66,20 @@ <refsect1> <title>Description</title> - <para>The <function>sd_bus_message_append</function> function appends - a sequence of items to message <parameter>m</parameter>. The - format string <parameter>types</parameter> describes the types of - arguments that follow.</para> + <para>The <function>sd_bus_message_append()</function> function + appends a sequence of fields to the D-Bus message object + <parameter>m</parameter>. The type string + <parameter>types</parameter> describes the types of the field + arguments that follow. For each type specified in the type string + one or more arguments need to be specified, in the same order as + declared in the type string.</para> - <para>The format string is composed of the elements shown in the + <para>The type string is composed of the elements shown in the table below. It contains zero or more single "complete types". Each complete type may be one of the basic types or a fully - described container type. A container type may be a structure, a - variant type code, an array with its element type, or a dictionary - with its entry type. The format string is + described container type. A container type may be a structure with + the contained types, a variant, an array with its element type, or + a dictionary entry with the contained types. The type string is <constant>NUL</constant>-terminated.</para> <para>In case of a basic type, one argument of the corresponding @@ -88,27 +92,32 @@ rules as if they were not nested.</para> <para>A variant is denoted by <literal>v</literal>. Corresponding - arguments must include a format string denoting a complete type, + arguments must begin with a type string denoting a complete type, and following that, arguments corresponding to the specified type. </para> <para>An array is denoted by <literal>a</literal> followed by a - complete type. Corresponding arguments must include the size of - the array, and then repeated this number of times, arguments - corresponding to the nested type.</para> + complete type. Corresponding arguments must begin with the number of + entries in the array, followed by the entries themselves, + matching the element type of the array.</para> <para>A dictionary is an array of dictionary entries, denoted by <literal>a</literal> followed by a pair of complete types between <literal>{</literal> and <literal>}</literal>. The first of those - types must be a basic type. Corresponding arguments must include - the size of the dictionary, and then repeated this number of - times, arguments corresponding to each of the two nested - types.</para> + types must be a basic type. Corresponding arguments must begin + with the number of dictionary entries, followed by a pair of + values for each entry matching the element type of + the dictionary entries.</para> + + <para>For further details on the D-Bus type system, please consult + the <ulink + url="http://dbus.freedesktop.org/doc/dbus-specification.html#type-system">D-Bus + Specification</ulink>.</para> <table> - <title>Item format specifiers</title> + <title>Item type specifiers</title> - <tgroup cols='4'> + <tgroup cols='5'> <xi:include href="sd_bus_message_append_basic.xml" xpointer="xpointer(//table[@id='format-specifiers'])//colspec" /> <xi:include href="sd_bus_message_append_basic.xml" xpointer="xpointer(//table[@id='format-specifiers']//thead)" /> @@ -120,6 +129,7 @@ <entry><constant>SD_BUS_TYPE_ARRAY</constant></entry> <entry>array</entry> <entry>determined by array type and size</entry> + <entry>int, followed by array contents</entry> </row> <row> @@ -127,6 +137,7 @@ <entry><constant>SD_BUS_TYPE_VARIANT</constant></entry> <entry>variant</entry> <entry>determined by the type argument</entry> + <entry>signature string, followed by variant contents</entry> </row> <row> @@ -134,6 +145,7 @@ <entry><constant>SD_BUS_TYPE_STRUCT_BEGIN</constant></entry> <entry>array start</entry> <entry morerows="1">determined by the nested types</entry> + <entry morerows="1">structure contents</entry> </row> <row> <entry><literal>)</literal></entry> @@ -146,6 +158,7 @@ <entry><constant>SD_BUS_TYPE_DICT_ENTRY_BEGIN</constant></entry> <entry>dictionary entry start</entry> <entry morerows="1">determined by the nested types</entry> + <entry morerows="1">dictionary contents</entry> </row> <row> <entry><literal>}</literal></entry> @@ -155,10 +168,11 @@ </tbody> </tgroup> </table> + </refsect1> <refsect1> - <title>Types string grammar</title> + <title>Types String Grammar</title> <programlisting>types ::= complete_type* complete_type ::= basic_type | variant | structure | array | dictionary @@ -194,7 +208,7 @@ uint32_t t = 7; double d = 8.0; sd_bus_message_append(m, "ynqiuxtd", y, n, q, i, u, x, t, d);</programlisting> - <para>Append a structure composed of string and a D-Bus path:</para> + <para>Append a structure composed of a string and a D-Bus path:</para> <programlisting>sd_bus_message_append(m, "(so)", "a string", "/a/path"); </programlisting> @@ -242,12 +256,8 @@ sd_bus_message_append(m, "ynqiuxtd", y, n, q, i, u, x, t, d);</programlisting> <para> <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, <citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>, - <citerefentry><refentrytitle>sd_bus_new</refentrytitle><manvolnum>3</manvolnum></citerefentry>, - <citerefentry><refentrytitle>sd_bus_ref</refentrytitle><manvolnum>3</manvolnum></citerefentry>, - <citerefentry><refentrytitle>sd_bus_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>, - <citerefentry project='die-net'><refentrytitle>ssh</refentrytitle><manvolnum>1</manvolnum></citerefentry>, - <citerefentry><refentrytitle>systemd-machined.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>, - <citerefentry><refentrytitle>machinectl</refentrytitle><manvolnum>1</manvolnum></citerefentry> + <citerefentry><refentrytitle>sd_bus_message_append_basic</refentrytitle><manvolnum>3</manvolnum></citerefentry>, + <citerefentry><refentrytitle>sd_bus_message_append_array</refentrytitle><manvolnum>3</manvolnum></citerefentry> </para> </refsect1> diff --git a/man/sd_bus_message_append_array.xml b/man/sd_bus_message_append_array.xml index c2adc6f43d..034466bf9c 100644 --- a/man/sd_bus_message_append_array.xml +++ b/man/sd_bus_message_append_array.xml @@ -49,7 +49,8 @@ <refname>sd_bus_message_append_array_iovec</refname> <refname>sd_bus_message_append_array_space</refname> - <refpurpose>Attach an array of items to a message</refpurpose> + <refpurpose>Appaned an array of fields to a D-Bus + message</refpurpose> </refnamediv> <refsynopsisdiv> @@ -69,6 +70,8 @@ <paramdef>sd_bus_message *<parameter>m</parameter></paramdef> <paramdef>char <parameter>type</parameter></paramdef> <paramdef>int <parameter>memfd</parameter></paramdef> + <paramdef>uint64_t <parameter>offset</parameter></paramdef> + <paramdef>uint64_t <parameter>size</parameter></paramdef> </funcprototype> <funcprototype> @@ -83,7 +86,7 @@ <funcdef>int sd_bus_message_append_array_space</funcdef> <paramdef>char <parameter>type</parameter></paramdef> <paramdef>size_t <parameter>size</parameter></paramdef> - <paramdef>char void **<parameter>ptr</parameter></paramdef> + <paramdef>void **<parameter>ptr</parameter></paramdef> </funcprototype> </funcsynopsis> </refsynopsisdiv> @@ -91,18 +94,19 @@ <refsect1> <title>Description</title> - <para>The <function>sd_bus_message_append_array</function> functionc - appends items to message <parameter>m</parameter> as the single - array. A container will be opened, items appended, and the - container closed. Parameter <parameter>type</parameter> determines - how pointer <parameter>p</parameter> is interpreted. + <para>The <function>sd_bus_message_append_array()</function> + function appends an array to a D-Bus message + <parameter>m</parameter>. A container will be opened, the array + contents appended, and the container closed. The parameter + <parameter>type</parameter> determines how the pointer + <parameter>p</parameter> is interpreted. <parameter>type</parameter> must be one of the "trivial" types <literal>y</literal>, <literal>n</literal>, <literal>q</literal>, <literal>i</literal>, <literal>u</literal>, <literal>x</literal>, <literal>t</literal>, <literal>d</literal> (but not - <literal>b</literal>), as defined by the - <ulink url="http://dbus.freedesktop.org/doc/dbus-specification.html#basic-types">Basic Types</ulink> - section of the D-Bus specification, and listed in + <literal>b</literal>), as defined by the <ulink + url="http://dbus.freedesktop.org/doc/dbus-specification.html#basic-types">Basic + Types</ulink> section of the D-Bus specification, and listed in <citerefentry><refentrytitle>sd_bus_message_append_basic</refentrytitle><manvolnum>3</manvolnum></citerefentry>. Pointer <parameter>p</parameter> must point to an array of size <parameter>size</parameter> bytes containing items of the @@ -110,50 +114,68 @@ multiple of the size of the type <parameter>type</parameter>. As a special case, <parameter>p</parameter> may be <constant>NULL</constant>, if <parameter>size</parameter> is 0. - </para> - - <para>The memory pointed at by <parameter>p</parameter> is copied - into the memory area containing the message and may be changed - after this call.</para> - - <para>The - <function>sd_bus_message_append_array_memfd</function> function appends - items to message <parameter>m</parameter>, similarly to - <function>sd_bus_message_append_array</function>. Contents of the - memory file descriptor <parameter>memfd</parameter> are used as - the contents of the array. Their size must be a multiple of the - size of the type <parameter>type</parameter>.</para> - - <para>The descriptor specified with <parameter>memfd</parameter> - will be sealed and cannot be modified after this call.</para> - - <para>The - <function>sd_bus_message_append_array_iovec</function> function appends - items to message <parameter>m</parameter>, similarly to - <function>sd_bus_message_append_array</function>. Contents of the - iovec <parameter>iov</parameter> are used as the contents of the - array. The total size of <parameter>iov</parameter> payload (the - sum of <structfield>iov_len</structfield> fields) must be a multiple - of the size of the type <parameter>type</parameter>.</para> - - <para>The <parameter>iov</parameter> argument must point to - <parameter>n</parameter> <structname>struct iovec</structname> - structures. Each structure may have the - <structname>iov_base</structname> field set, in which case the - memory pointed to will be copied into the message, or unset, in - which case a block of zeros of length + The memory pointed to by <parameter>p</parameter> is copied into + the memory area containing the message and stays in possession of + the caller. The caller may hence freely change the data after this + call without affecting the message the array was appended + to.</para> + + <para>The <function>sd_bus_message_append_array_memfd()</function> + function appends an array of a trivial type to message + <parameter>m</parameter>, similar to + <function>sd_bus_message_append_array()</function>. The contents + of the memory file descriptor <parameter>memfd</parameter> + starting at the specified offset and and of the specified size is + used as the contents of the array. The offset and size must be a + multiple of the size of the type + <parameter>type</parameter>. However, as a special exception, if + the offset is specified as zero and the size specified as + UINT64_MAX the full memory file descriptor contents is used. The + memory file descriptor is sealed by this call if it hasn't been + sealed yet, and cannot be modified a after this call. See + <citerefentry + project='man-pages'><refentrytitle>memfd_create</refentrytitle><manvolnum>2</manvolnum></citerefentry> + for details about memory file descriptors. Appending arrays with + memory file descriptors enables efficient zero-copy data transfer, + as the memory file descriptor may be passed as-is to the + destination, without copying the memory in it to the destination + process. Not all protocol transports support passing memory file + descriptors between participants, in which case this call will + automatically fall back to copying. Also, as memory file + descriptor passing is inefficient for smaller amounts of data + copying might still be enforced even where memory file descriptor + passing is supported.</para> + + <para>The <function>sd_bus_message_append_array_iovec()</function> + function appends an array of a trivial type to the message + <parameter>m</parameter>, similar to + <function>sd_bus_message_append_array()</function>. Contents of + the IO vector array <parameter>iov</parameter> are used as the + contents of the array. The total size of + <parameter>iov</parameter> payload (the sum of + <structfield>iov_len</structfield> fields) must be a multiple of + the size of the type <parameter>type</parameter>. The + <parameter>iov</parameter> argument must point to + <parameter>n</parameter> IO vector structures. Each structure may + have the <structname>iov_base</structname> field set, in which + case the memory pointed to will be copied into the message, or + unset (set to zero), in which case a block of zeros of length <structname>iov_len</structname> bytes will be inserted. The memory pointed at by <parameter>iov</parameter> may be changed after this call.</para> - <para>The - <function>sd_bus_message_append_array_space</function> function appends - space for an array of items to message <parameter>m</parameter>. - It behaves the same as - <function>sd_bus_message_append_array</function>, but instead - of copying items to the message, it returns a pointer to the - destination area to the caller in pointer <parameter>p</parameter>. - </para> + <para>The <function>sd_bus_message_append_array_space()</function> + function appends space for an array of a trivial type to message + <parameter>m</parameter>. It behaves the same as + <function>sd_bus_message_append_array()</function>, but instead of + copying items to the message, it returns a pointer to the + destination area to the caller in pointer + <parameter>p</parameter>. The caller should subsequently write the + array contents to this memory. Modifications of the memory + pointed to should only occur until the next operation on the bus + message is invoked, most imporantly the memory should not be + altered anymore when another field has been added to the message + or the message has been sealed.</para> </refsect1> <refsect1> @@ -183,6 +205,7 @@ <citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>, <citerefentry><refentrytitle>sd_bus_message_append</refentrytitle><manvolnum>3</manvolnum></citerefentry>, <citerefentry><refentrytitle>sd_bus_message_append_basic</refentrytitle><manvolnum>3</manvolnum></citerefentry>, + <citerefentry project='man-pages'><refentrytitle>memfd_create</refentrytitle><manvolnum>2</manvolnum></citerefentry>, <ulink url="http://dbus.freedesktop.org/doc/dbus-specification.html">The D-Bus specification</ulink> </para> </refsect1> diff --git a/man/sd_bus_message_append_basic.xml b/man/sd_bus_message_append_basic.xml index 91eaf87530..276953af69 100644 --- a/man/sd_bus_message_append_basic.xml +++ b/man/sd_bus_message_append_basic.xml @@ -45,7 +45,7 @@ <refnamediv> <refname>sd_bus_message_append_basic</refname> - <refpurpose>Attach a single part to a message</refpurpose> + <refpurpose>Attach a single field to a message</refpurpose> </refnamediv> <refsynopsisdiv> @@ -56,7 +56,7 @@ <funcdef>int sd_bus_message_append_basic</funcdef> <paramdef>sd_bus_message *<parameter>m</parameter></paramdef> <paramdef>char <parameter>type</parameter></paramdef> - <paramdef>char void *<parameter>p</parameter></paramdef> + <paramdef>const void *<parameter>p</parameter></paramdef> </funcprototype> </funcsynopsis> </refsynopsisdiv> @@ -64,31 +64,33 @@ <refsect1> <title>Description</title> - <para><function>sd_bus_message_append_basic</function> appends a - single item to the message <parameter>m</parameter>. Parameter - <parameter>type</parameter> determines how pointer + <para><function>sd_bus_message_append_basic()</function> appends a + single field to the message <parameter>m</parameter>. The + parameter <parameter>type</parameter> determines how the pointer <parameter>p</parameter> is interpreted. - <parameter>type</parameter> must be one of the basic types - as defined by the - - <ulink url="http://dbus.freedesktop.org/doc/dbus-specification.html#basic-types">Basic Types</ulink> - section of the D-Bus specification, and listed in the table below. + <parameter>type</parameter> must be one of the basic types as + defined by the <ulink + url="http://dbus.freedesktop.org/doc/dbus-specification.html#basic-types">Basic + Types</ulink> section of the D-Bus specification, and listed in + the table below. </para> <table id='format-specifiers'> - <title>Item format specifiers</title> + <title>Item type specifiers</title> - <tgroup cols='4'> + <tgroup cols='5'> <colspec colname='specifier' /> <colspec colname='constant' /> <colspec colname='description' /> <colspec colname='size' /> + <colspec colname='ctype' /> <thead> <row> <entry>Specifier</entry> <entry>Constant</entry> <entry>Description</entry> <entry>Size</entry> + <entry>Expected C Type</entry> </row> </thead> <tbody> @@ -97,6 +99,7 @@ <entry><constant>SD_BUS_TYPE_BYTE</constant></entry> <entry>unsigned integer</entry> <entry>1 byte</entry> + <entry>uint8_t</entry> </row> <row> @@ -104,6 +107,7 @@ <entry><constant>SD_BUS_TYPE_BOOLEAN</constant></entry> <entry>boolean</entry> <entry>4 bytes</entry> + <entry>int</entry> </row> <row> @@ -111,6 +115,7 @@ <entry><constant>SD_BUS_TYPE_INT16</constant></entry> <entry>signed integer</entry> <entry>2 bytes</entry> + <entry>int16_t</entry> </row> <row> @@ -118,6 +123,7 @@ <entry><constant>SD_BUS_TYPE_UINT16</constant></entry> <entry>unsigned integer</entry> <entry>2 bytes</entry> + <entry>uint16_t</entry> </row> <row> @@ -125,6 +131,7 @@ <entry><constant>SD_BUS_TYPE_INT32</constant></entry> <entry>signed integer</entry> <entry>4 bytes</entry> + <entry>int32_t</entry> </row> <row> @@ -132,6 +139,7 @@ <entry><constant>SD_BUS_TYPE_UINT32</constant></entry> <entry>unsigned integer</entry> <entry>4 bytes</entry> + <entry>uint32_t</entry> </row> <row> @@ -139,6 +147,7 @@ <entry><constant>SD_BUS_TYPE_INT64</constant></entry> <entry>signed integer</entry> <entry>8 bytes</entry> + <entry>int64_t</entry> </row> <row> @@ -146,6 +155,7 @@ <entry><constant>SD_BUS_TYPE_UINT64</constant></entry> <entry>unsigned integer</entry> <entry>8 bytes</entry> + <entry>uint64_t</entry> </row> <row> @@ -153,6 +163,7 @@ <entry><constant>SD_BUS_TYPE_DOUBLE</constant></entry> <entry>floating-point</entry> <entry>8 bytes</entry> + <entry>double</entry> </row> <row> @@ -160,6 +171,7 @@ <entry><constant>SD_BUS_TYPE_STRING</constant></entry> <entry>Unicode string</entry> <entry>variable</entry> + <entry>char[]</entry> </row> <row> @@ -167,6 +179,7 @@ <entry><constant>SD_BUS_TYPE_OBJECT_PATH</constant></entry> <entry>object path</entry> <entry>variable</entry> + <entry>char[]</entry> </row> <row> @@ -174,6 +187,7 @@ <entry><constant>SD_BUS_TYPE_SIGNATURE</constant></entry> <entry>signature</entry> <entry>variable</entry> + <entry>char[]</entry> </row> <row> @@ -181,16 +195,19 @@ <entry><constant>SD_BUS_TYPE_UNIX_FD</constant></entry> <entry>UNIX file descriptor</entry> <entry>4 bytes</entry> + <entry>int</entry> </row> </tbody> </tgroup> </table> - <para>The value of the parameter is copied into the memory area - containing the message and may be changed after this call. If - <parameter>type</parameter> is <literal>h</literal> (UNIX file - descriptor), it is always "consumed" by this call, and either - successfully appended to the message or closed.</para> + <para>The value of the parameter is copied into a memory area held + by the message object, stays in the possession of the caller and + may hence be freely changed after this call without affecting the + bus message it has been added to. If <parameter>type</parameter> + is <literal>h</literal> (UNIX file descriptor), the descriptor is + duplicated by this call and the passed descriptor stays in + possession of the caller.</para> <para>For types <literal>s</literal>, <literal>o</literal>, and <literal>g</literal>, the parameter <parameter>p</parameter> is diff --git a/man/sd_bus_negotiate_fds.xml b/man/sd_bus_negotiate_fds.xml index 04042f2136..1be44e2785 100644 --- a/man/sd_bus_negotiate_fds.xml +++ b/man/sd_bus_negotiate_fds.xml @@ -44,7 +44,7 @@ <refnamediv> <refname>sd_bus_negotiate_fds</refname> - <refname>sd_bus_negotiate_timestamps</refname> + <refname>sd_bus_negotiate_timestamp</refname> <refname>sd_bus_negotiate_creds</refname> <refpurpose>Control feature negotiation on bus connections</refpurpose> diff --git a/man/sd_bus_request_name.xml b/man/sd_bus_request_name.xml index 9b0a93d888..f07ae09555 100644 --- a/man/sd_bus_request_name.xml +++ b/man/sd_bus_request_name.xml @@ -45,7 +45,7 @@ <refnamediv> <refname>sd_bus_request_name</refname> <refname>sd_bus_release_name</refname> - <refpurpose>Request or release a well-known name on a bus</refpurpose> + <refpurpose>Request or release a well-known service name on a bus</refpurpose> </refnamediv> <refsynopsisdiv> @@ -71,9 +71,9 @@ <title>Description</title> <para><function>sd_bus_request_name()</function> requests a - well-known name on a bus. It takes a bus connection, a valid bus - name and a flags parameter. The flags parameter is a combination - of the following flags:</para> + well-known service name on a bus. It takes a bus connection, a + valid bus name and a flags parameter. The flags parameter is a + combination of the following flags:</para> <variablelist> <varlistentry> @@ -166,8 +166,11 @@ <varlistentry> <term><constant>-EINVAL</constant></term> - <listitem><para>A specified parameter is - invalid.</para></listitem> + <listitem><para>A specified parameter is invalid. This is also + generated when the requested name is a special service name + reserved by the D-Bus specification, or when the operation is + requested on a connection that does not refer to a + bus.</para></listitem> </varlistentry> <varlistentry> diff --git a/man/sd_pid_get_session.xml b/man/sd_pid_get_session.xml index b46d47101b..9c6706caf8 100644 --- a/man/sd_pid_get_session.xml +++ b/man/sd_pid_get_session.xml @@ -49,15 +49,17 @@ <refname>sd_pid_get_owner_uid</refname> <refname>sd_pid_get_machine_name</refname> <refname>sd_pid_get_slice</refname> + <refname>sd_pid_get_user_slice</refname> <refname>sd_peer_get_session</refname> <refname>sd_peer_get_unit</refname> <refname>sd_peer_get_user_unit</refname> <refname>sd_peer_get_owner_uid</refname> <refname>sd_peer_get_machine_name</refname> <refname>sd_peer_get_slice</refname> - <refpurpose>Determine session, service, owner of a - session, container/VM or slice of a specific - PID or socket peer</refpurpose> + <refname>sd_peer_get_user_slice</refname> + <refpurpose>Determine session, unit, owner of a session, + container/VM or slice of a specific PID or socket + peer</refpurpose> </refnamediv> <refsynopsisdiv> @@ -101,6 +103,12 @@ </funcprototype> <funcprototype> + <funcdef>int <function>sd_pid_get_user_slice</function></funcdef> + <paramdef>pid_t <parameter>pid</parameter></paramdef> + <paramdef>char **<parameter>slice</parameter></paramdef> + </funcprototype> + + <funcprototype> <funcdef>int <function>sd_peer_get_session</function></funcdef> <paramdef>int <parameter>fd</parameter></paramdef> <paramdef>char **<parameter>session</parameter></paramdef> @@ -135,6 +143,12 @@ <paramdef>int <parameter>fd</parameter></paramdef> <paramdef>char **<parameter>slice</parameter></paramdef> </funcprototype> + + <funcprototype> + <funcdef>int <function>sd_peer_get_user_slice</function></funcdef> + <paramdef>int <parameter>fd</parameter></paramdef> + <paramdef>char **<parameter>slice</parameter></paramdef> + </funcprototype> </funcsynopsis> </refsynopsisdiv> @@ -155,30 +169,29 @@ call after use.</para> <para><function>sd_pid_get_unit()</function> may be used to - determine the systemd system unit (i.e. system service) identifier - of a process identified by the specified PID. The unit name is a - short string, suitable for usage in file system paths. Note that - not all processes are part of a system unit/service (e.g. user - processes, or kernel threads). For processes not being part of a - systemd system unit this function will fail with -ENXIO (More - specifically: this call will not work for processes that are part - of user units, use <function>sd_pid_get_user_unit()</function> for - that.) The returned string needs to be freed with the libc - <citerefentry + determine the systemd system unit (i.e. system service or scope + unit) identifier of a process identified by the specified PID. The + unit name is a short string, suitable for usage in file system + paths. Note that not all processes are part of a system + unit/service (e.g. user processes, or kernel threads). For + processes not being part of a systemd system unit this function + will fail with -ENXIO (More specifically: this call will not work + for kernel threads.) The returned string needs to be freed with + the libc <citerefentry project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry> call after use.</para> <para><function>sd_pid_get_user_unit()</function> may be used to - determine the systemd user unit (i.e. user service) identifier of - a process identified by the specified PID. This is similar to - <function>sd_pid_get_unit()</function> but applies to user units - instead of system units.</para> + determine the systemd user unit (i.e. user service or scope unit) + identifier of a process identified by the specified PID. This is + similar to <function>sd_pid_get_unit()</function> but applies to + user units instead of system units.</para> <para><function>sd_pid_get_owner_uid()</function> may be used to - determine the Unix user identifier of the owner of the session of - a process identified the specified PID. Note that this function - will succeed for user processes which are shared between multiple - login sessions of the same user, where + determine the Unix UID (user identifier) of the owner of the + session of a process identified the specified PID. Note that this + function will succeed for user processes which are shared between + multiple login sessions of the same user, where <function>sd_pid_get_session()</function> will fail. For processes not being part of a login session and not being a shared process of a user this function will fail with -ENXIO.</para> @@ -200,6 +213,10 @@ <citerefentry project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry> call after use.</para> + <para>Similar, <function>sd_pid_get_user_slice()</function> + returns the user slice (as managed by the user's systemd instance) + of a process.</para> + <para>If the <varname>pid</varname> parameter of any of these functions is passed as 0, the operation is executed for the calling process.</para> @@ -208,10 +225,14 @@ <function>sd_peer_get_unit()</function>, <function>sd_peer_get_user_unit()</function>, <function>sd_peer_get_owner_uid()</function>, - <function>sd_peer_get_machine_name()</function> and - <function>sd_peer_get_slice()</function> calls operate similar to - their PID counterparts, but operate on a connected AF_UNIX socket - and retrieve information about the connected peer process.</para> + <function>sd_peer_get_machine_name()</function>, + <function>sd_peer_get_slice()</function> and + <function>sd_peer_get_user_slice()</function> calls operate + similar to their PID counterparts, but operate on a connected + AF_UNIX socket and retrieve information about the connected peer + process. Note that these fields are retrieved via + <filename>/proc</filename>, and hence are not suitable for + authorization purposes, as they are subject to races.</para> </refsect1> <refsect1> @@ -262,15 +283,17 @@ <function>sd_pid_get_owner_uid()</function>, <function>sd_pid_get_machine_name()</function>, <function>sd_pid_get_slice()</function>, + <function>sd_pid_get_user_slice()</function>, <function>sd_peer_get_session()</function>, <function>sd_peer_get_unit()</function>, <function>sd_peer_get_user_unit()</function>, <function>sd_peer_get_owner_uid()</function>, - <function>sd_peer_get_machine_name()</function> and - <function>sd_peer_get_slice()</function> interfaces are - available as a shared library, which can be compiled - and linked to with the - <constant>libsystemd</constant> <citerefentry project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry> + <function>sd_peer_get_machine_name()</function>, + <function>sd_peer_get_slice()</function> and + <function>sd_peer_get_user_slice()</function> interfaces are + available as a shared library, which can be compiled and linked to + with the <constant>libsystemd</constant> <citerefentry + project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry> file.</para> <para>Note that the login session identifier as diff --git a/man/systemd.journal-fields.xml b/man/systemd.journal-fields.xml index a101006a7e..afe1200d7e 100644 --- a/man/systemd.journal-fields.xml +++ b/man/systemd.journal-fields.xml @@ -440,7 +440,6 @@ </varlistentry> </variablelist> - </refsect1> <refsect1> diff --git a/src/basic/path-util.c b/src/basic/path-util.c index 537705446a..8f49d65266 100644 --- a/src/basic/path-util.c +++ b/src/basic/path-util.c @@ -528,7 +528,7 @@ int fd_is_mount_point(int fd, const char *filename, int flags) { * * If that didn't work we will try to read the mount id from * /proc/self/fdinfo/<fd>. This is almost as good as - * name_to_handle_at(), however, does not return the the + * name_to_handle_at(), however, does not return the * opaque file handle. The opaque file handle is pretty useful * to detect the root directory, which we should always * consider a mount point. Hence we use this only as diff --git a/src/basic/process-util.c b/src/basic/process-util.c index cfc876567d..2c05f2fee4 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -329,6 +329,9 @@ int get_process_environ(pid_t pid, char **env) { sz += cescape_char(c, outcome + sz); } + if (sz == 0) + return -ENOENT; + outcome[sz] = '\0'; *env = outcome; outcome = NULL; diff --git a/src/core/job.c b/src/core/job.c index 8a047df0c3..1448e5b69a 100644 --- a/src/core/job.c +++ b/src/core/job.c @@ -452,7 +452,7 @@ static bool job_is_runnable(Job *j) { j->type == JOB_RELOAD) { /* Immediate result is that the job is or might be - * started. In this case lets wait for the + * started. In this case let's wait for the * dependencies, regardless whether they are * starting or stopping something. */ @@ -462,7 +462,7 @@ static bool job_is_runnable(Job *j) { } /* Also, if something else is being stopped and we should - * change state after it, then lets wait. */ + * change state after it, then let's wait. */ SET_FOREACH(other, j->unit->dependencies[UNIT_BEFORE], i) if (other->job && diff --git a/src/core/service.c b/src/core/service.c index fa1e80b710..d72ff54daa 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -1235,7 +1235,7 @@ static int main_pid_good(Service *s) { /* Returns 0 if the pid is dead, 1 if it is good, -1 if we * don't know */ - /* If we know the pid file, then lets just check if it is + /* If we know the pid file, then let's just check if it is * still valid */ if (s->main_pid_known) { diff --git a/src/journal-remote/journal-gatewayd.c b/src/journal-remote/journal-gatewayd.c index d9450ae8cd..9a09f401e0 100644 --- a/src/journal-remote/journal-gatewayd.c +++ b/src/journal-remote/journal-gatewayd.c @@ -132,7 +132,7 @@ static int request_meta_ensure_tmp(RequestMeta *m) { if (fd < 0) return fd; - m->tmp = fdopen(fd, "rw"); + m->tmp = fdopen(fd, "w+"); if (!m->tmp) { safe_close(fd); return -errno; diff --git a/src/libsystemd-terminal/grdev-drm.c b/src/libsystemd-terminal/grdev-drm.c index 30c1a726eb..10c13e348a 100644 --- a/src/libsystemd-terminal/grdev-drm.c +++ b/src/libsystemd-terminal/grdev-drm.c @@ -2584,7 +2584,7 @@ static int unmanaged_card_new(grdev_card **out, grdev_session *session, struct u } else { /* We might get DRM-Master implicitly on open(); drop it immediately * so we acquire it only once we're actually enabled. We don't - * really care whether this call fails or not, but lets log any + * really care whether this call fails or not, but let's log any * weird errors, anyway. */ r = ioctl(fd, DRM_IOCTL_DROP_MASTER, 0); if (r < 0 && errno != EACCES && errno != EINVAL) @@ -2777,7 +2777,7 @@ static int managed_card_resume_device_fn(sd_bus_message *signal, if (cm->card.fd < 0) { /* This shouldn't happen. We should already own an FD from - * TakeDevice(). However, lets be safe and use this FD in case + * TakeDevice(). However, let's be safe and use this FD in case * we really don't have one. There is no harm in doing this * and our code works fine this way. */ fd = fcntl(fd, F_DUPFD_CLOEXEC, 3); diff --git a/src/libsystemd/sd-bus/GVARIANT-SERIALIZATION b/src/libsystemd/sd-bus/GVARIANT-SERIALIZATION index 859e2715f9..6aeb11364a 100644 --- a/src/libsystemd/sd-bus/GVARIANT-SERIALIZATION +++ b/src/libsystemd/sd-bus/GVARIANT-SERIALIZATION @@ -25,8 +25,8 @@ The header consists of the following: = 12 bytes -This header is then followed by the the fields array, whose first -value is a 32bit array size. +This header is then followed by the fields array, whose first value is +a 32bit array size. When using GVariant we keep the basic structure in place, only slightly alter the header, and define protocol version '2'. The new diff --git a/src/libsystemd/sd-bus/bus-common-errors.h b/src/libsystemd/sd-bus/bus-common-errors.h index b17b62ac93..0dbfbddcf6 100644 --- a/src/libsystemd/sd-bus/bus-common-errors.h +++ b/src/libsystemd/sd-bus/bus-common-errors.h @@ -58,6 +58,7 @@ #define BUS_ERROR_DEVICE_NOT_TAKEN "org.freedesktop.login1.DeviceNotTaken" #define BUS_ERROR_OPERATION_IN_PROGRESS "org.freedesktop.login1.OperationInProgress" #define BUS_ERROR_SLEEP_VERB_NOT_SUPPORTED "org.freedesktop.login1.SleepVerbNotSupported" +#define BUS_ERROR_SESSION_BUSY "org.freedesktop.login1.SessionBusy" #define BUS_ERROR_AUTOMATIC_TIME_SYNC_ENABLED "org.freedesktop.timedate1.AutomaticTimeSyncEnabled" diff --git a/src/login/logind-core.c b/src/login/logind-core.c index a6c01f7d85..96a20e27b9 100644 --- a/src/login/logind-core.c +++ b/src/login/logind-core.c @@ -317,7 +317,6 @@ int manager_get_session_by_pid(Manager *m, pid_t pid, Session **session) { int r; assert(m); - assert(session); if (pid < 1) return -EINVAL; @@ -330,7 +329,8 @@ int manager_get_session_by_pid(Manager *m, pid_t pid, Session **session) { if (!s) return 0; - *session = s; + if (session) + *session = s; return 1; } diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index b56a61cda4..cd9cab7334 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -689,47 +689,23 @@ static int method_create_session(sd_bus_message *message, void *userdata, sd_bus return r; } - manager_get_session_by_pid(m, leader, &session); - if (!session && vtnr > 0) - session = (vtnr < m->seat0->position_count) ? m->seat0->positions[vtnr] : NULL; - if (session) { - _cleanup_free_ char *path = NULL; - _cleanup_close_ int fifo_fd = -1; - - /* Session already exists, client is probably - * something like "su" which changes uid but is still - * the same session */ - - fifo_fd = session_create_fifo(session); - if (fifo_fd < 0) - return fifo_fd; - - path = session_bus_path(session); - if (!path) - return -ENOMEM; - - log_debug("Sending reply about an existing session: " - "id=%s object_path=%s uid=%u runtime_path=%s " - "session_fd=%d seat=%s vtnr=%u", - session->id, - path, - (uint32_t) session->user->uid, - session->user->runtime_path, - fifo_fd, - session->seat ? session->seat->id : "", - (uint32_t) session->vtnr); - - return sd_bus_reply_method_return( - message, "soshusub", - session->id, - path, - session->user->runtime_path, - fifo_fd, - (uint32_t) session->user->uid, - session->seat ? session->seat->id : "", - (uint32_t) session->vtnr, - true); - } + r = manager_get_session_by_pid(m, leader, NULL); + if (r > 0) + return sd_bus_error_setf(error, BUS_ERROR_SESSION_BUSY, "Already running in a session"); + + /* + * Old gdm and lightdm start the user-session on the same VT as + * the greeter session. But they destroy the greeter session + * after the user-session and want the user-session to take + * over the VT. We need to support this for + * backwards-compatibility, so make sure we allow new sessions + * on a VT that a greeter is running on. + */ + if (vtnr > 0 && + vtnr < m->seat0->position_count && + m->seat0->positions[vtnr] && + m->seat0->positions[vtnr]->class != SESSION_GREETER) + return sd_bus_error_setf(error, BUS_ERROR_SESSION_BUSY, "Already occupied by a session"); audit_session_from_pid(leader, &audit_id); if (audit_id > 0) { diff --git a/src/login/logind-seat.c b/src/login/logind-seat.c index 3c30eeaa95..fb5d076311 100644 --- a/src/login/logind-seat.c +++ b/src/login/logind-seat.c @@ -269,7 +269,7 @@ int seat_set_active(Seat *s, Session *session) { int seat_switch_to(Seat *s, unsigned int num) { /* Public session positions skip 0 (there is only F1-F12). Maybe it * will get reassigned in the future, so return error for now. */ - if (!num) + if (num == 0) return -EINVAL; if (num >= s->position_count || !s->positions[num]) { @@ -286,7 +286,7 @@ int seat_switch_to(Seat *s, unsigned int num) { int seat_switch_to_next(Seat *s) { unsigned int start, i; - if (!s->position_count) + if (s->position_count == 0) return -EINVAL; start = 1; @@ -307,7 +307,7 @@ int seat_switch_to_next(Seat *s) { int seat_switch_to_previous(Seat *s) { unsigned int start, i; - if (!s->position_count) + if (s->position_count == 0) return -EINVAL; start = 1; @@ -476,14 +476,14 @@ void seat_evict_position(Seat *s, Session *session) { session->pos = 0; - if (!pos) + if (pos == 0) return; if (pos < s->position_count && s->positions[pos] == session) { s->positions[pos] = NULL; /* There might be another session claiming the same - * position (eg., during gdm->session transition), so lets look + * position (eg., during gdm->session transition), so let's look * for it and set it on the free slot. */ LIST_FOREACH(sessions_by_seat, iter, s->sessions) { if (iter->pos == pos) { diff --git a/src/login/pam_systemd.c b/src/login/pam_systemd.c index 2f390237dc..f83d18b035 100644 --- a/src/login/pam_systemd.c +++ b/src/login/pam_systemd.c @@ -31,6 +31,7 @@ #include <security/pam_ext.h> #include <security/pam_misc.h> +#include "bus-common-errors.h" #include "util.h" #include "audit.h" #include "macro.h" @@ -399,8 +400,13 @@ _public_ PAM_EXTERN int pam_sm_open_session( remote_host, 0); if (r < 0) { - pam_syslog(handle, LOG_ERR, "Failed to create session: %s", bus_error_message(&error, r)); - return PAM_SYSTEM_ERR; + if (sd_bus_error_has_name(&error, BUS_ERROR_SESSION_BUSY)) { + pam_syslog(handle, LOG_DEBUG, "Cannot create session: %s", bus_error_message(&error, r)); + return PAM_SUCCESS; + } else { + pam_syslog(handle, LOG_ERR, "Failed to create session: %s", bus_error_message(&error, r)); + return PAM_SYSTEM_ERR; + } } r = sd_bus_message_read(reply, diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index d749eb49b6..3428109da4 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -756,9 +756,8 @@ static int parse_argv(int argc, char *argv[]) { /* If two parameters are specified, * the first one is the lower, the * second one the upper directory. And - * we'll also define the the - * destination mount point the same as - * the upper. */ + * we'll also define the destination + * mount point the same as the upper. */ upper = lower[1]; lower[1] = NULL; diff --git a/src/python-systemd/.gitignore b/src/python-systemd/.gitignore deleted file mode 100644 index 4124b7affd..0000000000 --- a/src/python-systemd/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/id128-constants.h -*.py[oc] diff --git a/src/python-systemd/Makefile b/src/python-systemd/Makefile deleted file mode 120000 index d0b0e8e008..0000000000 --- a/src/python-systemd/Makefile +++ /dev/null @@ -1 +0,0 @@ -../Makefile
\ No newline at end of file diff --git a/src/python-systemd/__init__.py b/src/python-systemd/__init__.py deleted file mode 100644 index 0d56b992f4..0000000000 --- a/src/python-systemd/__init__.py +++ /dev/null @@ -1,18 +0,0 @@ -# -*- Mode: python; indent-tabs-mode: nil -*- */ -# -# This file is part of systemd. -# -# Copyright 2012 David Strauss -# -# systemd is free software; you can redistribute it and/or modify it -# under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation; either version 2.1 of the License, or -# (at your option) any later version. -# -# systemd is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with systemd; If not, see <http://www.gnu.org/licenses/>. diff --git a/src/python-systemd/_daemon.c b/src/python-systemd/_daemon.c deleted file mode 100644 index 7c5f1b2bb6..0000000000 --- a/src/python-systemd/_daemon.c +++ /dev/null @@ -1,331 +0,0 @@ -/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ - -/*** - This file is part of systemd. - - Copyright 2013 Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. -***/ - -#define PY_SSIZE_T_CLEAN -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wredundant-decls" -#include <Python.h> -#pragma GCC diagnostic pop - -#include <stdbool.h> -#include <assert.h> -#include <sys/socket.h> - -#include "systemd/sd-daemon.h" -#include "pyutil.h" -#include "macro.h" - -PyDoc_STRVAR(module__doc__, - "Python interface to the libsystemd-daemon library.\n\n" - "Provides _listen_fds, notify, booted, and is_* functions\n" - "which wrap sd_listen_fds, sd_notify, sd_booted, sd_is_* and\n" - "useful for socket activation and checking if the system is\n" - "running under systemd." -); - -PyDoc_STRVAR(booted__doc__, - "booted() -> bool\n\n" - "Return True iff this system is running under systemd.\n" - "Wraps sd_daemon_booted(3)." -); - -static PyObject* booted(PyObject *self, PyObject *args) { - int r; - assert(args == NULL); - - r = sd_booted(); - if (set_error(r, NULL, NULL) < 0) - return NULL; - - return PyBool_FromLong(r); -} - -PyDoc_STRVAR(notify__doc__, - "notify(status, unset_environment=False) -> bool\n\n" - "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) { - int r; - const char* msg; - int unset = false; - - static const char* const kwlist[] = { - "status", - "unset_environment", - NULL, - }; -#if PY_MAJOR_VERSION >=3 && PY_MINOR_VERSION >= 3 - if (!PyArg_ParseTupleAndKeywords(args, keywds, "s|p:notify", - (char**) kwlist, &msg, &unset)) - return NULL; -#else - PyObject *obj = NULL; - if (!PyArg_ParseTupleAndKeywords(args, keywds, "s|O:notify", - (char**) kwlist, &msg, &obj)) - return NULL; - if (obj != NULL) - unset = PyObject_IsTrue(obj); - if (unset < 0) - return NULL; -#endif - - r = sd_notify(unset, msg); - if (set_error(r, NULL, NULL) < 0) - return NULL; - - return PyBool_FromLong(r); -} - - -PyDoc_STRVAR(listen_fds__doc__, - "_listen_fds(unset_environment=True) -> int\n\n" - "Return the number of descriptors passed to this process by the init system\n" - "as part of the socket-based activation logic.\n" - "Wraps sd_listen_fds(3)." -); - -static PyObject* listen_fds(PyObject *self, 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 != NULL) - 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); -} - -PyDoc_STRVAR(is_fifo__doc__, - "_is_fifo(fd, path) -> bool\n\n" - "Returns True iff the descriptor refers to a FIFO or a pipe.\n" - "Wraps sd_is_fifo(3)." -); - - -static PyObject* is_fifo(PyObject *self, PyObject *args) { - int r; - int fd; - const char *path = NULL; - -#if PY_MAJOR_VERSION >=3 && PY_MINOR_VERSION >= 1 - if (!PyArg_ParseTuple(args, "i|O&:_is_fifo", - &fd, Unicode_FSConverter, &path)) - return NULL; -#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) - return NULL; - - return PyBool_FromLong(r); -} - - -PyDoc_STRVAR(is_mq__doc__, - "_is_mq(fd, path) -> bool\n\n" - "Returns True iff the descriptor refers to a POSIX message queue.\n" - "Wraps sd_is_mq(3)." -); - -static PyObject* is_mq(PyObject *self, PyObject *args) { - int r; - int fd; - const char *path = NULL; - -#if PY_MAJOR_VERSION >=3 && PY_MINOR_VERSION >= 1 - if (!PyArg_ParseTuple(args, "i|O&:_is_mq", - &fd, Unicode_FSConverter, &path)) - return NULL; -#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) - return NULL; - - return PyBool_FromLong(r); -} - - - -PyDoc_STRVAR(is_socket__doc__, - "_is_socket(fd, family=AF_UNSPEC, type=0, listening=-1) -> bool\n\n" - "Returns True iff the descriptor refers to a socket.\n" - "Wraps sd_is_socket(3).\n\n" - "Constants for `family` are defined in the socket module." -); - -static PyObject* is_socket(PyObject *self, PyObject *args) { - int r; - int fd, family = AF_UNSPEC, type = 0, listening = -1; - - if (!PyArg_ParseTuple(args, "i|iii:_is_socket", - &fd, &family, &type, &listening)) - return NULL; - - r = sd_is_socket(fd, family, type, listening); - if (set_error(r, NULL, NULL) < 0) - return NULL; - - return PyBool_FromLong(r); -} - - -PyDoc_STRVAR(is_socket_inet__doc__, - "_is_socket_inet(fd, family=AF_UNSPEC, type=0, listening=-1, port=0) -> bool\n\n" - "Wraps sd_is_socket_inet(3).\n\n" - "Constants for `family` are defined in the socket module." -); - -static PyObject* is_socket_inet(PyObject *self, PyObject *args) { - int r; - int fd, family = AF_UNSPEC, type = 0, listening = -1, port = 0; - - if (!PyArg_ParseTuple(args, "i|iiii:_is_socket_inet", - &fd, &family, &type, &listening, &port)) - return NULL; - - if (port < 0 || port > UINT16_MAX) { - set_error(-EINVAL, NULL, "port must fit into uint16_t"); - return NULL; - } - - r = sd_is_socket_inet(fd, family, type, listening, (uint16_t) port); - if (set_error(r, NULL, NULL) < 0) - return NULL; - - return PyBool_FromLong(r); -} - - -PyDoc_STRVAR(is_socket_unix__doc__, - "_is_socket_unix(fd, type, listening, path) -> bool\n\n" - "Wraps sd_is_socket_unix(3)." -); - -static PyObject* is_socket_unix(PyObject *self, 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)) - return NULL; - if (_path) { - assert(PyBytes_Check(_path)); - 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) - return NULL; - - return PyBool_FromLong(r); -} - - -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__}, - { "_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_unix", is_socket_unix, METH_VARARGS, is_socket_unix__doc__}, - { NULL, NULL, 0, NULL } /* 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 == NULL) - 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, - "_daemon", /* name of module */ - module__doc__, /* module documentation, may be NULL */ - 0, /* size of per-interpreter state of the module */ - methods -}; - -DISABLE_WARNING_MISSING_PROTOTYPES; -PyMODINIT_FUNC PyInit__daemon(void) { - PyObject *m; - - m = PyModule_Create(&module); - if (m == NULL) - return NULL; - - if (PyModule_AddIntConstant(m, "LISTEN_FDS_START", SD_LISTEN_FDS_START) || - PyModule_AddStringConstant(m, "__version__", PACKAGE_VERSION)) { - Py_DECREF(m); - return NULL; - } - - return m; -} -REENABLE_WARNING; - -#endif diff --git a/src/python-systemd/_journal.c b/src/python-systemd/_journal.c deleted file mode 100644 index 456e4a2796..0000000000 --- a/src/python-systemd/_journal.c +++ /dev/null @@ -1,157 +0,0 @@ -/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ - -/*** - This file is part of systemd. - - Copyright 2012 David Strauss <david@davidstrauss.net> - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. -***/ - -#include <Python.h> - -#include <alloca.h> -#include "util.h" - -#define SD_JOURNAL_SUPPRESS_LOCATION -#include "systemd/sd-journal.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; - PyObject *ret = NULL; - PyObject **encoded; - - /* Allocate an array for the argument strings */ - argc = PyTuple_Size(args); - encoded = alloca0(argc * sizeof(PyObject*)); - - /* Allocate sufficient iovector space for the arguments. */ - iov = alloca(argc * sizeof(struct iovec)); - - /* Iterate through the Python arguments and fill the iovector. */ - for (i = 0; i < argc; ++i) { - PyObject *item = PyTuple_GetItem(args, i); - char *stritem; - Py_ssize_t length; - - if (PyUnicode_Check(item)) { - encoded[i] = PyUnicode_AsEncodedString(item, "utf-8", "strict"); - if (encoded[i] == NULL) - goto out; - item = encoded[i]; - } - if (PyBytes_AsStringAndSize(item, &stritem, &length)) - goto out; - - iov[i].iov_base = stritem; - iov[i].iov_len = length; - } - - /* Send the iovector to the journal. */ - r = sd_journal_sendv(iov, argc); - if (r < 0) { - errno = -r; - PyErr_SetFromErrno(PyExc_IOError); - goto out; - } - - /* End with success. */ - Py_INCREF(Py_None); - ret = Py_None; - -out: - for (i = 0; i < argc; ++i) - Py_XDECREF(encoded[i]); - - return ret; -} - -PyDoc_STRVAR(journal_stream_fd__doc__, - "stream_fd(identifier, priority, level_prefix) -> fd\n\n" - "Open a stream to journal by calling sd_journal_stream_fd(3)." -); - -static PyObject* journal_stream_fd(PyObject *self, PyObject *args) { - const char* identifier; - int priority, level_prefix; - int fd; - - if (!PyArg_ParseTuple(args, "sii:stream_fd", - &identifier, &priority, &level_prefix)) - return NULL; - - fd = sd_journal_stream_fd(identifier, priority, level_prefix); - if (fd < 0) { - errno = -fd; - return PyErr_SetFromErrno(PyExc_IOError); - } - - return PyLong_FromLong(fd); -} - -static PyMethodDef methods[] = { - { "sendv", journal_sendv, METH_VARARGS, journal_sendv__doc__ }, - { "stream_fd", journal_stream_fd, METH_VARARGS, journal_stream_fd__doc__ }, - { NULL, NULL, 0, NULL } /* Sentinel */ -}; - -#if PY_MAJOR_VERSION < 3 - -DISABLE_WARNING_MISSING_PROTOTYPES; -PyMODINIT_FUNC init_journal(void) { - PyObject *m; - - m = Py_InitModule("_journal", methods); - if (m == NULL) - return; - - PyModule_AddStringConstant(m, "__version__", PACKAGE_VERSION); -} -REENABLE_WARNING; - -#else - -static struct PyModuleDef module = { - PyModuleDef_HEAD_INIT, - "_journal", /* name of module */ - NULL, /* module documentation, may be NULL */ - -1, /* size of per-interpreter state of the module */ - methods -}; - -DISABLE_WARNING_MISSING_PROTOTYPES; -PyMODINIT_FUNC PyInit__journal(void) { - PyObject *m; - - m = PyModule_Create(&module); - if (m == NULL) - return NULL; - - if (PyModule_AddStringConstant(m, "__version__", PACKAGE_VERSION)) { - Py_DECREF(m); - return NULL; - } - - return m; -} -REENABLE_WARNING; - -#endif diff --git a/src/python-systemd/_reader.c b/src/python-systemd/_reader.c deleted file mode 100644 index 3a561269a7..0000000000 --- a/src/python-systemd/_reader.c +++ /dev/null @@ -1,1106 +0,0 @@ -/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ - -/*** - This file is part of systemd. - - Copyright 2013 Steven Hiscocks, Zbigniew Jędrzejewski-Szmek - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. -***/ - -#include <Python.h> -#include <structmember.h> -#include <datetime.h> -#include <time.h> -#include <stdio.h> - -#include "systemd/sd-journal.h" - -#include "pyutil.h" -#include "macro.h" -#include "util.h" -#include "strv.h" -#include "build.h" - -typedef struct { - PyObject_HEAD - sd_journal *j; -} Reader; -static PyTypeObject ReaderType; - -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__, - "A tuple of (timestamp, bootid) for holding monotonic timestamps"); - -static PyStructSequence_Field MonotonicType_fields[] = { - {(char*) "timestamp", (char*) "Time"}, - {(char*) "bootid", (char*) "Unique identifier of the boot"}, - {} /* Sentinel */ -}; - -static PyStructSequence_Desc Monotonic_desc = { - (char*) "journal.Monotonic", - MonotonicType__doc__, - MonotonicType_fields, - 2, -}; -#endif - -/** - * Convert a Python sequence object into a strv (char**), and - * None into a NULL pointer. - */ -static int strv_converter(PyObject* obj, void *_result) { - char ***result = _result; - Py_ssize_t i, len; - - assert(result); - - if (!obj) - return 0; - - if (obj == Py_None) { - *result = NULL; - return 1; - } - - if (!PySequence_Check(obj)) - return 0; - - len = PySequence_Length(obj); - *result = new0(char*, len + 1); - if (!*result) { - set_error(-ENOMEM, NULL, NULL); - return 0; - } - - for (i = 0; i < len; i++) { - PyObject *item; -#if PY_MAJOR_VERSION >=3 && PY_MINOR_VERSION >= 1 - int r; - PyObject *bytes; -#endif - char *s, *s2; - - item = PySequence_ITEM(obj, i); -#if PY_MAJOR_VERSION >=3 && PY_MINOR_VERSION >= 1 - r = PyUnicode_FSConverter(item, &bytes); - if (r == 0) - goto cleanup; - - s = PyBytes_AsString(bytes); -#else - s = PyString_AsString(item); -#endif - if (!s) - goto cleanup; - - s2 = strdup(s); - if (!s2) - log_oom(); - - (*result)[i] = s2; - } - - return 1; - -cleanup: - strv_free(*result); - *result = NULL; - - return 0; -} - -static void Reader_dealloc(Reader* self) { - sd_journal_close(self->j); - Py_TYPE(self)->tp_free((PyObject*)self); -} - -PyDoc_STRVAR(Reader__doc__, - "_Reader([flags | path | files]) -> ...\n\n" - "_Reader allows filtering and retrieval of Journal entries.\n" - "Note: this is a low-level interface, and probably not what you\n" - "want, use systemd.journal.Reader instead.\n\n" - "Argument `flags` sets open flags of the journal, which can be one\n" - "of, or ORed combination of constants: LOCAL_ONLY (default) opens\n" - "journal on local machine only; RUNTIME_ONLY opens only\n" - "volatile journal files; and SYSTEM opens journal files of\n" - "system services and the kernel, and CURRENT_USER opens files\n" - "of the current user.\n\n" - "Argument `path` is the directory of journal files.\n" - "Argument `files` is a list of files. Note that\n" - "`flags`, `path`, and `files` are exclusive.\n\n" - "_Reader implements the context manager protocol: the journal\n" - "will be closed when exiting the block."); -static int Reader_init(Reader *self, PyObject *args, PyObject *keywds) { - int flags = 0, r; - char *path = NULL; - char **files = NULL; - - static const char* const kwlist[] = {"flags", "path", "files", NULL}; - if (!PyArg_ParseTupleAndKeywords(args, keywds, "|izO&:__init__", (char**) kwlist, - &flags, &path, strv_converter, &files)) - return -1; - - if (!!flags + !!path + !!files > 1) { - PyErr_SetString(PyExc_ValueError, "cannot use more than one of flags, path, and files"); - return -1; - } - - if (!flags) - flags = SD_JOURNAL_LOCAL_ONLY; - - Py_BEGIN_ALLOW_THREADS - if (path) - r = sd_journal_open_directory(&self->j, path, 0); - else if (files) - r = sd_journal_open_files(&self->j, (const char**) files, 0); - else - r = sd_journal_open(&self->j, flags); - Py_END_ALLOW_THREADS - - return set_error(r, path, "Invalid flags or path"); -} - -PyDoc_STRVAR(Reader_fileno__doc__, - "fileno() -> int\n\n" - "Get a file descriptor to poll for changes in the journal.\n" - "This method invokes sd_journal_get_fd().\n" - "See man:sd_journal_get_fd(3)."); -static PyObject* Reader_fileno(Reader *self, PyObject *args) { - int fd; - - fd = sd_journal_get_fd(self->j); - set_error(fd, NULL, NULL); - if (fd < 0) - return NULL; - return long_FromLong(fd); -} - -PyDoc_STRVAR(Reader_reliable_fd__doc__, - "reliable_fd() -> bool\n\n" - "Returns True iff the journal can be polled reliably.\n" - "This method invokes sd_journal_reliable_fd().\n" - "See man:sd_journal_reliable_fd(3)."); -static PyObject* Reader_reliable_fd(Reader *self, PyObject *args) { - int r; - - r = sd_journal_reliable_fd(self->j); - if (set_error(r, NULL, NULL) < 0) - return NULL; - return PyBool_FromLong(r); -} - -PyDoc_STRVAR(Reader_get_events__doc__, - "get_events() -> int\n\n" - "Returns a mask of poll() events to wait for on the file\n" - "descriptor returned by .fileno().\n\n" - "See man:sd_journal_get_events(3) for further discussion."); -static PyObject* Reader_get_events(Reader *self, PyObject *args) { - int r; - - r = sd_journal_get_events(self->j); - if (set_error(r, NULL, NULL) < 0) - return NULL; - return long_FromLong(r); -} - -PyDoc_STRVAR(Reader_get_timeout__doc__, - "get_timeout() -> int or None\n\n" - "Returns a timeout value for usage in poll(), the time since the\n" - "epoch of clock_gettime(2) in microseconds, or None if no timeout\n" - "is necessary.\n\n" - "The return value must be converted to a relative timeout in\n" - "milliseconds if it is to be used as an argument for poll().\n" - "See man:sd_journal_get_timeout(3) for further discussion."); -static PyObject* Reader_get_timeout(Reader *self, PyObject *args) { - int r; - uint64_t t; - - r = sd_journal_get_timeout(self->j, &t); - if (set_error(r, NULL, NULL) < 0) - return NULL; - - if (t == (uint64_t) -1) - Py_RETURN_NONE; - - assert_cc(sizeof(unsigned long long) == sizeof(t)); - return PyLong_FromUnsignedLongLong(t); -} - -PyDoc_STRVAR(Reader_get_timeout_ms__doc__, - "get_timeout_ms() -> int\n\n" - "Returns a timeout value suitable for usage in poll(), the value\n" - "returned by .get_timeout() converted to relative ms, or -1 if\n" - "no timeout is necessary."); -static PyObject* Reader_get_timeout_ms(Reader *self, PyObject *args) { - int r; - uint64_t t; - - r = sd_journal_get_timeout(self->j, &t); - if (set_error(r, NULL, NULL) < 0) - return NULL; - - return absolute_timeout(t); -} - -PyDoc_STRVAR(Reader_close__doc__, - "close() -> None\n\n" - "Free resources allocated by this Reader object.\n" - "This method invokes sd_journal_close().\n" - "See man:sd_journal_close(3)."); -static PyObject* Reader_close(Reader *self, PyObject *args) { - assert(self); - assert(!args); - - sd_journal_close(self->j); - self->j = NULL; - Py_RETURN_NONE; -} - -PyDoc_STRVAR(Reader_get_usage__doc__, - "get_usage() -> int\n\n" - "Returns the total disk space currently used by journal\n" - "files (in bytes). If `SD_JOURNAL_LOCAL_ONLY` was\n" - "passed when opening the journal this value will only reflect\n" - "the size of journal files of the local host, otherwise\n" - "of all hosts.\n\n" - "This method invokes sd_journal_get_usage().\n" - "See man:sd_journal_get_usage(3)."); -static PyObject* Reader_get_usage(Reader *self, PyObject *args) { - int r; - uint64_t bytes; - - r = sd_journal_get_usage(self->j, &bytes); - if (set_error(r, NULL, NULL) < 0) - return NULL; - - assert_cc(sizeof(unsigned long long) == sizeof(bytes)); - return PyLong_FromUnsignedLongLong(bytes); -} - -PyDoc_STRVAR(Reader___enter____doc__, - "__enter__() -> self\n\n" - "Part of the context manager protocol.\n" - "Returns self.\n"); -static PyObject* Reader___enter__(PyObject *self, PyObject *args) { - assert(self); - assert(!args); - - Py_INCREF(self); - return self; -} - -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) { - return Reader_close(self, NULL); -} - -PyDoc_STRVAR(Reader_next__doc__, - "next([skip]) -> bool\n\n" - "Go to the next log entry. Optional skip value means to go to\n" - "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; - int r; - - if (!PyArg_ParseTuple(args, "|L:next", &skip)) - return NULL; - - if (skip == 0LL) { - 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); - else - assert_not_reached("should not be here"); - Py_END_ALLOW_THREADS - - if (set_error(r, NULL, NULL) < 0) - return NULL; - return PyBool_FromLong(r); -} - -PyDoc_STRVAR(Reader_previous__doc__, - "previous([skip]) -> bool\n\n" - "Go to the previous log entry. Optional skip value means to \n" - "go to the `skip`\\-th previous log entry.\n" - "Returns False if at start of file, True otherwise."); -static PyObject* Reader_previous(Reader *self, PyObject *args) { - int64_t skip = 1LL; - if (!PyArg_ParseTuple(args, "|L:previous", &skip)) - return NULL; - - return PyObject_CallMethod((PyObject *)self, (char*) "_next", - (char*) "L", -skip); -} - -static int extract(const char* msg, size_t msg_len, - PyObject **key, PyObject **value) { - PyObject *k = NULL, *v; - const char *delim_ptr; - - delim_ptr = memchr(msg, '=', msg_len); - if (!delim_ptr) { - PyErr_SetString(PyExc_OSError, - "journal gave us a field without '='"); - return -1; - } - - if (key) { - k = unicode_FromStringAndSize(msg, delim_ptr - (const char*) msg); - if (!k) - return -1; - } - - if (value) { - v = PyBytes_FromStringAndSize(delim_ptr + 1, - (const char*) msg + msg_len - (delim_ptr + 1)); - if (!v) { - Py_XDECREF(k); - return -1; - } - - *value = v; - } - - if (key) - *key = k; - - return 0; -} - -PyDoc_STRVAR(Reader_get__doc__, - "get(str) -> str\n\n" - "Return data associated with this key in current log entry.\n" - "Throws KeyError is the data is not available."); -static PyObject* Reader_get(Reader *self, PyObject *args) { - const char* field; - const void* msg; - size_t msg_len; - PyObject *value; - int r; - - assert(self); - assert(args); - - if (!PyArg_ParseTuple(args, "s:get", &field)) - return NULL; - - r = sd_journal_get_data(self->j, field, &msg, &msg_len); - if (r == -ENOENT) { - PyErr_SetString(PyExc_KeyError, field); - return NULL; - } - if (set_error(r, NULL, "field name is not valid") < 0) - return NULL; - - r = extract(msg, msg_len, NULL, &value); - if (r < 0) - return NULL; - return value; -} - -PyDoc_STRVAR(Reader_get_all__doc__, - "_get_all() -> dict\n\n" - "Return dictionary of the current log entry."); -static PyObject* Reader_get_all(Reader *self, PyObject *args) { - PyObject *dict; - const void *msg; - size_t msg_len; - int r; - - dict = PyDict_New(); - if (!dict) - return NULL; - - SD_JOURNAL_FOREACH_DATA(self->j, msg, msg_len) { - _cleanup_Py_DECREF_ PyObject *key = NULL, *value = NULL; - - r = extract(msg, msg_len, &key, &value); - if (r < 0) - goto error; - - if (PyDict_Contains(dict, key)) { - PyObject *cur_value = PyDict_GetItem(dict, key); - - if (PyList_CheckExact(cur_value)) { - r = PyList_Append(cur_value, value); - if (r < 0) - goto error; - } else { - _cleanup_Py_DECREF_ PyObject *tmp_list = PyList_New(0); - if (!tmp_list) - goto error; - - r = PyList_Append(tmp_list, cur_value); - if (r < 0) - goto error; - - r = PyList_Append(tmp_list, value); - if (r < 0) - goto error; - - r = PyDict_SetItem(dict, key, tmp_list); - if (r < 0) - goto error; - } - } else { - r = PyDict_SetItem(dict, key, value); - if (r < 0) - goto error; - } - } - - return dict; - -error: - Py_DECREF(dict); - return NULL; -} - -PyDoc_STRVAR(Reader_get_realtime__doc__, - "get_realtime() -> int\n\n" - "Return the realtime timestamp for the current journal entry\n" - "in microseconds.\n\n" - "Wraps sd_journal_get_realtime_usec().\n" - "See man:sd_journal_get_realtime_usec(3)."); -static PyObject* Reader_get_realtime(Reader *self, PyObject *args) { - uint64_t timestamp; - int r; - - assert(self); - assert(!args); - - r = sd_journal_get_realtime_usec(self->j, ×tamp); - if (set_error(r, NULL, NULL) < 0) - return NULL; - - assert_cc(sizeof(unsigned long long) == sizeof(timestamp)); - return PyLong_FromUnsignedLongLong(timestamp); -} - -PyDoc_STRVAR(Reader_get_monotonic__doc__, - "get_monotonic() -> (timestamp, bootid)\n\n" - "Return the monotonic timestamp for the current journal entry\n" - "as a tuple of time in microseconds and bootid.\n\n" - "Wraps sd_journal_get_monotonic_usec().\n" - "See man:sd_journal_get_monotonic_usec(3)."); -static PyObject* Reader_get_monotonic(Reader *self, PyObject *args) { - uint64_t timestamp; - sd_id128_t id; - PyObject *monotonic, *bootid, *tuple; - int r; - - assert(self); - assert(!args); - - r = sd_journal_get_monotonic_usec(self->j, ×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); - Py_XDECREF(tuple); - 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; -} - -PyDoc_STRVAR(Reader_add_match__doc__, - "add_match(match) -> None\n\n" - "Add a match to filter journal log entries. All matches of different\n" - "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) { - char *match; - int match_len, r; - if (!PyArg_ParseTuple(args, "s#:add_match", &match, &match_len)) - return NULL; - - r = sd_journal_add_match(self->j, match, match_len); - if (set_error(r, NULL, "Invalid match") < 0) - return NULL; - - Py_RETURN_NONE; -} - -PyDoc_STRVAR(Reader_add_disjunction__doc__, - "add_disjunction() -> None\n\n" - "Inserts a logical OR between matches added since previous\n" - "add_disjunction() or add_conjunction() and the next\n" - "add_disjunction() or add_conjunction().\n\n" - "See man: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); - if (set_error(r, NULL, NULL) < 0) - return NULL; - Py_RETURN_NONE; -} - -PyDoc_STRVAR(Reader_add_conjunction__doc__, - "add_conjunction() -> None\n\n" - "Inserts a logical AND between matches added since previous\n" - "add_disjunction() or add_conjunction() and the next\n" - "add_disjunction() or add_conjunction().\n\n" - "See man: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); - if (set_error(r, NULL, NULL) < 0) - return NULL; - Py_RETURN_NONE; -} - -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); - Py_RETURN_NONE; -} - -PyDoc_STRVAR(Reader_seek_head__doc__, - "seek_head() -> None\n\n" - "Jump to the beginning of the journal.\n" - "This method invokes sd_journal_seek_head().\n" - "See man:sd_journal_seek_head(3)."); -static PyObject* Reader_seek_head(Reader *self, PyObject *args) { - int r; - Py_BEGIN_ALLOW_THREADS - r = sd_journal_seek_head(self->j); - Py_END_ALLOW_THREADS - - if (set_error(r, NULL, NULL) < 0) - return NULL; - - Py_RETURN_NONE; -} - -PyDoc_STRVAR(Reader_seek_tail__doc__, - "seek_tail() -> None\n\n" - "Jump to the end of the journal.\n" - "This method invokes sd_journal_seek_tail().\n" - "See man:sd_journal_seek_tail(3)."); -static PyObject* Reader_seek_tail(Reader *self, PyObject *args) { - int r; - - Py_BEGIN_ALLOW_THREADS - r = sd_journal_seek_tail(self->j); - Py_END_ALLOW_THREADS - - if (set_error(r, NULL, NULL) < 0) - return NULL; - Py_RETURN_NONE; -} - -PyDoc_STRVAR(Reader_seek_realtime__doc__, - "seek_realtime(realtime) -> None\n\n" - "Seek to nearest matching journal entry to `realtime`. Argument\n" - "`realtime` in specified in seconds."); -static PyObject* Reader_seek_realtime(Reader *self, PyObject *args) { - uint64_t timestamp; - int r; - - if (!PyArg_ParseTuple(args, "K:seek_realtime", ×tamp)) - return NULL; - - Py_BEGIN_ALLOW_THREADS - r = sd_journal_seek_realtime_usec(self->j, timestamp); - Py_END_ALLOW_THREADS - - if (set_error(r, NULL, NULL) < 0) - return NULL; - - Py_RETURN_NONE; -} - -PyDoc_STRVAR(Reader_seek_monotonic__doc__, - "seek_monotonic(monotonic[, bootid]) -> None\n\n" - "Seek to nearest matching journal entry to `monotonic`. Argument\n" - "`monotonic` is an timestamp from boot in microseconds.\n" - "Argument `bootid` is a string representing which boot the\n" - "monotonic time is reference to. Defaults to current bootid."); -static PyObject* Reader_seek_monotonic(Reader *self, PyObject *args) { - char *bootid = NULL; - uint64_t timestamp; - sd_id128_t id; - int r; - - if (!PyArg_ParseTuple(args, "K|z:seek_monotonic", ×tamp, &bootid)) - return NULL; - - if (bootid) { - r = sd_id128_from_string(bootid, &id); - if (set_error(r, NULL, "Invalid bootid") < 0) - return NULL; - } else { - Py_BEGIN_ALLOW_THREADS - r = sd_id128_get_boot(&id); - Py_END_ALLOW_THREADS - - if (set_error(r, NULL, NULL) < 0) - return NULL; - } - - Py_BEGIN_ALLOW_THREADS - r = sd_journal_seek_monotonic_usec(self->j, id, timestamp); - Py_END_ALLOW_THREADS - - if (set_error(r, NULL, NULL) < 0) - return NULL; - - Py_RETURN_NONE; -} - - -PyDoc_STRVAR(Reader_process__doc__, - "process() -> state change (integer)\n\n" - "Process events and reset the readable state of the file\n" - "descriptor returned by .fileno().\n\n" - "Will return constants: NOP if no change; APPEND if new\n" - "entries have been added to the end of the journal; and\n" - "INVALIDATE if journal files have been added or removed.\n\n" - "See man:sd_journal_process(3) for further discussion."); -static PyObject* Reader_process(Reader *self, PyObject *args) { - int r; - - assert(!args); - - Py_BEGIN_ALLOW_THREADS - r = sd_journal_process(self->j); - Py_END_ALLOW_THREADS - if (set_error(r, NULL, NULL) < 0) - return NULL; - - return long_FromLong(r); -} - -PyDoc_STRVAR(Reader_wait__doc__, - "wait([timeout]) -> state change (integer)\n\n" - "Wait for a change in the journal. Argument `timeout` specifies\n" - "the maximum number of microseconds to wait before returning\n" - "regardless of wheter the journal has changed. If `timeout` is -1,\n" - "then block forever.\n\n" - "Will return constants: NOP if no change; APPEND if new\n" - "entries have been added to the end of the journal; and\n" - "INVALIDATE if journal files have been added or removed.\n\n" - "See man:sd_journal_wait(3) for further discussion."); -static PyObject* Reader_wait(Reader *self, PyObject *args) { - int r; - int64_t timeout; - - if (!PyArg_ParseTuple(args, "|L:wait", &timeout)) - return NULL; - - Py_BEGIN_ALLOW_THREADS - r = sd_journal_wait(self->j, timeout); - Py_END_ALLOW_THREADS - - if (set_error(r, NULL, NULL) < 0) - return NULL; - - return long_FromLong(r); -} - -PyDoc_STRVAR(Reader_seek_cursor__doc__, - "seek_cursor(cursor) -> None\n\n" - "Seek to journal entry by given unique reference `cursor`."); -static PyObject* Reader_seek_cursor(Reader *self, PyObject *args) { - const char *cursor; - int r; - - if (!PyArg_ParseTuple(args, "s:seek_cursor", &cursor)) - return NULL; - - Py_BEGIN_ALLOW_THREADS - r = sd_journal_seek_cursor(self->j, cursor); - Py_END_ALLOW_THREADS - - if (set_error(r, NULL, "Invalid cursor") < 0) - return NULL; - - Py_RETURN_NONE; -} - -PyDoc_STRVAR(Reader_get_cursor__doc__, - "get_cursor() -> str\n\n" - "Return a cursor string for the current journal entry.\n\n" - "Wraps sd_journal_get_cursor(). See man:sd_journal_get_cursor(3)."); -static PyObject* Reader_get_cursor(Reader *self, PyObject *args) { - _cleanup_free_ char *cursor = NULL; - int r; - - assert(self); - assert(!args); - - r = sd_journal_get_cursor(self->j, &cursor); - if (set_error(r, NULL, NULL) < 0) - return NULL; - - return unicode_FromString(cursor); -} - -PyDoc_STRVAR(Reader_test_cursor__doc__, - "test_cursor(str) -> bool\n\n" - "Test whether the cursor string matches current journal entry.\n\n" - "Wraps sd_journal_test_cursor(). See man:sd_journal_test_cursor(3)."); -static PyObject* Reader_test_cursor(Reader *self, PyObject *args) { - const char *cursor; - int r; - - assert(self); - assert(args); - - if (!PyArg_ParseTuple(args, "s:test_cursor", &cursor)) - return NULL; - - r = sd_journal_test_cursor(self->j, cursor); - if (set_error(r, NULL, NULL) < 0) - return NULL; - - return PyBool_FromLong(r); -} - -PyDoc_STRVAR(Reader_query_unique__doc__, - "query_unique(field) -> a set of values\n\n" - "Return a set of unique values appearing in journal for the\n" - "given `field`. Note this does not respect any journal matches."); -static PyObject* Reader_query_unique(Reader *self, PyObject *args) { - char *query; - int r; - const void *uniq; - size_t uniq_len; - PyObject *value_set, *key, *value; - - if (!PyArg_ParseTuple(args, "s:query_unique", &query)) - return NULL; - - Py_BEGIN_ALLOW_THREADS - r = sd_journal_query_unique(self->j, query); - Py_END_ALLOW_THREADS - - if (set_error(r, NULL, "Invalid field name") < 0) - return NULL; - - value_set = PySet_New(0); - key = unicode_FromString(query); - - SD_JOURNAL_FOREACH_UNIQUE(self->j, uniq, uniq_len) { - const char *delim_ptr; - - delim_ptr = memchr(uniq, '=', uniq_len); - value = PyBytes_FromStringAndSize( - delim_ptr + 1, - (const char*) uniq + uniq_len - (delim_ptr + 1)); - PySet_Add(value_set, value); - Py_DECREF(value); - } - - Py_DECREF(key); - return value_set; -} - -PyDoc_STRVAR(Reader_get_catalog__doc__, - "get_catalog() -> str\n\n" - "Retrieve a message catalog entry for the current journal entry.\n" - "Will throw IndexError if the entry has no MESSAGE_ID\n" - "and KeyError is the id is specified, but hasn't been found\n" - "in the catalog.\n\n" - "Wraps man:sd_journal_get_catalog(3)."); -static PyObject* Reader_get_catalog(Reader *self, PyObject *args) { - int r; - _cleanup_free_ char *msg = NULL; - - assert(self); - assert(!args); - - Py_BEGIN_ALLOW_THREADS - r = sd_journal_get_catalog(self->j, &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); - if (r == 0) { - const size_t l = sizeof("MESSAGE_ID"); - assert(mid_len > l); - PyErr_Format(PyExc_KeyError, "%.*s", (int) (mid_len - l), - (const char*) mid + l); - } else if (r == -ENOENT) - PyErr_SetString(PyExc_IndexError, "no MESSAGE_ID field"); - else - set_error(r, NULL, NULL); - return NULL; - } - - if (set_error(r, NULL, NULL) < 0) - return NULL; - - return unicode_FromString(msg); -} - -PyDoc_STRVAR(get_catalog__doc__, - "get_catalog(id128) -> str\n\n" - "Retrieve a message catalog entry for the given id.\n" - "Wraps man:sd_journal_get_catalog_for_message_id(3)."); -static PyObject* get_catalog(PyObject *self, PyObject *args) { - int r; - char *id_ = NULL; - sd_id128_t id; - _cleanup_free_ char *msg = NULL; - - assert(args); - - if (!PyArg_ParseTuple(args, "z:get_catalog", &id_)) - return NULL; - - r = sd_id128_from_string(id_, &id); - if (set_error(r, NULL, "Invalid id128") < 0) - return NULL; - - Py_BEGIN_ALLOW_THREADS - r = sd_journal_get_catalog_for_message_id(id, &msg); - Py_END_ALLOW_THREADS - - if (set_error(r, NULL, NULL) < 0) - return NULL; - - return unicode_FromString(msg); -} - -PyDoc_STRVAR(data_threshold__doc__, - "Threshold for field size truncation in bytes.\n\n" - "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) { - size_t cvalue; - int r; - - r = sd_journal_get_data_threshold(self->j, &cvalue); - if (set_error(r, NULL, NULL) < 0) - return NULL; - - return long_FromSize_t(cvalue); -} - -static int Reader_set_data_threshold(Reader *self, PyObject *value, void *closure) { - int r; - - if (value == NULL) { - PyErr_SetString(PyExc_AttributeError, "Cannot delete data threshold"); - return -1; - } - - if (!long_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)); - 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 == NULL); -} - -static PyGetSetDef Reader_getsetters[] = { - { (char*) "data_threshold", - (getter) Reader_get_data_threshold, - (setter) Reader_set_data_threshold, - (char*) data_threshold__doc__, - NULL }, - { (char*) "closed", - (getter) Reader_get_closed, - NULL, - (char*) closed__doc__, - NULL }, - {} /* Sentinel */ -}; - -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__}, - {"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__}, - {"get_catalog", (PyCFunction) Reader_get_catalog, METH_NOARGS, Reader_get_catalog__doc__}, - {} /* Sentinel */ -}; - -static PyTypeObject ReaderType = { - PyVarObject_HEAD_INIT(NULL, 0) - .tp_name = "_reader._Reader", - .tp_basicsize = sizeof(Reader), - .tp_dealloc = (destructor) Reader_dealloc, - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - .tp_doc = Reader__doc__, - .tp_methods = Reader_methods, - .tp_getset = Reader_getsetters, - .tp_init = (initproc) Reader_init, - .tp_new = PyType_GenericNew, -}; - -static PyMethodDef methods[] = { - { "_get_catalog", get_catalog, METH_VARARGS, get_catalog__doc__}, - {} /* Sentinel */ -}; - -#if PY_MAJOR_VERSION >= 3 -static PyModuleDef module = { - PyModuleDef_HEAD_INIT, - "_reader", - module__doc__, - -1, - 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 == NULL) - return NULL; - - if (!initialized) { - PyStructSequence_InitType(&MonotonicType, &Monotonic_desc); - initialized = true; - } -#else - m = Py_InitModule3("_reader", methods, module__doc__); - if (m == NULL) - 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) || - PyModule_AddIntConstant(m, "LOCAL_ONLY", SD_JOURNAL_LOCAL_ONLY) || - PyModule_AddIntConstant(m, "RUNTIME_ONLY", SD_JOURNAL_RUNTIME_ONLY) || - PyModule_AddIntConstant(m, "SYSTEM", SD_JOURNAL_SYSTEM) || - PyModule_AddIntConstant(m, "SYSTEM_ONLY", SD_JOURNAL_SYSTEM_ONLY) || - PyModule_AddIntConstant(m, "CURRENT_USER", SD_JOURNAL_CURRENT_USER) || - 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/src/python-systemd/daemon.py b/src/python-systemd/daemon.py deleted file mode 100644 index 82011ca606..0000000000 --- a/src/python-systemd/daemon.py +++ /dev/null @@ -1,55 +0,0 @@ -from ._daemon import (__version__, - booted, - notify, - _listen_fds, - _is_fifo, - _is_socket, - _is_socket_inet, - _is_socket_unix, - _is_mq, - LISTEN_FDS_START) -from socket import AF_UNSPEC as _AF_UNSPEC - -def _convert_fileobj(fileobj): - try: - return fileobj.fileno() - except AttributeError: - return fileobj - -def is_fifo(fileobj, path=None): - fd = _convert_fileobj(fileobj) - return _is_fifo(fd, path) - -def is_socket(fileobj, family=_AF_UNSPEC, type=0, listening=-1): - fd = _convert_fileobj(fileobj) - return _is_socket(fd, family, type, listening) - -def is_socket_inet(fileobj, family=_AF_UNSPEC, type=0, listening=-1, port=0): - fd = _convert_fileobj(fileobj) - return _is_socket_inet(fd, family, type, listening, port) - -def is_socket_unix(fileobj, type=0, listening=-1, path=None): - fd = _convert_fileobj(fileobj) - return _is_socket_unix(fd, type, listening, path) - -def is_mq(fileobj, path=None): - fd = _convert_fileobj(fileobj) - return _is_mq(fd, path) - -def listen_fds(unset_environment=True): - """Return a list of socket activated descriptors - - Example:: - - (in primary window) - $ systemd-activate -l 2000 python3 -c \\ - 'from systemd.daemon import listen_fds; print(listen_fds())' - (in another window) - $ telnet localhost 2000 - (in primary window) - ... - Execing python3 (...) - [3] - """ - num = _listen_fds(unset_environment) - return list(range(LISTEN_FDS_START, LISTEN_FDS_START + num)) diff --git a/src/python-systemd/docs/.gitignore b/src/python-systemd/docs/.gitignore deleted file mode 100644 index b06a965e6a..0000000000 --- a/src/python-systemd/docs/.gitignore +++ /dev/null @@ -1 +0,0 @@ -!layout.html diff --git a/src/python-systemd/docs/conf.py b/src/python-systemd/docs/conf.py deleted file mode 100644 index 1919170bb1..0000000000 --- a/src/python-systemd/docs/conf.py +++ /dev/null @@ -1,279 +0,0 @@ -# -*- coding: utf-8 -*- -# -# python-systemd documentation build configuration file, created by -# sphinx-quickstart on Sat Feb 9 13:49:42 2013. -# -# This file is execfile()d with the current directory set to its containing dir. -# -# Note that not all possible configuration values are present in this -# autogenerated file. -# -# All configuration values have a default; values that are commented out -# serve to show the default. - -import sys, os - -# If extensions (or modules to document with autodoc) are in another directory, -# add these directories to sys.path here. If the directory is relative to the -# documentation root, use os.path.abspath to make it absolute, like shown here. -#sys.path.insert(0, os.path.abspath('.')) - -# -- General configuration ----------------------------------------------------- - -# If your documentation needs a minimal Sphinx version, state it here. -#needs_sphinx = '1.0' - -# Add any Sphinx extension module names here, as strings. They can be extensions -# coming with Sphinx (named 'sphinx.ext.*') or your custom ones. -extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.intersphinx', 'sphinx.ext.coverage', 'sphinx.ext.viewcode'] - -# Add any paths that contain templates here, relative to this directory. -templates_path = ['.'] - -# The suffix of source filenames. -source_suffix = '.rst' - -# The encoding of source files. -#source_encoding = 'utf-8-sig' - -# The master toctree document. -master_doc = 'index' - -# General information about the project. -project = u'python-systemd' - -# The language for content autogenerated by Sphinx. Refer to documentation -# for a list of supported languages. -#language = None - -# There are two options for replacing |today|: either, you set today to some -# non-false value, then it is used: -#today = '' -# Else, today_fmt is used as the format for a strftime call. -#today_fmt = '%B %d, %Y' - -# List of patterns, relative to source directory, that match files and -# directories to ignore when looking for source files. -exclude_patterns = [] - -# The reST default role (used for this markup: `text`) to use for all documents. -#default_role = None - -# If true, '()' will be appended to :func: etc. cross-reference text. -#add_function_parentheses = True - -# If true, the current module name will be prepended to all description -# unit titles (such as .. function::). -#add_module_names = True - -# If true, sectionauthor and moduleauthor directives will be shown in the -# output. They are ignored by default. -#show_authors = False - -# The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' - -# A list of ignored prefixes for module index sorting. -#modindex_common_prefix = [] - - -# -- Options for HTML output --------------------------------------------------- - -# The theme to use for HTML and HTML Help pages. See the documentation for -# a list of builtin themes. -html_theme = 'default' - -# Theme options are theme-specific and customize the look and feel of a theme -# further. For a list of options available for each theme, see the -# documentation. -#html_theme_options = {} - -# Add any paths that contain custom themes here, relative to this directory. -#html_theme_path = [] - -# The name for this set of Sphinx documents. If None, it defaults to -# "<project> v<release> documentation". -#html_title = None - -# A shorter title for the navigation bar. Default is the same as html_title. -#html_short_title = None - -# The name of an image file (relative to this directory) to place at the top -# of the sidebar. -#html_logo = None - -# The name of an image file (within the static path) to use as favicon of the -# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 -# pixels large. -#html_favicon = None - -# Add any paths that contain custom static files (such as style sheets) here, -# relative to this directory. They are copied after the builtin static files, -# so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['.'] - -# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, -# using the given strftime format. -#html_last_updated_fmt = '%b %d, %Y' - -# If true, SmartyPants will be used to convert quotes and dashes to -# typographically correct entities. -#html_use_smartypants = True - -# Custom sidebar templates, maps document names to template names. -#html_sidebars = {} - -# Additional templates that should be rendered to pages, maps page names to -# template names. -#html_additional_pages = {} - -# If false, no module index is generated. -#html_domain_indices = True - -# If false, no index is generated. -#html_use_index = True - -# If true, the index is split into individual pages for each letter. -#html_split_index = False - -# If true, links to the reST sources are added to the pages. -html_show_sourcelink = False - -# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. -#html_show_sphinx = True - -# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. -#html_show_copyright = True - -# If true, an OpenSearch description file will be output, and all pages will -# contain a <link> tag referring to it. The value of this option must be the -# base URL from which the finished HTML is served. -#html_use_opensearch = '' - -# This is the file name suffix for HTML files (e.g. ".xhtml"). -#html_file_suffix = None - -# Output file base name for HTML help builder. -htmlhelp_basename = 'python-systemddoc' - - -# -- Options for LaTeX output -------------------------------------------------- - -latex_elements = { -# The paper size ('letterpaper' or 'a4paper'). -#'papersize': 'letterpaper', - -# The font size ('10pt', '11pt' or '12pt'). -#'pointsize': '10pt', - -# Additional stuff for the LaTeX preamble. -#'preamble': '', -} - -# Grouping the document tree into LaTeX files. List of tuples -# (source start file, target name, title, author, documentclass [howto/manual]). -latex_documents = [ - ('index', 'python-systemd.tex', u'python-systemd Documentation', - None, 'manual'), -] - -# The name of an image file (relative to this directory) to place at the top of -# the title page. -#latex_logo = None - -# For "manual" documents, if this is true, then toplevel headings are parts, -# not chapters. -#latex_use_parts = False - -# If true, show page references after internal links. -#latex_show_pagerefs = False - -# If true, show URL addresses after external links. -#latex_show_urls = False - -# Documents to append as an appendix to all manuals. -#latex_appendices = [] - -# If false, no module index is generated. -#latex_domain_indices = True - - -# -- Options for manual page output -------------------------------------------- - -# One entry per manual page. List of tuples -# (source start file, name, description, authors, manual section). -man_pages = [ - ('index', 'python-systemd', u'python-systemd Documentation', - [], 1) -] - -# If true, show URL addresses after external links. -#man_show_urls = False - - -# -- Options for Texinfo output ------------------------------------------------ - -# Grouping the document tree into Texinfo files. List of tuples -# (source start file, target name, title, author, -# dir menu entry, description, category) -texinfo_documents = [ - ('index', 'python-systemd', u'python-systemd Documentation', - u'David Strauss, Zbigniew Jędrzejewski-Szmek, Marti Raudsepp, Steven Hiscocks', 'python-systemd', 'One line description of project.', - 'Miscellaneous'), -] - -# Documents to append as an appendix to all manuals. -#texinfo_appendices = [] - -# If false, no module index is generated. -#texinfo_domain_indices = True - -# How to display URL addresses: 'footnote', 'no', or 'inline'. -#texinfo_show_urls = 'footnote' - - -# -- Options for Epub output --------------------------------------------------- - -# Bibliographic Dublin Core info. -epub_title = u'python-systemd' -epub_author = u'David Strauss, Zbigniew Jędrzejewski-Szmek, Marti Raudsepp, Steven Hiscocks' -epub_publisher = u'David Strauss, Zbigniew Jędrzejewski-Szmek, Marti Raudsepp, Steven Hiscocks' -epub_copyright = u'2013, David Strauss, Zbigniew Jędrzejewski-Szmek, Marti Raudsepp, Steven Hiscocks' - -# The language of the text. It defaults to the language option -# or en if the language is not set. -#epub_language = '' - -# The scheme of the identifier. Typical schemes are ISBN or URL. -#epub_scheme = '' - -# The unique identifier of the text. This can be a ISBN number -# or the project homepage. -#epub_identifier = '' - -# A unique identification for the text. -#epub_uid = '' - -# A tuple containing the cover image and cover page html template filenames. -#epub_cover = () - -# HTML files that should be inserted before the pages created by sphinx. -# The format is a list of tuples containing the path and title. -#epub_pre_files = [] - -# HTML files shat should be inserted after the pages created by sphinx. -# The format is a list of tuples containing the path and title. -#epub_post_files = [] - -# A list of files that should not be packed into the epub file. -#epub_exclude_files = [] - -# The depth of the table of contents in toc.ncx. -#epub_tocdepth = 3 - -# Allow duplicate toc entries. -#epub_tocdup = True - - -# Example configuration for intersphinx: refer to the Python standard library. -intersphinx_mapping = {'http://docs.python.org/': None} diff --git a/src/python-systemd/docs/daemon.rst b/src/python-systemd/docs/daemon.rst deleted file mode 100644 index 0ad11edaf3..0000000000 --- a/src/python-systemd/docs/daemon.rst +++ /dev/null @@ -1,18 +0,0 @@ -`systemd.daemon` module -======================= - -.. automodule:: systemd.daemon - :members: - :undoc-members: - :inherited-members: - - .. autoattribute:: systemd.daemon.LISTEN_FDS_START - - .. autofunction:: _listen_fds - .. autofunction:: _is_fifo - .. autofunction:: _is_socket - .. autofunction:: _is_socket_unix - .. autofunction:: _is_socket_inet - .. autofunction:: _is_mq - .. autofunction:: notify - .. autofunction:: booted diff --git a/src/python-systemd/docs/default.css b/src/python-systemd/docs/default.css deleted file mode 100644 index 7c097d64a2..0000000000 --- a/src/python-systemd/docs/default.css +++ /dev/null @@ -1,196 +0,0 @@ -@import url("basic.css"); - -/* -- page layout ----------------------------------------------------------- */ - -div.documentwrapper { - float: left; - width: 100%; -} - -div.bodywrapper { - margin: 0 0 0 230px; -} - -div.body { - background-color: #ffffff; - color: #000000; - padding: 0 20px 30px 20px; -} - -div.footer { - color: #ffffff; - width: 100%; - padding: 9px 0 9px 0; - text-align: center; - font-size: 75%; -} - -div.footer a { - color: #ffffff; - text-decoration: underline; -} - -div.related { - background-color: #133f52; - line-height: 30px; - color: #ffffff; -} - -div.related a { - color: #ffffff; -} - -div.sphinxsidebar { - background-color: #dddddd; -} - -div.sphinxsidebar p.topless { - margin: 5px 10px 10px 10px; -} - -div.sphinxsidebar ul { - margin: 10px; - padding: 0; -} - -div.sphinxsidebar input { - border: 1px solid #000000; - font-family: sans-serif; - font-size: 1em; -} - - - -/* -- hyperlink styles ------------------------------------------------------ */ - -a { - text-decoration: none; -} - -a:hover { - text-decoration: underline; -} - - - -/* -- body styles ----------------------------------------------------------- */ - -div.body h1, -div.body h2, -div.body h3, -div.body h4, -div.body h5, -div.body h6 { - font-family: 'Trebuchet MS', sans-serif; - background-color: #f2f2f2; - font-weight: normal; - color: #20435c; - border-bottom: 1px solid #ccc; - margin: 20px -20px 10px -20px; - padding: 3px 0 3px 10px; -} - -div.body h1 { margin-top: 0; font-size: 200%; } -div.body h2 { font-size: 160%; } -div.body h3 { font-size: 140%; } -div.body h4 { font-size: 120%; } -div.body h5 { font-size: 110%; } -div.body h6 { font-size: 100%; } - -a.headerlink { - color: #c60f0f; - font-size: 0.8em; - padding: 0 4px 0 4px; - text-decoration: none; -} - -a.headerlink:hover { - background-color: #c60f0f; - color: white; -} - -div.body p, div.body dd, div.body li { - text-align: justify; - line-height: 130%; -} - -div.admonition p.admonition-title + p { - display: inline; -} - -div.admonition p { - margin-bottom: 5px; -} - -div.admonition pre { - margin-bottom: 5px; -} - -div.admonition ul, div.admonition ol { - margin-bottom: 5px; -} - -div.note { - background-color: #eee; - border: 1px solid #ccc; -} - -div.seealso { - background-color: #ffc; - border: 1px solid #ff6; -} - -div.topic { - background-color: #eee; -} - -div.warning { - background-color: #ffe4e4; - border: 1px solid #f66; -} - -p.admonition-title { - display: inline; -} - -p.admonition-title:after { - content: ":"; -} - -pre { - padding: 5px; - background-color: #eeffcc; - color: #333333; - line-height: 120%; - border: 1px solid #ac9; - border-left: none; - border-right: none; -} - -tt { - background-color: #ecf0f3; - padding: 0 1px 0 1px; - font-size: 0.95em; -} - -th { - background-color: #ede; -} - -.warning tt { - background: #efc2c2; -} - -.note tt { - background: #d6d6d6; -} - -.viewcode-back { - font-family: sans-serif; -} - -div.viewcode-block:target { - background-color: #f4debf; - border-top: 1px solid #ac9; - border-bottom: 1px solid #ac9; -} diff --git a/src/python-systemd/docs/id128.rst b/src/python-systemd/docs/id128.rst deleted file mode 100644 index 89c37f3470..0000000000 --- a/src/python-systemd/docs/id128.rst +++ /dev/null @@ -1,40 +0,0 @@ -`systemd.id128` module -====================== - -.. automodule:: systemd.id128 - :members: - :undoc-members: - :inherited-members: - - .. autoattribute:: systemd.id128.SD_MESSAGE_COREDUMP - .. autoattribute:: systemd.id128.SD_MESSAGE_FORWARD_SYSLOG_MISSED - .. autoattribute:: systemd.id128.SD_MESSAGE_HIBERNATE_KEY - .. autoattribute:: systemd.id128.SD_MESSAGE_JOURNAL_DROPPED - .. autoattribute:: systemd.id128.SD_MESSAGE_JOURNAL_MISSED - .. autoattribute:: systemd.id128.SD_MESSAGE_JOURNAL_START - .. autoattribute:: systemd.id128.SD_MESSAGE_JOURNAL_STOP - .. autoattribute:: systemd.id128.SD_MESSAGE_LID_CLOSED - .. autoattribute:: systemd.id128.SD_MESSAGE_LID_OPENED - .. autoattribute:: systemd.id128.SD_MESSAGE_OVERMOUNTING - .. autoattribute:: systemd.id128.SD_MESSAGE_POWER_KEY - .. autoattribute:: systemd.id128.SD_MESSAGE_SEAT_START - .. autoattribute:: systemd.id128.SD_MESSAGE_SEAT_STOP - .. 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_SLEEP_START - .. autoattribute:: systemd.id128.SD_MESSAGE_SLEEP_STOP - .. autoattribute:: systemd.id128.SD_MESSAGE_SPAWN_FAILED - .. autoattribute:: systemd.id128.SD_MESSAGE_STARTUP_FINISHED - .. autoattribute:: systemd.id128.SD_MESSAGE_SUSPEND_KEY - .. autoattribute:: systemd.id128.SD_MESSAGE_TIMEZONE_CHANGE - .. autoattribute:: systemd.id128.SD_MESSAGE_TIME_CHANGE - .. autoattribute:: systemd.id128.SD_MESSAGE_UNIT_FAILED - .. autoattribute:: systemd.id128.SD_MESSAGE_UNIT_RELOADED - .. autoattribute:: systemd.id128.SD_MESSAGE_UNIT_RELOADING - .. autoattribute:: systemd.id128.SD_MESSAGE_UNIT_STARTED - .. autoattribute:: systemd.id128.SD_MESSAGE_UNIT_STARTING - .. autoattribute:: systemd.id128.SD_MESSAGE_UNIT_STOPPED - .. autoattribute:: systemd.id128.SD_MESSAGE_UNIT_STOPPING - .. autoattribute:: systemd.id128.SD_MESSAGE_CONFIG_ERROR - .. autoattribute:: systemd.id128.SD_MESSAGE_BOOTCHART diff --git a/src/python-systemd/docs/index.rst b/src/python-systemd/docs/index.rst deleted file mode 100644 index e78d966274..0000000000 --- a/src/python-systemd/docs/index.rst +++ /dev/null @@ -1,24 +0,0 @@ -.. python-systemd documentation master 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. - -Welcome to python-systemd's documentation! -========================================== - -Contents: - -.. toctree:: - :maxdepth: 2 - - journal - id128 - daemon - login - -Indices and tables -================== - -* :ref:`genindex` -* :ref:`modindex` -* :ref:`search` diff --git a/src/python-systemd/docs/journal.rst b/src/python-systemd/docs/journal.rst deleted file mode 100644 index ea74cf85c4..0000000000 --- a/src/python-systemd/docs/journal.rst +++ /dev/null @@ -1,64 +0,0 @@ -`systemd.journal` module -======================== - -.. automodule:: systemd.journal - :members: send, sendv, stream, stream_fd - :undoc-members: - -`JournalHandler` class ----------------------- - -.. autoclass:: JournalHandler - -Accessing the Journal ---------------------- - -.. autoclass:: _Reader - :undoc-members: - :inherited-members: - -.. autoclass:: Reader - :undoc-members: - :inherited-members: - - .. automethod:: __init__ - -.. autofunction:: _get_catalog -.. autofunction:: get_catalog - -.. autoclass:: Monotonic - -.. autoattribute:: systemd.journal.DEFAULT_CONVERTERS - -Example: polling for journal events -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -This example shows that journal events can be waited for (using -e.g. `poll`). This makes it easy to integrate Reader in an external -event loop: - - >>> import select - >>> from systemd import journal - >>> j = journal.Reader() - >>> j.seek_tail() - >>> p = select.poll() - >>> p.register(j, j.get_events()) - >>> p.poll() - [(3, 1)] - >>> j.get_next() - - -Journal access types -~~~~~~~~~~~~~~~~~~~~ - -.. autoattribute:: systemd.journal.LOCAL_ONLY -.. autoattribute:: systemd.journal.RUNTIME_ONLY -.. autoattribute:: systemd.journal.SYSTEM -.. autoattribute:: systemd.journal.CURRENT_USER - -Journal event types -~~~~~~~~~~~~~~~~~~~ - -.. autoattribute:: systemd.journal.NOP -.. autoattribute:: systemd.journal.APPEND -.. autoattribute:: systemd.journal.INVALIDATE diff --git a/src/python-systemd/docs/layout.html b/src/python-systemd/docs/layout.html deleted file mode 100644 index 930a6a7afe..0000000000 --- a/src/python-systemd/docs/layout.html +++ /dev/null @@ -1,15 +0,0 @@ -{% extends "!layout.html" %} - -{% block relbar1 %} - <a href="../man/systemd.index.html">Index </a>· - <a href="../man/systemd.directives.html">Directives </a>· - <a href="index.html">Python </a>· - <span style="float:right">systemd {{release}}</span> - <hr /> -{% endblock %} - -{# remove the lower relbar #} -{% block relbar2 %} {% endblock %} - -{# remove the footer #} -{% block footer %} {% endblock %} diff --git a/src/python-systemd/docs/login.rst b/src/python-systemd/docs/login.rst deleted file mode 100644 index 6b4de64c55..0000000000 --- a/src/python-systemd/docs/login.rst +++ /dev/null @@ -1,28 +0,0 @@ -`systemd.login` module -======================= - -.. automodule:: systemd.login - :members: - -.. autoclass:: Monitor - :undoc-members: - :inherited-members: - -Example: polling for events -~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -This example shows that session/uid/seat/machine events can be waited -for (using e.g. `poll`). This makes it easy to integrate Monitor in an -external event loop: - - >>> import select - >>> from systemd import login - >>> m = login.Monitor("machine") - >>> p = select.poll() - >>> p.register(m, m.get_events()) - >>> login.machine_names() - [] - >>> p.poll() - [(3, 1)] - >>> login.machine_names() - ['fedora-19.nspawn'] diff --git a/src/python-systemd/id128.c b/src/python-systemd/id128.c deleted file mode 100644 index 5ec7309a54..0000000000 --- a/src/python-systemd/id128.c +++ /dev/null @@ -1,163 +0,0 @@ -/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ - -/*** - This file is part of systemd. - - Copyright 2013 Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. -***/ - -#include <Python.h> - -#include "systemd/sd-messages.h" - -#include "pyutil.h" -#include "log.h" -#include "util.h" -#include "macro.h" - -PyDoc_STRVAR(module__doc__, - "Python interface to the libsystemd-id128 library.\n\n" - "Provides SD_MESSAGE_* constants and functions to query and generate\n" - "128-bit unique identifiers." -); - -PyDoc_STRVAR(randomize__doc__, - "randomize() -> UUID\n\n" - "Return a new random 128-bit unique identifier.\n" - "Wraps sd_id128_randomize(3)." -); - -PyDoc_STRVAR(get_machine__doc__, - "get_machine() -> UUID\n\n" - "Return a 128-bit unique identifier for this machine.\n" - "Wraps sd_id128_get_machine(3)." -); - -PyDoc_STRVAR(get_boot__doc__, - "get_boot() -> UUID\n\n" - "Return a 128-bit unique identifier for this boot.\n" - "Wraps sd_id128_get_boot(3)." -); - -static PyObject* make_uuid(sd_id128_t id) { - _cleanup_Py_DECREF_ PyObject - *uuid = NULL, *UUID = NULL, *bytes = NULL, - *args = NULL, *kwargs = NULL; - - uuid = PyImport_ImportModule("uuid"); - if (!uuid) - return NULL; - - UUID = PyObject_GetAttrString(uuid, "UUID"); - bytes = PyBytes_FromStringAndSize((const char*) &id.bytes, sizeof(id.bytes)); - args = Py_BuildValue("()"); - kwargs = PyDict_New(); - if (!UUID || !bytes || !args || !kwargs) - return NULL; - - if (PyDict_SetItemString(kwargs, "bytes", bytes) < 0) - return NULL; - - return PyObject_Call(UUID, args, kwargs); -} - -#define helper(name) \ - static PyObject *name(PyObject *self, PyObject *args) { \ - sd_id128_t id; \ - int r; \ - \ - assert(args == NULL); \ - \ - r = sd_id128_##name(&id); \ - if (r < 0) { \ - errno = -r; \ - return PyErr_SetFromErrno(PyExc_IOError); \ - } \ - \ - return make_uuid(id); \ - } - -helper(randomize) -helper(get_machine) -helper(get_boot) - -static PyMethodDef methods[] = { - { "randomize", randomize, METH_NOARGS, randomize__doc__}, - { "get_machine", get_machine, METH_NOARGS, get_machine__doc__}, - { "get_boot", get_boot, METH_NOARGS, get_boot__doc__}, - { NULL, NULL, 0, NULL } /* Sentinel */ -}; - -static int add_id(PyObject *module, const char* name, sd_id128_t id) { - PyObject *obj; - - obj = make_uuid(id); - if (!obj) - return -1; - - 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 == NULL) - 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, - "id128", /* name of module */ - module__doc__, /* module documentation, may be NULL */ - -1, /* size of per-interpreter state of the module */ - methods -}; - -DISABLE_WARNING_MISSING_PROTOTYPES; -PyMODINIT_FUNC PyInit_id128(void) { - PyObject *m; - - m = PyModule_Create(&module); - if (m == NULL) - return NULL; - - if ( /* a series of lines like 'add_id() ||' follow */ -#define JOINER || -#include "id128-constants.h" -#undef JOINER - PyModule_AddStringConstant(m, "__version__", PACKAGE_VERSION)) { - Py_DECREF(m); - return NULL; - } - - return m; -} -REENABLE_WARNING; - -#endif diff --git a/src/python-systemd/journal.py b/src/python-systemd/journal.py deleted file mode 100644 index dd1f229973..0000000000 --- a/src/python-systemd/journal.py +++ /dev/null @@ -1,548 +0,0 @@ -# -*- Mode: python; coding:utf-8; indent-tabs-mode: nil -*- */ -# -# This file is part of systemd. -# -# Copyright 2012 David Strauss <david@davidstrauss.net> -# Copyright 2012 Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> -# Copyright 2012 Marti Raudsepp <marti@juffo.org> -# -# systemd is free software; you can redistribute it and/or modify it -# under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation; either version 2.1 of the License, or -# (at your option) any later version. -# -# systemd is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with systemd; If not, see <http://www.gnu.org/licenses/>. - -from __future__ import division - -import sys as _sys -import datetime as _datetime -import uuid as _uuid -import traceback as _traceback -import os as _os -import logging as _logging -if _sys.version_info >= (3,3): - from collections import ChainMap as _ChainMap -from syslog import (LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR, - LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG) -from ._journal import __version__, sendv, stream_fd -from ._reader import (_Reader, NOP, APPEND, INVALIDATE, - LOCAL_ONLY, RUNTIME_ONLY, - SYSTEM, SYSTEM_ONLY, CURRENT_USER, - _get_catalog) -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]), - _uuid.UUID(bytes=m[1]))) - -def _convert_source_monotonic(s): - return _datetime.timedelta(microseconds=int(s)) - -def _convert_realtime(t): - return _datetime.datetime.fromtimestamp(t / 1000000) - -def _convert_timestamp(s): - return _datetime.datetime.fromtimestamp(int(s) / 1000000) - -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 - -DEFAULT_CONVERTERS = { - 'MESSAGE_ID': _convert_uuid, - '_MACHINE_ID': _convert_uuid, - '_BOOT_ID': _convert_uuid, - 'PRIORITY': int, - 'LEADER': int, - 'SESSION_ID': int, - 'USERSPACE_USEC': int, - 'INITRD_USEC': int, - 'KERNEL_USEC': int, - '_UID': int, - '_GID': int, - '_PID': int, - 'SYSLOG_FACILITY': int, - 'SYSLOG_PID': int, - '_AUDIT_SESSION': int, - '_AUDIT_LOGINUID': int, - '_SYSTEMD_SESSION': int, - '_SYSTEMD_OWNER_UID': int, - 'CODE_LINE': int, - 'ERRNO': int, - 'EXIT_STATUS': int, - '_SOURCE_REALTIME_TIMESTAMP': _convert_timestamp, - '__REALTIME_TIMESTAMP': _convert_realtime, - '_SOURCE_MONOTONIC_TIMESTAMP': _convert_source_monotonic, - '__MONOTONIC_TIMESTAMP': _convert_monotonic, - '__CURSOR': _convert_trivial, - 'COREDUMP': bytes, - 'COREDUMP_PID': int, - 'COREDUMP_UID': int, - 'COREDUMP_GID': int, - 'COREDUMP_SESSION': int, - 'COREDUMP_SIGNAL': int, - 'COREDUMP_TIMESTAMP': _convert_timestamp, -} - -_IDENT_LETTER = set('ABCDEFGHIJKLMNOPQRTSUVWXYZ_') - -def _valid_field_name(s): - return not (set(s) - _IDENT_LETTER) - -class Reader(_Reader): - """Reader allows the access and filtering of systemd journal - entries. Note that in order to access the system journal, a - non-root user must be in the `systemd-journal` group. - - Example usage to print out all informational or higher level - messages for systemd-udevd for this boot: - - >>> j = journal.Reader() - >>> j.this_boot() - >>> j.log_level(journal.LOG_INFO) - >>> j.add_match(_SYSTEMD_UNIT="systemd-udevd.service") - >>> for entry in j: - ... print(entry['MESSAGE']) - - See systemd.journal-fields(7) for more info on typical fields - found in the journal. - """ - def __init__(self, flags=0, path=None, files=None, converters=None): - """Create an instance of Reader, which allows filtering and - return of journal entries. - - Argument `flags` sets open flags of the journal, which can be one - of, or ORed combination of constants: LOCAL_ONLY (default) opens - journal on local machine only; RUNTIME_ONLY opens only - volatile journal files; and SYSTEM_ONLY opens only - journal files of system services and the kernel. - - Argument `path` is the directory of journal files. Note that - `flags` and `path` are exclusive. - - Argument `converters` is a dictionary which updates the - DEFAULT_CONVERTERS to convert journal field values. Field - names are used as keys into this dictionary. The values must - be single argument functions, which take a `bytes` object and - return a converted value. When there's no entry for a field - name, then the default UTF-8 decoding will be attempted. If - the conversion fails with a ValueError, unconverted bytes - object will be returned. (Note that ValueEror is a superclass - of UnicodeDecodeError). - - Reader implements the context manager protocol: the journal - will be closed when exiting the block. - """ - super(Reader, self).__init__(flags, path, files) - if _sys.version_info >= (3,3): - self.converters = _ChainMap() - if converters is not None: - self.converters.maps.append(converters) - self.converters.maps.append(DEFAULT_CONVERTERS) - else: - self.converters = DEFAULT_CONVERTERS.copy() - if converters is not None: - self.converters.update(converters) - - def _convert_field(self, key, value): - """Convert value using self.converters[key] - - If `key` is not present in self.converters, a standard unicode - decoding will be attempted. If the conversion (either - key-specific or the default one) fails with a ValueError, the - original bytes object will be returned. - """ - convert = self.converters.get(key, bytes.decode) - try: - return convert(value) - except ValueError: - # Leave in default bytes - return value - - def _convert_entry(self, entry): - """Convert entire journal entry utilising _covert_field""" - result = {} - for key, value in entry.items(): - if isinstance(value, list): - result[key] = [self._convert_field(key, val) for val in value] - else: - result[key] = self._convert_field(key, value) - return result - - def __iter__(self): - """Part of iterator protocol. - Returns self. - """ - return self - - def __next__(self): - """Part of iterator protocol. - Returns self.get_next() or raises StopIteration. - """ - ans = self.get_next() - if ans: - return ans - 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. - All matches of different field are combined in a logical AND, - and matches of the same field are automatically combined in a - logical OR. - Matches can be passed as strings of form "FIELD=value", or - keyword arguments FIELD="value". - """ - args = list(args) - args.extend(_make_line(key, val) for key, val in kwargs.items()) - for arg in args: - super(Reader, self).add_match(arg) - - def get_next(self, skip=1): - """Return the next log entry as a mapping type, currently - a standard dictionary of fields. - - Optional skip value will return the `skip`\-th log entry. - - Entries will be processed with converters specified during - Reader creation. - """ - if super(Reader, self)._next(skip): - entry = super(Reader, self)._get_all() - if entry: - entry['__REALTIME_TIMESTAMP'] = self._get_realtime() - entry['__MONOTONIC_TIMESTAMP'] = self._get_monotonic() - entry['__CURSOR'] = self._get_cursor() - return self._convert_entry(entry) - return dict() - - def get_previous(self, skip=1): - """Return the previous log entry as a mapping type, - currently a standard dictionary of fields. - - Optional skip value will return the -`skip`\-th log entry. - - Entries will be processed with converters specified during - Reader creation. - - Equivalent to get_next(-skip). - """ - return self.get_next(-skip) - - def query_unique(self, field): - """Return unique values appearing in the journal for given `field`. - - Note this does not respect any journal matches. - - Entries will be processed with converters specified during - Reader creation. - """ - return set(self._convert_field(field, value) - for value in super(Reader, self).query_unique(field)) - - def wait(self, timeout=None): - """Wait for a change in the journal. `timeout` is the maximum - time in seconds to wait, or None, to wait forever. - - Returns one of NOP (no change), APPEND (new entries have been - added to the end of the journal), or INVALIDATE (journal files - have been added or removed). - """ - us = -1 if timeout is None else int(timeout * 1000000) - return super(Reader, self).wait(us) - - def seek_realtime(self, realtime): - """Seek to a matching journal entry nearest to `realtime` time. - - Argument `realtime` must be either an integer unix timestamp - or datetime.datetime instance. - """ - if isinstance(realtime, _datetime.datetime): - realtime = float(realtime.strftime("%s.%f")) * 1000000 - return super(Reader, self).seek_realtime(int(realtime)) - - def seek_monotonic(self, monotonic, bootid=None): - """Seek to a matching journal entry nearest to `monotonic` time. - - Argument `monotonic` is a timestamp from boot in either - seconds or a datetime.timedelta instance. Argument `bootid` - is a string or UUID representing which boot the monotonic time - is reference to. Defaults to current bootid. - """ - if isinstance(monotonic, _datetime.timedelta): - monotonic = monotonic.totalseconds() - monotonic = int(monotonic * 1000000) - if isinstance(bootid, _uuid.UUID): - bootid = bootid.hex - return super(Reader, self).seek_monotonic(monotonic, bootid) - - def log_level(self, level): - """Set maximum log `level` by setting matches for PRIORITY. - """ - if 0 <= level <= 7: - for i in range(level+1): - self.add_match(PRIORITY="%d" % i) - else: - raise ValueError("Log level must be 0 <= level <= 7") - - def messageid_match(self, messageid): - """Add match for log entries with specified `messageid`. - - `messageid` can be string of hexadicimal digits or a UUID - instance. Standard message IDs can be found in systemd.id128. - - Equivalent to add_match(MESSAGE_ID=`messageid`). - """ - if isinstance(messageid, _uuid.UUID): - messageid = messageid.hex - self.add_match(MESSAGE_ID=messageid) - - def this_boot(self, bootid=None): - """Add match for _BOOT_ID equal to current boot ID or the specified boot ID. - - If specified, bootid should be either a UUID or a 32 digit hex number. - - Equivalent to add_match(_BOOT_ID='bootid'). - """ - if bootid is None: - bootid = _id128.get_boot().hex - else: - bootid = getattr(bootid, 'hex', bootid) - self.add_match(_BOOT_ID=bootid) - - def this_machine(self, machineid=None): - """Add match for _MACHINE_ID equal to the ID of this machine. - - If specified, machineid should be either a UUID or a 32 digit hex number. - - Equivalent to add_match(_MACHINE_ID='machineid'). - """ - if machineid is None: - machineid = _id128.get_machine().hex - else: - machineid = getattr(machineid, 'hex', machineid) - self.add_match(_MACHINE_ID=machineid) - - -def get_catalog(mid): - if isinstance(mid, _uuid.UUID): - mid = mid.hex - return _get_catalog(mid) - -def _make_line(field, value): - if isinstance(value, bytes): - return field.encode('utf-8') + b'=' + value - elif isinstance(value, int): - return field + '=' + str(value) - else: - return field + '=' + value - -def send(MESSAGE, MESSAGE_ID=None, - CODE_FILE=None, CODE_LINE=None, CODE_FUNC=None, - **kwargs): - r"""Send a message to the journal. - - >>> journal.send('Hello world') - >>> journal.send('Hello, again, world', FIELD2='Greetings!') - >>> journal.send('Binary message', BINARY=b'\xde\xad\xbe\xef') - - Value of the MESSAGE argument will be used for the MESSAGE= - field. MESSAGE must be a string and will be sent as UTF-8 to - the journal. - - MESSAGE_ID can be given to uniquely identify the type of - message. It must be a string or a uuid.UUID object. - - CODE_LINE, CODE_FILE, and CODE_FUNC can be specified to - identify the caller. Unless at least on of the three is given, - values are extracted from the stack frame of the caller of - send(). CODE_FILE and CODE_FUNC must be strings, CODE_LINE - must be an integer. - - Additional fields for the journal entry can only be specified - as keyword arguments. The payload can be either a string or - bytes. A string will be sent as UTF-8, and bytes will be sent - as-is to the journal. - - Other useful fields include PRIORITY, SYSLOG_FACILITY, - SYSLOG_IDENTIFIER, SYSLOG_PID. - """ - - args = ['MESSAGE=' + MESSAGE] - - if MESSAGE_ID is not None: - id = getattr(MESSAGE_ID, 'hex', MESSAGE_ID) - args.append('MESSAGE_ID=' + id) - - if CODE_LINE == CODE_FILE == CODE_FUNC == None: - 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: - args.append('CODE_LINE={:d}'.format(CODE_LINE)) - if CODE_FUNC is not None: - args.append('CODE_FUNC=' + CODE_FUNC) - - args.extend(_make_line(key, val) for key, val in kwargs.items()) - return sendv(*args) - -def stream(identifier, priority=LOG_DEBUG, level_prefix=False): - r"""Return a file object wrapping a stream to journal. - - Log messages written to this file as simple newline sepearted - text strings are written to the journal. - - The file will be line buffered, so messages are actually sent - after a newline character is written. - - >>> stream = journal.stream('myapp') - >>> stream - <open file '<fdopen>', mode 'w' at 0x...> - >>> stream.write('message...\n') - - will produce the following message in the journal:: - - PRIORITY=7 - SYSLOG_IDENTIFIER=myapp - MESSAGE=message... - - Using the interface with print might be more convinient: - - >>> from __future__ import print_function - >>> print('message...', file=stream) - - priority is the syslog priority, one of `LOG_EMERG`, - `LOG_ALERT`, `LOG_CRIT`, `LOG_ERR`, `LOG_WARNING`, - `LOG_NOTICE`, `LOG_INFO`, `LOG_DEBUG`. - - level_prefix is a boolean. If true, kernel-style log priority - level prefixes (such as '<1>') are interpreted. See - sd-daemon(3) for more information. - """ - - fd = stream_fd(identifier, priority, level_prefix) - return _os.fdopen(fd, 'w', 1) - -class JournalHandler(_logging.Handler): - """Journal handler class for the Python logging framework. - - Please see the Python logging module documentation for an - overview: http://docs.python.org/library/logging.html. - - To create a custom logger whose messages go only to journal: - - >>> log = logging.getLogger('custom_logger_name') - >>> log.propagate = False - >>> log.addHandler(journal.JournalHandler()) - >>> log.warn("Some message: %s", detail) - - Note that by default, message levels `INFO` and `DEBUG` are - ignored by the logging framework. To enable those log levels: - - >>> log.setLevel(logging.DEBUG) - - To redirect all logging messages to journal regardless of where - they come from, attach it to the root logger: - - >>> logging.root.addHandler(journal.JournalHandler()) - - For more complex configurations when using `dictConfig` or - `fileConfig`, specify `systemd.journal.JournalHandler` as the - handler class. Only standard handler configuration options - are supported: `level`, `formatter`, `filters`. - - To attach journal MESSAGE_ID, an extra field is supported: - - >>> import uuid - >>> mid = uuid.UUID('0123456789ABCDEF0123456789ABCDEF') - >>> log.warn("Message with ID", extra={'MESSAGE_ID': mid}) - - Fields to be attached to all messages sent through this - handler can be specified as keyword arguments. This probably - makes sense only for SYSLOG_IDENTIFIER and similar fields - which are constant for the whole program: - - >>> journal.JournalHandler(SYSLOG_IDENTIFIER='my-cool-app') - - The following journal fields will be sent: - `MESSAGE`, `PRIORITY`, `THREAD_NAME`, `CODE_FILE`, `CODE_LINE`, - `CODE_FUNC`, `LOGGER` (name as supplied to getLogger call), - `MESSAGE_ID` (optional, see above), `SYSLOG_IDENTIFIER` (defaults - to sys.argv[0]). - """ - - def __init__(self, level=_logging.NOTSET, **kwargs): - super(JournalHandler, self).__init__(level) - - for name in kwargs: - if not _valid_field_name(name): - raise ValueError('Invalid field name: ' + name) - if 'SYSLOG_IDENTIFIER' not in kwargs: - kwargs['SYSLOG_IDENTIFIER'] = _sys.argv[0] - self._extra = kwargs - - def emit(self, record): - """Write record as journal event. - - MESSAGE is taken from the message provided by the - user, and PRIORITY, LOGGER, THREAD_NAME, - CODE_{FILE,LINE,FUNC} fields are appended - automatically. In addition, record.MESSAGE_ID will be - used if present. - """ - try: - msg = self.format(record) - pri = self.mapPriority(record.levelno) - mid = getattr(record, 'MESSAGE_ID', None) - send(msg, - MESSAGE_ID=mid, - PRIORITY=format(pri), - LOGGER=record.name, - THREAD_NAME=record.threadName, - CODE_FILE=record.pathname, - CODE_LINE=record.lineno, - CODE_FUNC=record.funcName, - **self._extra) - except Exception: - self.handleError(record) - - @staticmethod - def mapPriority(levelno): - """Map logging levels to journald priorities. - - Since Python log level numbers are "sparse", we have - to map numbers in between the standard levels too. - """ - if levelno <= _logging.DEBUG: - return LOG_DEBUG - elif levelno <= _logging.INFO: - return LOG_INFO - elif levelno <= _logging.WARNING: - return LOG_WARNING - elif levelno <= _logging.ERROR: - return LOG_ERR - elif levelno <= _logging.CRITICAL: - return LOG_CRIT - else: - return LOG_ALERT diff --git a/src/python-systemd/login.c b/src/python-systemd/login.c deleted file mode 100644 index e844f5fc69..0000000000 --- a/src/python-systemd/login.c +++ /dev/null @@ -1,376 +0,0 @@ -/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ - -/*** - This file is part of systemd. - - Copyright 2013 Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. -***/ - -#define PY_SSIZE_T_CLEAN -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wredundant-decls" -#include <Python.h> -#pragma GCC diagnostic pop - -#include "systemd/sd-login.h" -#include "pyutil.h" -#include "util.h" -#include "strv.h" - -PyDoc_STRVAR(module__doc__, - "Python interface to the libsystemd-login library." -); - -#define helper(name) \ -static PyObject* name(PyObject *self, PyObject *args) { \ - _cleanup_strv_free_ char **list = NULL; \ - int r; \ - PyObject *ans; \ - \ - assert(args == NULL); \ - \ - r = sd_get_##name(&list); \ - if (r < 0) { \ - errno = -r; \ - return PyErr_SetFromErrno(PyExc_IOError); \ - } \ - \ - ans = PyList_New(r); \ - if (!ans) \ - return NULL; \ - \ - for (r--; r >= 0; r--) { \ - PyObject *s = unicode_FromString(list[r]); \ - if (!s) { \ - Py_DECREF(ans); \ - return NULL; \ - } \ - \ - PyList_SetItem(ans, r, s); \ - } \ - \ - return ans; \ -} - -helper(seats) -helper(sessions) -helper(machine_names) -#undef helper - -static PyObject* uids(PyObject *self, PyObject *args) { - _cleanup_free_ uid_t *list = NULL; - int r; - PyObject *ans; - - assert(args == NULL); - - r = sd_get_uids(&list); - if (r < 0) { - errno = -r; - return PyErr_SetFromErrno(PyExc_IOError); - } - - ans = PyList_New(r); - if (!ans) - return NULL; - - for (r--; r >= 0; r--) { - PyObject *s = long_FromLong(list[r]); - if (!s) { - Py_DECREF(ans); - return NULL; - } - - PyList_SetItem(ans, r, s); - } - - return ans; -} - -PyDoc_STRVAR(seats__doc__, - "seats() -> list\n\n" - "Returns a list of currently available local seats.\n" - "Wraps sd_get_seats(3)." -); - -PyDoc_STRVAR(sessions__doc__, - "sessions() -> list\n\n" - "Returns a list of current login sessions.\n" - "Wraps sd_get_sessions(3)." -); - -PyDoc_STRVAR(machine_names__doc__, - "machine_names() -> list\n\n" - "Returns a list of currently running virtual machines\n" - "and containers on the system.\n" - "Wraps sd_get_machine_names(3)." -); - -PyDoc_STRVAR(uids__doc__, - "uids() -> list\n\n" - "Returns a list of uids of users who currently have login sessions.\n" - "Wraps sd_get_uids(3)." -); - -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__}, - {} /* Sentinel */ -}; - - -typedef struct { - PyObject_HEAD - sd_login_monitor *monitor; -} Monitor; -static PyTypeObject MonitorType; - -static void Monitor_dealloc(Monitor* self) { - sd_login_monitor_unref(self->monitor); - Py_TYPE(self)->tp_free((PyObject*)self); -} - -PyDoc_STRVAR(Monitor__doc__, - "Monitor([category]) -> ...\n\n" - "Monitor may be used to monitor login sessions, users, seats,\n" - "and virtual machines/containers. Monitor provides a file\n" - "descriptor which can be integrated in an external event loop.\n" - "See man:sd_login_monitor_new(3) for the details about what\n" - "can be monitored."); -static int Monitor_init(Monitor *self, PyObject *args, PyObject *keywds) { - const char *category = NULL; - int r; - - static const char* const kwlist[] = {"category", NULL}; - if (!PyArg_ParseTupleAndKeywords(args, keywds, "|z:__init__", (char**) kwlist, - &category)) - return -1; - - Py_BEGIN_ALLOW_THREADS - r = sd_login_monitor_new(category, &self->monitor); - Py_END_ALLOW_THREADS - - return set_error(r, NULL, "Invalid category"); -} - - -PyDoc_STRVAR(Monitor_fileno__doc__, - "fileno() -> int\n\n" - "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) { - int fd = sd_login_monitor_get_fd(self->monitor); - set_error(fd, NULL, NULL); - if (fd < 0) - return NULL; - return long_FromLong(fd); -} - - -PyDoc_STRVAR(Monitor_get_events__doc__, - "get_events() -> int\n\n" - "Returns a mask of poll() events to wait for on the file\n" - "descriptor returned by .fileno().\n\n" - "See man: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); - set_error(r, NULL, NULL); - if (r < 0) - return NULL; - return long_FromLong(r); -} - - -PyDoc_STRVAR(Monitor_get_timeout__doc__, - "get_timeout() -> int or None\n\n" - "Returns a timeout value for usage in poll(), the time since the\n" - "epoch of clock_gettime(2) in microseconds, or None if no timeout\n" - "is necessary.\n\n" - "The return value must be converted to a relative timeout in\n" - "milliseconds if it is to be used as an argument for poll().\n" - "See man:sd_login_monitor_get_timeout(3) for further discussion."); -static PyObject* Monitor_get_timeout(Monitor *self, PyObject *args) { - int r; - uint64_t t; - - r = sd_login_monitor_get_timeout(self->monitor, &t); - set_error(r, NULL, NULL); - if (r < 0) - return NULL; - - if (t == (uint64_t) -1) - Py_RETURN_NONE; - - assert_cc(sizeof(unsigned long long) == sizeof(t)); - return PyLong_FromUnsignedLongLong(t); -} - - -PyDoc_STRVAR(Monitor_get_timeout_ms__doc__, - "get_timeout_ms() -> int\n\n" - "Returns a timeout value suitable for usage in poll(), the value\n" - "returned by .get_timeout() converted to relative ms, or -1 if\n" - "no timeout is necessary."); -static PyObject* Monitor_get_timeout_ms(Monitor *self, PyObject *args) { - int r; - uint64_t t; - - r = sd_login_monitor_get_timeout(self->monitor, &t); - set_error(r, NULL, NULL); - if (r < 0) - return NULL; - - return absolute_timeout(t); -} - - -PyDoc_STRVAR(Monitor_close__doc__, - "close() -> None\n\n" - "Free resources allocated by this Monitor object.\n" - "This method invokes sd_login_monitor_unref().\n" - "See man:sd_login_monitor_unref(3)."); -static PyObject* Monitor_close(Monitor *self, PyObject *args) { - assert(self); - assert(!args); - - sd_login_monitor_unref(self->monitor); - self->monitor = NULL; - Py_RETURN_NONE; -} - - -PyDoc_STRVAR(Monitor_flush__doc__, - "flush() -> None\n\n" - "Reset the wakeup state of the monitor object.\n" - "This method invokes sd_login_monitor_flush().\n" - "See man:sd_login_monitor_flush(3)."); -static PyObject* Monitor_flush(Monitor *self, PyObject *args) { - assert(self); - assert(!args); - - Py_BEGIN_ALLOW_THREADS - sd_login_monitor_flush(self->monitor); - Py_END_ALLOW_THREADS - Py_RETURN_NONE; -} - - -PyDoc_STRVAR(Monitor___enter____doc__, - "__enter__() -> self\n\n" - "Part of the context manager protocol.\n" - "Returns self.\n"); -static PyObject* Monitor___enter__(PyObject *self, PyObject *args) { - assert(self); - assert(!args); - - Py_INCREF(self); - return self; -} - - -PyDoc_STRVAR(Monitor___exit____doc__, - "__exit__(type, value, traceback) -> None\n\n" - "Part of the context manager protocol.\n" - "Closes the monitor..\n"); -static PyObject* Monitor___exit__(Monitor *self, PyObject *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__}, - {} /* Sentinel */ -}; - -static PyTypeObject MonitorType = { - PyVarObject_HEAD_INIT(NULL, 0) - .tp_name = "login.Monitor", - .tp_basicsize = sizeof(Monitor), - .tp_dealloc = (destructor) Monitor_dealloc, - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - .tp_doc = Monitor__doc__, - .tp_methods = Monitor_methods, - .tp_init = (initproc) Monitor_init, - .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 == NULL) - 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 -}; - -DISABLE_WARNING_MISSING_PROTOTYPES; -PyMODINIT_FUNC PyInit_login(void) { - PyObject *m; - - if (PyType_Ready(&MonitorType) < 0) - return NULL; - - m = PyModule_Create(&module); - if (m == NULL) - return NULL; - - if (PyModule_AddStringConstant(m, "__version__", PACKAGE_VERSION)) { - Py_DECREF(m); - return NULL; - } - - Py_INCREF(&MonitorType); - if (PyModule_AddObject(m, "Monitor", (PyObject *) &MonitorType)) { - Py_DECREF(&MonitorType); - Py_DECREF(m); - return NULL; - } - - return m; -} -REENABLE_WARNING; - -#endif diff --git a/src/python-systemd/pyutil.c b/src/python-systemd/pyutil.c deleted file mode 100644 index 722c4f5b5f..0000000000 --- a/src/python-systemd/pyutil.c +++ /dev/null @@ -1,80 +0,0 @@ -/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ - -/*** - This file is part of systemd. - - Copyright 2013 Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. -***/ - -#include <Python.h> -#include "pyutil.h" - -void cleanup_Py_DECREFp(PyObject **p) { - if (!*p) - return; - - Py_DECREF(*p); -} - -PyObject* absolute_timeout(uint64_t t) { - if (t == (uint64_t) -1) - return PyLong_FromLong(-1); - else { - struct timespec ts; - uint64_t n; - int msec; - - clock_gettime(CLOCK_MONOTONIC, &ts); - n = (uint64_t) ts.tv_sec * 1000000 + ts.tv_nsec / 1000; - msec = t > n ? (int) ((t - n + 999) / 1000) : 0; - - return PyLong_FromLong(msec); - } -} - -int set_error(int r, const char* path, const char* invalid_message) { - if (r >= 0) - return r; - if (r == -EINVAL && invalid_message) - PyErr_SetString(PyExc_ValueError, invalid_message); - else if (r == -ENOMEM) - PyErr_SetString(PyExc_MemoryError, "Not enough memory"); - else { - errno = -r; - PyErr_SetFromErrnoWithFilename(PyExc_OSError, path); - } - return -1; -} - -#if PY_MAJOR_VERSION >=3 && PY_MINOR_VERSION >= 1 -int Unicode_FSConverter(PyObject* obj, void *_result) { - PyObject **result = _result; - - assert(result); - - if (!obj) - /* cleanup: we don't return Py_CLEANUP_SUPPORTED, so - * we can assume that it was PyUnicode_FSConverter. */ - return PyUnicode_FSConverter(obj, result); - - if (obj == Py_None) { - *result = NULL; - return 1; - } - - return PyUnicode_FSConverter(obj, result); -} -#endif diff --git a/src/python-systemd/pyutil.h b/src/python-systemd/pyutil.h deleted file mode 100644 index 1477e7bf9c..0000000000 --- a/src/python-systemd/pyutil.h +++ /dev/null @@ -1,54 +0,0 @@ -/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ - -#pragma once - -/*** - This file is part of systemd. - - Copyright 2013 Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. -***/ - -#ifndef Py_TYPE -/* avoid duplication warnings from errors in Python 2.7 headers */ -# include <Python.h> -#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_ __attribute__((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/src/resolve/resolved-dns-packet.c b/src/resolve/resolved-dns-packet.c index bb74b1828e..47cc9751ed 100644 --- a/src/resolve/resolved-dns-packet.c +++ b/src/resolve/resolved-dns-packet.c @@ -691,7 +691,7 @@ int dns_packet_append_rr(DnsPacket *p, const DnsResourceRecord *rr, size_t *star if (r < 0) goto fail; - r = dns_packet_append_uint8(p, rr->rrsig.key_tag, NULL); + r = dns_packet_append_uint16(p, rr->rrsig.key_tag, NULL); if (r < 0) goto fail; diff --git a/src/test/test-pty.c b/src/test/test-pty.c index 3f97a64ccd..fbab3d4ebe 100644 --- a/src/test/test-pty.c +++ b/src/test/test-pty.c @@ -133,7 +133,7 @@ int main(int argc, char *argv[]) { /* Oh, there're ugly races in the TTY layer regarding HUP vs IN. Turns * out they appear only 10% of the time. I fixed all of them and - * don't see them, anymore. But lets be safe and run this 1000 times + * don't see them, anymore. But let's be safe and run this 1000 times * so we catch any new ones, in case they appear again. */ for (i = 0; i < 1000; ++i) test_pty(); |