chiark / gitweb /
resolved: when there's already somebody listening on the LLMNR ports, simple disable...
[elogind.git] / src / python-systemd / daemon.py
1 from ._daemon import (__version__,
2                       booted,
3                       notify,
4                       _listen_fds,
5                       _is_fifo,
6                       _is_socket,
7                       _is_socket_inet,
8                       _is_socket_unix,
9                       _is_mq,
10                       LISTEN_FDS_START)
11 from socket import AF_UNSPEC as _AF_UNSPEC
12
13 def _convert_fileobj(fileobj):
14     try:
15         return fileobj.fileno()
16     except AttributeError:
17         return fileobj
18
19 def is_fifo(fileobj, path=None):
20     fd = _convert_fileobj(fileobj)
21     return _is_fifo(fd, path)
22
23 def is_socket(fileobj, family=_AF_UNSPEC, type=0, listening=-1):
24     fd = _convert_fileobj(fileobj)
25     return _is_socket(fd, family, type, listening)
26
27 def is_socket_inet(fileobj, family=_AF_UNSPEC, type=0, listening=-1, port=0):
28     fd = _convert_fileobj(fileobj)
29     return _is_socket_inet(fd, family, type, listening)
30
31 def is_socket_unix(fileobj, type=0, listening=-1, path=None):
32     fd = _convert_fileobj(fileobj)
33     return _is_socket_unix(fd, type, listening, path)
34
35 def is_mq(fileobj, path=None):
36     fd = _convert_fileobj(fileobj)
37     return _is_mq(fd, path)
38
39 def listen_fds(unset_environment=True):
40     """Return a list of socket activated descriptors
41
42     Example::
43
44       (in primary window)
45       $ systemd-activate -l 2000 python3 -c \\
46           'from systemd.daemon import listen_fds; print(listen_fds())'
47       (in another window)
48       $ telnet localhost 2000
49       (in primary window)
50       ...
51       Execing python3 (...)
52       [3]
53     """
54     num = _listen_fds(unset_environment)
55     return list(range(LISTEN_FDS_START, LISTEN_FDS_START + num))