1 from ._daemon import (__version__,
10 from socket import AF_UNSPEC as _AF_UNSPEC
12 def _convert_fileobj(fileobj):
14 return fileobj.fileno()
15 except AttributeError:
18 def is_fifo(fileobj, path=None):
19 fd = _convert_fileobj(fileobj)
20 return _is_fifo(fd, path)
22 def is_socket(fileobj, family=_AF_UNSPEC, type=0, listening=-1):
23 fd = _convert_fileobj(fileobj)
24 return _is_socket(fd, family, type, listening)
26 def is_socket_inet(fileobj, family=_AF_UNSPEC, type=0, listening=-1, port=0):
27 fd = _convert_fileobj(fileobj)
28 return _is_socket_inet(fd, family, type, listening)
30 def is_socket_unix(fileobj, type=0, listening=-1, path=None):
31 fd = _convert_fileobj(fileobj)
32 return _is_socket_unix(fd, type, listening, path)
34 def is_mq(fileobj, path=None):
35 fd = _convert_fileobj(fileobj)
36 return _is_mq(fd, path)
38 def listen_fds(unset_environment=True):
39 """Return a list of socket activated descriptors
44 $ systemd-activate -l 2000 python3 -c \\
45 'from systemd.daemon import listen_fds; print(listen_fds())'
47 $ telnet localhost 2000
53 num = _listen_fds(unset_environment)
54 return list(range(LISTEN_FDS_START, LISTEN_FDS_START + num))