diff options
Diffstat (limited to 'systemd/daemon.py')
-rw-r--r-- | systemd/daemon.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/systemd/daemon.py b/systemd/daemon.py index 217b595..168e55d 100644 --- a/systemd/daemon.py +++ b/systemd/daemon.py @@ -4,6 +4,7 @@ from ._daemon import (__version__, booted, notify, _listen_fds, + _listen_fds_with_names, _is_fifo, _is_socket, _is_socket_inet, @@ -69,3 +70,24 @@ def listen_fds(unset_environment=True): """ num = _listen_fds(unset_environment) return list(range(LISTEN_FDS_START, LISTEN_FDS_START + num)) + +def listen_fds_with_names(unset_environment=True): + """Return a dictionary of socket activated descriptors as {fd: name} + + Example:: + + (in primary window) + $ systemd-socket-activate -l 2000 -l 4000 --fdname=2K:4K python3 -c \\ + 'from systemd.daemon import listen_fds_with_names; print(listen_fds_with_names())' + (in another window) + $ telnet localhost 2000 + (in primary window) + ... + Execing python3 (...) + [3] + """ + composite = _listen_fds_with_names(unset_environment) + retval = {} + for i in range(0, composite[0]): + retval[i+LISTEN_FDS_START] = composite[1+i] + return retval |